History

feat(orchestration): bound thread history and resume payloads

- Add paginated thread history with bounded snapshots and replay limits - Trim oversized wire payloads and support progressive mobile history loading

Julius Marminge committed 3 months ago

Commit 7d42d311 parent e3883a943 files · +4239 −211Browse files

Showing the changes to apps/server/src/orchestration-v2/ShellStream.test.ts (1 of 43 files). Show all

Unified · Split

apps/server/src/orchestration-v2/ShellStream.test.ts+45−0
@@ -5,6 +5,7 @@ import type { · 4 unmodified lines
55 OrchestrationV2StoredEvent,
66 OrchestrationV2ThreadShell,
77 } from "@t3tools/contracts";
8+import { ThreadId } from "@t3tools/contracts";
89 import * as Effect from "effect/Effect";
910 import * as Stream from "effect/Stream";
1011
@@ -16,6 +17,7 @@ import { · 5 unmodified lines
1617 shellStreamItemFromEnrichmentRefresh,
1718 shellStreamItemFromThreadShell,
1819 shellStreamItemsFromInitialSnapshot,
20+ shellStreamItemsFromResumeSnapshot,
1921 } from "./ShellStream.ts";
2022
2123 function project(sequence: number, id: string): ApplicationStoredEvent {
@@ -198,6 +200,35 @@ describe("shellStreamItemFromEnrichmentRefresh", () => { · 176 unmodified lines
198200 });
199201
200202 describe("shellStreamItemsFromInitialSnapshot", () => {
203+ it("keeps thread rows out of the metadata-only enrichment frame", () => {
204+ const snapshot = {
205+ ...emptyShellSnapshot,
206+ projects: [
207+ { id: "project-a", workspaceRoot: "/workspace/a" },
208+ { id: "project-b", workspaceRoot: "/workspace/b" },
209+ ],
210+ threads: [shellFixture({})],
211+ archivedThreads: [shellFixture({ id: ThreadId.make("thread-archived"), archivedAt: null })],
212+ } as unknown as OrchestrationV2ShellSnapshot;
213+
214+ const items = shellStreamItemsFromInitialSnapshot({
215+ snapshot,
216+ resolvedRepositoryIdentityRoots: ["/workspace/a"],
217+ });
218+
219+ expect(items[0]).toEqual({ kind: "snapshot", snapshot });
220+ expect(items[1]).toMatchObject({
221+ kind: "snapshot",
222+ snapshot: {
223+ projects: [{ id: "project-a", workspaceRoot: "/workspace/a" }],
224+ threads: [],
225+ archivedThreads: [],
226+ },
227+ resolvedRepositoryIdentityRoots: ["/workspace/a"],
228+ });
229+ expect(JSON.stringify(items[1]).length).toBeLessThan(JSON.stringify(items[0]).length);
230+ });
231+
201232 it("emits unmarked authoritative then same-sequence marked enrichment when roots resolved", () => {
202233 const snapshot = {
203234 ...emptyShellSnapshot,
@@ -229,6 +260,20 @@ describe("shellStreamItemsFromInitialSnapshot", () => { · 25 unmodified lines
229260 });
230261 });
231262
263+describe("shellStreamItemsFromResumeSnapshot", () => {
264+ it("never repeats the authoritative shell snapshot", () => {
265+ expect(
266+ shellStreamItemsFromResumeSnapshot({
267+ snapshot: {
268+ ...emptyShellSnapshot,
269+ threads: [shellFixture({})],
270+ },
271+ resolvedRepositoryIdentityRoots: [],
272+ }),
273+ ).toEqual([]);
274+ });
275+});
276+
232277 describe("composeShellStreamWithEnrichment", () => {
233278 it.effect(
234279 "emits every initial item before enrichment even when enrichment is already ready",