fix: 支持显式放行遗留字段删除的重发分类

This commit is contained in:
que01 committed 2026-10-21 09:00:05 +08:00
1 parent 3738be884b
commit cb046a4c27
3 files changed
+173 -20

No files matched your search

@@ -17,24 +17,27 @@ function snapshot(overrides = {}) {
};
}
test("detects a contract-only stale publication", () => {
const current = snapshot({
const staleContract = () =>
snapshot({
generatedAt: "2026-10-20T01:00:00.000Z",
visualTemplateDefinition: { supportedIndustryTemplates: ["doors"] },
templatePackageManifest: { supportedIndustryTemplates: ["doors"] },
installation: { templateVersion: "1.0.7" },
});
assert.deepEqual(classifyContractRefresh(snapshot(), current), {
test("detects a contract-only stale publication", () => {
assert.deepEqual(classifyContractRefresh(snapshot(), staleContract()), {
status: "contract-stale",
changedKeys: ["visualTemplateDefinition", "templatePackageManifest", "installation"],
blockingKeys: [],
allowedChanges: [],
});
});
test("ignores generated timestamps when the publication is current", () => {
assert.deepEqual(
classifyContractRefresh(snapshot(), snapshot({ generatedAt: "2026-10-21T00:00:00.000Z" })),
{ status: "current", changedKeys: [], blockingKeys: [] },
{ status: "current", changedKeys: [], blockingKeys: [], allowedChanges: [] },
);
});
@@ -47,5 +50,74 @@ test("blocks automatic publication when draft content has diverged", () => {
status: "content-diverged",
changedKeys: ["installation", "brand"],
blockingKeys: ["brand"],
allowedChanges: [],
});
});
test("treats a missing key and an explicit null as the same value", () => {
const current = snapshot({ brand: { name: "林境门作", miniAppSettings: null } });
assert.equal(classifyContractRefresh(snapshot(), current).status, "current");
});
test("allows an explicitly permitted legacy field removal", () => {
const published = snapshot({
brand: { name: "林境门作", config: { visualTemplateKey: "doors" } },
});
const current = snapshot({ brand: { name: "林境门作", config: {} } });
assert.deepEqual(
classifyContractRefresh(published, current, {
allowedRemovedKeys: ["brand.config.visualTemplateKey"],
}),
{
status: "contract-stale",
changedKeys: ["brand"],
blockingKeys: [],
allowedChanges: ["brand.config.visualTemplateKey"],
},
);
});
test("does not allow an unlisted legacy field removal", () => {
const published = snapshot({
brand: { name: "林境门作", config: { visualTemplateKey: "doors" } },
});
const current = snapshot({ brand: { name: "林境门作", config: {} } });
assert.deepEqual(classifyContractRefresh(published, current), {
status: "content-diverged",
changedKeys: ["brand"],
blockingKeys: ["brand"],
allowedChanges: [],
});
});
test("does not allow a permitted legacy field to change value", () => {
const published = snapshot({
brand: { name: "林境门作", config: { visualTemplateKey: "doors" } },
});
const current = snapshot({ brand: { name: "林境门作", config: { visualTemplateKey: "other" } } });
assert.deepEqual(
classifyContractRefresh(published, current, {
allowedRemovedKeys: ["brand.config.visualTemplateKey"],
}),
{
status: "content-diverged",
changedKeys: ["brand"],
blockingKeys: ["brand"],
allowedChanges: [],
},
);
});
test("blocks when a permitted removal is combined with other content changes", () => {
const published = snapshot({
brand: { name: "林境门作", config: { visualTemplateKey: "doors" } },
});
const current = snapshot({
brand: { name: "林境门作", config: {}, miniAppSettings: { appId: "wx-test" } },
});
const result = classifyContractRefresh(published, current, {
allowedRemovedKeys: ["brand.config.visualTemplateKey"],
});
assert.equal(result.status, "content-diverged");
assert.deepEqual(result.blockingKeys, ["brand"]);
});