Skip to content

test: ensure cross-platform environment isolation in isolateHome - #133

Open
reginaldalfret wants to merge 1 commit into
spotify:mainfrom
reginaldalfret:fix/cross-platform-test-isolation
Open

reginaldalfret wants to merge 1 commit into
spotify:mainfrom
reginaldalfret:fix/cross-platform-test-isolation

Conversation

@reginaldalfret

Copy link
Copy Markdown

Summary

PR #116 introduced isolateHome in @spotify-confidence/testing to isolate test runs from developer config directories like ~/.cursor/. However, it only stubbed process.env.HOME.

On Windows, Node.js os.homedir() evaluates process.env.USERPROFILE first before falling back to HOME. As a result, tests using isolateHome on Windows did not redirect os.homedir() to the isolated temporary directory, causing tests (such as cursor disconnectMcpServer) to access and mutate the developer's real host machine configs.

Changes

  1. packages/testing/src/scaffold/home-scaffold.ts: Stub both HOME and USERPROFILE to ensure os.homedir() correctly resolves to the temporary test directory across all platforms.
  2. packages/testing/__tests__/home-scaffold.test.ts: Add unit tests verifying environment isolation and cleanup across platforms.
  3. packages/testing/package.json: Add missing "test": "vitest run" script so testing package utilities are exercised.
  4. packages/core/__tests__/auth/credentials/store.test.ts: Skip POSIX permission checks (0700 / 0600) on Windows using existing isWindows helper, as Windows filesystem does not support POSIX permission bits.
  5. packages/cli/__tests__/commands/mcp.test.ts & plugin.test.ts: Use resolve() for --dir assertion paths to support cross-platform path separators consistently with plugin install.

Validation

  • pnpm typecheck: Passed across all packages.
  • pnpm --filter @spotify-confidence/testing test: Passed (4/4 tests).
  • pnpm --filter @spotify-confidence/core test: Passed (156 passed, 2 skipped).
  • pnpm --filter @spotify-confidence/cli test: Passed (257/257 tests).
  • Prettier & ESLint checks: Clean.

Stub both HOME and USERPROFILE in isolateHome to ensure Node's os.homedir()
is properly redirected to the isolated temporary directory across all
operating systems. On Windows, os.homedir() prioritizes USERPROFILE over
HOME, which previously led to tests writing to the host user's actual
~/.cursor configuration.

Also:
- Add unit tests for isolateHome in packages/testing
- Enable vitest runner in @spotify-confidence/testing
- Skip POSIX permission bit checks on Windows in store.test.ts
- Normalize path resolution assertions for --dir in CLI tests

Signed-off-by: reginaldalfret <reginaldalfret@gmail.com>
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