fix: 收口模板契约与安全门禁

统一模板包 visual 契约并补齐完成证据;修复 release 版本一致性、管理员 token 撤销、CORS 与默认品牌配置;收敛依赖安全风险并完成全量回归验证。
This commit is contained in:
que01 committed 2026-10-18 22:05:31 +08:00
1 parent 456171aa85
commit 4f0b50c7f1
84 files changed
+7367 -5180

No files matched your search

+43
View File
@@ -133,11 +133,24 @@ export type TemplateSampleContent = {
capabilityKey: string;
};
export type TemplateVisualPresentation = {
description: string;
variants: Record<string, string>;
theme: { colors: Record<string, string>; radius: Record<string, string> };
layout?: {
home: string[];
offerings: string[];
detail: string[];
profile: string[];
};
};
export type TemplatePackageManifest = {
packageKey: string;
version: string;
displayName: string;
visualTemplateKey: string;
visualPresentation: TemplateVisualPresentation;
runtimeContract: typeof TEMPLATE_RUNTIME_CONTRACT;
supportedIndustryTemplates: string[];
entrypoints: Record<string, string>;
@@ -179,6 +192,36 @@ export function validateTemplatePackageManifest(value: unknown): string[] {
if (manifest.runtimeContract !== TEMPLATE_RUNTIME_CONTRACT)
errors.push(`runtimeContract must be ${TEMPLATE_RUNTIME_CONTRACT}`);
if (!manifest.displayName?.trim()) errors.push("displayName is required");
const presentation = manifest.visualPresentation;
if (
!presentation ||
typeof presentation !== "object" ||
!presentation.description?.trim() ||
!presentation.variants ||
typeof presentation.variants !== "object" ||
Array.isArray(presentation.variants) ||
!Object.values(presentation.variants).every(
(variant) => typeof variant === "string" && variant.trim(),
) ||
!presentation.theme ||
typeof presentation.theme !== "object" ||
!presentation.theme.colors ||
typeof presentation.theme.colors !== "object" ||
!presentation.theme.radius ||
typeof presentation.theme.radius !== "object"
) {
errors.push("visualPresentation requires description, variants, theme.colors and theme.radius");
} else if (presentation.layout) {
const layout = presentation.layout;
if (
!(["home", "offerings", "detail", "profile"] as const).every(
(page) =>
Array.isArray(layout[page]) && layout[page].every((item) => typeof item === "string"),
)
) {
errors.push("visualPresentation.layout must contain page module arrays");
}
}
if (
!Array.isArray(manifest.supportedIndustryTemplates) ||
!manifest.supportedIndustryTemplates.length
@@ -74,6 +74,23 @@ test("template contract rejects technical or incomplete admin declarations", ()
]);
});
test("template package manifests must declare package-owned visual presentation", () => {
const manifestPath = path.join(packageRoot, "template-acheng-campus-food/template.json");
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
delete manifest.visualPresentation;
assert.deepEqual(validateTemplatePackageManifest(manifest), [
"visualPresentation requires description, variants, theme.colors and theme.radius",
]);
manifest.visualPresentation = {
description: "无效视觉",
variants: { hero: "hero" },
theme: { colors: { background: "#fff" }, radius: { card: "16rpx" } },
layout: { home: ["hero"], offerings: [], detail: [], profile: [] },
};
assert.deepEqual(validateTemplatePackageManifest(manifest), []);
});
test("template admin sections must point to a declared Mini Program page", () => {
const manifestPath = path.join(packageRoot, "template-acheng-campus-food/template.json");
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));