fix: 增加模板契约发布快照重发工具
This commit is contained in:
1 parent
ea81c754ed
commit
193858c727
2 files changed
+165
No files matched your search
@@ -0,0 +1,51 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { classifyContractRefresh } from "./republish-stale-template-contracts.mjs";
|
||||
|
||||
function snapshot(overrides = {}) {
|
||||
return {
|
||||
generatedAt: "2026-10-20T00:00:00.000Z",
|
||||
templateKey: "doors",
|
||||
templateDefinition: { key: "doors" },
|
||||
visualTemplateDefinition: { supportedIndustryTemplates: ["personal", "doors"] },
|
||||
visualTemplateManifest: { pages: [] },
|
||||
templatePackageManifest: { supportedIndustryTemplates: ["personal", "doors"] },
|
||||
installation: { templateVersion: "1.0.6" },
|
||||
brand: { name: "林境门作" },
|
||||
offerings: [{ name: "入户门" }],
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
test("detects a contract-only stale publication", () => {
|
||||
const current = snapshot({
|
||||
generatedAt: "2026-10-20T01:00:00.000Z",
|
||||
visualTemplateDefinition: { supportedIndustryTemplates: ["doors"] },
|
||||
templatePackageManifest: { supportedIndustryTemplates: ["doors"] },
|
||||
installation: { templateVersion: "1.0.7" },
|
||||
});
|
||||
assert.deepEqual(classifyContractRefresh(snapshot(), current), {
|
||||
status: "contract-stale",
|
||||
changedKeys: ["visualTemplateDefinition", "templatePackageManifest", "installation"],
|
||||
blockingKeys: [],
|
||||
});
|
||||
});
|
||||
|
||||
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: [] },
|
||||
);
|
||||
});
|
||||
|
||||
test("blocks automatic publication when draft content has diverged", () => {
|
||||
const current = snapshot({
|
||||
installation: { templateVersion: "1.0.7" },
|
||||
brand: { name: "尚未发布的品牌名" },
|
||||
});
|
||||
assert.deepEqual(classifyContractRefresh(snapshot(), current), {
|
||||
status: "content-diverged",
|
||||
changedKeys: ["installation", "brand"],
|
||||
blockingKeys: ["brand"],
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user