fix(tests): isolate session-store specs from shared on-disk file#239
Merged
Conversation
session-store.spec.ts and auth.spec.ts both read/write the real data/config/sessions.json and share the module-level cache. Under Vitest's default parallel file execution they race: session-store's beforeEach deletes the file while auth's createSession()/revokeAllSessions() write it, so e.g. "revokeAllSessions wipes everything" (expects 3) or "persists across cache reset" can intermittently fail on multi-core / loaded machines. It also clobbered the operator's real login sessions. Add a lazily-read OPENALICE_SESSIONS_FILE seam to session-store.ts (same spirit as the existing _reset/_unlinkFile test seams; unset in production) and point each spec at its own mkdtemp file. The two files no longer share state and never touch the real sessions.json.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Summary
session-store.spec.tsandauth.spec.tsboth read/write the realdata/config/sessions.jsonand sharesession-store.ts's module-level cache. Under Vitest's default parallel file execution they race —session-store'sbeforeEachdeletes the file whileauth'screateSession()/revokeAllSessions()write it. Result: intermittent failures likerevokeAllSessions wipes everything(expects 3, gets 4) orpersists across cache resetreturning null, only on multi-core / loaded machines. It also clobbered the operator's real login sessions.OPENALICE_SESSIONS_FILEseam tosession-store.ts(same spirit as the existing_reset/_unlinkFiletest seams; unset in production → zero behavior change) and pointed each spec at its ownmkdtempfile. The two files no longer share state and never touch the realsessions.json.Test plan
npx tsc --noEmitcleanpnpm testpasses (90 files / 1701 tests)data/config/sessions.jsonleft untouched after the run (confirms tests no longer write it)Boundary touch
Touches
src/services/auth/(auth/session store) and its tests — no change to runtime auth behavior; the new env var is a test-only seam that production never sets.🤖 Generated with Claude Code
Generated by Claude Code