Open History to see the last commit
1import { ClaudeSettings } from "@t3tools/contracts";
2import * as NodeServices from "@effect/platform-node/NodeServices";
3import { assert, it } from "@effect/vitest";
4import * as Effect from "effect/Effect";
5import * as FileSystem from "effect/FileSystem";
6import * as Path from "effect/Path";
7import * as Schema from "effect/Schema";
8
9import {
10 buildClaudeCapabilitiesProbeQueryOptions,
11 CLAUDE_CAPABILITIES_PROBE_SETTING_SOURCES,
12 isLegacyClaudeModel,
13 probeClaudeCapabilities,
14} from "./ClaudeProvider.ts";
15
16const decodeClaudeSettings = Schema.decodeSync(ClaudeSettings);
17
18it("keeps only the Claude 5 family out of legacy models", () => {
19 assert.deepStrictEqual(
20 ["claude-fable-5", "claude-opus-5", "claude-sonnet-5", "claude-opus-4-8"].map((model) => [
21 model,
22 isLegacyClaudeModel(model),
23 ]),
24 [
25 ["claude-fable-5", false],
26 ["claude-opus-5", false],
27 ["claude-sonnet-5", false],
28 ["claude-opus-4-8", true],
29 ],
30 );
31});
32
33it("isolates Claude capability probes without dropping workspace setting sources", () => {
34 const abortController = new AbortController();
35 const options = buildClaudeCapabilitiesProbeQueryOptions({
36 executablePath: "/usr/bin/claude",
37 abortController,
38 environment: {
39 HOME: "/home/user",
40 ENABLE_CLAUDEAI_MCP_SERVERS: "true",
41 },
42 cwd: "/workspace/project",
43 });
44
45 assert.deepEqual(options.mcpServers, {});
46 assert.equal(options.strictMcpConfig, true);
47 assert.equal(options.cwd, "/workspace/project");
48 assert.deepEqual(options.settingSources, [...CLAUDE_CAPABILITIES_PROBE_SETTING_SOURCES]);
49 assert.deepEqual(options.allowedTools, []);
50 assert.equal(options.persistSession, false);
51 assert.equal(options.pathToClaudeCodeExecutable, "/usr/bin/claude");
52 assert.equal(options.abortController, abortController);
53 assert.equal(options.env?.HOME, "/home/user");
54 assert.equal(options.env?.ENABLE_CLAUDEAI_MCP_SERVERS, "false");
55});
56
57it.layer(NodeServices.layer)("Claude capability probe SDK boundary", (it) => {
58 it.effect("serializes strict no-MCP options and still resolves account capabilities", () =>
59 Effect.gen(function* () {
60 const fs = yield* FileSystem.FileSystem;
61 const path = yield* Path.Path;
62 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-probe-sdk-" });
63 const executablePath = path.join(tempDir, "fake-claude.mjs");
64 const invocationPath = path.join(tempDir, "invocation.json");
65 const workspaceCwd = path.join(tempDir, "workspace");
66 yield* fs.makeDirectory(workspaceCwd, { recursive: true });
67
68 yield* fs.writeFileString(
69 executablePath,
70 [
71 "#!/usr/bin/env node",
72 'import { existsSync, readFileSync, writeFileSync } from "node:fs";',
73 'import { createInterface } from "node:readline";',
74 "const args = process.argv.slice(2);",
75 'const mcpConfigIndex = args.indexOf("--mcp-config");',
76 "const rawMcpConfig = mcpConfigIndex >= 0 ? args[mcpConfigIndex + 1] : undefined;",
77 "let mcpConfig;",
78 "if (rawMcpConfig) {",
79 ' const contents = existsSync(rawMcpConfig) ? readFileSync(rawMcpConfig, "utf8") : rawMcpConfig;',
80 " try { mcpConfig = JSON.parse(contents); } catch { mcpConfig = contents; }",
81 "}",
82 "writeFileSync(process.env.T3_PROBE_INVOCATION_PATH, JSON.stringify({",
83 " args,",
84 " cwd: process.cwd(),",
85 " connectorEnv: process.env.ENABLE_CLAUDEAI_MCP_SERVERS,",
86 " mcpConfig,",
87 "}));",
88 "const lines = createInterface({ input: process.stdin });",
89 'lines.on("line", (line) => {',
90 " const message = JSON.parse(line);",
91 ' if (message.type !== "control_request" || message.request?.subtype !== "initialize") return;',
92 " process.stdout.write(JSON.stringify({",
93 ' type: "control_response",',
94 " response: {",
95 ' subtype: "success",',
96 " request_id: message.request_id,",
97 " response: {",
98 ' commands: [{ name: "review", description: "Review changes", argumentHint: "[path]" }],',
99 " agents: [],",
100 ' output_style: "default",',
101 ' available_output_styles: ["default"],',
102 " models: [],",
103 ' account: { email: "dev@example.com", subscriptionType: "pro", tokenSource: "oauth" },',
104 " },",
105 " },",
106 ' }) + "\\n");',
107 "});",
108 "setInterval(() => {}, 1_000);",
109 "",
110 ].join("\n"),
111 );
112 yield* fs.chmod(executablePath, 0o755);
113
114 const capabilities = yield* probeClaudeCapabilities(
115 decodeClaudeSettings({ binaryPath: executablePath }),
116 {
117 ...process.env,
118 T3_PROBE_INVOCATION_PATH: invocationPath,
119 ENABLE_CLAUDEAI_MCP_SERVERS: "true",
120 },
121 workspaceCwd,
122 );
123
124 assert.deepEqual(capabilities, {
125 email: "dev@example.com",
126 subscriptionType: "pro",
127 tokenSource: "oauth",
128 apiProvider: undefined,
129 slashCommands: [
130 {
131 name: "review",
132 description: "Review changes",
133 input: { hint: "[path]" },
134 },
135 ],
136 });
137
138 // @effect-diagnostics-next-line preferSchemaOverJson:off
139 const invocation = JSON.parse(yield* fs.readFileString(invocationPath)) as {
140 readonly args: ReadonlyArray<string>;
141 readonly cwd: string;
142 readonly connectorEnv: string;
143 readonly mcpConfig: unknown;
144 };
145 assert.equal(invocation.cwd, yield* fs.realPath(workspaceCwd));
146 assert.equal(invocation.connectorEnv, "false");
147 assert.equal(invocation.args.includes("--strict-mcp-config"), true);
148 assert.equal(invocation.args.includes("--mcp-config"), false);
149 assert.equal(invocation.mcpConfig, undefined);
150
151 assert.equal(invocation.args.includes("--setting-sources=user,project,local"), true);
152 }).pipe(Effect.scoped),
153 );
154});