Spaces:
Running
Running
File size: 899 Bytes
d806877 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | 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));
|