import { describe, expect, it } from "vitest"; import { defineToolcraft } from "../schema/define-toolcraft"; import { createToolcraftState } from "./create-template-state"; import { createToolcraftPersistenceSnapshot, parseToolcraftPersistenceSnapshot, } from "../composition/public-persistence"; describe("Toolcraft persisted control values", () => { it("uses the schema default when persisted Color is not a canonical string", () => { const schema = defineToolcraft({ base: { identity: { id: "runtime-test", title: "Toolcraft App" }, canvas: { enabled: true }, panels: { controls: { sections: [ { id: "test-section-1", controls: { fill: { applicability: { mode: "always" as const }, defaultValue: "#112233", target: "appearance.fill", type: "color", }, }, }, ], title: "Controls", }, }, persistence: { storage: "localStorage", }, }, modules: [], }); const snapshot = createToolcraftPersistenceSnapshot( createToolcraftState(schema), schema.persistence, ); const legacySnapshot = { ...snapshot, state: { ...snapshot?.state, values: { ...snapshot?.state.values, "appearance.fill": { hex: "#abc" }, }, }, }; const restored = parseToolcraftPersistenceSnapshot( schema, JSON.stringify(legacySnapshot), ); expect(restored?.values?.["appearance.fill"]).toBe("#112233"); }); });