Skip to content

test(cli): unit tests get a fake home directory and NO_COLOR - #271

Merged
stewartjarod merged 5 commits into
mainfrom
advisor/058-cli-tests-fake-home
Nov 13, 2026
Merged

stewartjarod merged 5 commits into
mainfrom
advisor/058-cli-tests-fake-home

Conversation

@stewartjarod

Copy link
Copy Markdown
Contributor

What

CLI unit tests can no longer read or write the developer's real home directory, and they run with NO_COLOR=1.

On 2026-11-12, a test rewrote a real ~/.wraps/pulumi/Pulumi.yaml. Setting HOME inside a test did nothing, and code inside node_modules (conf/env-paths for telemetry, Pulumi automation) still resolved the real home even when node:os was mocked.

How

  • packages/cli/vitest.config.ts:
    • uses pool: "forks";
    • points test.env at one temp home per run, covering HOME, USERPROFILE, the XDG_* dirs and PULUMI_HOME;
    • in a forked worker, os.homedir() follows HOME, so this covers source code, node_modules and child processes.
  • src/__tests__/setup/fake-home-global.ts creates the temp home and removes it. It deletes only the dir it created, and only when that dir is a wraps-cli-home-* dir directly under os.tmpdir().
  • src/__tests__/setup/fake-home.test.ts proves the setup works. It checks:
    • the env;
    • os.homedir() through named, default and bare os imports;
    • getWrapsDir();
    • the telemetry config path through conf;
    • a spawned child process;
    • the teardown guard.
  • client.test.ts pins its telemetry config dir to a mkdtemp dir.
  • NO_COLOR=1: picocolors (and clack) let it win over CI/FORCE_COLOR, so a plain run matches CI's colour handling. CI still changes isInteractive() and telemetry, and CLAUDE.md says so.
  • packages/cli/CLAUDE.md gets a new "Tests" section.

Checks

  • CLI vitest, plain and with CI=true: 3711/3711.
  • The CLI suite runs in about 1m, down from about 1m40s.
  • Real ~/.wraps/pulumi/Pulumi.yaml, ~/.config/wraps-nodejs/telemetry.json, ~/.wraps and ~/.pulumi: mtimes unchanged across runs. No temp dirs left behind.
  • turbo typecheck --filter=@wraps.dev/cli and biome: pass.

Tests and docs only. No release needed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GxJAQQr6pNB7qCy8dj9CYR

stewartjarod and others added 5 commits November 13, 2026 09:22
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GxJAQQr6pNB7qCy8dj9CYR
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GxJAQQr6pNB7qCy8dj9CYR
The node:os mock cannot reach node_modules (conf, env-paths, Pulumi automation)
or direct process.env.HOME readers. Forked workers get HOME, USERPROFILE, XDG_*
and PULUMI_HOME pointing into one temp dir per run, created by a globalSetup.
client.test.ts pins its conf dir to a temp dir. Docs now say NO_COLOR covers
colour only.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GxJAQQr6pNB7qCy8dj9CYR
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GxJAQQr6pNB7qCy8dj9CYR
teardown() removes only the dir setup() created, and only when it sits directly
under os.tmpdir(). The config assigns WRAPS_CLI_TEST_HOME with = (the proof test
checks the dir exists and HOME matches). client.test.ts uses mkdtempSync.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GxJAQQr6pNB7qCy8dj9CYR
@vercel
vercel Bot temporarily deployed to Preview – wraps-website November 13, 2026 18:07 Inactive
@vercel
vercel Bot temporarily deployed to Preview – wraps-web November 13, 2026 18:07 Inactive
@vercel

vercel Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated
wraps-web Skipped Skipped Nov 13, 2026 6:07pm UTC
wraps-website Skipped Skipped Nov 13, 2026 6:07pm UTC

Request Review

@stewartjarod
stewartjarod merged commit 0fdef74 into main Nov 13, 2026
23 checks passed
@stewartjarod
stewartjarod deleted the advisor/058-cli-tests-fake-home branch November 13, 2026 19:51

This branch was previously deployed

2 inactive deployments
Preview – wraps-website — ca6aef0d Deployed Nov 13, 2026 by vercel[bot]
Preview – wraps-web — ca6aef0d Deployed Nov 13, 2026 by vercel[bot]
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