Open History to see the last commit
1import {
2 CommandId,
3 EventId,
4 ProjectId,
5 ThreadId,
6 type OrchestrationEvent,
7} from "@t3tools/contracts";
8import { expect, it } from "@effect/vitest";
9import * as Effect from "effect/Effect";
10
11import { createEmptyReadModel, projectEvent } from "./projector.ts";
12
13function makeEvent(input: {
14 readonly sequence: number;
15 readonly type: OrchestrationEvent["type"];
16 readonly payload: unknown;
17}): OrchestrationEvent {
18 return {
19 sequence: input.sequence,
20 eventId: EventId.make(`event-${input.sequence}`),
21 type: input.type,
22 aggregateKind: "thread",
23 aggregateId: ThreadId.make("thread-1"),
24 occurredAt: "2026-01-01T00:00:00.000Z",
25 commandId: CommandId.make(`command-${input.sequence}`),
26 causationEventId: null,
27 correlationId: null,
28 metadata: {},
29 payload: input.payload as never,
30 } as OrchestrationEvent;
31}
32
33it.effect("projects settled lifecycle events", () =>
34 Effect.gen(function* () {
35 const now = "2026-01-01T00:00:00.000Z";
36 const created = yield* projectEvent(
37 createEmptyReadModel(now),
38 makeEvent({
39 sequence: 1,
40 type: "thread.created",
41 payload: {
42 threadId: ThreadId.make("thread-1"),
43 projectId: ProjectId.make("project-1"),
44 title: "Thread",
45 modelSelection: { provider: "codex", model: "gpt-5.4" },
46 runtimeMode: "full-access",
47 interactionMode: "default",
48 branch: null,
49 worktreePath: null,
50 createdAt: now,
51 updatedAt: now,
52 },
53 }),
54 );
55 const settled = yield* projectEvent(
56 created,
57 makeEvent({
58 sequence: 2,
59 type: "thread.settled",
60 payload: { threadId: ThreadId.make("thread-1"), settledAt: now, updatedAt: now },
61 }),
62 );
63 expect(settled.threads[0]?.settledOverride).toBe("settled");
64 expect(settled.threads[0]?.settledAt).toBe(now);
65
66 const userUnsettled = yield* projectEvent(
67 settled,
68 makeEvent({
69 sequence: 3,
70 type: "thread.unsettled",
71 payload: { threadId: ThreadId.make("thread-1"), reason: "user", updatedAt: now },
72 }),
73 );
74 expect(userUnsettled.threads[0]?.settledOverride).toBe("active");
75 expect(userUnsettled.threads[0]?.settledAt).toBeNull();
76
77 const activityUnsettled = yield* projectEvent(
78 userUnsettled,
79 makeEvent({
80 sequence: 4,
81 type: "thread.unsettled",
82 payload: { threadId: ThreadId.make("thread-1"), reason: "activity", updatedAt: now },
83 }),
84 );
85 expect(activityUnsettled.threads[0]?.settledOverride).toBeNull();
86 expect(activityUnsettled.threads[0]?.settledAt).toBeNull();
87 }),
88);