Open History to see the last commit
1import {
2 EnvironmentId,
3 MessageId,
4 NodeId,
5 RunId,
6 RuntimeRequestId,
7 TurnItemId,
8} from "@t3tools/contracts";
9import * as DateTime from "effect/DateTime";
10import { describe, expect, it } from "vite-plus/test";
11
12import { presentThreadShell } from "./models.ts";
13import { deriveLatestThreadRun, deriveThreadRuntime } from "./threadExecution.ts";
14import { derivePendingThreadRequests } from "./threadRequests.ts";
15import { v2Projection, v2ThreadShell } from "./orchestrationV2TestFixtures.ts";
16
17const environmentId = EnvironmentId.make("environment-v2");
18
19describe("V2 client presentation", () => {
20 it("presents shell timestamps and status without constructing V1 state", () => {
21 const shell = presentThreadShell(environmentId, v2ThreadShell);
22 expect(shell.environmentId).toBe(environmentId);
23 expect(shell.createdAt).toBe("2026-06-20T00:00:00.000Z");
24 expect(shell.runtime).toBeNull();
25 expect(shell.source).toBe(v2ThreadShell);
26 });
27
28 it("derives execution summaries without wrapping or copying the projection", () => {
29 const runId = RunId.make("run-1");
30 const now = DateTime.makeUnsafe("2026-06-20T01:00:00.000Z");
31 const projection = {
32 ...v2Projection,
33 runs: [
34 {
35 id: runId,
36 threadId: v2Projection.thread.id,
37 ordinal: 1,
38 providerInstanceId: v2Projection.thread.providerInstanceId,
39 modelSelection: v2Projection.thread.modelSelection,
40 providerThreadId: null,
41 userMessageId: MessageId.make("message-user"),
42 rootNodeId: null,
43 activeAttemptId: null,
44 status: "running" as const,
45 requestedAt: now,
46 startedAt: now,
47 completedAt: null,
48 checkpointId: null,
49 contextHandoffId: null,
50 },
51 ],
52 messages: [
53 {
54 id: MessageId.make("message-user"),
55 threadId: v2Projection.thread.id,
56 runId,
57 nodeId: null,
58 role: "user" as const,
59 text: "Hello",
60 attachments: [],
61 streaming: false,
62 createdBy: "user" as const,
63 creationSource: "web" as const,
64 createdAt: now,
65 updatedAt: now,
66 },
67 ],
68 updatedAt: now,
69 };
70
71 expect(deriveLatestThreadRun(projection)).toMatchObject({
72 runId,
73 status: "running",
74 requestedAt: "2026-06-20T01:00:00.000Z",
75 assistantMessageId: null,
76 });
77 expect(deriveThreadRuntime(projection)).toMatchObject({
78 status: "running",
79 activeRunId: runId,
80 providerInstanceId: projection.thread.providerInstanceId,
81 });
82 });
83
84 it("joins pending request entities to their native turn-item display data", () => {
85 const now = DateTime.makeUnsafe("2026-06-20T01:00:00.000Z");
86 const requestId = RuntimeRequestId.make("request-approval");
87 const item = {
88 id: TurnItemId.make("item-approval"),
89 threadId: v2Projection.thread.id,
90 runId: null,
91 nodeId: NodeId.make("node-root"),
92 providerThreadId: null,
93 providerTurnId: null,
94 nativeItemRef: null,
95 parentItemId: null,
96 ordinal: 0,
97 status: "completed" as const,
98 title: null,
99 startedAt: now,
100 completedAt: now,
101 updatedAt: now,
102 type: "approval_request" as const,
103 requestId,
104 requestKind: "command" as const,
105 prompt: "Allow command?",
106 };
107 const projection = {
108 ...v2Projection,
109 runtimeRequests: [
110 {
111 id: requestId,
112 nodeId: NodeId.make("node-root"),
113 providerTurnId: null,
114 nativeRequestRef: null,
115 kind: "command" as const,
116 status: "pending" as const,
117 responseCapability: {
118 type: "not_resumable" as const,
119 reason: "provider disconnected",
120 },
121 createdAt: now,
122 resolvedAt: null,
123 },
124 ],
125 turnItems: [item],
126 updatedAt: now,
127 };
128
129 expect(derivePendingThreadRequests(projection).approvals).toEqual([
130 {
131 requestId,
132 requestKind: "command",
133 createdAt: "2026-06-20T01:00:00.000Z",
134 detail: "Allow command?",
135 responseCapability: "not_resumable",
136 },
137 ]);
138 expect(derivePendingThreadRequests(projection).userInputs).toEqual([]);
139 });
140});