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

McpInvocationContext.test.ts

66 lines2.4 KB

1import { expect, it } from "@effect/vitest";
2import {
3 EnvironmentId,
4 McpCapabilityUnavailableError,
5 PreviewAutomationUnavailableError,
6 ProviderInstanceId,
7 ThreadId,
8} from "@t3tools/contracts";
9import * as Effect from "effect/Effect";
10​
11import * as McpInvocationContext from "./McpInvocationContext.ts";
12​
13it.effect("reports the scoped credential context when preview capability is unavailable", () => {
14 const invocation: McpInvocationContext.McpInvocationScope = {
15 environmentId: EnvironmentId.make("environment-1"),
16 threadId: ThreadId.make("thread-1"),
17 providerSessionId: "provider-session-1",
18 providerInstanceId: ProviderInstanceId.make("codex"),
19 capabilities: new Set(),
20 issuedAt: 1,
21 };
22​
23 return Effect.gen(function* () {
24 const error = yield* McpInvocationContext.requireMcpCapability("preview").pipe(
25 Effect.provideService(McpInvocationContext.McpInvocationContext, invocation),
26 Effect.flip,
27 );
28​
29 expect(error).toBeInstanceOf(PreviewAutomationUnavailableError);
30 expect(error).toMatchObject({
31 capability: "preview",
32 environmentId: invocation.environmentId,
33 threadId: invocation.threadId,
34 providerSessionId: invocation.providerSessionId,
35 providerInstanceId: invocation.providerInstanceId,
36 });
37 expect(error.message).toContain("MCP credential does not grant the preview capability");
38 expect(error.message).toContain("use a headless browser from the shell");
39 });
40});
41​
42it.effect("reports other missing capabilities with the neutral error", () => {
43 const invocation: McpInvocationContext.McpInvocationScope = {
44 environmentId: EnvironmentId.make("environment-1"),
45 threadId: ThreadId.make("thread-1"),
46 providerSessionId: "provider-session-1",
47 providerInstanceId: ProviderInstanceId.make("codex"),
48 capabilities: new Set(["preview"]),
49 issuedAt: 1,
50 };
51​
52 return Effect.gen(function* () {
53 const error = yield* McpInvocationContext.requireMcpCapability("pull-requests").pipe(
54 Effect.provideService(McpInvocationContext.McpInvocationContext, invocation),
55 Effect.flip,
56 );
57​
58 expect(error).toBeInstanceOf(McpCapabilityUnavailableError);
59 expect(error).toMatchObject({ capability: "pull-requests", threadId: invocation.threadId });
60​
61 const scope = yield* McpInvocationContext.requireMcpCapability("preview").pipe(
62 Effect.provideService(McpInvocationContext.McpInvocationContext, invocation),
63 );
64 expect(scope).toBe(invocation);
65 });
66});