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

orchestratorMcp.test.ts

166 lines5.4 KB

1import { describe, expect, it } from "@effect/vitest";
2import * as Schema from "effect/Schema";
3​
4import {
5 OrchestratorMcpCreateThreadsInput,
6 OrchestratorMcpDelegateTaskInput,
7 OrchestratorMcpDelegateTaskResult,
8 OrchestratorMcpThreadInterruptInput,
9 OrchestratorMcpThreadListInput,
10 OrchestratorMcpThreadReadInput,
11 OrchestratorMcpThreadSendInput,
12 OrchestratorMcpThreadWaitInput,
13} from "./orchestratorMcp.ts";
14​
15const decodeCreateThreadsInput = Schema.decodeUnknownSync(OrchestratorMcpCreateThreadsInput);
16const decodeDelegateTaskInput = Schema.decodeUnknownSync(OrchestratorMcpDelegateTaskInput);
17const decodeDelegateTaskResult = Schema.decodeUnknownSync(OrchestratorMcpDelegateTaskResult);
18const decodeThreadInterruptInput = Schema.decodeUnknownSync(OrchestratorMcpThreadInterruptInput);
19const decodeThreadListInput = Schema.decodeUnknownSync(OrchestratorMcpThreadListInput);
20const decodeThreadReadInput = Schema.decodeUnknownSync(OrchestratorMcpThreadReadInput);
21const decodeThreadSendInput = Schema.decodeUnknownSync(OrchestratorMcpThreadSendInput);
22const decodeThreadWaitInput = Schema.decodeUnknownSync(OrchestratorMcpThreadWaitInput);
23​
24describe("orchestrator MCP contracts", () => {
25 it("decodes cross-provider delegated task requests and durable results", () => {
26 const request = decodeDelegateTaskInput({
27 task: "Inspect the workspace and report the result.",
28 target: {
29 providerInstanceId: "claudeAgent",
30 model: "claude-sonnet-4-6",
31 },
32 mode: "wait",
33 timeoutMs: 5_000,
34 clientRequestId: "delegate-1",
35 runtimeMode: "inherit",
36 interactionMode: "inherit",
37 });
38 const result = decodeDelegateTaskResult({
39 taskId: "node-task-1",
40 childThreadId: "thread-child-1",
41 childRunId: "run-child-1",
42 childNodeId: "node-task-1",
43 status: "completed",
44 workState: "result_available",
45 hasPendingChildRuns: false,
46 providerInstanceId: "claudeAgent",
47 model: "claude-sonnet-4-6",
48 summary: "Workspace inspected.",
49 resultContextTransferId: "context-transfer-result-1",
50 latestTerminalRunId: "run-child-1",
51 latestTerminalStatus: "completed",
52 latestTerminalSummary: "Workspace inspected.",
53 latestTerminalResultContextTransferId: "context-transfer-result-1",
54 waitTimedOut: false,
55 });
56​
57 expect(request.target?.providerInstanceId).toBe("claudeAgent");
58 expect(result.status).toBe("completed");
59 expect(result.summary).toBe("Workspace inspected.");
60 });
61​
62 it("decodes target model options in canonical and shorthand shapes", () => {
63 const canonical = decodeDelegateTaskInput({
64 task: "Say hello.",
65 target: {
66 providerInstanceId: "codex",
67 model: "gpt-5.6-luna",
68 options: [{ id: "reasoning", value: "low" }],
69 },
70 });
71 const shorthand = decodeDelegateTaskInput({
72 task: "Say hello.",
73 target: {
74 providerInstanceId: "codex",
75 model: "gpt-5.6-luna",
76 options: { reasoning: "low", fastMode: true },
77 },
78 });
79​
80 expect(canonical.target?.options).toEqual([{ id: "reasoning", value: "low" }]);
81 expect(shorthand.target?.options).toEqual([
82 { id: "reasoning", value: "low" },
83 { id: "fastMode", value: true },
84 ]);
85 });
86​
87 it("rejects target model options that are not strings or booleans", () => {
88 expect(() =>
89 decodeDelegateTaskInput({
90 task: "Say hello.",
91 target: {
92 providerInstanceId: "codex",
93 model: "gpt-5.6-luna",
94 // Must fail loudly instead of being dropped like legacy persistence.
95 options: { reasoning: 3 },
96 },
97 }),
98 ).toThrow();
99 expect(() =>
100 decodeDelegateTaskInput({
101 task: "Say hello.",
102 target: {
103 providerInstanceId: "codex",
104 model: "gpt-5.6-luna",
105 options: [{ id: "reasoning", value: null }],
106 },
107 }),
108 ).toThrow();
109 });
110​
111 it("decodes mixed prompted and empty thread batches", () => {
112 const request = decodeCreateThreadsInput({
113 clientRequestId: "threads-1",
114 threads: [
115 { title: "Inherited empty thread" },
116 {
117 prompt: "Review the API.",
118 target: { driverKind: "claudeAgent" },
119 runtimeMode: "approval-required",
120 },
121 ],
122 });
123​
124 expect(request.threads).toHaveLength(2);
125 expect(request.threads[0]?.prompt).toBeUndefined();
126 expect(request.threads[1]?.target?.driverKind).toBe("claudeAgent");
127 });
128​
129 it("decodes project-scoped thread orchestration requests", () => {
130 expect(
131 decodeThreadListInput({
132 statuses: ["running", "completed"],
133 includeSubagents: false,
134 limit: 25,
135 }).statuses,
136 ).toEqual(["running", "completed"]);
137 expect(
138 decodeThreadReadInput({
139 threadId: "thread-loop-1",
140 view: "activity",
141 afterPosition: 10,
142 }).afterPosition,
143 ).toBe(10);
144 expect(
145 decodeThreadSendInput({
146 threadId: "thread-loop-1",
147 message: "Continue with the next iteration.",
148 mode: "steer",
149 clientRequestId: "send-loop-2",
150 }).mode,
151 ).toBe("steer");
152 expect(
153 decodeThreadWaitInput({
154 threadId: "thread-loop-1",
155 runId: "run-loop-2",
156 timeoutMs: 5_000,
157 }).runId,
158 ).toBe("run-loop-2");
159 expect(
160 decodeThreadInterruptInput({
161 threadId: "thread-loop-1",
162 reason: "Loop converged.",
163 }).reason,
164 ).toBe("Loop converged.");
165 });
166});