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"], }); });