Skip to content

[Fix] Isolate Slack install-after-auth route tests from developer .env.local - #986

Merged
mrubens merged 1 commit into
developfrom
claude/upbeat-leavitt-b09197
Aug 2, 2026
Merged

[Fix] Isolate Slack install-after-auth route tests from developer .env.local#986
mrubens merged 1 commit into
developfrom
claude/upbeat-leavitt-b09197

Conversation

@mrubens

@mrubens mrubens commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Problem

apps/web/src/app/api/slack/install-after-auth/__tests__/route.test.ts fails locally for any developer whose repo-root .env.local sets R_PUBLIC_URL (e.g. an ngrok URL). The test stubbed process.env.R_APP_URL/R_PUBLIC_URL (isolation added in #758), but the route resolves the public URL via getCallbackHost → the dotenvx-backed web Env proxy, which reads the repo-root .env.local file directly — so the file value bypasses the process.env stubs. Symptom: expected http://localhost:13000/... but received https://<ngrok-domain>/... in the two redirect tests.

Fix

Replace the process.env stub/restore dance with the existing repo pattern (vi.hoisted env state + vi.mock('@/lib/server/env'), as in trpc/commands/linear/index.test.ts): spread the real module and override Env with a test-owned object, so dotenvx file resolution is never consulted. getPublicAppUrl stays unmocked so the real R_PUBLIC_URL ?? R_APP_URL preference 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

  • Reproduced the failure first with a repo-root .env.local setting R_PUBLIC_URL=https://example-dev.ngrok.app (2/3 failed)
  • After the fix: 3/3 pass both with and without that .env.local present
  • pnpm lint and pnpm --filter web check-types clean

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.
@roomote-community

roomote-community Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

No code issues found. See task

Reviewed 3b58745

@mrubens
mrubens merged commit 14bee40 into develop Aug 2, 2026
18 checks passed
@mrubens
mrubens deleted the claude/upbeat-leavitt-b09197 branch August 2, 2026 05:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant