|
1 | 1 | import { describe, expect, test, beforeEach, afterEach } from "bun:test" |
2 | | -import { mkdtempSync, writeFileSync, mkdirSync, rmSync } from "node:fs" |
| 2 | +import { mkdtempSync, readFileSync, writeFileSync, mkdirSync, rmSync } from "node:fs" |
3 | 3 | import { tmpdir } from "node:os" |
4 | 4 | import path from "node:path" |
5 | 5 | import * as PlanStore from "../../src/deepagent/plan-store" |
@@ -65,17 +65,20 @@ describe("I33-1 plan-store single authority", () => { |
65 | 65 | expect(PlanStore.getPlanDoc("s2")?.steps[0].status).toBe("done") |
66 | 66 | }) |
67 | 67 |
|
68 | | - test("session-state.setPlan/getPlan delegate to the store (body NOT on session state)", () => { |
| 68 | + test("session-state.setPlan/getPlan delegate to the store (body NOT on session state)", async () => { |
69 | 69 | SessionState.getOrCreate("s3", "high") |
70 | 70 | const p = plan("s3", [step("step_1")]) |
71 | 71 | SessionState.setPlan("s3", p) |
| 72 | + // saveToDisk() is debounced via setImmediate (PERF, c0b79979): yield one event-loop turn so |
| 73 | + // flushToDisk lands sessions.json before the synchronous read below. |
| 74 | + await new Promise((resolve) => setImmediate(resolve)) |
72 | 75 | // readable via session-state (delegates to plan-store) AND directly from plan-store (same doc) |
73 | 76 | expect(SessionState.getPlan("s3")?.goal).toBe("goal s3") |
74 | 77 | expect(PlanStore.getPlanDoc("s3")?.goal).toBe("goal s3") |
75 | 78 | // the latch pointer is bound to the plan id (the hot-path value object that STAYS on session state) |
76 | 79 | expect(SessionState.planLatch("s3")?.plan_id).toBe(p.plan_id) |
77 | 80 | // the persisted sessions.json must NOT carry the plan body (authority moved to the store) |
78 | | - const raw = require("node:fs").readFileSync(path.join(stateDir, "sessions.json"), "utf8") |
| 81 | + const raw = readFileSync(path.join(stateDir, "sessions.json"), "utf8") |
79 | 82 | expect(JSON.parse(raw)["s3"].plan).toBeUndefined() |
80 | 83 | }) |
81 | 84 |
|
|
0 commit comments