Skip to content

Commit 8e71780

Browse files
committed
test(core): await debounced sessions.json flush in plan-store test
saveToDisk() became setImmediate-debounced in c0b7997, but the I33-1 plan-store test still read sessions.json synchronously right after SessionState.setPlan, racing the deferred flush and failing with ENOENT (observed as the unit (macos) CI failure on #89). Yield one event-loop turn before the assertion so flushToDisk lands the file first. Signed-off-by: thomas-yanga <odie_majere@outlook.com>
1 parent 721ac77 commit 8e71780

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

packages/core/test/deepagent/plan-store.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
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"
33
import { tmpdir } from "node:os"
44
import path from "node:path"
55
import * as PlanStore from "../../src/deepagent/plan-store"
@@ -65,17 +65,20 @@ describe("I33-1 plan-store single authority", () => {
6565
expect(PlanStore.getPlanDoc("s2")?.steps[0].status).toBe("done")
6666
})
6767

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 () => {
6969
SessionState.getOrCreate("s3", "high")
7070
const p = plan("s3", [step("step_1")])
7171
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))
7275
// readable via session-state (delegates to plan-store) AND directly from plan-store (same doc)
7376
expect(SessionState.getPlan("s3")?.goal).toBe("goal s3")
7477
expect(PlanStore.getPlanDoc("s3")?.goal).toBe("goal s3")
7578
// the latch pointer is bound to the plan id (the hot-path value object that STAYS on session state)
7679
expect(SessionState.planLatch("s3")?.plan_id).toBe(p.plan_id)
7780
// 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")
7982
expect(JSON.parse(raw)["s3"].plan).toBeUndefined()
8083
})
8184

0 commit comments

Comments
 (0)