History

test(mcp): await provider start in organization coverage

Julius Marminge committed 2 months ago

Commit 2ca67be1 parent f7f2a811 file · +11 −3Browse files

Unified · Split

apps/server/src/mcp/OrchestratorMcpToolkit.integration.test.ts+11−3
@@ -180,6 +180,7 @@ function makeDeterministicAdapter(input: { · 179 unmodified lines
180180 readonly capabilities: OrchestrationV2ProviderCapabilities;
181181 readonly capturedTurns: Ref.Ref<ReadonlyArray<CapturedTurn>>;
182182 readonly shouldComplete: (turn: ProviderAdapterV2TurnInput) => boolean;
183+ readonly startedGate?: (turn: ProviderAdapterV2TurnInput) => Deferred.Deferred<void> | undefined;
183184 readonly terminalGate?: (turn: ProviderAdapterV2TurnInput) => Deferred.Deferred<void> | undefined;
184185 readonly response: (turn: ProviderAdapterV2TurnInput) => string;
185186 }): ProviderAdapterV2Shape {
@@ -282,6 +283,10 @@ function makeDeterministicAdapter(input: { · 96 unmodified lines
282283 },
283284 },
284285 ]);
286+ const startedGate = input.startedGate?.(turnInput);
287+ if (startedGate !== undefined) {
288+ yield* Deferred.succeed(startedGate, undefined);
289+ }
285290 const terminalGate = input.terminalGate?.(turnInput);
286291 if (terminalGate !== undefined) {
287292 yield* Deferred.await(terminalGate);
@@ -477,6 +482,7 @@ describe("orchestrator MCP toolkit", () => { · 189 unmodified lines
477482 Effect.gen(function* () {
478483 const cwd = yield* checkpointWorkspace("orchestrator-mcp-toolkit");
479484 const capturedTurns = yield* Ref.make<ReadonlyArray<CapturedTurn>>([]);
485+ const providerStartGates = new Map<string, Deferred.Deferred<void>>();
480486 const parentTerminalGates = new Map<ThreadId, Deferred.Deferred<void>>();
481487 const deliveryTerminalGates = new Map<ThreadId, Deferred.Deferred<void>>();
482488 const registryLayer = makeProviderAdapterRegistryLayer([
@@ -487,6 +493,7 @@ describe("orchestrator MCP toolkit", () => { · 4 unmodified lines
487493 capturedTurns,
488494 shouldComplete: (turn) =>
489495 turn.threadId !== parentThreadId && turn.message.text !== cancellationPrompt,
496+ startedGate: (turn) => providerStartGates.get(turn.message.text),
490497 terminalGate: (turn) =>
491498 turn.message.text.startsWith("Delegated task") ||
492499 turn.message.text.startsWith("Delegated tasks")
@@ -2236,6 +2243,8 @@ describe("orchestrator MCP toolkit", () => { · 1743 unmodified lines
22362243 state: { archivedAt: null },
22372244 });
22382245
2246+ const blockedThreadStarted = yield* Deferred.make<void>();
2247+ providerStartGates.set(cancellationPrompt, blockedThreadStarted);
22392248 const blockedThreadCall = yield* invoke("create_threads", {
22402249 threads: [{ prompt: cancellationPrompt, title: "Organization blockers" }],
22412250 clientRequestId: "organize-blockers-create",
@@ -2243,9 +2252,8 @@ describe("orchestrator MCP toolkit", () => { · 1 unmodified line
22432252 const blockedThread = (yield* decodeCreateThreadsResult(
22442253 blockedThreadCall.structuredContent,
22452254 ).pipe(Effect.orDie)).threads[0]!;
2246− yield* waitForProjection(orchestrator, blockedThread.threadId, (projection) =>
2247− projection.runs.some((run) => run.status === "running"),
2248− );
2255+ yield* Deferred.await(blockedThreadStarted);
2256+ providerStartGates.delete(cancellationPrompt);
22492257 yield* invoke("t3_thread_send", {
22502258 threadId: blockedThread.threadId,
22512259 message: "Queue this behind the active run.",