local-label-queue / action_driver.mjs
WideChaos's picture
Publish Local Label Queue 0.1.0
d806877 verified
Raw History Blame Contribute Delete
899 Bytes
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));