Skip to content

Commit bfacfef

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

2 files changed

Lines changed: 73 additions & 55 deletions

File tree

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

Lines changed: 2 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -177,62 +177,9 @@ const makeTildeProviderFixtures = Effect.fn(
177177
);
178178
yield* fileSystem.chmod(codexPath, 0o755);
179179

180-
yield* fileSystem.writeFileString(
180+
yield* fileSystem.copyFile(
181+
path.join(import.meta.dirname, "testing/ProviderInstanceRegistryLive.fixture.mjs"),
181182
claudePath,
182-
[
183-
"#!/usr/bin/env node",
184-
'import { existsSync } from "node:fs";',
185-
'import * as NodeReadline from "node:readline";',
186-
'if (process.argv.includes("--version")) {',
187-
' process.stdout.write("claude 2.1.219\\n");',
188-
" process.exit(0);",
189-
"}",
190-
"const lines = NodeReadline.createInterface({ input: process.stdin });",
191-
'lines.on("line", (line) => {',
192-
" const message = JSON.parse(line);",
193-
' if (message.type !== "control_request") return;',
194-
' if (message.request?.subtype === "get_usage") {',
195-
" const marker = process.env.T3_CLAUDE_RESET_MARKER;",
196-
" if (process.env.T3_CLAUDE_USAGE_FAILS_AFTER_CLAIM && marker && existsSync(marker)) {",
197-
" process.stdout.write(JSON.stringify({",
198-
' type: "control_response",',
199-
' response: { subtype: "error", request_id: message.request_id, error: "usage failed" },',
200-
' }) + "\\n");',
201-
" return;",
202-
" }",
203-
" process.stdout.write(JSON.stringify({",
204-
' type: "control_response",',
205-
' response: { subtype: "success", request_id: message.request_id, response: {',
206-
' session: {}, subscription_type: "pro", rate_limits_available: true,',
207-
" rate_limits: { five_hour: { utilization: marker && existsSync(marker) ? 0 : 100, resets_at: null } },",
208-
" } },",
209-
' }) + "\\n");',
210-
" return;",
211-
" }",
212-
' if (message.request?.subtype !== "initialize") return;',
213-
" process.stdout.write(JSON.stringify({",
214-
' type: "control_response",',
215-
" response: {",
216-
' subtype: "success",',
217-
" request_id: message.request_id,",
218-
" response: {",
219-
" commands: [], agents: [], models: [],",
220-
' output_style: "default", available_output_styles: ["default"],',
221-
' account: { email: "[email protected]", subscriptionType: "pro", tokenSource: "oauth" },',
222-
" },",
223-
" },",
224-
' }) + "\\n");',
225-
"});",
226-
"// Stay alive for follow-up control requests, but never outlive the",
227-
"// parent: the probe aborts the SDK without awaiting the child, so an",
228-
"// unconditional interval would strand this process until reboot.",
229-
"const keepAlive = setInterval(() => {}, 1_000);",
230-
'lines.on("close", () => {',
231-
" clearInterval(keepAlive);",
232-
" process.exit(0);",
233-
"});",
234-
"",
235-
].join("\n"),
236183
);
237184
yield* fileSystem.chmod(claudePath, 0o755);
238185
yield* fileSystem.makeDirectory(claudeHomePath);
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env node
2+
import * as NodeFS from "node:fs";
3+
import * as NodeReadline from "node:readline";
4+
if (process.argv.includes("--version")) {
5+
process.stdout.write("claude 2.1.219\n");
6+
process.exit(0);
7+
}
8+
const lines = NodeReadline.createInterface({ input: process.stdin });
9+
lines.on("line", (line) => {
10+
const message = JSON.parse(line);
11+
if (message.type !== "control_request") return;
12+
if (message.request?.subtype === "get_usage") {
13+
const marker = process.env.T3_CLAUDE_RESET_MARKER;
14+
if (process.env.T3_CLAUDE_USAGE_FAILS_AFTER_CLAIM && marker && NodeFS.existsSync(marker)) {
15+
process.stdout.write(
16+
JSON.stringify({
17+
type: "control_response",
18+
response: { subtype: "error", request_id: message.request_id, error: "usage failed" },
19+
}) + "\n",
20+
);
21+
return;
22+
}
23+
process.stdout.write(
24+
JSON.stringify({
25+
type: "control_response",
26+
response: {
27+
subtype: "success",
28+
request_id: message.request_id,
29+
response: {
30+
session: {},
31+
subscription_type: "pro",
32+
rate_limits_available: true,
33+
rate_limits: {
34+
five_hour: {
35+
utilization: marker && NodeFS.existsSync(marker) ? 0 : 100,
36+
resets_at: null,
37+
},
38+
},
39+
},
40+
},
41+
}) + "\n",
42+
);
43+
return;
44+
}
45+
if (message.request?.subtype !== "initialize") return;
46+
process.stdout.write(
47+
JSON.stringify({
48+
type: "control_response",
49+
response: {
50+
subtype: "success",
51+
request_id: message.request_id,
52+
response: {
53+
commands: [],
54+
agents: [],
55+
models: [],
56+
output_style: "default",
57+
available_output_styles: ["default"],
58+
account: { email: "[email protected]", subscriptionType: "pro", tokenSource: "oauth" },
59+
},
60+
},
61+
}) + "\n",
62+
);
63+
});
64+
// Stay alive for follow-up control requests, but never outlive the
65+
// parent: the probe aborts the SDK without awaiting the child, so an
66+
// unconditional interval would strand this process until reboot.
67+
const keepAlive = setInterval(() => {}, 1_000);
68+
lines.on("close", () => {
69+
clearInterval(keepAlive);
70+
process.exit(0);
71+
});

0 commit comments

Comments
 (0)