Open History to see the last commit
1import * as NodeFS from "node:fs";
2
3const argv = process.argv.slice(2);
4const args = argv.join(" ");
5
6function fail(message, code) {
7 process.stderr.write(message + "\n");
8 process.exit(code);
9}
10
11const permissionIndex = argv.indexOf("--permission-mode");
12if (permissionIndex === -1 || argv[permissionIndex + 1] !== "dontAsk") {
13 fail("text generation must deny permission prompts", 12);
14}
15const toolsIndex = argv.indexOf("--tools");
16if (
17 toolsIndex === -1 ||
18 argv[toolsIndex + 1] !== (process.env.T3_FAKE_CLAUDE_EXPECTED_TOOLS ?? "")
19) {
20 fail("text generation did not receive the expected tool set", 6);
21}
22if (argv.includes("--dangerously-skip-permissions")) {
23 fail("text generation must not bypass permissions", 7);
24}
25if (!argv.includes("--disable-slash-commands")) {
26 fail("text generation must disable skills", 8);
27}
28if (!argv.includes("--strict-mcp-config")) {
29 fail("text generation must not load configured MCP servers", 9);
30}
31if (process.env.T3_FAKE_CLAUDE_REJECTS_NO_SESSION_PERSISTENCE === "1") {
32 if (argv.includes("--no-session-persistence")) {
33 fail("error: unknown option '--no-session-persistence'", 1);
34 }
35} else if (!argv.includes("--no-session-persistence")) {
36 fail("text generation must not save a resumable session", 16);
37}
38const settingsIndex = argv.indexOf("--settings");
39if (settingsIndex === -1 || JSON.parse(argv[settingsIndex + 1]).disableAllHooks !== true) {
40 fail("text generation must disable hooks", 10);
41}
42const cwdMustNotBe = process.env.T3_FAKE_CLAUDE_CWD_MUST_NOT_BE;
43if (cwdMustNotBe && NodeFS.realpathSync(process.cwd()) === NodeFS.realpathSync(cwdMustNotBe)) {
44 fail("text generation ran in the project directory", 11);
45}
46
47let stdinContent = "";
48if (!process.stdin.isTTY) {
49 const chunks = [];
50 for await (const chunk of process.stdin) {
51 chunks.push(chunk);
52 }
53 stdinContent = Buffer.concat(chunks).toString("utf8");
54}
55
56const argsMustContain = process.env.T3_FAKE_CLAUDE_ARGS_MUST_CONTAIN;
57if (argsMustContain && !args.includes(argsMustContain)) {
58 fail("args missing expected content", 2);
59}
60
61const argsMustNotContain = process.env.T3_FAKE_CLAUDE_ARGS_MUST_NOT_CONTAIN;
62if (argsMustNotContain && args.includes(argsMustNotContain)) {
63 fail("args contained forbidden content", 3);
64}
65
66const stdinMustContain = process.env.T3_FAKE_CLAUDE_STDIN_MUST_CONTAIN;
67if (stdinMustContain && !stdinContent.includes(stdinMustContain)) {
68 fail("stdin missing expected content", 4);
69}
70
71const configDirMustBe = process.env.T3_FAKE_CLAUDE_CONFIG_DIR_MUST_BE;
72if (configDirMustBe && process.env.CLAUDE_CONFIG_DIR !== configDirMustBe) {
73 fail("CLAUDE_CONFIG_DIR was " + (process.env.CLAUDE_CONFIG_DIR ?? ""), 5);
74}
75
76const stderrText = process.env.T3_FAKE_CLAUDE_STDERR;
77if (stderrText) {
78 process.stderr.write(stderrText + "\n");
79}
80
81process.stdout.write(process.env.T3_FAKE_CLAUDE_OUTPUT ?? "");
82process.exitCode = Number(process.env.T3_FAKE_CLAUDE_EXIT_CODE ?? 0);