Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions tests/e2e-export-handoff.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,16 @@ test("e2e export: real proxy compresses via real tool call, block persists, bili
`compression result not observed: bodies=${bodies.length} final=${finalText.slice(0, 120)}`,
);

// debounceMs: 0 — the debounced persistence write lands within a tick.
await new Promise((r) => setTimeout(r, 100));

// `bili export` reads the SAME dir with a fresh store — proving the
// on-disk file is self-sufficient, not an artifact of the live session.
const sessions = await listSessions({ dir });
// debounceMs: 0 — the debounced write lands within a tick, BUT a
// transient ENOENT (CI Windows temp sweep) defers the flush into the
// kernel's retry ladder (~1.5s) or the spill. Poll with headroom
// instead of a fixed 100ms sleep.
const deadline = Date.now() + 10_000;
let sessions = await listSessions({ dir });
while ((sessions.length < 1 || (sessions[0]?.blocks ?? 0) < 1) && Date.now() < deadline) {
await new Promise((r) => setTimeout(r, 25));
sessions = await listSessions({ dir });
}
assert.equal(sessions.length, 1, `expected 1 persisted session, got ${sessions.length}: ${sessions.map((s) => s.id).join(",")}`);
assert.ok(sessions[0]!.blocks >= 1, "real compression block did not persist");

Expand Down
22 changes: 20 additions & 2 deletions tests/proxy-persist.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ async function settle(ms = 30): Promise<void> {
await new Promise((r) => setTimeout(r, ms));
}

/** Poll probe() until it returns non-nullish, failing after deadlineMs.
* Used where a write can legitimately land late: acp-kernel retries
* transient ENOENT/ENOTDIR (CI Windows temp sweeps) with backoff, so a
* debounced flush may surface seconds after its 5ms timer — a fixed
* sleep would flake even though the data is safe. */
async function waitFor<T>(probe: () => T | null | undefined, deadlineMs: number, what: string): Promise<T> {
const start = Date.now();
for (;;) {
const v = probe();
if (v != null) return v;
if (Date.now() - start > deadlineMs) throw new Error(`timed out after ${deadlineMs}ms waiting for ${what}`);
await settle(10);
}
}

await withTempStore("writeNow round-trips state + blockContents", async (store, dir) => {
const s = makeSession("sess-1");
s.stats.requests = 42;
Expand Down Expand Up @@ -103,9 +118,12 @@ await withTempStore("scheduleSave debounces and eventually writes", async (store
store.scheduleSave(s);
s.stats.requests = 3;
store.scheduleSave(s);
await settle();
// Poll rather than one fixed settle(): if the flush hits a transient
// ENOENT (temp sweep) the kernel retries with backoff, so the write can
// land well past the 5ms debounce. Deadline covers the retry ladder
// (~1.5s) with headroom.
const loaded = await waitFor(() => store.loadSync("debounce-1"), 5000, "debounced write to land");
assert.equal(readdirSync(dir).length, 1, "exactly one top-level entry (the _unknown subdir) happened");
const loaded = store.loadSync("debounce-1");
assert.equal(loaded!.stats.requests, 3, "latest value persisted");
});

Expand Down
Loading