Skip to content

Commit 0d74b6d

Browse files
committed
test(server): the fake Claude CLI is a fixture file, not a generated string
Signed-off-by: Yordis Prieto <[email protected]>
1 parent 8ed276c commit 0d74b6d

2 files changed

Lines changed: 69 additions & 63 deletions

File tree

‎apps/server/src/provider/Layers/ClaudeCapabilitiesProbe.test.ts‎

Lines changed: 3 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ it.layer(NodeServices.layer)("Claude capability probe SDK boundary", (it) => {
5858
const fs = yield* FileSystem.FileSystem;
5959
const path = yield* Path.Path;
6060
const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-probe-sdk-" });
61-
const executablePath = path.join(tempDir, "fake-claude.mjs");
61+
const executablePath = yield* path.fromFileUrl(
62+
new URL("./testing/ClaudeCapabilitiesProbe.fixture.mjs", import.meta.url),
63+
);
6264
const invocationPath = path.join(tempDir, "invocation.json");
6365
// The probe aborts the SDK without awaiting the child's exit, and on
6466
// Windows a directory that is still some process's cwd cannot be
@@ -80,68 +82,6 @@ it.layer(NodeServices.layer)("Claude capability probe SDK boundary", (it) => {
8082
),
8183
);
8284

83-
yield* fs.writeFileString(
84-
executablePath,
85-
[
86-
"#!/usr/bin/env node",
87-
'import { existsSync, readFileSync, writeFileSync } from "node:fs";',
88-
'import { createInterface } from "node:readline";',
89-
"const args = process.argv.slice(2);",
90-
'const mcpConfigIndex = args.indexOf("--mcp-config");',
91-
"const rawMcpConfig = mcpConfigIndex >= 0 ? args[mcpConfigIndex + 1] : undefined;",
92-
"let mcpConfig;",
93-
"if (rawMcpConfig) {",
94-
' const contents = existsSync(rawMcpConfig) ? readFileSync(rawMcpConfig, "utf8") : rawMcpConfig;',
95-
" try { mcpConfig = JSON.parse(contents); } catch { mcpConfig = contents; }",
96-
"}",
97-
"writeFileSync(process.env.T3_PROBE_INVOCATION_PATH, JSON.stringify({",
98-
" args,",
99-
" cwd: process.cwd(),",
100-
" connectorEnv: process.env.ENABLE_CLAUDEAI_MCP_SERVERS,",
101-
" mcpConfig,",
102-
"}));",
103-
"const lines = createInterface({ input: process.stdin });",
104-
'lines.on("line", (line) => {',
105-
" const message = JSON.parse(line);",
106-
' if (message.type !== "control_request") return;',
107-
" const reply = (response) => process.stdout.write(JSON.stringify({",
108-
' type: "control_response",',
109-
' response: { subtype: "success", request_id: message.request_id, response },',
110-
' }) + "\\n");',
111-
' if (message.request?.subtype === "initialize") {',
112-
" reply({",
113-
' commands: [{ name: "review", description: "Review changes", argumentHint: "[path]" }],',
114-
" agents: [],",
115-
' output_style: "default",',
116-
' available_output_styles: ["default"],',
117-
" models: [],",
118-
' account: { email: "[email protected]", subscriptionType: "pro", tokenSource: "oauth" },',
119-
" });",
120-
" }",
121-
" // The probe follows initialize with get_usage on the same process.",
122-
' if (message.request?.subtype === "get_usage") {',
123-
" reply({",
124-
" session: {},",
125-
' subscription_type: "pro",',
126-
" rate_limits_available: true,",
127-
' rate_limits: { five_hour: { utilization: 12, resets_at: "2026-07-18T14:39:00Z" } },',
128-
" behaviors: null,",
129-
" });",
130-
" }",
131-
"});",
132-
"// Stay alive for follow-up control requests, but never outlive the",
133-
"// parent: the probe aborts the SDK without awaiting the child, so an",
134-
"// unconditional interval would strand this process until reboot.",
135-
"const keepAlive = setInterval(() => {}, 1_000);",
136-
'lines.on("close", () => {',
137-
" clearInterval(keepAlive);",
138-
" process.exit(0);",
139-
"});",
140-
"",
141-
].join("\n"),
142-
);
143-
yield* fs.chmod(executablePath, 0o755);
144-
14585
const capabilities = yield* probeClaudeCapabilities(
14686
decodeClaudeSettings({ binaryPath: executablePath }),
14787
{
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env node
2+
import * as NodeFS from "node:fs";
3+
import * as NodeReadline from "node:readline";
4+
const args = process.argv.slice(2);
5+
const mcpConfigIndex = args.indexOf("--mcp-config");
6+
const rawMcpConfig = mcpConfigIndex >= 0 ? args[mcpConfigIndex + 1] : undefined;
7+
let mcpConfig;
8+
if (rawMcpConfig) {
9+
const contents = NodeFS.existsSync(rawMcpConfig)
10+
? NodeFS.readFileSync(rawMcpConfig, "utf8")
11+
: rawMcpConfig;
12+
try {
13+
mcpConfig = JSON.parse(contents);
14+
} catch {
15+
mcpConfig = contents;
16+
}
17+
}
18+
NodeFS.writeFileSync(
19+
process.env.T3_PROBE_INVOCATION_PATH,
20+
JSON.stringify({
21+
args,
22+
cwd: process.cwd(),
23+
connectorEnv: process.env.ENABLE_CLAUDEAI_MCP_SERVERS,
24+
mcpConfig,
25+
}),
26+
);
27+
const lines = NodeReadline.createInterface({ input: process.stdin });
28+
lines.on("line", (line) => {
29+
const message = JSON.parse(line);
30+
if (message.type !== "control_request") return;
31+
const reply = (response) =>
32+
process.stdout.write(
33+
JSON.stringify({
34+
type: "control_response",
35+
response: { subtype: "success", request_id: message.request_id, response },
36+
}) + "\n",
37+
);
38+
if (message.request?.subtype === "initialize") {
39+
reply({
40+
commands: [{ name: "review", description: "Review changes", argumentHint: "[path]" }],
41+
agents: [],
42+
output_style: "default",
43+
available_output_styles: ["default"],
44+
models: [],
45+
account: { email: "[email protected]", subscriptionType: "pro", tokenSource: "oauth" },
46+
});
47+
}
48+
// The probe follows initialize with get_usage on the same process.
49+
if (message.request?.subtype === "get_usage") {
50+
reply({
51+
session: {},
52+
subscription_type: "pro",
53+
rate_limits_available: true,
54+
rate_limits: { five_hour: { utilization: 12, resets_at: "2026-07-18T14:39:00Z" } },
55+
behaviors: null,
56+
});
57+
}
58+
});
59+
// Stay alive for follow-up control requests, but never outlive the
60+
// parent: the probe aborts the SDK without awaiting the child, so an
61+
// unconditional interval would strand this process until reboot.
62+
const keepAlive = setInterval(() => {}, 1_000);
63+
lines.on("close", () => {
64+
clearInterval(keepAlive);
65+
process.exit(0);
66+
});

0 commit comments

Comments
 (0)