[Fix] Isolate Slack install-after-auth route tests from developer .env.local - #986
Merged
Conversation
The tests stubbed process.env.R_APP_URL/R_PUBLIC_URL, but the route resolves the public URL through the dotenvx-backed web Env proxy, which reads the repo-root .env.local directly - so a developer-local R_PUBLIC_URL (e.g. an ngrok host) leaked into the redirect assertions. Mock the Env accessor with a test-owned object instead, keeping the real getPublicAppUrl preference logic under test.
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
apps/web/src/app/api/slack/install-after-auth/__tests__/route.test.tsfails locally for any developer whose repo-root.env.localsetsR_PUBLIC_URL(e.g. an ngrok URL). The test stubbedprocess.env.R_APP_URL/R_PUBLIC_URL(isolation added in #758), but the route resolves the public URL viagetCallbackHost→ the dotenvx-backed webEnvproxy, which reads the repo-root.env.localfile directly — so the file value bypasses theprocess.envstubs. Symptom:expected http://localhost:13000/... but received https://<ngrok-domain>/...in the two redirect tests.Fix
Replace the
process.envstub/restore dance with the existing repo pattern (vi.hoistedenv state +vi.mock('@/lib/server/env'), as intrpc/commands/linear/index.test.ts): spread the real module and overrideEnvwith a test-owned object, so dotenvx file resolution is never consulted.getPublicAppUrlstays unmocked so the realR_PUBLIC_URL ?? R_APP_URLpreference logic remains under test.Verification
pnpm exec dotenvx run -f .env.test -- pnpm --filter web exec vitest run src/app/api/slack/install-after-auth/__tests__/route.test.ts.env.localsettingR_PUBLIC_URL=https://example-dev.ngrok.app(2/3 failed).env.localpresentpnpm lintandpnpm --filter web check-typesclean