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

+2 -1
View File
@@ -80,7 +80,8 @@ function resolveTargets(envType, preview) {
if (envType === "admin") return [path.resolve(taroRoot, "../admin/dist")];
if (process.env.MINIAPP_OUTPUT_ROOT)
return [path.resolve(taroRoot, process.env.MINIAPP_OUTPUT_ROOT)];
const templateKey = process.env.TEMPLATE_KEY;
// 单模板构建默认使用餐饮试点;多模板预览必须显式 --preview。
const templateKey = process.env.TEMPLATE_KEY ?? "acheng-campus-food";
if (!templateKey) throw new Error("TEMPLATE_KEY is required for non-preview masking");
return [path.join(taroRoot, "dist", templateKey, envType)];
}
+1 -1
View File
@@ -32,7 +32,7 @@
"@types/react": "18.3.18",
"@types/react-dom": "18.3.5",
"@vitejs/plugin-react": "4.7.0",
"vite": "4.5.14",
"vite": "6.4.3",
"@types/node": "^22.10.0",
"@babel/plugin-proposal-decorators": "^7.25.9",
"@babel/plugin-transform-class-properties": "^7.25.9",
@@ -180,11 +180,25 @@ const runtimeWorkspace = {
trustPresentation: {},
capabilities: [],
plugins: [{ key: "inquiry", status: "enabled", config: {} }],
visualTemplate: {
key: "",
version: "",
name: "",
supportedIndustryTemplates: [],
variants: {},
},
theme: { colors: {} },
};
const templateContent = JSON.parse(
fs.readFileSync("../../packages/template-acheng-campus-food/template.json", "utf8"),
);
runtimeWorkspace.visualTemplate = {
key: templateContent.visualTemplateKey,
version: templateContent.version,
name: templateContent.displayName,
supportedIndustryTemplates: templateContent.supportedIndustryTemplates,
variants: templateContent.visualPresentation.variants,
};
// 根据真实声明生成完整列表数据,让每种内容区域都实际渲染。
const additionalFoodTrust = templateContent.trustContentTypes
@@ -706,6 +720,13 @@ test("林境模板支持首页和主理人区域点选", async ({ page }) => {
const editorialContent = JSON.parse(
fs.readFileSync("../../packages/template-linjing-editorial/template.json", "utf8"),
);
editorialWorkspace.visualTemplate = {
key: editorialContent.visualTemplateKey,
version: editorialContent.version,
name: editorialContent.displayName,
supportedIndustryTemplates: editorialContent.supportedIndustryTemplates,
variants: editorialContent.visualPresentation.variants,
};
await page.route("**/api/**", (route) => {
const url = new URL(route.request().url());
const path = url.pathname.replace(/^\/api/, "");
@@ -58,7 +58,7 @@ const runtimeWorkspace = {
},
visualTemplate: {
key: "acheng-campus-food",
version: "1.0.2",
version: "1.0.3",
name: "阿成校园餐",
},
templateData: {},
@@ -31,8 +31,15 @@ type PreviewVersion = {
contentChecksum: string;
};
type PreviewWorkspace = {
offerings: unknown[];
trustItems: unknown[];
inquiryForms: unknown[];
trustPresentation: Record<string, unknown>;
};
type PreviewBundle = {
preview: Record<string, unknown>;
preview: Record<string, unknown> & { workspace: PreviewWorkspace };
version: PreviewVersion;
};
@@ -158,7 +165,13 @@ test("导入包预览矩阵展示身份、资源和完整媒体槽位", async ({
localStorage.setItem("adminToken", "fixture-token");
localStorage.setItem("adminPlatformTemplateRole", "template_admin");
});
const emptyPreview = structuredClone(preview);
emptyPreview.workspace.offerings = [];
emptyPreview.workspace.trustItems = [];
emptyPreview.workspace.inquiryForms = [];
emptyPreview.workspace.trustPresentation = {};
let attempts = 0;
let serveEmptyPreview = false;
const writes: string[] = [];
await page.route("**/api/**", async (route) => {
const url = new URL(route.request().url());
@@ -170,7 +183,9 @@ test("导入包预览矩阵展示身份、资源和完整媒体槽位", async ({
json:
attempts === 1
? { error: { code: "HTTP_400", message: "预览测试失败,请重试" } }
: preview,
: serveEmptyPreview
? emptyPreview
: preview,
});
}
if (url.pathname.endsWith("/admin/templates"))
@@ -224,6 +239,23 @@ test("导入包预览矩阵展示身份、资源和完整媒体槽位", async ({
),
});
}
// 清空业务记录后重新打开真实包预览,验证空态不是仅在源码中存在。
serveEmptyPreview = true;
await modal.getByRole("button", { name: "关闭" }).click();
await expect(modal).toBeHidden();
await page.getByRole("button", { name: /预览/ }).click();
await expect(modal.locator(".component-template-preview .runtime-state")).toContainText(
/正在整理中/,
);
if (evidenceDirectory) {
await page.screenshot({
path: path.join(
evidenceDirectory,
`empty-${String(sequence).padStart(2, "0")}-${mediaCase.packageKey}-${mediaCase.industry}.png`,
),
});
}
await page.unroute("**/api/**");
});
}