Make ClaudeTextGeneration tests hermetic on Windows#4508
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Approved Test-only changes that make the ClaudeTextGeneration test infrastructure cross-platform compatible. Converts shell script stub to Node.js and adds Windows PATH handling. No production code is affected. You can customize Macroscope's approvability policy. Learn more. |
What Changed
The
ClaudeTextGenerationtest fixture now works on Windows. The fakeclaudebinary is a Node script with a platform-appropriate entry point —claude.cmdon Windows, a#!/bin/shshim elsewhere — and PATH is built with the platform's separator instead of a hardcoded:.One file, test-only. No production code changes.
Why
Fixes #4507.
On Windows all 5 tests in this file fail on unmodified
main. The fixture never takes effect, so the real installed Claude CLI runs instead: assertions compare fixture strings against live model output, and the run makes real billed API calls.Two POSIX-only assumptions caused it:
:. Windows uses;, so the fixture'sbindirectory never became its own PATH entry.bin/claudecontaining a#!/bin/shscript. Windows resolves executables throughPATHEXT, so an extension-less file is skipped — and even with a correct extension a shebang script is not executable there.Fixing only the separator is not enough, since the shebang stub still would not run. So the stub logic moved into Node (
claude-stub.mjs) with a thin platform-specific launcher in front of it. TheT3_FAKE_CLAUDE_*env contract and every exit code are unchanged.No production change was needed:
resolveSpawnCommandalready resolves throughPATHEXTand spawns.cmdwithshell: true.Validation
Windows 11, this file only:
The 134s to 4s drop is the signal that no network calls happen anymore.
vp fmt,vp lint --report-unused-disable-directives,git diff --check, andpnpm --filter t3 typecheckare all clean for this scope.I do not have a POSIX machine, so the shell shim is verified behaviourally under
shrather than by running the suite: happy path, args-must-contain pass and fail, stdin-must-contain pass and fail, custom exit code, and config-dir mismatch all return the same exit codes as the old script (0, 0, 2, 4, 0, 7, 5). The full suite on Linux and macOS is unverified by me and worth confirming in CI.One note so it is not a surprise: on Windows the run now emits
DEP0190(passing args withshell: true). That comes from the existingresolveSpawnCommandpath and is not introduced here — it simply was not reachable from this test before, because the stub never resolved.Not included
ClaudeTextGeneration.test.tsbuildsclaudeConfigDirfromprocess.cwd(), which leaves a.claude-work-test/directory behind in the repo after the run. It is recorded in #4507 and left out here to keep this focused.Checklist
Note
Low Risk
Test fixture changes only; no production behavior, auth, or data paths are touched.
Overview
ClaudeTextGeneration tests now install a cross-platform fake
claudeinstead of a POSIX-only shell script, so Windows no longer falls through to the real CLI on PATH.The shared stub logic moves into
claude-stub.mjs, preserving the existingT3_FAKE_CLAUDE_*env contract and exit codes.makeFakeClaudeBinarywritesclaude.cmd(Node launcher) on Windows and a thin#!/bin/shshim elsewhere.withFakeClaudeEnvprepends the fixturebintoPATHusing;on Windows and:elsewhere viaisHostWindows.Test-only change; no production spawn or Claude integration code is modified.
Reviewed by Cursor Bugbot for commit ace6621. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Make
ClaudeTextGenerationtests hermetic on Windowsclaude-stub.mjs) that handles argument, stdin, stderr, exit code, and env validations portably.claude.cmdlauncher that forwards tonode claude-stub.mjs; on non-Windows, writes an executable shell wrapper as before.withFakeClaudeEnvto use;as the delimiter on Windows so the fake binary is discoverable.Macroscope summarized ace6621.