Open History to see the last commit
1import * as Orchestrator from "../orchestration-v2/Orchestrator.ts";
2import * as ProjectionStore from "../orchestration-v2/ProjectionStore.ts";
3import * as ThreadManagementService from "../orchestration-v2/ThreadManagementService.ts";
4import { expect, it } from "@effect/vitest";
5import { NodeHttpServer } from "@effect/platform-node";
6import * as NodeServices from "@effect/platform-node/NodeServices";
7import {
8 EnvironmentId,
9 OrchestratorMcpEnvironmentTarget,
10 OrchestratorMcpFailure,
11 PreviewTabId,
12 ProviderInstanceId,
13 ProviderInteractionMode,
14 RuntimeMode,
15 ThreadId,
16} from "@t3tools/contracts";
17import * as Context from "effect/Context";
18import * as Deferred from "effect/Deferred";
19import * as Effect from "effect/Effect";
20import * as Layer from "effect/Layer";
21import * as Schema from "effect/Schema";
22import * as Stream from "effect/Stream";
23import { McpSchema, McpServer, Tool, Toolkit } from "effect/ai";
24import { HttpBody, HttpClient, HttpClientRequest, HttpRouter } from "effect/http";
25
26import * as ProjectService from "../project/ProjectService.ts";
27import * as PullRequestReviewGuideService from "../pullRequest/PullRequestReviewGuideService.ts";
28import * as ServerConfig from "../config.ts";
29import * as ServerSettings from "../serverSettings.ts";
30import { advertisedJsonSchema } from "./advertisedJsonSchema.ts";
31import * as McpHttpServer from "./McpHttpServer.ts";
32import * as McpToolAccess from "./McpToolAccess.ts";
33import * as McpToolAccessTestkit from "./McpToolAccess.testkit.ts";
34import * as McpInvocationContext from "./McpInvocationContext.ts";
35import * as McpSessionRegistry from "./McpSessionRegistry.ts";
36import * as OrchestratorMcpService from "./OrchestratorMcpService.ts";
37import * as PreviewAutomationBroker from "./PreviewAutomationBroker.ts";
38import { OrchestratorToolkit } from "./toolkits/orchestrator/tools.ts";
39import { PreviewToolkit } from "./toolkits/preview/tools.ts";
40import { ProjectToolkit } from "./toolkits/project/tools.ts";
41
42const environmentId = EnvironmentId.make("environment-mcp-test");
43const threadId = ThreadId.make("thread-mcp-test");
44const alternateTabId = PreviewTabId.make("tab-mcp-alternate");
45const decodeJsonText = Schema.decodeUnknownSync(Schema.fromJsonString(Schema.Unknown));
46const invocation = {
47 environmentId,
48 requestNamespace: "provider-session-mcp-test",
49 thread: {
50 threadId,
51 providerSessionId: "provider-session-mcp-test",
52 providerInstanceId: ProviderInstanceId.make("codex"),
53 },
54 client: undefined,
55 capabilities: new Set(["preview"] as const),
56 issuedAt: 1,
57};
58const client = McpSchema.McpServerClient.of({
59 clientId: 1,
60 clientCapabilities: {},
61 clientInfo: { name: "mcp-test", version: "1.0.0" },
62 protocolVersion: "2025-06-18",
63 initializePayload: {
64 protocolVersion: "2025-06-18",
65 capabilities: {},
66 clientInfo: { name: "mcp-test", version: "1.0.0" },
67 },
68 getClient: Effect.die("unused"),
69});
70const layerTest = McpHttpServer.layerPreviewToolkit.pipe(
71 Layer.provideMerge(McpServer.McpServer.layer),
72 Layer.provideMerge(McpToolAccessTestkit.liveThreadsLayer),
73 Layer.provideMerge(PreviewAutomationBroker.layer),
74 Layer.provideMerge(ServerConfig.layerTest(process.cwd(), { prefix: "t3-mcp-http-server-test-" })),
75 Layer.provideMerge(NodeServices.layer),
76);
77const layerPullRequestsTest = McpHttpServer.layerPullRequestsToolkit.pipe(
78 Layer.provideMerge(McpServer.McpServer.layer),
79 Layer.provideMerge(McpToolAccessTestkit.liveThreadsLayer),
80 Layer.provide(
81 Layer.mergeAll(
82 Layer.mock(ProjectService.ProjectService)({}),
83 Layer.mock(PullRequestReviewGuideService.PullRequestReviewGuideService)({}),
84 Layer.mock(Orchestrator.OrchestratorV2)({}),
85 Layer.mock(ProjectionStore.ProjectionStoreV2)({}),
86 NodeServices.layer,
87 ),
88 ),
89);
90
91const snapshotResult = {
92 url: "http://example.test/",
93 title: "Example",
94 loading: false,
95 visibleText: "Example",
96 interactiveElements: [],
97 accessibilityTree: {},
98 consoleEntries: [],
99 networkEntries: [],
100 actionTimeline: [],
101 screenshot: {
102 mimeType: "image/png",
103 data: Buffer.from("png").toString("base64"),
104 width: 10,
105 height: 5,
106 },
107};
108
109const serveSnapshots = (clientId: string, result: unknown) =>
110 Effect.gen(function* () {
111 const broker = yield* PreviewAutomationBroker.PreviewAutomationBroker;
112 const connected = yield* Deferred.make<void>();
113 const inputs: Array<unknown> = [];
114 const events = yield* broker.connect({ clientId, environmentId });
115 yield* Stream.runForEach(events, (event) => {
116 if (event.type === "connected") return Deferred.succeed(connected, undefined);
117 inputs.push(event.request.input);
118 return broker.respond({
119 clientId,
120 connectionId: event.connectionId,
121 requestId: event.request.requestId,
122 ok: true,
123 result,
124 });
125 }).pipe(Effect.forkScoped);
126 yield* Deferred.await(connected);
127 return inputs;
128 });
129
130const callTool = (name: string, args: Record<string, unknown>) =>
131 Effect.gen(function* () {
132 const server = yield* McpServer.McpServer;
133 return yield* server
134 .callTool({ name, arguments: args })
135 .pipe(
136 Effect.provideService(McpInvocationContext.McpInvocationContext, invocation),
137 Effect.provideService(McpSchema.McpServerClient, client),
138 );
139 });
140
141const callSnapshot = (args: Record<string, unknown>) => callTool("preview_snapshot", args);
142
143const layerRecordingTools = (calls: Array<unknown>) => {
144 const RecordingToolkit = Toolkit.make(
145 OrchestratorToolkit.tools.delegate_task,
146 OrchestratorToolkit.tools.t3_thread_read,
147 OrchestratorToolkit.tools.t3_thread_wait,
148 ProjectToolkit.tools.t3_project_update,
149 );
150 const record = McpToolAccess.reads((params: unknown) =>
151 Effect.sync(() => calls.push(params)).pipe(
152 Effect.andThen(
153 Effect.fail(new OrchestratorMcpFailure({ code: "thread_not_found", message: "Recorded." })),
154 ),
155 ),
156 );
157 return McpHttpServer.toolkitRegistration(
158 RecordingToolkit,
159 McpToolAccess.toLayer(RecordingToolkit, {
160 delegate_task: record,
161 t3_thread_read: record,
162 t3_thread_wait: record,
163 t3_project_update: record,
164 }),
165 ).pipe(
166 Layer.provideMerge(McpServer.McpServer.layer),
167 Layer.provide(
168 Layer.mergeAll(
169 McpToolAccessTestkit.liveThreadsLayer,
170 Layer.mock(OrchestratorMcpService.OrchestratorMcpService)({}),
171 Layer.mock(ProjectService.ProjectService)({}),
172 NodeServices.layer,
173 ),
174 ),
175 );
176};
177
178it.effect.each([{}, { includeImage: false }])(
179 "returns bounded structural preview snapshot failures %#",
180 (input) =>
181 Effect.scoped(
182 Effect.gen(function* () {
183 const server = yield* McpServer.McpServer;
184 const broker = yield* PreviewAutomationBroker.PreviewAutomationBroker;
185 const events = yield* broker.connect({
186 clientId: "mcp-failure-client",
187 environmentId,
188 });
189 yield* Stream.runForEach(events, (event) =>
190 event.type === "connected"
191 ? Effect.void
192 : broker.respond({
193 clientId: "mcp-failure-client",
194 connectionId: event.connectionId,
195 requestId: event.request.requestId,
196 ok: false,
197 error: {
198 _tag: "PreviewAutomationExecutionError",
199 message: "sensitive renderer failure",
200 detail: { consoleOutput: "sensitive browser output" },
201 },
202 }),
203 ).pipe(Effect.forkScoped);
204 yield* Effect.yieldNow;
205
206 const snapshot = yield* server
207 .callTool({ name: "preview_snapshot", arguments: input })
208 .pipe(
209 Effect.provideService(McpInvocationContext.McpInvocationContext, invocation),
210 Effect.provideService(McpSchema.McpServerClient, client),
211 );
212
213 const message = "Preview automation snapshot failed on client mcp-failure-client.";
214 expect(snapshot.isError).toBe(true);
215 expect(snapshot.content).toEqual([
216 { type: "text", text: `Preview snapshot failed: ${message}` },
217 ]);
218 expect(snapshot.structuredContent).toEqual({
219 error: {
220 _tag: "PreviewAutomationExecutionError",
221 operation: "snapshot",
222 failureCount: 1,
223 message,
224 },
225 });
226 }),
227 ).pipe(Effect.provide(layerTest)),
228);
229
230it.effect.each([
231 { mode: "default", input: {}, images: false },
232 { mode: "explicit image", input: { includeImage: true }, images: true },
233 { mode: "text only", input: { includeImage: false }, images: false },
234])("returns fresh $mode snapshots on repeated MCP calls", ({ input, images }) =>
235 Effect.scoped(
236 Effect.gen(function* () {
237 const server = yield* McpServer.McpServer;
238 const broker = yield* PreviewAutomationBroker.PreviewAutomationBroker;
239 const connected = yield* Deferred.make<void>();
240 const png =
241 "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jRZkAAAAASUVORK5CYII=";
242 const page = {
243 url: "http://example.test/",
244 loading: false,
245 visibleText: "Save your changes",
246 interactiveElements: [
247 {
248 tag: "button",
249 role: "button",
250 name: "Save",
251 selector: "#save",
252 x: 0,
253 y: 0,
254 width: 20,
255 height: 10,
256 },
257 ],
258 accessibilityTree: { role: "document", name: "Example" },
259 consoleEntries: [],
260 networkEntries: [],
261 actionTimeline: [],
262 };
263 const screenshot = { mimeType: "image/png", width: 1, height: 1 };
264 let requests = 0;
265 const events = yield* broker.connect({ clientId: "mcp-image-option-client", environmentId });
266 yield* Stream.runForEach(events, (event) => {
267 if (event.type === "connected") return Deferred.succeed(connected, undefined);
268 requests += 1;
269 expect(event.request).toMatchObject({
270 operation: "snapshot",
271 tabId: alternateTabId,
272 threadId,
273 });
274 expect(event.request.input).toEqual({});
275 return broker.respond({
276 clientId: "mcp-image-option-client",
277 connectionId: event.connectionId,
278 requestId: event.request.requestId,
279 ok: true,
280 result: {
281 ...page,
282 title: `Snapshot ${requests}`,
283 screenshot: { ...screenshot, data: png },
284 },
285 });
286 }).pipe(Effect.forkScoped);
287 yield* Deferred.await(connected);
288
289 for (const call of [1, 2, 3, 4, 5, 6]) {
290 const snapshot = yield* server
291 .callTool({
292 name: "preview_snapshot",
293 arguments: { ...input, tabId: alternateTabId },
294 })
295 .pipe(
296 Effect.provideService(McpInvocationContext.McpInvocationContext, invocation),
297 Effect.provideService(McpSchema.McpServerClient, client),
298 );
299 const metadata = { ...page, title: `Snapshot ${call}`, screenshot };
300 const { accessibilityTree: _tree, ...boundedMetadata } = metadata;
301 expect(snapshot.isError).toBe(false);
302 expect(snapshot.structuredContent).toEqual({
303 ...boundedMetadata,
304 omitted: ["accessibilityTree (use interactiveElements locators or preview_evaluate)"],
305 });
306 const [identity, text, ...rest] = snapshot.content;
307 expect(identity?.type === "text" ? decodeJsonText(identity.text) : null).toEqual({
308 url: page.url,
309 });
310 expect(text?.type === "text" ? decodeJsonText(text.text) : null).toEqual(boundedMetadata);
311 expect(rest).toEqual([
312 {
313 type: "text",
314 text: "Snapshot text was bounded. Omitted: accessibilityTree (use interactiveElements locators or preview_evaluate).",
315 },
316 ...(images
317 ? [
318 {
319 type: "image",
320 mimeType: "image/png",
321 data: new Uint8Array(Buffer.from(png, "base64")),
322 },
323 ]
324 : []),
325 ]);
326 }
327
328 const nextDefault = yield* server
329 .callTool({
330 name: "preview_snapshot",
331 arguments: { tabId: alternateTabId },
332 })
333 .pipe(
334 Effect.provideService(McpInvocationContext.McpInvocationContext, invocation),
335 Effect.provideService(McpSchema.McpServerClient, client),
336 );
337 expect(nextDefault.content.map((content) => content.type)).toEqual(["text", "text", "text"]);
338 expect(nextDefault.structuredContent).toMatchObject({ title: "Snapshot 7", screenshot });
339 expect(nextDefault.structuredContent).not.toHaveProperty("accessibilityTree");
340 expect(requests).toBe(7);
341 }),
342 ).pipe(Effect.provide(layerTest)),
343);
344
345it.effect("refuses preview tools to a client outside a thread before they run", () =>
346 Effect.gen(function* () {
347 const server = yield* McpServer.McpServer;
348 const readOnly = {
349 ...invocation,
350 thread: undefined,
351 requestNamespace: "client:session-1",
352 client: { sessionId: "session-1", label: "Claude Code", access: "read-only" as const },
353 };
354 const click = yield* server
355 .callTool({ name: "preview_act", arguments: { action: "click", locator: "text=Send" } })
356 .pipe(
357 Effect.provideService(McpInvocationContext.McpInvocationContext, readOnly),
358 Effect.provideService(McpSchema.McpServerClient, client),
359 );
360 expect(click.isError).toBe(true);
361 expect(click.content).toEqual([
362 { type: "text", text: expect.stringContaining("needs an agent running inside T3 Code") },
363 ]);
364 }).pipe(Effect.provide(layerTest)),
365);
366
367it.effect("advertises the compact input schema for every registered tool", () =>
368 Effect.gen(function* () {
369 const server = yield* McpServer.McpServer;
370 const tools: Record<string, Tool.Any> = PreviewToolkit.tools;
371
372 expect(server.tools.length).toBe(Object.keys(tools).length);
373 for (const { tool } of server.tools) {
374 expect(tool.inputSchema, tool.name).toEqual(advertisedJsonSchema(tools[tool.name]!));
375 }
376 }).pipe(Effect.provide(layerTest)),
377);
378
379it.effect("checks each preview_act action against that action's own input", () =>
380 Effect.scoped(
381 Effect.gen(function* () {
382 const inputs = yield* serveSnapshots("mcp-act-client", {});
383
384 const missingKey = yield* callTool("preview_act", { action: "press" });
385 expect(missingKey.isError).toBe(true);
386 expect(inputs).toEqual([]);
387
388 const click = yield* callTool("preview_act", {
389 action: "click",
390 locator: "text=Send",
391 key: "Enter",
392 });
393 expect(click.isError).toBe(false);
394 expect(inputs[0]).toEqual({ locator: "text=Send" });
395
396 yield* callTool("preview_act", { action: "type", selector: "#name", text: "Ada" });
397 expect(inputs.at(-2)).toEqual({ selector: "#name", text: "Ada" });
398 }),
399 ).pipe(Effect.provide(layerTest)),
400);
401
402it.effect("decodes null optional arguments the way it decodes omitted ones", () => {
403 const calls: Array<unknown> = [];
404 return Effect.gen(function* () {
405 const thread = { threadId: "thread-null-arguments" };
406 yield* callTool("t3_thread_read", thread);
407 yield* callTool("t3_thread_read", { ...thread, afterPosition: null, view: null });
408 yield* callTool("delegate_task", { task: "Inspect", target: {} });
409 yield* callTool("delegate_task", { task: "Inspect", title: null, target: { model: null } });
410 yield* callTool("t3_project_update", { projectId: "project-1", projectIcon: null });
411
412 expect(calls).toHaveLength(5);
413 expect(calls[1]).toEqual(calls[0]);
414 expect(calls[3]).toEqual(calls[2]);
415 expect(calls[4]).toStrictEqual({ projectId: "project-1", projectIcon: null });
416 }).pipe(Effect.provide(layerRecordingTools(calls)));
417});
418
419it.effect(
420 "clamps t3_thread_read page sizes above their maximum instead of rejecting the call",
421 () => {
422 const calls: Array<unknown> = [];
423 return Effect.gen(function* () {
424 const thread = { threadId: "thread-clamped-arguments" };
425 // Codex never shows the model these bounds, so an over-large page must still read.
426 yield* callTool("t3_thread_read", {
427 ...thread,
428 limit: 150,
429 runLimit: 80,
430 maxCharsPerItem: 60_000,
431 });
432 yield* callTool("t3_thread_read", {
433 ...thread,
434 limit: 100,
435 runLimit: 50,
436 maxCharsPerItem: 50_000,
437 });
438 yield* callTool("t3_thread_read", { ...thread, limit: 7, runLimit: 1, maxCharsPerItem: 1 });
439
440 expect(calls).toEqual([
441 { ...thread, limit: 100, runLimit: 50, maxCharsPerItem: 50_000 },
442 { ...thread, limit: 100, runLimit: 50, maxCharsPerItem: 50_000 },
443 { ...thread, limit: 7, runLimit: 1, maxCharsPerItem: 1 },
444 ]);
445 }).pipe(Effect.provide(layerRecordingTools(calls)));
446 },
447);
448
449it.effect.each(["limit", "runLimit", "maxCharsPerItem"])(
450 "still rejects a t3_thread_read %s below its minimum",
451 (field) => {
452 const calls: Array<unknown> = [];
453 return Effect.gen(function* () {
454 // Zero is a different request than one item, so it fails rather than answering another question.
455 const rejected = yield* callTool("t3_thread_read", {
456 threadId: "thread-below-minimum",
457 [field]: 0,
458 }).pipe(Effect.flip);
459
460 expect(String(rejected)).toContain("greater than or equal to 1");
461 expect(calls).toEqual([]);
462 }).pipe(Effect.provide(layerRecordingTools(calls)));
463 },
464);
465
466it("keeps cross-tool routing out of the delegate_task description", () => {
467 const description = OrchestratorToolkit.tools.delegate_task.description ?? "";
468 expect(description).toContain("Start one child agent with only `task`");
469 // Review rounds, follow-ups, and polling are routed in the system text.
470 expect(description).not.toContain("t3_thread_send");
471 expect(description).not.toContain("Do not poll");
472 expect(description).not.toContain("Prefer native");
473});
474
475it.effect(
476 "registers the pull request toolkit and surfaces a missing capability as a tool error",
477 () =>
478 Effect.gen(function* () {
479 const server = yield* McpServer.McpServer;
480 const names = server.tools.map(({ tool }) => tool.name);
481 expect(names).toEqual(
482 expect.arrayContaining([
483 "link_pull_request",
484 "unlink_pull_request",
485 "list_thread_pull_requests",
486 ]),
487 );
488 const linkTool = server.tools.find(({ tool }) => tool.name === "link_pull_request");
489 expect(linkTool?.tool.annotations?.idempotentHint).toBe(true);
490 expect(linkTool?.tool.annotations?.openWorldHint).toBe(false);
491 expect(linkTool?.tool.description).toContain("Link a PR to this thread");
492 expect(linkTool?.tool.description).toContain("settles the thread on merge");
493
494 const denied = yield* server
495 .callTool({ name: "list_thread_pull_requests", arguments: {} })
496 .pipe(
497 Effect.provideService(McpInvocationContext.McpInvocationContext, invocation),
498 Effect.provideService(McpSchema.McpServerClient, client),
499 );
500 expect(denied.isError).toBe(true);
501 expect(denied.content).toEqual([
502 { type: "text", text: "MCP credential does not grant the pull-requests capability." },
503 ]);
504 }).pipe(Effect.provide(layerPullRequestsTest)),
505);
506
507it.effect("bounds large ARIA trees without dropping every server locator", () =>
508 Effect.scoped(
509 Effect.gen(function* () {
510 const accessibilityTree = Array.from(
511 { length: 2_000 },
512 (_, index) => `- button "删除 ${index}" [ref=t3-snapshot-e${index}]`,
513 ).join("\n");
514 yield* serveSnapshots("mcp-large-server-refs", { ...snapshotResult, accessibilityTree });
515 const result = yield* callSnapshot({ includeImage: false });
516 expect(result.isError).toBe(false);
517 const metadata = result.structuredContent as { accessibilityTree: string };
518 expect(metadata.accessibilityTree).toContain("[ref=t3-snapshot-e0]");
519 expect(metadata.accessibilityTree.length).toBeLessThan(accessibilityTree.length);
520 const body = result.content[1];
521 expect(Buffer.byteLength(body?.type === "text" ? body.text : "", "utf8")).toBeLessThanOrEqual(
522 McpHttpServer.MAX_SNAPSHOT_TEXT_BYTES,
523 );
524 }),
525 ).pipe(Effect.provide(layerTest)),
526);
527
528it.effect("keeps the snapshot text under the agent's output ceiling", () =>
529 Effect.scoped(
530 Effect.gen(function* () {
531 const pageText = "/Users/theo/Code/project\nClaude, Codex · 79 threads\n".repeat(600);
532 const element = (name: string, index: number) => ({
533 tag: "div",
534 role: "presentation",
535 name,
536 selector: `div:nth-of-type(${index})`,
537 x: 0,
538 y: 0,
539 width: 10,
540 height: 10,
541 });
542 const oversized = {
543 ...snapshotResult,
544 visibleText: pageText,
545 interactiveElements: [
546 element(pageText, 1),
547 element(pageText, 2),
548 element(pageText, 3),
549 element("Continue", 4),
550 ],
551 accessibilityTree: { nodes: Array.from({ length: 2_000 }, (_, i) => ({ nodeId: `${i}` })) },
552 consoleEntries: Array.from({ length: 100 }, (_, i) => ({
553 level: "log",
554 text: `entry ${i}`,
555 timestamp: "t",
556 })),
557 };
558 yield* serveSnapshots("mcp-bounded-client", oversized);
559
560 const snapshot = yield* callSnapshot({ includeImage: false });
561
562 expect(snapshot.isError).toBe(false);
563 const [identity, text, notice] = snapshot.content;
564 expect(identity?.type === "text" ? decodeJsonText(identity.text) : null).toEqual({
565 url: oversized.url,
566 });
567 expect(text?.type).toBe("text");
568 const body = text?.type === "text" ? text.text : "";
569 expect(Buffer.byteLength(body, "utf8")).toBeLessThanOrEqual(
570 McpHttpServer.MAX_SNAPSHOT_TEXT_BYTES,
571 );
572 const parsed = decodeJsonText(body) as {
573 readonly accessibilityTree?: unknown;
574 readonly visibleText: string;
575 readonly interactiveElements: ReadonlyArray<{ readonly name: string }>;
576 readonly consoleEntries: ReadonlyArray<{ readonly text: string }>;
577 };
578 expect(parsed.accessibilityTree).toBeUndefined();
579 expect(parsed.visibleText.length).toBeLessThanOrEqual(8_001);
580 expect(parsed.interactiveElements).toHaveLength(4);
581 expect(parsed.interactiveElements[0]?.name.length).toBeLessThanOrEqual(201);
582 expect(parsed.interactiveElements[3]?.name).toBe("Continue");
583 expect(parsed.consoleEntries).toHaveLength(40);
584 expect(parsed.consoleEntries[0]?.text).toBe("entry 60");
585 expect(notice?.type === "text" ? notice.text : "").toContain("accessibilityTree");
586 expect(notice?.type === "text" ? notice.text : "").toContain("60 older console entries");
587 expect(snapshot.structuredContent).toEqual({
588 ...parsed,
589 omitted: expect.arrayContaining(["60 older console entries"]),
590 });
591 }),
592 ).pipe(Effect.provide(layerTest)),
593);
594
595// regression: #10501 keep preview snapshots usable by the agent
596it.effect("bounds the snapshot text even when nothing but logs and the title are large", () =>
597 Effect.scoped(
598 Effect.gen(function* () {
599 const oversized = {
600 ...snapshotResult,
601 title: "t".repeat(70_000),
602 interactiveElements: [],
603 consoleEntries: [{ level: "log", text: "x".repeat(70_000), timestamp: "t" }],
604 };
605 yield* serveSnapshots("mcp-bounded-logs-client", oversized);
606
607 const snapshot = yield* callSnapshot({ includeImage: false });
608
609 const [, text] = snapshot.content;
610 const body = text?.type === "text" ? text.text : "";
611 expect(Buffer.byteLength(body, "utf8")).toBeLessThanOrEqual(
612 McpHttpServer.MAX_SNAPSHOT_TEXT_BYTES,
613 );
614 const parsed = decodeJsonText(body) as {
615 readonly title: string;
616 readonly consoleEntries: ReadonlyArray<{ readonly text: string }>;
617 };
618 expect(parsed.title.length).toBe(2_049);
619 expect(parsed.consoleEntries[0]?.text.length).toBe(501);
620 const notice = snapshot.content[2];
621 const noticeText = notice?.type === "text" ? notice.text : "";
622 expect(noticeText).toContain("url or title after 2048 characters");
623 expect(noticeText).toContain("console entries text after 500 characters");
624 }),
625 ).pipe(Effect.provide(layerTest)),
626);
627
628// regression: #13558 preview snapshots overflowed the agent's tool output
629it.effect("bounds page text made of wide characters before dropping locators", () =>
630 Effect.scoped(
631 Effect.gen(function* () {
632 yield* serveSnapshots("mcp-wide-text-client", {
633 ...snapshotResult,
634 visibleText: "界".repeat(9_000),
635 interactiveElements: Array.from({ length: 20 }, (_, i) => ({
636 tag: "button",
637 role: "button",
638 name: `Button ${i}`,
639 selector: `#button-${i}`,
640 x: 0,
641 y: 0,
642 width: 10,
643 height: 10,
644 })),
645 });
646
647 const snapshot = yield* callSnapshot({ includeImage: false });
648
649 const [, text, notice] = snapshot.content;
650 const body = text?.type === "text" ? text.text : "";
651 expect(Buffer.byteLength(body, "utf8")).toBeLessThanOrEqual(
652 McpHttpServer.MAX_SNAPSHOT_TEXT_BYTES,
653 );
654 const parsed = decodeJsonText(body) as {
655 readonly visibleText: string;
656 readonly interactiveElements: ReadonlyArray<unknown>;
657 };
658 expect(parsed.visibleText).toMatch(/^界+…$/);
659 expect(parsed.interactiveElements).toHaveLength(20);
660 expect(notice?.type === "text" ? notice.text : "").toContain(
661 "visibleText after 4000 characters",
662 );
663 }),
664 ).pipe(Effect.provide(layerTest)),
665);
666
667it.effect("terminates HTTP MCP sessions with DELETE", () =>
668 Effect.scoped(
669 Effect.gen(function* () {
670 const token = "providerTokenWithoutDots";
671 const scope: McpInvocationContext.McpInvocationScope = {
672 environmentId,
673 requestNamespace: "provider-session",
674 thread: {
675 threadId: ThreadId.make("thread-provider"),
676 providerSessionId: "provider-session",
677 providerInstanceId: ProviderInstanceId.make("codex"),
678 },
679 client: undefined,
680 capabilities: new Set(["orchestration"]),
681 issuedAt: 1,
682 };
683 const layerServer = McpHttpServer.layerMcpTransport.pipe(
684 Layer.provide(ServerSettings.layerTest()),
685 Layer.provide(
686 Layer.mock(McpSessionRegistry.McpSessionRegistry)({
687 resolve: (presented) =>
688 Effect.succeed(
689 presented === token
690 ? (scope as McpInvocationContext.McpThreadInvocationScope)
691 : undefined,
692 ),
693 }),
694 ),
695 );
696 yield* HttpRouter.serve(layerServer, {
697 disableListenLog: true,
698 disableLogger: true,
699 }).pipe(Layer.build);
700 const httpClient = (yield* HttpClient.HttpClient).pipe(
701 HttpClient.mapRequest(HttpClientRequest.bearerToken(token)),
702 );
703
704 const initializeResponse = yield* httpClient.post("/mcp", {
705 headers: { accept: "application/json, text/event-stream" },
706 body: HttpBody.text(
707 `{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"mcp-test","version":"1.0.0"}}}`,
708 "application/json",
709 ),
710 });
711 const sessionId = initializeResponse.headers["mcp-session-id"];
712 expect(initializeResponse.status).toBe(200);
713 expect(sessionId).not.toBeNull();
714
715 const missingSessionResponse = yield* httpClient.del("/mcp");
716 expect(missingSessionResponse.status).toBe(400);
717
718 const unknownSessionResponse = yield* httpClient.del("/mcp", {
719 headers: { "mcp-session-id": "unknown-session" },
720 });
721 expect(unknownSessionResponse.status).toBe(404);
722
723 const terminateResponse = yield* httpClient.del("/mcp", {
724 headers: { "mcp-session-id": sessionId! },
725 });
726 expect(terminateResponse.status).toBe(204);
727
728 const reusedSessionResponse = yield* httpClient.post("/mcp", {
729 headers: {
730 accept: "application/json, text/event-stream",
731 "mcp-session-id": sessionId!,
732 },
733 body: HttpBody.text(
734 `{"jsonrpc":"2.0","id":2,"method":"ping","params":{}}`,
735 "application/json",
736 ),
737 });
738 expect(reusedSessionResponse.status).toBe(404);
739 }),
740 ).pipe(Effect.provide(NodeHttpServer.layerTest)),
741);
742
743it.effect("admits provider and OAuth client credentials and points only clients at OAuth", () =>
744 Effect.scoped(
745 Effect.gen(function* () {
746 const providerToken = "providerTokenWithoutDots";
747 const clientToken = "client-payload.client-signature";
748 const providerScope: McpInvocationContext.McpInvocationScope = {
749 environmentId,
750 requestNamespace: "provider-session",
751 thread: {
752 threadId: ThreadId.make("thread-provider"),
753 providerSessionId: "provider-session",
754 providerInstanceId: ProviderInstanceId.make("codex"),
755 },
756 client: undefined,
757 capabilities: new Set(["orchestration"]),
758 issuedAt: 1,
759 };
760 const clientScope: McpInvocationContext.McpInvocationScope = {
761 environmentId,
762 requestNamespace: "client:session-1",
763 thread: undefined,
764 client: { sessionId: "session-1", label: "Claude Code", access: "auto" },
765 capabilities: new Set(["orchestration"]),
766 issuedAt: 1,
767 };
768 const seen: Array<McpInvocationContext.McpInvocationScope> = [];
769 const ProbeToolkit = Toolkit.make(
770 Tool.make("probe", {
771 description: "Reports the caller.",
772 success: Schema.Struct({ ok: Schema.Boolean }),
773 failure: OrchestratorMcpFailure,
774 failureMode: "return",
775 dependencies: [McpInvocationContext.McpInvocationContext],
776 }),
777 );
778 const serverLayer = McpHttpServer.toolkitRegistration(
779 ProbeToolkit,
780 McpToolAccess.toLayer(ProbeToolkit, {
781 probe: McpToolAccess.reads(() =>
782 McpInvocationContext.McpInvocationContext.pipe(
783 Effect.tap((scope) => Effect.sync(() => seen.push(scope))),
784 Effect.as({ ok: true }),
785 ),
786 ),
787 }),
788 ).pipe(
789 Layer.provideMerge(
790 McpHttpServer.layerMcpTransport.pipe(Layer.provide(ServerSettings.layerTest())),
791 ),
792 Layer.provide(
793 Layer.mock(McpSessionRegistry.McpSessionRegistry)({
794 resolve: (token) =>
795 Effect.succeed(
796 token === providerToken
797 ? (providerScope as McpInvocationContext.McpThreadInvocationScope)
798 : undefined,
799 ),
800 }),
801 ),
802 Layer.provide(
803 Layer.succeed(McpHttpServer.McpClientAuthenticator, {
804 authenticate: (request) =>
805 Effect.succeed(
806 request.headers.authorization === `Bearer ${clientToken}` ? clientScope : undefined,
807 ),
808 }),
809 ),
810 );
811 yield* HttpRouter.serve(serverLayer, { disableListenLog: true, disableLogger: true }).pipe(
812 Layer.build,
813 );
814 const httpClient = yield* HttpClient.HttpClient;
815 const call = (token: string | undefined) =>
816 Effect.gen(function* () {
817 const headers = {
818 accept: "application/json, text/event-stream",
819 ...(token === undefined ? {} : { authorization: `Bearer ${token}` }),
820 };
821 const initialize = yield* httpClient.post("/mcp", {
822 headers,
823 body: HttpBody.text(
824 `{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"probe","version":"1.0.0"}}}`,
825 "application/json",
826 ),
827 });
828 if (initialize.status !== 200) return initialize;
829 return yield* httpClient.post("/mcp", {
830 headers: {
831 ...headers,
832 "mcp-session-id": initialize.headers["mcp-session-id"]!,
833 "mcp-protocol-version": "2025-06-18",
834 },
835 body: HttpBody.text(
836 `{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"probe","arguments":{}}}`,
837 "application/json",
838 ),
839 });
840 });
841
842 expect((yield* call(providerToken)).status).toBe(200);
843 expect((yield* call(clientToken)).status).toBe(200);
844 expect(seen.map((scope) => scope.requestNamespace)).toEqual([
845 "provider-session",
846 "client:session-1",
847 ]);
848
849 const missing = yield* call(undefined);
850 expect(missing.status).toBe(401);
851 expect(missing.headers["www-authenticate"]).toMatch(
852 /^Bearer resource_metadata="http:\/\/[^"]+\/\.well-known\/oauth-protected-resource\/mcp"$/,
853 );
854
855 const expiredClient = yield* call("stale-payload.stale-signature");
856 expect(expiredClient.headers["www-authenticate"]).toContain("resource_metadata=");
857 expect(expiredClient.headers["www-authenticate"]).toContain('error="invalid_token"');
858
859 const deadProvider = yield* call("deadProviderToken");
860 expect(deadProvider.status).toBe(401);
861 expect(deadProvider.headers["www-authenticate"]).toBe('Bearer error="invalid_token"');
862 }),
863 ).pipe(Effect.provide(NodeHttpServer.layerTest)),
864);
865
866it.effect("hides tools for links and refuses another environment while the beta is off", () =>
867 Effect.scoped(
868 Effect.gen(function* () {
869 const token = "linksToken";
870 const scope: McpInvocationContext.McpThreadInvocationScope = {
871 environmentId,
872 requestNamespace: token,
873 thread: {
874 threadId: ThreadId.make("thread-links"),
875 providerSessionId: token,
876 providerInstanceId: ProviderInstanceId.make("codex"),
877 },
878 client: undefined,
879 capabilities: new Set(["orchestration"]),
880 issuedAt: 1,
881 };
882 const LinksToolkit = Toolkit.make(
883 Tool.make("links", {
884 description: "Lists links.",
885 success: Schema.Struct({ links: Schema.Number }),
886 failure: OrchestratorMcpFailure,
887 failureMode: "return",
888 }).annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenWhileLinksOff),
889 Tool.make("where", {
890 description: "Says where it ran.",
891 parameters: Schema.Struct({ environmentId: OrchestratorMcpEnvironmentTarget }),
892 success: Schema.Struct({ ranIn: Schema.String }),
893 failure: OrchestratorMcpFailure,
894 failureMode: "return",
895 }),
896 );
897 const settingsContext = yield* Layer.build(ServerSettings.layerTest());
898 const settings = Context.get(settingsContext, ServerSettings.ServerSettingsService);
899 const serverLayer = McpHttpServer.toolkitRegistration(
900 LinksToolkit,
901 McpToolAccess.toLayer(LinksToolkit, {
902 links: McpToolAccess.reads(() => Effect.succeed({ links: 0 })),
903 where: McpToolAccess.reads(() => Effect.succeed({ ranIn: "here" })),
904 }),
905 ).pipe(
906 Layer.provideMerge(
907 McpHttpServer.layerMcpTransport.pipe(
908 Layer.provide(Layer.succeedContext(settingsContext)),
909 ),
910 ),
911 Layer.provide(McpToolAccessTestkit.liveThreadsLayer),
912 Layer.provide(
913 Layer.mock(McpSessionRegistry.McpSessionRegistry)({
914 resolve: (presented) => Effect.succeed(presented === token ? scope : undefined),
915 }),
916 ),
917 );
918 yield* HttpRouter.serve(serverLayer, { disableListenLog: true, disableLogger: true }).pipe(
919 Layer.build,
920 );
921 const httpClient = yield* HttpClient.HttpClient;
922 const headers = {
923 accept: "application/json, text/event-stream",
924 authorization: `Bearer ${token}`,
925 };
926 const initialize = yield* httpClient.post("/mcp", {
927 headers,
928 body: HttpBody.text(
929 `{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"probe","version":"1.0.0"}}}`,
930 "application/json",
931 ),
932 });
933 const rpc = (method: string, params: object) =>
934 httpClient
935 .post("/mcp", {
936 headers: {
937 ...headers,
938 "mcp-session-id": initialize.headers["mcp-session-id"]!,
939 "mcp-protocol-version": "2025-06-18",
940 },
941 body: HttpBody.text(
942 JSON.stringify({ jsonrpc: "2.0", id: 2, method, params }),
943 "application/json",
944 ),
945 })
946 .pipe(Effect.flatMap((response) => response.json));
947 const listed = () =>
948 rpc("tools/list", {}).pipe(
949 Effect.map((body) =>
950 (body as { result: { tools: ReadonlyArray<{ name: string }> } }).result.tools.map(
951 (tool) => tool.name,
952 ),
953 ),
954 );
955 const ranIn = (where: EnvironmentId) =>
956 rpc("tools/call", { name: "where", arguments: { environmentId: where } }).pipe(
957 Effect.map(
958 (body) =>
959 (
960 body as {
961 result: {
962 isError?: boolean;
963 structuredContent?: unknown;
964 content: ReadonlyArray<{ text: string }>;
965 };
966 }
967 ).result,
968 ),
969 );
970 const elsewhere = EnvironmentId.make("environment-elsewhere");
971
972 expect(yield* listed()).toEqual(["where"]);
973 expect(yield* ranIn(elsewhere)).toMatchObject({
974 isError: true,
975 content: [{ text: expect.stringContaining("Linked environments is off on this machine") }],
976 });
977 expect((yield* ranIn(environmentId)).structuredContent).toEqual({ ranIn: "here" });
978
979 yield* settings.updateSettings({ linkedEnvironmentsEnabled: true });
980 expect(yield* listed()).toEqual(["links", "where"]);
981 // On, the call goes on to the forwarding, which this server lacks.
982 expect(yield* ranIn(elsewhere)).toMatchObject({
983 isError: true,
984 content: [{ text: expect.stringContaining("cannot reach linked environments") }],
985 });
986 }),
987 ).pipe(Effect.provide(NodeHttpServer.layerTest)),
988);
989
990it.effect("lists pull request watch tools only to threads that are not delegated children", () =>
991 Effect.scoped(
992 Effect.gen(function* () {
993 const scopeFor = (
994 token: string,
995 subagent: boolean,
996 ): McpInvocationContext.McpThreadInvocationScope => ({
997 environmentId,
998 requestNamespace: token,
999 thread: {
1000 threadId: ThreadId.make(`thread-${token}`),
1001 providerSessionId: token,
1002 providerInstanceId: ProviderInstanceId.make("codex"),
1003 subagent,
1004 },
1005 client: undefined,
1006 capabilities: new Set(["pull-requests"]),
1007 issuedAt: 1,
1008 });
1009 const scopes = new Map([
1010 ["parentToken", scopeFor("parentToken", false)],
1011 ["childToken", scopeFor("childToken", true)],
1012 ]);
1013 const serverLayer = McpHttpServer.layerPullRequestsToolkit.pipe(
1014 Layer.provideMerge(
1015 McpHttpServer.layerMcpTransport.pipe(Layer.provide(ServerSettings.layerTest())),
1016 ),
1017 Layer.provide(
1018 Layer.mock(McpSessionRegistry.McpSessionRegistry)({
1019 resolve: (token) => Effect.succeed(scopes.get(token)),
1020 }),
1021 ),
1022 Layer.provide(
1023 Layer.mergeAll(
1024 McpToolAccessTestkit.liveThreadsLayer,
1025 Layer.mock(ProjectService.ProjectService)({}),
1026 Layer.mock(PullRequestReviewGuideService.PullRequestReviewGuideService)({}),
1027 Layer.mock(Orchestrator.OrchestratorV2)({}),
1028 Layer.mock(ProjectionStore.ProjectionStoreV2)({}),
1029 NodeServices.layer,
1030 ),
1031 ),
1032 );
1033 yield* HttpRouter.serve(serverLayer, { disableListenLog: true, disableLogger: true }).pipe(
1034 Layer.build,
1035 );
1036 const httpClient = yield* HttpClient.HttpClient;
1037 const listedTools = (token: string) =>
1038 Effect.gen(function* () {
1039 const headers = {
1040 accept: "application/json, text/event-stream",
1041 authorization: `Bearer ${token}`,
1042 };
1043 const initialize = yield* httpClient.post("/mcp", {
1044 headers,
1045 body: HttpBody.text(
1046 `{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"probe","version":"1.0.0"}}}`,
1047 "application/json",
1048 ),
1049 });
1050 const listed = yield* httpClient.post("/mcp", {
1051 headers: {
1052 ...headers,
1053 "mcp-session-id": initialize.headers["mcp-session-id"]!,
1054 "mcp-protocol-version": "2025-06-18",
1055 },
1056 body: HttpBody.text(
1057 `{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}`,
1058 "application/json",
1059 ),
1060 });
1061 const body = (yield* listed.json) as {
1062 readonly result: { readonly tools: ReadonlyArray<{ readonly name: string }> };
1063 };
1064 return body.result.tools.map((tool) => tool.name);
1065 });
1066
1067 const parentTools = yield* listedTools("parentToken");
1068 const childTools = yield* listedTools("childToken");
1069 expect(parentTools).toEqual(
1070 expect.arrayContaining(["link_pull_request", "watch_pull_request", "unwatch_pull_request"]),
1071 );
1072 expect(childTools).toContain("link_pull_request");
1073 expect(childTools).not.toContain("watch_pull_request");
1074 expect(childTools).not.toContain("unwatch_pull_request");
1075 }),
1076 ).pipe(Effect.provide(NodeHttpServer.layerTest)),
1077);
1078
1079it.effect(
1080 "narrows an OAuth client's modes to the T3-Mode-Limit it sends, and never widens them",
1081 () =>
1082 Effect.scoped(
1083 Effect.gen(function* () {
1084 const clientToken = "client-payload.client-signature";
1085 const clientScope: McpInvocationContext.McpInvocationScope = {
1086 environmentId,
1087 requestNamespace: "client:linked",
1088 thread: undefined,
1089 client: { sessionId: "linked", label: "T3 Code · laptop", access: "auto" },
1090 capabilities: new Set(["orchestration"]),
1091 issuedAt: 1,
1092 };
1093 // Starts a thread at the modes the gate hands it, so the outcome is those modes.
1094 const StartsToolkit = Toolkit.make(
1095 Tool.make("starts", {
1096 description: "Reports the modes a started thread would run with.",
1097 parameters: Schema.Struct({
1098 runtimeMode: Schema.optional(RuntimeMode),
1099 interactionMode: Schema.optional(ProviderInteractionMode),
1100 }),
1101 success: Schema.Struct({ modes: Schema.String }),
1102 failure: OrchestratorMcpFailure,
1103 failureMode: "return",
1104 dependencies: [
1105 McpInvocationContext.McpInvocationContext,
1106 ThreadManagementService.ThreadManagementService,
1107 ],
1108 }),
1109 );
1110 const serverLayer = McpHttpServer.toolkitRegistration(
1111 StartsToolkit,
1112 McpToolAccess.toLayer(StartsToolkit, {
1113 starts: McpToolAccess.startsThreads(
1114 (input) => input,
1115 (_, modes) =>
1116 Effect.succeed({ modes: `${modes.runtimeMode}/${modes.interactionMode}` }),
1117 "stamped",
1118 ),
1119 }),
1120 ).pipe(
1121 Layer.provideMerge(
1122 McpHttpServer.layerMcpTransport.pipe(Layer.provide(ServerSettings.layerTest())),
1123 ),
1124 Layer.provide(McpToolAccessTestkit.liveThreadsLayer),
1125 Layer.provide(
1126 Layer.mock(McpSessionRegistry.McpSessionRegistry)({
1127 // @effect-diagnostics-next-line effectSucceedWithVoid:off - This optional result requires undefined, not the wider void type.
1128 resolve: () => Effect.succeed(undefined),
1129 }),
1130 ),
1131 Layer.provide(
1132 Layer.succeed(McpHttpServer.McpClientAuthenticator, {
1133 authenticate: (request) =>
1134 Effect.succeed(
1135 request.headers.authorization === `Bearer ${clientToken}`
1136 ? clientScope
1137 : undefined,
1138 ),
1139 }),
1140 ),
1141 );
1142 yield* HttpRouter.serve(serverLayer, { disableListenLog: true, disableLogger: true }).pipe(
1143 Layer.build,
1144 );
1145 const httpClient = yield* HttpClient.HttpClient;
1146 const decodeOutcome = Schema.decodeUnknownEffect(
1147 Schema.fromJsonString(
1148 Schema.Struct({
1149 result: Schema.Struct({
1150 content: Schema.Array(Schema.Struct({ text: Schema.String })),
1151 }),
1152 }),
1153 ),
1154 );
1155 const decodeText = Schema.decodeUnknownEffect(
1156 Schema.fromJsonString(
1157 Schema.Union([
1158 Schema.Struct({ modes: Schema.String }),
1159 Schema.Struct({ code: Schema.String }),
1160 ]),
1161 ),
1162 );
1163 /** Starts a thread as the client, with `limit` as T3-Mode-Limit; the HTTP status or the outcome. */
1164 const start = (limit: string | undefined, args: Record<string, string> = {}) =>
1165 Effect.gen(function* () {
1166 const headers = {
1167 accept: "application/json, text/event-stream",
1168 authorization: `Bearer ${clientToken}`,
1169 ...(limit === undefined ? {} : { "t3-mode-limit": limit }),
1170 };
1171 const initialize = yield* httpClient.post("/mcp", {
1172 headers,
1173 body: HttpBody.text(
1174 `{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"probe","version":"1.0.0"}}}`,
1175 "application/json",
1176 ),
1177 });
1178 if (initialize.status !== 200) return initialize.status;
1179 const response = yield* httpClient.post("/mcp", {
1180 headers: {
1181 ...headers,
1182 "mcp-session-id": initialize.headers["mcp-session-id"]!,
1183 "mcp-protocol-version": "2025-06-18",
1184 },
1185 body: HttpBody.text(
1186 JSON.stringify({
1187 jsonrpc: "2.0",
1188 id: 2,
1189 method: "tools/call",
1190 params: { name: "starts", arguments: args },
1191 }),
1192 "application/json",
1193 ),
1194 });
1195 const body = yield* decodeOutcome(yield* response.text);
1196 const outcome = yield* decodeText(
1197 body.result.content.map((part) => part.text).join(""),
1198 );
1199 return "code" in outcome ? outcome.code : outcome.modes;
1200 });
1201
1202 // Approved for auto: without the header the client keeps its ceiling.
1203 expect(yield* start(undefined)).toBe("auto/default");
1204 // The header narrows both modes, and asking above it is refused.
1205 expect(yield* start("approval-required/plan")).toBe("approval-required/plan");
1206 expect(yield* start("approval-required/plan", { runtimeMode: "auto" })).toBe(
1207 "runtime_mode_escalation_denied",
1208 );
1209 expect(yield* start("auto-accept-edits/plan", { interactionMode: "default" })).toBe(
1210 "interaction_mode_escalation_denied",
1211 );
1212 // A broader header changes nothing: the approved ceiling still holds.
1213 expect(yield* start("full-access/default")).toBe("auto/default");
1214 expect(yield* start("full-access/default", { runtimeMode: "full-access" })).toBe(
1215 "runtime_mode_escalation_denied",
1216 );
1217 // A malformed header is refused before anything runs.
1218 expect(yield* start("auto")).toBe(400);
1219 expect(yield* start("auto/default/extra")).toBe(400);
1220 expect(yield* start("root/default")).toBe(400);
1221 }),
1222 ).pipe(Effect.provide(NodeHttpServer.layerTest)),
1223);