Open History to see the last commit
1import { presentThreadShell } from "@t3tools/client-runtime/state/shell";
2import {
3 EnvironmentId,
4 ProjectId,
5 ProviderInstanceId,
6 ThreadId,
7 type OrchestrationV2ThreadProjection,
8} from "@t3tools/contracts";
9import * as DateTime from "effect/DateTime";
10
11import type { ChatMessage, Thread } from "./types";
12
13const DEFAULT_TIMESTAMP = "2026-01-01T00:00:00.000Z";
14
15export type ThreadFixtureOverrides = Partial<Thread> & {
16 /** Test-only fallback data for the generic thread-sort contract. */
17 readonly messages?: ReadonlyArray<ChatMessage>;
18 /** Accepted while older unit cases are migrated; never consumed by production code. */
19 readonly proposedPlans?: ReadonlyArray<unknown>;
20};
21
22export function makeThreadProjectionFixture(): OrchestrationV2ThreadProjection {
23 const now = DateTime.makeUnsafe(DEFAULT_TIMESTAMP);
24 const id = ThreadId.make("thread-test");
25 const providerInstanceId = ProviderInstanceId.make("codex");
26 return {
27 thread: {
28 id,
29 projectId: ProjectId.make("project-test"),
30 title: "Thread",
31 providerInstanceId,
32 modelSelection: { instanceId: providerInstanceId, model: "gpt-5.4" },
33 runtimeMode: "full-access",
34 interactionMode: "default",
35 branch: null,
36 worktreePath: null,
37 activeProviderThreadId: null,
38 lineage: { rootThreadId: id, parentThreadId: null, relationshipToParent: null },
39 forkedFrom: null,
40 createdBy: "user",
41 creationSource: "web",
42 createdAt: now,
43 updatedAt: now,
44 archivedAt: null,
45 deletedAt: null,
46 },
47 runs: [],
48 attempts: [],
49 nodes: [],
50 subagents: [],
51 providerSessions: [],
52 providerThreads: [],
53 providerTurns: [],
54 runtimeRequests: [],
55 messages: [],
56 plans: [],
57 turnItems: [],
58 checkpointScopes: [],
59 checkpoints: [],
60 contextHandoffs: [],
61 contextTransfers: [],
62 visibleTurnItems: [],
63 updatedAt: now,
64 };
65}
66
67/** Creates a structurally complete V2 shell for UI unit tests. */
68export function makeThreadFixture(overrides: ThreadFixtureOverrides = {}): Thread {
69 const environmentId = overrides.environmentId ?? EnvironmentId.make("environment-test");
70 const id = overrides.id ?? ThreadId.make("thread-test");
71 const projectId = overrides.projectId ?? ProjectId.make("project-test");
72 const providerInstanceId =
73 overrides.providerInstanceId ??
74 overrides.modelSelection?.instanceId ??
75 ProviderInstanceId.make("codex");
76 const modelSelection = overrides.modelSelection ?? {
77 instanceId: providerInstanceId,
78 model: "gpt-5.4",
79 };
80 const createdAt = DateTime.makeUnsafe(DEFAULT_TIMESTAMP);
81 const updatedAt = DateTime.makeUnsafe(DEFAULT_TIMESTAMP);
82 const archivedAt =
83 overrides.archivedAt === null || overrides.archivedAt === undefined
84 ? null
85 : DateTime.makeUnsafe(overrides.archivedAt);
86 const deletedAt =
87 overrides.deletedAt === null || overrides.deletedAt === undefined
88 ? null
89 : DateTime.makeUnsafe(overrides.deletedAt);
90 const shell = presentThreadShell(environmentId, {
91 id,
92 projectId,
93 title: overrides.title ?? "Thread",
94 providerInstanceId,
95 modelSelection,
96 runtimeMode: overrides.runtimeMode ?? "full-access",
97 interactionMode: overrides.interactionMode ?? "default",
98 branch: overrides.branch ?? null,
99 worktreePath: overrides.worktreePath ?? null,
100 activeProviderThreadId: overrides.activeProviderThreadId ?? null,
101 lineage: overrides.lineage ?? {
102 rootThreadId: id,
103 parentThreadId: null,
104 relationshipToParent: null,
105 },
106 forkedFrom: overrides.forkedFrom ?? null,
107 createdBy: "user",
108 creationSource: "web",
109 latestRunId: overrides.latestRun?.runId ?? null,
110 activeRunId: overrides.runtime?.activeRunId ?? null,
111 status: overrides.runtime?.status ?? "idle",
112 pendingRuntimeRequest: null,
113 latestVisibleMessage: null,
114 latestUserMessageAt:
115 overrides.latestUserMessageAt === null || overrides.latestUserMessageAt === undefined
116 ? null
117 : DateTime.makeUnsafe(overrides.latestUserMessageAt),
118 hasActionableProposedPlan: overrides.hasActionableProposedPlan ?? false,
119 itemCount: overrides.itemCount ?? 0,
120 visibleItemCount: overrides.visibleItemCount ?? 0,
121 createdAt,
122 updatedAt,
123 archivedAt,
124 deletedAt,
125 });
126
127 return { ...shell, ...overrides };
128}