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

orchestration.test.ts

218 lines6.7 KB

1import assert from "node:assert/strict";
2import { it } from "@effect/vitest";
3import { Effect, Schema } from "effect";
4​
5import {
6 DEFAULT_PROVIDER_INTERACTION_MODE,
7 DEFAULT_RUNTIME_MODE,
8 OrchestrationGetTurnDiffInput,
9 OrchestrationSession,
10 ProjectCreateCommand,
11 ThreadTurnStartCommand,
12 ThreadCreatedPayload,
13 ThreadTurnDiff,
14 ThreadTurnStartRequestedPayload,
15} from "./orchestration";
16​
17const decodeTurnDiffInput = Schema.decodeUnknownEffect(OrchestrationGetTurnDiffInput);
18const decodeThreadTurnDiff = Schema.decodeUnknownEffect(ThreadTurnDiff);
19const decodeProjectCreateCommand = Schema.decodeUnknownEffect(ProjectCreateCommand);
20const decodeThreadTurnStartCommand = Schema.decodeUnknownEffect(ThreadTurnStartCommand);
21const decodeThreadTurnStartRequestedPayload = Schema.decodeUnknownEffect(
22 ThreadTurnStartRequestedPayload,
23);
24const decodeOrchestrationSession = Schema.decodeUnknownEffect(OrchestrationSession);
25const decodeThreadCreatedPayload = Schema.decodeUnknownEffect(ThreadCreatedPayload);
26​
27it.effect("parses turn diff input when fromTurnCount <= toTurnCount", () =>
28 Effect.gen(function* () {
29 const parsed = yield* decodeTurnDiffInput({
30 threadId: "thread-1",
31 fromTurnCount: 1,
32 toTurnCount: 2,
33 });
34 assert.strictEqual(parsed.fromTurnCount, 1);
35 assert.strictEqual(parsed.toTurnCount, 2);
36 }),
37);
38​
39it.effect("rejects turn diff input when fromTurnCount > toTurnCount", () =>
40 Effect.gen(function* () {
41 const result = yield* Effect.exit(
42 decodeTurnDiffInput({
43 threadId: "thread-1",
44 fromTurnCount: 3,
45 toTurnCount: 2,
46 }),
47 );
48 assert.strictEqual(result._tag, "Failure");
49 }),
50);
51​
52it.effect("rejects thread turn diff when fromTurnCount > toTurnCount", () =>
53 Effect.gen(function* () {
54 const result = yield* Effect.exit(
55 decodeThreadTurnDiff({
56 threadId: "thread-1",
57 fromTurnCount: 3,
58 toTurnCount: 2,
59 diff: "patch",
60 }),
61 );
62 assert.strictEqual(result._tag, "Failure");
63 }),
64);
65​
66it.effect("trims branded ids and command string fields at decode boundaries", () =>
67 Effect.gen(function* () {
68 const parsed = yield* decodeProjectCreateCommand({
69 type: "project.create",
70 commandId: " cmd-1 ",
71 projectId: " project-1 ",
72 title: " Project Title ",
73 workspaceRoot: " /tmp/workspace ",
74 defaultModel: " gpt-5.2 ",
75 createdAt: "2026-01-01T00:00:00.000Z",
76 });
77 assert.strictEqual(parsed.commandId, "cmd-1");
78 assert.strictEqual(parsed.projectId, "project-1");
79 assert.strictEqual(parsed.title, "Project Title");
80 assert.strictEqual(parsed.workspaceRoot, "/tmp/workspace");
81 assert.strictEqual(parsed.defaultModel, "gpt-5.2");
82 }),
83);
84​
85it.effect("rejects command fields that become empty after trim", () =>
86 Effect.gen(function* () {
87 const result = yield* Effect.exit(
88 decodeProjectCreateCommand({
89 type: "project.create",
90 commandId: "cmd-1",
91 projectId: "project-1",
92 title: " ",
93 workspaceRoot: "/tmp/workspace",
94 createdAt: "2026-01-01T00:00:00.000Z",
95 }),
96 );
97 assert.strictEqual(result._tag, "Failure");
98 }),
99);
100​
101it.effect("decodes thread.turn.start defaults for provider and runtime mode", () =>
102 Effect.gen(function* () {
103 const parsed = yield* decodeThreadTurnStartCommand({
104 type: "thread.turn.start",
105 commandId: "cmd-turn-1",
106 threadId: "thread-1",
107 message: {
108 messageId: "msg-1",
109 role: "user",
110 text: "hello",
111 attachments: [],
112 },
113 createdAt: "2026-01-01T00:00:00.000Z",
114 });
115 assert.strictEqual(parsed.provider, undefined);
116 assert.strictEqual(parsed.runtimeMode, DEFAULT_RUNTIME_MODE);
117 assert.strictEqual(parsed.interactionMode, DEFAULT_PROVIDER_INTERACTION_MODE);
118 }),
119);
120​
121it.effect("preserves explicit provider and runtime mode in thread.turn.start", () =>
122 Effect.gen(function* () {
123 const parsed = yield* decodeThreadTurnStartCommand({
124 type: "thread.turn.start",
125 commandId: "cmd-turn-2",
126 threadId: "thread-1",
127 message: {
128 messageId: "msg-2",
129 role: "user",
130 text: "hello",
131 attachments: [],
132 },
133 provider: "codex",
134 runtimeMode: "full-access",
135 createdAt: "2026-01-01T00:00:00.000Z",
136 });
137 assert.strictEqual(parsed.provider, "codex");
138 assert.strictEqual(parsed.runtimeMode, "full-access");
139 assert.strictEqual(parsed.interactionMode, DEFAULT_PROVIDER_INTERACTION_MODE);
140 }),
141);
142​
143it.effect("decodes thread.created runtime mode for historical events", () =>
144 Effect.gen(function* () {
145 const parsed = yield* decodeThreadCreatedPayload({
146 threadId: "thread-1",
147 projectId: "project-1",
148 title: "Thread title",
149 model: "gpt-5.4",
150 interactionMode: "default",
151 branch: null,
152 worktreePath: null,
153 createdAt: "2026-01-01T00:00:00.000Z",
154 updatedAt: "2026-01-01T00:00:00.000Z",
155 });
156​
157 assert.strictEqual(parsed.runtimeMode, DEFAULT_RUNTIME_MODE);
158 }),
159);
160​
161it.effect("accepts provider-scoped model options in thread.turn.start", () =>
162 Effect.gen(function* () {
163 const parsed = yield* decodeThreadTurnStartCommand({
164 type: "thread.turn.start",
165 commandId: "cmd-turn-options",
166 threadId: "thread-1",
167 message: {
168 messageId: "msg-options",
169 role: "user",
170 text: "hello",
171 attachments: [],
172 },
173 provider: "codex",
174 model: "gpt-5.3-codex",
175 modelOptions: {
176 codex: {
177 reasoningEffort: "high",
178 fastMode: true,
179 },
180 },
181 createdAt: "2026-01-01T00:00:00.000Z",
182 });
183 assert.strictEqual(parsed.provider, "codex");
184 assert.strictEqual(parsed.modelOptions?.codex?.reasoningEffort, "high");
185 assert.strictEqual(parsed.modelOptions?.codex?.fastMode, true);
186 }),
187);
188​
189it.effect(
190 "decodes thread.turn-start-requested defaults for provider, runtime mode, and interaction mode",
191 () =>
192 Effect.gen(function* () {
193 const parsed = yield* decodeThreadTurnStartRequestedPayload({
194 threadId: "thread-1",
195 messageId: "msg-1",
196 createdAt: "2026-01-01T00:00:00.000Z",
197 });
198 assert.strictEqual(parsed.provider, undefined);
199 assert.strictEqual(parsed.runtimeMode, DEFAULT_RUNTIME_MODE);
200 assert.strictEqual(parsed.interactionMode, DEFAULT_PROVIDER_INTERACTION_MODE);
201 }),
202);
203​
204it.effect("decodes orchestration session runtime mode defaults", () =>
205 Effect.gen(function* () {
206 const parsed = yield* decodeOrchestrationSession({
207 threadId: "thread-1",
208 status: "idle",
209 providerName: null,
210 providerSessionId: null,
211 providerThreadId: null,
212 activeTurnId: null,
213 lastError: null,
214 updatedAt: "2026-01-01T00:00:00.000Z",
215 });
216 assert.strictEqual(parsed.runtimeMode, DEFAULT_RUNTIME_MODE);
217 }),
218);