"use strict"; const test = require("node:test"); const assert = require("node:assert/strict"); const os = require("node:os"); const path = require("node:path"); const fs = require("node:fs/promises"); const { JsonFileStateStore, InMemoryStateStore } = require("../src/lib/state-store"); test("load returns null when state file does not exist", async () => { const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "xartaudio-state-test-")); const store = new JsonFileStateStore(path.join(tempDir, "missing.json")); const data = await store.load(); assert.equal(data, null); }); test("save and load roundtrip state", async () => { const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "xartaudio-state-test-")); const filePath = path.join(tempDir, "state.json"); const store = new JsonFileStateStore(filePath); const expected = { version: 1, engine: { jobs: { "1": { id: "1", status: "completed" } }, nextJobId: 2, }, }; await store.save(expected); const actual = await store.load(); assert.deepEqual(actual, expected); }); test("in memory state store roundtrips without filesystem", async () => { const store = new InMemoryStateStore(); assert.equal(await store.load(), null); await store.save({ engine: { jobs: {} } }); const loaded = await store.load(); assert.deepEqual(loaded, { engine: { jobs: {} } }); });