Skip to content

Commit 56e2a88

Browse files
luke2xclaude
andcommitted
test(history): expect long turns to page by size
ThreadFind still required every page to start at a user message, the whole-turn rule this PR removes. It now checks that each page fits the byte budget (or holds one oversized item) and that every message is paged exactly once. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 7f822da commit 56e2a88

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

‎apps/server/src/orchestration-v2/ThreadFind.test.ts‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ import * as SqlitePersistence from "../persistence/Sqlite.ts";
2424
import * as ProjectionStore from "./ProjectionStore.ts";
2525
import * as ProjectStore from "./ProjectStore.ts";
2626
import * as EventStore from "./EventStore.ts";
27-
import { encodeThreadHistoryCursor, selectHistoryPageFromCursor } from "./threadHistoryPaging.ts";
27+
import {
28+
encodeThreadHistoryCursor,
29+
selectHistoryPageFromCursor,
30+
THREAD_HISTORY_PAGE_POLICY,
31+
} from "./threadHistoryPaging.ts";
2832
import { projectTurnItemForWire } from "./WireProjection.ts";
2933

3034
const layerTest = Layer.mergeAll(EventStore.layer, ProjectionStore.layer, ProjectStore.layer).pipe(
@@ -722,7 +726,7 @@ describe("V2 history materialization", () => {
722726
}).pipe(Effect.provide(layerTest)),
723727
);
724728

725-
it.effect("pages complete turns without duplicating or skipping messages", () =>
729+
it.effect("pages long turns without duplicating or skipping messages", () =>
726730
Effect.gen(function* () {
727731
const projection = yield* setup;
728732
const items = Array.from({ length: 45 }, (_, turn) => [
@@ -763,7 +767,12 @@ describe("V2 history materialization", () => {
763767
snapshotSequence: snapshot.snapshotSequence,
764768
}),
765769
});
766-
assert.equal(page.items[0]?.item.type, "user_message");
770+
// A turn larger than the byte budget is split, but only a lone oversized item may exceed it.
771+
assert.isTrue(
772+
page.items.length === 1 ||
773+
Buffer.byteLength(JSON.stringify(page.items), "utf8") <=
774+
THREAD_HISTORY_PAGE_POLICY.maxEncodedBytes,
775+
);
767776
collected.unshift(...page.items.map((row) => String(row.sourceItemId)));
768777
cursor = page.nextCursor;
769778
}

0 commit comments

Comments
 (0)