fix(tests): mock runLink to prevent env var leakage in unit tests#843
fix(tests): mock runLink to prevent env var leakage in unit tests#843zbigniewsobiecki merged 1 commit intodevfrom
Conversation
nhopeatall
left a comment
There was a problem hiding this comment.
LGTM — Correct, minimal fix for a real test environment isolation issue. The root cause analysis is accurate: buildRunLinkFooterFromEnv() reads process.env directly, and Vitest's unstubEnvs only resets vars set via vi.stubEnv(), not pre-existing env vars from the CASCADE agent runtime. Mocking the module to return '' is the right approach.
The three files that got the mock are exactly the test files whose assertions would fail when the run link footer is appended to PR body/comment text. Other test files that import the same core functions either mock the core functions themselves (e.g., file-input-flags.test.ts, createPRReview.test.ts) or don't assert on body content (e.g., core/createPR.test.ts uses expect.any(Object)), so they're not affected.
One minor note: tests/unit/gadgets/github/core/createPR.test.ts also calls buildRunLinkFooterFromEnv transitively (via the real createPR function) without mocking it, but currently doesn't fail because none of its assertions check the exact body string. If someone adds a body assertion to that file later, they'd hit the same issue — but that's a future concern, not a blocker.
🕵️ claude-code · claude-opus-4-6 · run details
Summary
CASCADE_RUN_LINKS_ENABLED,CASCADE_DASHBOARD_URL,CASCADE_RUN_ID) leaking into the test processvi.mockforsrc/utils/runLink.js(returningbuildRunLinkFooterFromEnv: () => '') in three test files where the production code appends a run link footer to PR body/comment textRoot Cause
buildRunLinkFooterFromEnv()readsCASCADE_RUN_LINKS_ENABLED,CASCADE_DASHBOARD_URL, andCASCADE_RUN_IDfromprocess.env. When tests run inside a CASCADE agent worker, these env vars are always present. Vitest'sunstubEnvs: trueonly resets vars set viavi.stubEnv()— it does not clear pre-existing process env vars.Files Changed
tests/unit/gadgets/pm/core/postComment.test.ts— addedrunLink.jsmocktests/unit/gadgets/github.test.ts— addedrunLink.jsmocktests/unit/gadgets/github/core/misc.test.ts— addedrunLink.jsmockTest plan
npm run test:unit— all 4917 tests pass (was 8 failing)npm run typecheck— no errorsnpm run lint— no errors🔗 Card: https://trello.com/c/74pLprzc/364-plan-fixing-any-and-all-test-failures
🤖 Generated with Claude Code
🕵️ claude-code · claude-sonnet-4-6 · run details