Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

shellReducer.test.ts

84 lines2.6 KB

1import { ProjectId, ThreadId } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3​
4import { v2Project, v2ShellSnapshot, v2ThreadShell } from "./orchestrationV2TestFixtures.ts";
5import { applyShellStreamEvent } from "./shellReducer.ts";
6​
7describe("applyShellStreamEvent", () => {
8 it("ignores stale project updates without mutating the snapshot", () => {
9 const snapshotWithProject = {
10 ...v2ShellSnapshot,
11 snapshotSequence: 4,
12 projects: [v2Project],
13 };
14​
15 for (const sequence of [3, 4]) {
16 const next = applyShellStreamEvent(snapshotWithProject, {
17 kind: "project.updated",
18 sequence,
19 project: { ...v2Project, title: "Stale Title" },
20 });
21​
22 expect(next).toBe(snapshotWithProject);
23 expect(next.snapshotSequence).toBe(4);
24 expect(next.projects[0]?.title).toBe(v2Project.title);
25 }
26 });
27​
28 it("applies project updates and removals", () => {
29 const updated = applyShellStreamEvent(v2ShellSnapshot, {
30 kind: "project.updated",
31 sequence: 1,
32 project: { ...v2Project, title: "Updated" },
33 });
34 expect(updated.projects[0]?.title).toBe("Updated");
35 expect(updated.snapshotSequence).toBe(1);
36​
37 const removed = applyShellStreamEvent(updated, {
38 kind: "project.removed",
39 sequence: 2,
40 projectId: ProjectId.make(v2Project.id),
41 });
42 expect(removed.projects).toEqual([]);
43 });
44​
45 it("moves a thread between active and archive without duplicating it", () => {
46 const archived = applyShellStreamEvent(v2ShellSnapshot, {
47 kind: "thread.updated",
48 sequence: 3,
49 location: "archive",
50 thread: { ...v2ThreadShell, archivedAt: v2ThreadShell.updatedAt },
51 });
52 expect(archived.threads).toEqual([]);
53 expect(archived.archivedThreads).toHaveLength(1);
54​
55 const active = applyShellStreamEvent(archived, {
56 kind: "thread.updated",
57 sequence: 4,
58 location: "active",
59 thread: v2ThreadShell,
60 });
61 expect(active.threads).toHaveLength(1);
62 expect(active.archivedThreads).toEqual([]);
63 });
64​
65 it("removes a thread from either collection", () => {
66 const next = applyShellStreamEvent(v2ShellSnapshot, {
67 kind: "thread.removed",
68 sequence: 5,
69 location: "active",
70 threadId: ThreadId.make(v2ThreadShell.id),
71 });
72 expect(next.threads).toEqual([]);
73 expect(next.snapshotSequence).toBe(5);
74 });
75​
76 it("leaves unknown future events unchanged", () => {
77 const next = applyShellStreamEvent(v2ShellSnapshot, {
78 kind: "future.event",
79 sequence: 99,
80 } as never);
81​
82 expect(next).toBe(v2ShellSnapshot);
83 });
84});