fix(test): isolate mockCurrentUser in announcement-admin-route tests - #6991
Conversation
Replace the shared mutable mockCurrentUser object with a vi.fn() factory (mockGetCurrentUser) that returns a fresh user object per middleware invocation. The 403 test now uses mockReturnValue instead of mutating the shared reference. Under the root vitest config (pool: 'threads'), the shared mutable object could race with other test files' workers when modules were cached across threads, producing intermittent 403→404 failures where mock state was clobbered between mutation and request. Refs adcontextprotocol#6740
There was a problem hiding this comment.
Ladon verdict: Approve
Approve — test-only change with no blocking or medium findings.
This PR touches a single test file (tests/announcement/announcement-admin-route.test.ts, +7/−6), replacing a shared mutable mockCurrentUser object with a mockGetCurrentUser vi.fn() and setting return values via mockReturnValue instead of mutating a shared reference across sequential requests. The fix eliminates in-place mutation of shared state and is self-consistent.
No protocol surface (static/schemas/source/**), docs, changeset, or released-artifact scope is touched — schema↔docs coherence, changeset, oneOf, and immutability gates do not apply. No no-auto-approve team match, gated_paths is false, and high_risk is false.
Decision table: rows 1–8 do not fire (no critical/high, no medium, no gated paths, no deletions, no team gate). Falls through to row 9 → approve. Note review_decision is REVIEW_REQUIRED, but with gated_paths: false and no other trigger, that does not block approval.
…ests announcement-channel-resolver: replace manual process.env delete/restore with vi.stubEnv + vi.unstubAllEnvs. The old pattern leaked SLACK_EDITORIAL_REVIEW_CHANNEL mutations to concurrent thread workers under the root vitest threads pool. addie/admin-tools: replace unconditional process.env assignments (ADMIN_API_KEY, BASE_URL) with vi.stubEnv so values are automatically restored after each test, preventing cross-thread env bleed. Refs adcontextprotocol#6740
Replace direct process.env assignments and manual delete/restore with vi.stubEnv + vi.unstubAllEnvs in beforeEach. The old pattern leaked STRIPE_WEBHOOK_SECRET and STRIPE_SECRET_KEY mutations to concurrent thread workers under the root vitest threads pool. Refs adcontextprotocol#6740
Summary
Eliminate thread-safety issues in test files that run under the root vitest config (
pool: 'threads') by isolating shared mutable state. This addresses root cause (3) from the #6740 triage and hardens all otherprocess.envmutation sites found in thetests/tree against cross-thread bleed.Root causes (1) and (2) were fixed in #6800.
Changes
tests/announcement/announcement-admin-route.test.ts— shared mutable mock objectmockCurrentUsershared object withmockGetCurrentUservi.fn() factorymockGetCurrentUser()per invocation instead of sharing a referencemockReturnValue()instead of property mutationtests/announcement/announcement-channel-resolver.test.ts— env var leakprocess.envdelete/restore withvi.stubEnv+vi.unstubAllEnvsafterEachandORIGINAL_ENVmanual save/restore patternSLACK_EDITORIAL_REVIEW_CHANNELmutations no longer leak to concurrent workerstests/addie/admin-tools.test.ts— env var leakprocess.env.ADMIN_API_KEY/process.env.BASE_URLassignments withvi.stubEnvvi.unstubAllEnvs()inbeforeEachfor automatic restorationtests/billing/webhook-security.test.ts— env var leakprocess.env.STRIPE_WEBHOOK_SECRET/STRIPE_SECRET_KEYassignments withvi.stubEnvvi.unstubAllEnvs()inbeforeEachfor automatic restorationVerification
npx vitest run tests/announcement/— 175/175 passednpx vitest run tests/addie/admin-tools.test.ts— 30/30 passednpx vitest run tests/billing/webhook-security.test.ts— 7/7 passedtests/files for remaining non-idempotentprocess.envmutations — zero remainingRefs #6740