Open History to see the last commit
1import { assert, it } from "@effect/vitest";
2import * as Effect from "effect/Effect";
3import * as Exit from "effect/Exit";
4import * as Schema from "effect/Schema";
5import { CommandId, ProjectId, ThreadId } from "./baseSchemas.ts";
6
7import {
8 DEFAULT_PROVIDER_INTERACTION_MODE,
9 DEFAULT_RUNTIME_MODE,
10 type ChatImageAttachment,
11 ClientOrchestrationCommand,
12 ModelSelection,
13 OrchestrationCommand,
14 OrchestrationDispatchCommandError,
15 OrchestrationEvent,
16 OrchestrationGetFullThreadDiffInput,
17 OrchestrationGetTurnDiffInput,
18 OrchestrationLatestTurn,
19 ProjectCreatedPayload,
20 ProjectMetaUpdatedPayload,
21 OrchestrationProposedPlan,
22 OrchestrationSession,
23 OrchestrationThread,
24 OrchestrationThreadShell,
25 ProjectCreateCommand,
26 OrchestrationMessage,
27 ThreadMessageSentPayload,
28 ThreadMetaUpdatedPayload,
29 ThreadTurnStartCommand,
30 ThreadCreatedPayload,
31 ThreadTurnDiff,
32 ThreadTurnStartRequestedPayload,
33 SnapShotAccessibility,
34 isProviderSendTurnSupportedImageMimeType,
35 PROVIDER_SEND_TURN_MAX_FILE_BYTES,
36} from "./orchestration.ts";
37import { ProviderInstanceId } from "./providerInstance.ts";
38
39const decodeTurnDiffInput = Schema.decodeUnknownEffect(OrchestrationGetTurnDiffInput);
40const decodeFullThreadDiffInput = Schema.decodeUnknownEffect(OrchestrationGetFullThreadDiffInput);
41const decodeThreadTurnDiff = Schema.decodeUnknownEffect(ThreadTurnDiff);
42const decodeProjectCreateCommand = Schema.decodeUnknownEffect(ProjectCreateCommand);
43const decodeProjectCreatedPayload = Schema.decodeUnknownEffect(ProjectCreatedPayload);
44const decodeProjectMetaUpdatedPayload = Schema.decodeUnknownEffect(ProjectMetaUpdatedPayload);
45const decodeThreadTurnStartCommand = Schema.decodeUnknownEffect(ThreadTurnStartCommand);
46const decodeClientOrchestrationCommand = Schema.decodeUnknownEffect(ClientOrchestrationCommand);
47const decodeOrchestrationMessage = Schema.decodeUnknownEffect(OrchestrationMessage);
48const decodeThreadMessageSentPayload = Schema.decodeUnknownEffect(ThreadMessageSentPayload);
49const decodeThreadTurnStartRequestedPayload = Schema.decodeUnknownEffect(
50 ThreadTurnStartRequestedPayload,
51);
52const decodeOrchestrationLatestTurn = Schema.decodeUnknownEffect(OrchestrationLatestTurn);
53const decodeOrchestrationProposedPlan = Schema.decodeUnknownEffect(OrchestrationProposedPlan);
54const decodeOrchestrationSession = Schema.decodeUnknownEffect(OrchestrationSession);
55const decodeOrchestrationThread = Schema.decodeUnknownEffect(OrchestrationThread);
56const decodeOrchestrationThreadShell = Schema.decodeUnknownEffect(OrchestrationThreadShell);
57const encodeThreadCreatedPayload = Schema.encodeEffect(ThreadCreatedPayload);
58
59function getOptionValue(
60 options: ReadonlyArray<{ id: string; value: unknown }> | undefined,
61 id: string,
62): unknown {
63 return options?.find((option) => option.id === id)?.value;
64}
65const decodeThreadCreatedPayload = Schema.decodeUnknownEffect(ThreadCreatedPayload);
66const decodeOrchestrationCommand = Schema.decodeUnknownEffect(OrchestrationCommand);
67const decodeOrchestrationEvent = Schema.decodeUnknownEffect(OrchestrationEvent);
68const decodeThreadMetaUpdatedPayload = Schema.decodeUnknownEffect(ThreadMetaUpdatedPayload);
69const decodeDispatchCommandError = Schema.decodeUnknownEffect(OrchestrationDispatchCommandError);
70const decodeSnapShotAccessibility = Schema.decodeUnknownEffect(SnapShotAccessibility);
71
72it.effect("decodes a dispatch error after its bootstrap thread was deleted", () =>
73 Effect.gen(function* () {
74 const error = yield* decodeDispatchCommandError({
75 _tag: "OrchestrationDispatchCommandError",
76 message: "Failed to create worktree.",
77 bootstrapThreadDisposition: "deleted",
78 });
79
80 assert.strictEqual(error.bootstrapThreadDisposition, "deleted");
81 }),
82);
83
84it.effect("parses turn diff input when fromTurnCount <= toTurnCount", () =>
85 Effect.gen(function* () {
86 const parsed = yield* decodeTurnDiffInput({
87 threadId: "thread-1",
88 fromTurnCount: 1,
89 toTurnCount: 2,
90 });
91 assert.strictEqual(parsed.fromTurnCount, 1);
92 assert.strictEqual(parsed.toTurnCount, 2);
93 }),
94);
95
96it.effect("parses turn diff input with whitespace ignoring enabled", () =>
97 Effect.gen(function* () {
98 const parsed = yield* decodeTurnDiffInput({
99 threadId: "thread-1",
100 fromTurnCount: 1,
101 toTurnCount: 2,
102 ignoreWhitespace: true,
103 });
104 assert.strictEqual(parsed.ignoreWhitespace, true);
105 }),
106);
107
108it.effect("parses full thread diff input with whitespace ignoring enabled", () =>
109 Effect.gen(function* () {
110 const parsed = yield* decodeFullThreadDiffInput({
111 threadId: "thread-1",
112 toTurnCount: 2,
113 ignoreWhitespace: true,
114 });
115 assert.strictEqual(parsed.ignoreWhitespace, true);
116 }),
117);
118
119it.effect("rejects turn diff input when fromTurnCount > toTurnCount", () =>
120 Effect.gen(function* () {
121 const result = yield* Effect.exit(
122 decodeTurnDiffInput({
123 threadId: "thread-1",
124 fromTurnCount: 3,
125 toTurnCount: 2,
126 }),
127 );
128 assert.strictEqual(result._tag, "Failure");
129 }),
130);
131
132it.effect("rejects thread turn diff when fromTurnCount > toTurnCount", () =>
133 Effect.gen(function* () {
134 const result = yield* Effect.exit(
135 decodeThreadTurnDiff({
136 threadId: "thread-1",
137 fromTurnCount: 3,
138 toTurnCount: 2,
139 diff: "patch",
140 }),
141 );
142 assert.strictEqual(result._tag, "Failure");
143 }),
144);
145
146it.effect("trims branded ids and command string fields at decode boundaries", () =>
147 Effect.gen(function* () {
148 const parsed = yield* decodeProjectCreateCommand({
149 type: "project.create",
150 commandId: " cmd-1 ",
151 projectId: " project-1 ",
152 title: " Project Title ",
153 workspaceRoot: " /tmp/workspace ",
154 defaultModelSelection: {
155 provider: "codex",
156 model: " gpt-5.2 ",
157 },
158 createdAt: "2026-01-01T00:00:00.000Z",
159 });
160 assert.strictEqual(parsed.commandId, "cmd-1");
161 assert.strictEqual(parsed.projectId, "project-1");
162 assert.strictEqual(parsed.title, "Project Title");
163 assert.strictEqual(parsed.workspaceRoot, "/tmp/workspace");
164 assert.strictEqual(parsed.createWorkspaceRootIfMissing, undefined);
165 assert.deepStrictEqual(parsed.defaultModelSelection, {
166 instanceId: ProviderInstanceId.make("codex"),
167 model: "gpt-5.2",
168 });
169 }),
170);
171
172it.effect("decodes project.create with createWorkspaceRootIfMissing enabled", () =>
173 Effect.gen(function* () {
174 const parsed = yield* decodeProjectCreateCommand({
175 type: "project.create",
176 commandId: "cmd-1",
177 projectId: "project-1",
178 title: "Project Title",
179 workspaceRoot: "/tmp/workspace",
180 createWorkspaceRootIfMissing: true,
181 createdAt: "2026-01-01T00:00:00.000Z",
182 });
183
184 assert.strictEqual(parsed.createWorkspaceRootIfMissing, true);
185 }),
186);
187
188it.effect("decodes historical project.created payloads with a default provider", () =>
189 Effect.gen(function* () {
190 const parsed = yield* decodeProjectCreatedPayload({
191 projectId: "project-1",
192 title: "Project Title",
193 workspaceRoot: "/tmp/workspace",
194 defaultModelSelection: {
195 provider: "codex",
196 model: "gpt-5.4",
197 },
198 scripts: [],
199 createdAt: "2026-01-01T00:00:00.000Z",
200 updatedAt: "2026-01-01T00:00:00.000Z",
201 });
202 assert.strictEqual(parsed.defaultModelSelection?.instanceId, "codex");
203 }),
204);
205
206it.effect("decodes project.meta-updated payloads with explicit default provider", () =>
207 Effect.gen(function* () {
208 const parsed = yield* decodeProjectMetaUpdatedPayload({
209 projectId: "project-1",
210 defaultModelSelection: {
211 provider: "claudeAgent",
212 model: "claude-opus-4-6",
213 },
214 updatedAt: "2026-01-01T00:00:00.000Z",
215 });
216 assert.strictEqual(parsed.defaultModelSelection?.instanceId, "claudeAgent");
217 }),
218);
219
220it.effect("rejects command fields that become empty after trim", () =>
221 Effect.gen(function* () {
222 const result = yield* Effect.exit(
223 decodeProjectCreateCommand({
224 type: "project.create",
225 commandId: "cmd-1",
226 projectId: "project-1",
227 title: " ",
228 workspaceRoot: "/tmp/workspace",
229 createdAt: "2026-01-01T00:00:00.000Z",
230 }),
231 );
232 assert.strictEqual(result._tag, "Failure");
233 }),
234);
235
236it.effect("decodes thread.turn.start defaults for provider and runtime mode", () =>
237 Effect.gen(function* () {
238 const parsed = yield* decodeThreadTurnStartCommand({
239 type: "thread.turn.start",
240 commandId: "cmd-turn-1",
241 threadId: "thread-1",
242 message: {
243 messageId: "msg-1",
244 role: "user",
245 text: "hello",
246 attachments: [],
247 },
248 createdAt: "2026-01-01T00:00:00.000Z",
249 });
250 assert.strictEqual(parsed.modelSelection, undefined);
251 assert.strictEqual(parsed.runtimeMode, DEFAULT_RUNTIME_MODE);
252 assert.strictEqual(parsed.interactionMode, DEFAULT_PROVIDER_INTERACTION_MODE);
253 }),
254);
255
256it.effect("accepts inline images, uploaded images, and uploaded files from clients", () =>
257 Effect.gen(function* () {
258 const command = yield* decodeClientOrchestrationCommand({
259 type: "thread.turn.start",
260 commandId: "cmd-turn-attachments",
261 threadId: "thread-1",
262 message: {
263 messageId: "msg-attachments",
264 role: "user",
265 text: "hello",
266 attachments: [
267 {
268 type: "image",
269 name: "legacy.png",
270 mimeType: "image/png",
271 sizeBytes: 3,
272 dataUrl: "data:image/png;base64,YWJj",
273 },
274 {
275 type: "image",
276 id: "pending-00000000-0000-4000-8000-000000000001",
277 name: "uploaded.png",
278 mimeType: "image/png",
279 sizeBytes: 3,
280 },
281 {
282 type: "file",
283 id: "pending-00000000-0000-4000-8000-000000000002-pdf",
284 name: "report.pdf",
285 mimeType: "application/pdf",
286 sizeBytes: 3,
287 },
288 ],
289 },
290 runtimeMode: "full-access",
291 interactionMode: "default",
292 createdAt: "2026-01-01T00:00:00.000Z",
293 });
294
295 if (command.type !== "thread.turn.start") {
296 assert.fail(`Expected thread.turn.start, received ${command.type}.`);
297 }
298 assert.strictEqual(command.message.attachments.length, 3);
299 assert.strictEqual("dataUrl" in command.message.attachments[0]!, true);
300 assert.strictEqual("id" in command.message.attachments[1]!, true);
301 assert.strictEqual(command.message.attachments[2]!.type, "file");
302 }),
303);
304
305// Attachments ride on persisted events and thread streams with no client
306// version negotiation. A type this build does not know must decode instead of
307// failing the whole message.
308it.effect("tolerates attachment types from newer builds when decoding messages", () =>
309 Effect.gen(function* () {
310 const futureAttachment = {
311 type: "somethingnew",
312 id: "thread-1-00000000-0000-4000-8000-000000000003-glb",
313 name: "scene.glb",
314 mimeType: "model/gltf-binary",
315 sizeBytes: 12,
316 };
317
318 const message = yield* decodeOrchestrationMessage({
319 id: "message-1",
320 role: "user",
321 text: "look at this",
322 attachments: [futureAttachment],
323 turnId: null,
324 streaming: false,
325 createdAt: "2026-01-01T00:00:00.000Z",
326 updatedAt: "2026-01-01T00:00:00.000Z",
327 });
328 assert.strictEqual(message.attachments?.length, 1);
329 assert.strictEqual(message.attachments?.[0]!.type, "somethingnew");
330
331 const payload = yield* decodeThreadMessageSentPayload({
332 threadId: "thread-1",
333 messageId: "message-1",
334 role: "user",
335 text: "look at this",
336 attachments: [futureAttachment],
337 turnId: null,
338 streaming: false,
339 createdAt: "2026-01-01T00:00:00.000Z",
340 updatedAt: "2026-01-01T00:00:00.000Z",
341 });
342 assert.strictEqual(payload.attachments?.[0]!.type, "somethingnew");
343 }),
344);
345
346// The tolerant member must not catch malformed known attachments: a file over
347// the size cap or an image with a bad mime has to fail its own schema, not
348// slide through the open one with those constraints unchecked.
349it.effect("rejects malformed known attachment types instead of tolerating them", () =>
350 Effect.gen(function* () {
351 const base = {
352 id: "thread-1-00000000-0000-4000-8000-000000000003-pdf",
353 name: "report.pdf",
354 mimeType: "application/pdf",
355 };
356 const decode = (attachment: unknown) =>
357 decodeOrchestrationMessage({
358 id: "message-1",
359 role: "user",
360 text: "look at this",
361 attachments: [attachment],
362 turnId: null,
363 streaming: false,
364 createdAt: "2026-01-01T00:00:00.000Z",
365 updatedAt: "2026-01-01T00:00:00.000Z",
366 });
367
368 const oversizedFile = yield* Effect.exit(
369 decode({ ...base, type: "file", sizeBytes: PROVIDER_SEND_TURN_MAX_FILE_BYTES + 1 }),
370 );
371 assert.strictEqual(Exit.isFailure(oversizedFile), true);
372
373 const badMimeImage = yield* Effect.exit(
374 decode({ ...base, type: "image", mimeType: "application/pdf", sizeBytes: 12 }),
375 );
376 assert.strictEqual(Exit.isFailure(badMimeImage), true);
377 }),
378);
379
380it.effect("preserves window capture metadata in thread.turn.start", () =>
381 Effect.gen(function* () {
382 const parsed = yield* decodeThreadTurnStartCommand({
383 type: "thread.turn.start",
384 commandId: "cmd-snap-shot",
385 threadId: "thread-1",
386 message: {
387 messageId: "msg-snap-shot",
388 role: "user",
389 text: "Review this window",
390 attachments: [
391 {
392 type: "image",
393 id: "snap-shot-1",
394 name: "editor.png",
395 mimeType: "image/png",
396 sizeBytes: 4,
397 source: {
398 kind: "snap-shot",
399 capturedAt: "2026-08-24T11:00:00.000Z",
400 appName: "Editor",
401 windowTitle: "main.ts",
402 accessibleText: "const answer = 42;",
403 accessibility: {
404 format: "element-tree",
405 coordinateSpace: "captured-image",
406 imageSize: { width: 800, height: 600 },
407 truncated: false,
408 root: {
409 role: "window",
410 name: "main.ts",
411 bounds: { x: 0, y: 0, width: 800, height: 600 },
412 children: [
413 {
414 role: "text",
415 value: "const answer = 42;",
416 bounds: { x: 20, y: 40, width: 180, height: 20 },
417 children: [],
418 },
419 ],
420 },
421 },
422 appIdentifier: "com.example.editor",
423 appIconDataUrl: "data:image/png;base64,iVBORw==",
424 },
425 },
426 ],
427 },
428 createdAt: "2026-08-24T11:00:00.000Z",
429 });
430
431 const attachment = parsed.message.attachments[0];
432 assert.strictEqual(attachment?.type, "image");
433 assert.deepStrictEqual((attachment as ChatImageAttachment).source, {
434 kind: "snap-shot",
435 capturedAt: "2026-08-24T11:00:00.000Z",
436 appName: "Editor",
437 windowTitle: "main.ts",
438 accessibleText: "const answer = 42;",
439 accessibility: {
440 format: "element-tree",
441 coordinateSpace: "captured-image",
442 imageSize: { width: 800, height: 600 },
443 truncated: false,
444 root: {
445 role: "window",
446 name: "main.ts",
447 bounds: { x: 0, y: 0, width: 800, height: 600 },
448 children: [
449 {
450 role: "text",
451 value: "const answer = 42;",
452 bounds: { x: 20, y: 40, width: 180, height: 20 },
453 children: [],
454 },
455 ],
456 },
457 },
458 appIdentifier: "com.example.editor",
459 appIconDataUrl: "data:image/png;base64,iVBORw==",
460 });
461 }),
462);
463
464it.effect("rejects accessibility trees above the serialized payload limit", () =>
465 Effect.gen(function* () {
466 const result = yield* Effect.exit(
467 decodeSnapShotAccessibility({
468 format: "element-tree",
469 coordinateSpace: "captured-image",
470 imageSize: { width: 800, height: 600 },
471 truncated: false,
472 root: {
473 role: "window",
474 bounds: { x: 0, y: 0, width: 800, height: 600 },
475 children: Array.from({ length: 10 }, () => ({
476 role: "text",
477 value: "x".repeat(8_000),
478 bounds: null,
479 children: [],
480 })),
481 },
482 }),
483 );
484
485 assert.strictEqual(Exit.isFailure(result), true);
486 }),
487);
488
489it.effect("preserves explicit provider and runtime mode in thread.turn.start", () =>
490 Effect.gen(function* () {
491 const parsed = yield* decodeThreadTurnStartCommand({
492 type: "thread.turn.start",
493 commandId: "cmd-turn-2",
494 threadId: "thread-1",
495 message: {
496 messageId: "msg-2",
497 role: "user",
498 text: "hello",
499 attachments: [],
500 },
501 modelSelection: {
502 provider: "codex",
503 model: "gpt-5.4",
504 },
505 runtimeMode: "full-access",
506 createdAt: "2026-01-01T00:00:00.000Z",
507 });
508 assert.strictEqual(parsed.modelSelection?.instanceId, "codex");
509 assert.strictEqual(parsed.runtimeMode, "full-access");
510 assert.strictEqual(parsed.interactionMode, DEFAULT_PROVIDER_INTERACTION_MODE);
511 }),
512);
513
514it.effect("accepts bootstrap metadata in thread.turn.start", () =>
515 Effect.gen(function* () {
516 const parsed = yield* decodeThreadTurnStartCommand({
517 type: "thread.turn.start",
518 commandId: "cmd-turn-bootstrap",
519 threadId: "thread-1",
520 message: {
521 messageId: "msg-bootstrap",
522 role: "user",
523 text: "hello",
524 attachments: [],
525 },
526 bootstrap: {
527 createThread: {
528 projectId: "project-1",
529 title: "Bootstrap thread",
530 modelSelection: {
531 provider: "codex",
532 model: "gpt-5.4",
533 },
534 runtimeMode: "full-access",
535 interactionMode: "default",
536 branch: null,
537 worktreePath: null,
538 createdAt: "2026-01-01T00:00:00.000Z",
539 },
540 prepareWorktree: {
541 projectCwd: "/tmp/workspace",
542 baseBranch: "main",
543 branch: "t3code/example",
544 startFromOrigin: true,
545 },
546 runSetupScript: true,
547 },
548 createdAt: "2026-01-01T00:00:00.000Z",
549 });
550 assert.strictEqual(parsed.bootstrap?.createThread?.projectId, "project-1");
551 assert.strictEqual(parsed.bootstrap?.prepareWorktree?.baseBranch, "main");
552 assert.strictEqual(parsed.bootstrap?.prepareWorktree?.startFromOrigin, true);
553 assert.strictEqual(parsed.bootstrap?.runSetupScript, true);
554 }),
555);
556
557it.effect("decodes thread.created runtime mode for historical events", () =>
558 Effect.gen(function* () {
559 const parsed = yield* decodeThreadCreatedPayload({
560 threadId: "thread-1",
561 projectId: "project-1",
562 title: "Thread title",
563 modelSelection: {
564 provider: "codex",
565 model: "gpt-5.4",
566 },
567 interactionMode: "default",
568 branch: null,
569 worktreePath: null,
570 createdAt: "2026-01-01T00:00:00.000Z",
571 updatedAt: "2026-01-01T00:00:00.000Z",
572 });
573
574 assert.strictEqual(parsed.runtimeMode, DEFAULT_RUNTIME_MODE);
575 assert.strictEqual(parsed.modelSelection.instanceId, "codex");
576 }),
577);
578
579it.effect("decodes thread.meta-updated payloads with explicit provider", () =>
580 Effect.gen(function* () {
581 const parsed = yield* decodeThreadMetaUpdatedPayload({
582 threadId: "thread-1",
583 regenerateTitle: true,
584 previousTitle: "Previous title",
585 titleRegeneration: {
586 requestId: "cmd-title-regenerate",
587 startedAt: "2026-01-01T00:00:00.000Z",
588 },
589 modelSelection: {
590 provider: "claudeAgent",
591 model: "claude-opus-4-6",
592 },
593 updatedAt: "2026-01-01T00:00:00.000Z",
594 });
595 assert.strictEqual(parsed.previousTitle, "Previous title");
596 assert.strictEqual(parsed.titleRegeneration?.requestId, "cmd-title-regenerate");
597 assert.strictEqual(parsed.modelSelection?.instanceId, "claudeAgent");
598 }),
599);
600
601it.effect("decodes thread archive and unarchive commands", () =>
602 Effect.gen(function* () {
603 const archive = yield* decodeOrchestrationCommand({
604 type: "thread.archive",
605 commandId: "cmd-archive-1",
606 threadId: "thread-1",
607 });
608 const unarchive = yield* decodeOrchestrationCommand({
609 type: "thread.unarchive",
610 commandId: "cmd-unarchive-1",
611 threadId: "thread-1",
612 });
613
614 assert.strictEqual(archive.type, "thread.archive");
615 assert.strictEqual(unarchive.type, "thread.unarchive");
616 }),
617);
618
619it.effect("decodes thread settle and unsettle commands", () =>
620 Effect.gen(function* () {
621 const settle = yield* decodeOrchestrationCommand({
622 type: "thread.settle",
623 commandId: "cmd-settle-1",
624 threadId: "thread-1",
625 });
626 const unsettle = yield* decodeOrchestrationCommand({
627 type: "thread.unsettle",
628 commandId: "cmd-unsettle-1",
629 threadId: "thread-1",
630 reason: "user",
631 });
632
633 assert.strictEqual(settle.type, "thread.settle");
634 assert.strictEqual(unsettle.type, "thread.unsettle");
635
636 // "activity" is server-owned: it exists on the event, never on the
637 // command, so a client cannot forge the neutral reset.
638 const forged = yield* decodeOrchestrationCommand({
639 type: "thread.unsettle",
640 commandId: "cmd-unsettle-2",
641 threadId: "thread-1",
642 reason: "activity",
643 }).pipe(Effect.flip);
644 assert.ok(forged);
645 }),
646);
647
648it.effect("defaults settled fields when decoding historical thread data", () =>
649 Effect.gen(function* () {
650 const common = {
651 id: "thread-1",
652 projectId: "project-1",
653 title: "Historical thread",
654 modelSelection: { provider: "codex", model: "gpt-5.4" },
655 runtimeMode: "full-access",
656 interactionMode: "default",
657 branch: null,
658 worktreePath: null,
659 latestTurn: null,
660 createdAt: "2026-01-01T00:00:00.000Z",
661 updatedAt: "2026-01-01T00:00:00.000Z",
662 archivedAt: null,
663 session: null,
664 };
665 const thread = yield* decodeOrchestrationThread({
666 ...common,
667 deletedAt: null,
668 messages: [],
669 proposedPlans: [],
670 activities: [],
671 checkpoints: [],
672 });
673 const shell = yield* decodeOrchestrationThreadShell({
674 ...common,
675 latestUserMessageAt: null,
676 hasPendingApprovals: false,
677 hasPendingUserInput: false,
678 hasActionableProposedPlan: false,
679 });
680
681 assert.strictEqual(thread.settledOverride, null);
682 assert.strictEqual(thread.settledAt, null);
683 assert.strictEqual(shell.settledOverride, null);
684 assert.strictEqual(shell.settledAt, null);
685 }),
686);
687
688it.effect("decodes thread archived and unarchived events", () =>
689 Effect.gen(function* () {
690 const archived = yield* decodeOrchestrationEvent({
691 sequence: 1,
692 eventId: "event-archive-1",
693 aggregateKind: "thread",
694 aggregateId: "thread-1",
695 type: "thread.archived",
696 occurredAt: "2026-01-01T00:00:00.000Z",
697 commandId: "cmd-archive-1",
698 causationEventId: null,
699 correlationId: "cmd-archive-1",
700 metadata: {},
701 payload: {
702 threadId: "thread-1",
703 archivedAt: "2026-01-01T00:00:00.000Z",
704 updatedAt: "2026-01-01T00:00:00.000Z",
705 },
706 });
707 const unarchived = yield* decodeOrchestrationEvent({
708 sequence: 2,
709 eventId: "event-unarchive-1",
710 aggregateKind: "thread",
711 aggregateId: "thread-1",
712 type: "thread.unarchived",
713 occurredAt: "2026-01-02T00:00:00.000Z",
714 commandId: "cmd-unarchive-1",
715 causationEventId: null,
716 correlationId: "cmd-unarchive-1",
717 metadata: {},
718 payload: {
719 threadId: "thread-1",
720 updatedAt: "2026-01-02T00:00:00.000Z",
721 },
722 });
723
724 if (archived.type !== "thread.archived") {
725 assert.fail(`Expected thread.archived event, received ${archived.type}.`);
726 }
727 assert.strictEqual(archived.payload.archivedAt, "2026-01-01T00:00:00.000Z");
728 assert.strictEqual(unarchived.type, "thread.unarchived");
729 }),
730);
731
732it.effect("decodes thread settled and unsettled events", () =>
733 Effect.gen(function* () {
734 const settled = yield* decodeOrchestrationEvent({
735 sequence: 1,
736 eventId: "event-settle-1",
737 aggregateKind: "thread",
738 aggregateId: "thread-1",
739 type: "thread.settled",
740 occurredAt: "2026-01-01T00:00:00.000Z",
741 commandId: "cmd-settle-1",
742 causationEventId: null,
743 correlationId: "cmd-settle-1",
744 metadata: {},
745 payload: {
746 threadId: "thread-1",
747 settledAt: "2026-01-01T00:00:00.000Z",
748 updatedAt: "2026-01-01T00:00:00.000Z",
749 },
750 });
751 const unsettled = yield* decodeOrchestrationEvent({
752 sequence: 2,
753 eventId: "event-unsettle-1",
754 aggregateKind: "thread",
755 aggregateId: "thread-1",
756 type: "thread.unsettled",
757 occurredAt: "2026-01-02T00:00:00.000Z",
758 commandId: "cmd-unsettle-1",
759 causationEventId: null,
760 correlationId: "cmd-unsettle-1",
761 metadata: {},
762 payload: {
763 threadId: "thread-1",
764 reason: "user",
765 updatedAt: "2026-01-02T00:00:00.000Z",
766 },
767 });
768
769 assert.strictEqual(settled.type, "thread.settled");
770 assert.strictEqual(unsettled.type, "thread.unsettled");
771 }),
772);
773
774it.effect("accepts provider-scoped model options in thread.turn.start", () =>
775 Effect.gen(function* () {
776 const parsed = yield* decodeThreadTurnStartCommand({
777 type: "thread.turn.start",
778 commandId: "cmd-turn-options",
779 threadId: "thread-1",
780 message: {
781 messageId: "msg-options",
782 role: "user",
783 text: "hello",
784 attachments: [],
785 },
786 modelSelection: {
787 provider: "codex",
788 model: "gpt-5.3-codex",
789 options: [
790 { id: "reasoningEffort", value: "high" },
791 { id: "fastMode", value: true },
792 ],
793 },
794 createdAt: "2026-01-01T00:00:00.000Z",
795 });
796 assert.strictEqual(parsed.modelSelection?.instanceId, "codex");
797 assert.strictEqual(getOptionValue(parsed.modelSelection?.options, "reasoningEffort"), "high");
798 assert.strictEqual(getOptionValue(parsed.modelSelection?.options, "fastMode"), true);
799 }),
800);
801
802it.effect("normalizes legacy object-shaped modelSelection.options on decode", () =>
803 Effect.gen(function* () {
804 const parsed = yield* decodeThreadCreatedPayload({
805 threadId: "thread-1",
806 projectId: "project-1",
807 title: "Legacy options thread",
808 modelSelection: {
809 provider: "claudeAgent",
810 model: "claude-opus-4-6",
811 options: {
812 effort: "max",
813 fastMode: true,
814 // Falsy/garbage entries are dropped, matching migration 026.
815 emptyStr: " ",
816 nullish: null,
817 nested: { foo: 1 },
818 },
819 },
820 branch: null,
821 worktreePath: null,
822 createdAt: "2026-01-01T00:00:00.000Z",
823 updatedAt: "2026-01-01T00:00:00.000Z",
824 });
825
826 assert.strictEqual(parsed.modelSelection.instanceId, ProviderInstanceId.make("claudeAgent"));
827 assert.deepStrictEqual(parsed.modelSelection.options, [
828 { id: "effort", value: "max" },
829 { id: "fastMode", value: true },
830 ]);
831 }),
832);
833
834it.effect("normalizes legacy object-shaped defaultModelSelection.options on decode", () =>
835 Effect.gen(function* () {
836 const parsed = yield* decodeProjectCreatedPayload({
837 projectId: "project-1",
838 title: "Legacy default project",
839 workspaceRoot: "/tmp/legacy",
840 defaultModelSelection: {
841 provider: "codex",
842 model: "gpt-5.4",
843 options: { reasoningEffort: "low" },
844 },
845 scripts: [],
846 createdAt: "2026-01-01T00:00:00.000Z",
847 updatedAt: "2026-01-01T00:00:00.000Z",
848 });
849
850 assert.deepStrictEqual(parsed.defaultModelSelection?.options, [
851 { id: "reasoningEffort", value: "low" },
852 ]);
853 }),
854);
855
856it.effect(
857 "normalizes legacy object-shaped options on decode and re-encodes as canonical array",
858 () =>
859 Effect.gen(function* () {
860 const decoded = yield* decodeThreadCreatedPayload({
861 threadId: "thread-1",
862 projectId: "project-1",
863 title: "Round trip thread",
864 modelSelection: {
865 provider: "codex",
866 model: "gpt-5.4",
867 options: { fastMode: true },
868 },
869 branch: null,
870 worktreePath: null,
871 createdAt: "2026-01-01T00:00:00.000Z",
872 updatedAt: "2026-01-01T00:00:00.000Z",
873 });
874
875 const encoded = yield* encodeThreadCreatedPayload(decoded);
876 assert.deepStrictEqual(encoded.modelSelection.options, [{ id: "fastMode", value: true }]);
877 }),
878);
879
880it.effect("accepts a title seed in thread.turn.start", () =>
881 Effect.gen(function* () {
882 const parsed = yield* decodeThreadTurnStartCommand({
883 type: "thread.turn.start",
884 commandId: "cmd-turn-title-seed",
885 threadId: "thread-1",
886 message: {
887 messageId: "msg-title-seed",
888 role: "user",
889 text: "hello",
890 attachments: [],
891 },
892 titleSeed: "Investigate reconnect failures",
893 createdAt: "2026-01-01T00:00:00.000Z",
894 });
895 assert.strictEqual(parsed.titleSeed, "Investigate reconnect failures");
896 }),
897);
898
899it.effect("decodes active reorder commands through client and orchestration boundaries", () =>
900 Effect.gen(function* () {
901 const input = {
902 type: "thread.active.reorder",
903 commandId: "cmd-active-reorder",
904 threadId: "thread-1",
905 orderKey: "gm",
906 };
907 const clientCommand = yield* decodeClientOrchestrationCommand(input);
908 const command = yield* decodeOrchestrationCommand(input);
909 for (const decoded of [clientCommand, command]) {
910 assert.strictEqual(decoded.type, "thread.active.reorder");
911 if (decoded.type === "thread.active.reorder") {
912 assert.strictEqual(decoded.threadId, "thread-1");
913 assert.strictEqual(decoded.orderKey, "gm");
914 }
915 }
916 const emptyKey = yield* Effect.exit(
917 decodeClientOrchestrationCommand({ ...input, orderKey: " " }),
918 );
919 assert.isTrue(Exit.isFailure(emptyKey));
920 }),
921);
922
923it.effect("decodes active placement on existing metadata events while accepting old payloads", () =>
924 Effect.gen(function* () {
925 const payload = { threadId: "thread-1", updatedAt: "2026-01-01T00:00:00.000Z" };
926 const oldPayload = yield* decodeThreadMetaUpdatedPayload(payload);
927 assert.strictEqual(oldPayload.activeOrderKey, undefined);
928 const resetPayload = yield* decodeThreadMetaUpdatedPayload({
929 ...payload,
930 activeOrderKey: null,
931 });
932 assert.strictEqual(resetPayload.activeOrderKey, null);
933 const event = yield* decodeOrchestrationEvent({
934 type: "thread.meta-updated",
935 sequence: 1,
936 eventId: "event-active-reorder",
937 aggregateKind: "thread",
938 aggregateId: "thread-1",
939 occurredAt: "2026-01-02T00:00:00.000Z",
940 commandId: "cmd-active-reorder",
941 causationEventId: null,
942 correlationId: null,
943 metadata: {},
944 payload: { ...payload, activeOrderKey: "gm" },
945 });
946 assert.strictEqual(event.type, "thread.meta-updated");
947 if (event.type === "thread.meta-updated") {
948 assert.strictEqual(event.payload.activeOrderKey, "gm");
949 assert.strictEqual(event.payload.updatedAt, payload.updatedAt);
950 }
951 }),
952);
953
954it.effect("accepts a title regeneration intent in thread.meta.update", () =>
955 Effect.gen(function* () {
956 const parsed = yield* decodeOrchestrationCommand({
957 type: "thread.meta.update",
958 commandId: "cmd-title-regenerate",
959 threadId: "thread-1",
960 regenerateTitle: true,
961 });
962 assert.strictEqual(parsed.type, "thread.meta.update");
963 if (parsed.type === "thread.meta.update") {
964 assert.strictEqual(parsed.regenerateTitle, true);
965 }
966 }),
967);
968
969it.effect("accepts a linked pull request in thread.meta.update", () =>
970 Effect.gen(function* () {
971 const linkedPullRequest = {
972 projectId: "project-1",
973 repository: "pingdotgg/t3code",
974 number: 42,
975 url: "https://github.com/pingdotgg/t3code/pull/42",
976 };
977 const parsed = yield* decodeOrchestrationCommand({
978 type: "thread.meta.update",
979 commandId: "cmd-link-pull-request",
980 threadId: "thread-1",
981 linkedPullRequest,
982 });
983
984 assert.strictEqual(parsed.type, "thread.meta.update");
985 if (parsed.type === "thread.meta.update") {
986 assert.deepStrictEqual(parsed.linkedPullRequest, linkedPullRequest);
987 }
988 }),
989);
990
991it.effect("accepts an internal title regeneration completion", () =>
992 Effect.gen(function* () {
993 const parsed = yield* decodeOrchestrationCommand({
994 type: "thread.title.regeneration.complete",
995 commandId: "cmd-title-regeneration-complete",
996 threadId: "thread-1",
997 requestId: "cmd-title-regenerate",
998 title: "Updated title",
999 });
1000 assert.strictEqual(parsed.type, "thread.title.regeneration.complete");
1001 if (parsed.type === "thread.title.regeneration.complete") {
1002 assert.strictEqual(parsed.requestId, "cmd-title-regenerate");
1003 assert.strictEqual(parsed.title, "Updated title");
1004 }
1005 }),
1006);
1007
1008it.effect("accepts pull request synchronization only as an internal command", () =>
1009 Effect.gen(function* () {
1010 const pullRequest = {
1011 projectId: ProjectId.make("project-1"),
1012 repository: "pingdotgg/t3code",
1013 number: 42,
1014 url: "https://github.com/pingdotgg/t3code/pull/42",
1015 };
1016 const command = {
1017 type: "thread.pull-request.sync" as const,
1018 commandId: CommandId.make("cmd-pull-request-sync"),
1019 threadId: ThreadId.make("thread-1"),
1020 projectId: pullRequest.projectId,
1021 snapshotSequence: 12,
1022 expected: {
1023 workspaceRoot: "/workspace/project",
1024 branch: "feature",
1025 worktreePath: null,
1026 linkedPullRequest: null,
1027 branchPullRequest: null,
1028 },
1029 branchPullRequest: pullRequest,
1030 linkedPullRequest: pullRequest,
1031 };
1032
1033 assert.deepStrictEqual(yield* decodeOrchestrationCommand(command), command);
1034 assert.ok(yield* decodeClientOrchestrationCommand(command).pipe(Effect.flip));
1035
1036 const cleared = { ...command, branchPullRequest: null };
1037 assert.deepStrictEqual(yield* decodeOrchestrationCommand(cleared), cleared);
1038
1039 const metadata = yield* decodeClientOrchestrationCommand({
1040 type: "thread.meta.update",
1041 commandId: "cmd-forged-branch-pull-request",
1042 threadId: "thread-1",
1043 branchPullRequest: pullRequest,
1044 });
1045 assert.isFalse("branchPullRequest" in metadata);
1046 }),
1047);
1048
1049it.effect("rejects an explicit title combined with title regeneration", () =>
1050 Effect.gen(function* () {
1051 const result = yield* Effect.exit(
1052 decodeOrchestrationCommand({
1053 type: "thread.meta.update",
1054 commandId: "cmd-title-regenerate-with-title",
1055 threadId: "thread-1",
1056 title: "Explicit title",
1057 regenerateTitle: true,
1058 }),
1059 );
1060 assert.strictEqual(result._tag, "Failure");
1061 }),
1062);
1063
1064it.effect("accepts a source proposed plan reference in thread.turn.start", () =>
1065 Effect.gen(function* () {
1066 const parsed = yield* decodeThreadTurnStartCommand({
1067 type: "thread.turn.start",
1068 commandId: "cmd-turn-source-plan",
1069 threadId: "thread-2",
1070 message: {
1071 messageId: "msg-source-plan",
1072 role: "user",
1073 text: "implement this",
1074 attachments: [],
1075 },
1076 sourceProposedPlan: {
1077 threadId: "thread-1",
1078 planId: "plan-1",
1079 },
1080 createdAt: "2026-01-01T00:00:00.000Z",
1081 });
1082 assert.deepStrictEqual(parsed.sourceProposedPlan, {
1083 threadId: "thread-1",
1084 planId: "plan-1",
1085 });
1086 }),
1087);
1088
1089it.effect(
1090 "decodes thread.turn-start-requested defaults for provider, runtime mode, and interaction mode",
1091 () =>
1092 Effect.gen(function* () {
1093 const parsed = yield* decodeThreadTurnStartRequestedPayload({
1094 threadId: "thread-1",
1095 messageId: "msg-1",
1096 createdAt: "2026-01-01T00:00:00.000Z",
1097 });
1098 assert.strictEqual(parsed.modelSelection, undefined);
1099 assert.strictEqual(parsed.runtimeMode, DEFAULT_RUNTIME_MODE);
1100 assert.strictEqual(parsed.interactionMode, DEFAULT_PROVIDER_INTERACTION_MODE);
1101 assert.strictEqual(parsed.sourceProposedPlan, undefined);
1102 }),
1103);
1104
1105it.effect("decodes thread.turn-start-requested source proposed plan metadata when present", () =>
1106 Effect.gen(function* () {
1107 const parsed = yield* decodeThreadTurnStartRequestedPayload({
1108 threadId: "thread-2",
1109 messageId: "msg-2",
1110 sourceProposedPlan: {
1111 threadId: "thread-1",
1112 planId: "plan-1",
1113 },
1114 createdAt: "2026-01-01T00:00:00.000Z",
1115 });
1116 assert.deepStrictEqual(parsed.sourceProposedPlan, {
1117 threadId: "thread-1",
1118 planId: "plan-1",
1119 });
1120 }),
1121);
1122
1123it.effect("decodes thread.turn-start-requested title seed when present", () =>
1124 Effect.gen(function* () {
1125 const parsed = yield* decodeThreadTurnStartRequestedPayload({
1126 threadId: "thread-2",
1127 messageId: "msg-2",
1128 titleSeed: "Investigate reconnect failures",
1129 createdAt: "2026-01-01T00:00:00.000Z",
1130 });
1131 assert.strictEqual(parsed.titleSeed, "Investigate reconnect failures");
1132 }),
1133);
1134
1135it.effect("decodes latest turn source proposed plan metadata when present", () =>
1136 Effect.gen(function* () {
1137 const parsed = yield* decodeOrchestrationLatestTurn({
1138 turnId: "turn-2",
1139 state: "running",
1140 requestedAt: "2026-01-01T00:00:00.000Z",
1141 startedAt: "2026-01-01T00:00:01.000Z",
1142 completedAt: null,
1143 assistantMessageId: null,
1144 sourceProposedPlan: {
1145 threadId: "thread-1",
1146 planId: "plan-1",
1147 },
1148 });
1149 assert.deepStrictEqual(parsed.sourceProposedPlan, {
1150 threadId: "thread-1",
1151 planId: "plan-1",
1152 });
1153 }),
1154);
1155
1156it.effect("decodes orchestration session runtime mode defaults", () =>
1157 Effect.gen(function* () {
1158 const parsed = yield* decodeOrchestrationSession({
1159 threadId: "thread-1",
1160 status: "idle",
1161 providerName: null,
1162 providerSessionId: null,
1163 providerThreadId: null,
1164 activeTurnId: null,
1165 lastError: null,
1166 updatedAt: "2026-01-01T00:00:00.000Z",
1167 });
1168 assert.strictEqual(parsed.runtimeMode, DEFAULT_RUNTIME_MODE);
1169 }),
1170);
1171
1172it.effect("defaults proposed plan implementation metadata for historical rows", () =>
1173 Effect.gen(function* () {
1174 const parsed = yield* decodeOrchestrationProposedPlan({
1175 id: "plan-1",
1176 turnId: "turn-1",
1177 planMarkdown: "# Plan",
1178 createdAt: "2026-01-01T00:00:00.000Z",
1179 updatedAt: "2026-01-01T00:00:00.000Z",
1180 });
1181 assert.strictEqual(parsed.implementedAt, null);
1182 assert.strictEqual(parsed.implementationThreadId, null);
1183 }),
1184);
1185
1186it.effect("preserves proposed plan implementation metadata when present", () =>
1187 Effect.gen(function* () {
1188 const parsed = yield* decodeOrchestrationProposedPlan({
1189 id: "plan-2",
1190 turnId: "turn-2",
1191 planMarkdown: "# Plan",
1192 implementedAt: "2026-01-02T00:00:00.000Z",
1193 implementationThreadId: "thread-2",
1194 createdAt: "2026-01-01T00:00:00.000Z",
1195 updatedAt: "2026-01-02T00:00:00.000Z",
1196 });
1197 assert.strictEqual(parsed.implementedAt, "2026-01-02T00:00:00.000Z");
1198 assert.strictEqual(parsed.implementationThreadId, "thread-2");
1199 }),
1200);
1201
1202// ── ModelSelection: instance-keyed wire shape + legacy decoder ────────
1203//
1204// `ModelSelection` is routing-keyed on `instanceId` — never a driver kind.
1205// Persisted and in-flight payloads from pre-instance builds carry a
1206// `provider` field whose value was a driver kind; those payloads are migrated
1207// at the wire boundary by
1208// promoting `provider` to the default instance id for that driver
1209// (built-in drivers use the driver kind slug as their default instance id, so
1210// the migration is a 1:1 rename).
1211//
1212// These tests pin the rollback/fork tolerance invariant: legacy payloads
1213// decode cleanly for fork-provided drivers, and the decoded form uses
1214// `instanceId` uniformly regardless of origin.
1215
1216const decodeModelSelection = Schema.decodeUnknownEffect(ModelSelection);
1217const encodeModelSelection = Schema.encodeUnknownEffect(ModelSelection);
1218
1219it.effect("ModelSelection migrates legacy `provider` field to `instanceId`", () =>
1220 Effect.gen(function* () {
1221 const parsed = yield* decodeModelSelection({
1222 provider: "codex",
1223 model: "gpt-5-codex",
1224 options: [{ id: "reasoningEffort", value: "high" }],
1225 });
1226 assert.strictEqual(parsed.instanceId, ProviderInstanceId.make("codex"));
1227 assert.strictEqual(parsed.model, "gpt-5-codex");
1228 assert.deepStrictEqual(parsed.options, [{ id: "reasoningEffort", value: "high" }]);
1229 }),
1230);
1231
1232it.effect("ModelSelection accepts an explicit instanceId routing key", () =>
1233 Effect.gen(function* () {
1234 const parsed = yield* decodeModelSelection({
1235 instanceId: "codex_personal",
1236 model: "gpt-5-codex",
1237 });
1238 assert.strictEqual(parsed.instanceId, ProviderInstanceId.make("codex_personal"));
1239 }),
1240);
1241
1242it.effect("ModelSelection prefers explicit instanceId over legacy provider", () =>
1243 Effect.gen(function* () {
1244 const parsed = yield* decodeModelSelection({
1245 provider: "codex",
1246 instanceId: "codex_personal",
1247 model: "gpt-5-codex",
1248 });
1249 assert.strictEqual(parsed.instanceId, ProviderInstanceId.make("codex_personal"));
1250 }),
1251);
1252
1253it.effect(
1254 "ModelSelection decodes unknown driver kinds via legacy provider (rollback / fork invariant)",
1255 () =>
1256 Effect.gen(function* () {
1257 const parsed = yield* decodeModelSelection({
1258 provider: "ollama",
1259 model: "llama3:70b",
1260 options: [{ id: "temperature", value: "0.4" }],
1261 });
1262 assert.strictEqual(parsed.instanceId, ProviderInstanceId.make("ollama"));
1263 assert.strictEqual(parsed.model, "llama3:70b");
1264 }),
1265);
1266
1267it.effect("ModelSelection encodes to the canonical instanceId wire form", () =>
1268 Effect.gen(function* () {
1269 const decoded = yield* decodeModelSelection({
1270 provider: "ollama",
1271 model: "llama3:70b",
1272 options: [{ id: "temperature", value: "0.4" }],
1273 });
1274 const encoded = yield* encodeModelSelection(decoded);
1275 assert.deepStrictEqual(encoded, {
1276 instanceId: "ollama",
1277 model: "llama3:70b",
1278 options: [{ id: "temperature", value: "0.4" }],
1279 });
1280 }),
1281);
1282
1283it.effect("ModelSelection rejects malformed instance ids", () =>
1284 Effect.gen(function* () {
1285 const result = yield* Effect.exit(
1286 decodeModelSelection({
1287 instanceId: "1invalid", // must start with a letter
1288 model: "x",
1289 }),
1290 );
1291 assert.strictEqual(result._tag, "Failure");
1292 }),
1293);
1294
1295it.effect("project favicon overrides accept only supported image files", () =>
1296 Effect.gen(function* () {
1297 const valid = yield* decodeOrchestrationCommand({
1298 type: "project.meta.update",
1299 commandId: "cmd-project-favicon",
1300 projectId: "project-1",
1301 faviconPath: "brand/icon.svg",
1302 });
1303 assert.strictEqual(valid.type, "project.meta.update");
1304
1305 const invalid = yield* Effect.exit(
1306 decodeOrchestrationCommand({
1307 type: "project.meta.update",
1308 commandId: "cmd-project-secret",
1309 projectId: "project-1",
1310 faviconPath: ".env",
1311 }),
1312 );
1313 assert.strictEqual(invalid._tag, "Failure");
1314 }),
1315);
1316
1317it.effect("project icon overrides accept Lucide icons, colors, and emoji", () =>
1318 Effect.gen(function* () {
1319 const lucide = yield* decodeOrchestrationCommand({
1320 type: "project.meta.update",
1321 commandId: "cmd-project-lucide-icon",
1322 projectId: "project-1",
1323 projectIcon: { kind: "lucide", name: "alarm-clock", color: "violet" },
1324 });
1325 assert.strictEqual(lucide.type, "project.meta.update");
1326
1327 const emoji = yield* decodeOrchestrationCommand({
1328 type: "project.meta.update",
1329 commandId: "cmd-project-emoji-icon",
1330 projectId: "project-1",
1331 projectIcon: { kind: "emoji", emoji: "👩🏽💻" },
1332 });
1333 assert.strictEqual(emoji.type, "project.meta.update");
1334
1335 const invalid = yield* Effect.exit(
1336 decodeOrchestrationCommand({
1337 type: "project.meta.update",
1338 commandId: "cmd-project-invalid-icon",
1339 projectId: "project-1",
1340 projectIcon: { kind: "lucide", name: "Alarm Clock", color: "ultraviolet" },
1341 }),
1342 );
1343 assert.strictEqual(invalid._tag, "Failure");
1344 }),
1345);
1346
1347it.effect("rejects thread history imports without messages", () =>
1348 Effect.gen(function* () {
1349 const result = yield* Effect.exit(
1350 decodeOrchestrationCommand({
1351 type: "thread.history.import",
1352 commandId: "command-empty-history",
1353 threadId: "thread-1",
1354 messages: [],
1355 }),
1356 );
1357
1358 assert.strictEqual(result._tag, "Failure");
1359 }),
1360);
1361
1362it("isProviderSendTurnSupportedImageMimeType accepts raster formats and rejects svg", () => {
1363 assert.strictEqual(isProviderSendTurnSupportedImageMimeType("image/png"), true);
1364 assert.strictEqual(isProviderSendTurnSupportedImageMimeType("IMAGE/JPEG"), true);
1365 assert.strictEqual(isProviderSendTurnSupportedImageMimeType("image/svg+xml"), false);
1366});