Skip to content

Commit a3d0f82

Browse files
committed
test(e2e): warm past the one-time stable-id cutover in pi cache-stability
The 'materializes queued text drops only on an execute pass' test queued a drop then asserted the next turn stays a defer pass. But a fresh Pi session's first real-id pass performs the one-time v25 stable-id-scheme cutover, which forces execute+materialize regardless of pressure — draining the queued op early and failing the defer-survival assertion. The test predates the cutover. Fix: add a warm-up turn so the cutover completes (scheme → 1) before the drop is queued, and resolve the drop's tag_number from the DB by content (it's no longer guaranteed to be tag 1 with the warm-up ahead of it). Pure test correction; no product change. Full Pi host suite now 38/0.
1 parent 374b395 commit a3d0f82

1 file changed

Lines changed: 41 additions & 4 deletions

File tree

packages/e2e-tests/tests/pi-cache-stability.test.ts

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,16 @@ describe("pi cache stability", () => {
275275
},
276276
async (h) => {
277277
h.mock.script([
278+
// Warm-up turn. A fresh Pi session starts at stable-id
279+
// scheme 0; the FIRST pass that resolves real SessionEntry
280+
// ids performs the one-time v25 cutover, which forces an
281+
// execute+materialize regardless of pressure. We burn that
282+
// here so the defer-survival assertion below isn't drained
283+
// by the cutover instead of by a real execute decision.
284+
{
285+
text: "warm-up: absorb the one-time stable-id cutover",
286+
usage: { input_tokens: 10, output_tokens: 5, cache_creation_input_tokens: 10 },
287+
},
278288
{
279289
text: "low pressure one",
280290
usage: { input_tokens: 10, output_tokens: 5, cache_creation_input_tokens: 10 },
@@ -289,27 +299,54 @@ describe("pi cache stability", () => {
289299
},
290300
]);
291301

302+
// Warm-up turn: lets the stable-id cutover complete (scheme → 1)
303+
// before we queue a drop, so the next turn is a genuine defer.
304+
const warm = await h.sendPrompt("warm-up turn", { timeoutMs: 60_000 });
305+
expect(warm.sessionId).toBeTruthy();
306+
292307
const firstText = "pi queued drop target should survive one defer pass";
293-
const first = await h.sendPrompt(firstText, { timeoutMs: 60_000 });
308+
const first = await h.sendPrompt(firstText, {
309+
timeoutMs: 60_000,
310+
continueSession: true,
311+
});
294312
expect(first.sessionId).toBeTruthy();
295313
await h.waitFor(() => h.countTags(first.sessionId!) > 0, { label: "tag ready" });
296-
queueDrop(h, first.sessionId!, 1);
314+
// Drop the firstText message's tag. Resolve its tag number from
315+
// the DB rather than hardcoding — with the warm-up turn ahead of
316+
// it, firstText is no longer guaranteed to be tag 1.
317+
const dropTag = readDb(h, (db) => {
318+
const row = db
319+
.prepare(
320+
`SELECT t.tag_number AS n FROM tags t
321+
JOIN source_contents sc
322+
ON sc.session_id = t.session_id AND sc.tag_id = t.tag_number
323+
WHERE t.session_id = ? AND t.type = 'message'
324+
AND sc.content LIKE '%queued drop target%'
325+
ORDER BY t.tag_number DESC LIMIT 1`,
326+
)
327+
.get(first.sessionId!) as { n: number } | undefined;
328+
return row?.n;
329+
});
330+
expect(dropTag).toBeGreaterThan(0);
331+
queueDrop(h, first.sessionId!, dropTag!);
297332

298333
await h.sendPrompt("second turn stays defer and must not drain pending_ops", {
299334
timeoutMs: 60_000,
300335
continueSession: true,
301336
});
302337
expect(h.countPendingOps(first.sessionId!)).toBe(1);
303338
expect(JSON.stringify(h.mock.lastRequest()!.body)).toContain(firstText);
304-
expect(JSON.stringify(h.mock.lastRequest()!.body)).not.toContain("truncated §1§");
339+
expect(JSON.stringify(h.mock.lastRequest()!.body)).not.toContain(
340+
`truncated §${dropTag}§`,
341+
);
305342

306343
await h.sendPrompt("third turn sees prior high usage and executes drops", {
307344
timeoutMs: 60_000,
308345
continueSession: true,
309346
});
310347
expect(h.countPendingOps(first.sessionId!)).toBe(0);
311348
expect(h.countDroppedTags(first.sessionId!)).toBeGreaterThanOrEqual(1);
312-
expect(JSON.stringify(h.mock.lastRequest()!.body)).toContain("truncated §1§");
349+
expect(JSON.stringify(h.mock.lastRequest()!.body)).toContain(`truncated §${dropTag}§`);
313350
},
314351
);
315352
}, 180_000);

0 commit comments

Comments
 (0)