import fs from "node:fs"; import { createSession, exportCheckpoint, readCheckpoint, sessionFromCheckpoint, } from "./queue.mjs"; const cases = JSON.parse(fs.readFileSync(0, "utf8")), results = []; for (const c of cases) { const s = await createSession(c.inventory), trace = []; for (const action of c.actions) { if (action.type === "undo") s.undo(); else s.decide(action.status, action.label, action.id); trace.push({ summary: s.summary(), revision: s.revision, undo_count: s.undoCount, }); } const checkpoint = await exportCheckpoint(s); const restored = sessionFromCheckpoint( await readCheckpoint(new TextEncoder().encode(JSON.stringify(checkpoint))), ); results.push({ trace, checkpoint, restored_payload: restored.payload(), restored_undo_count: restored.undoCount, }); } console.log(JSON.stringify(results));