test: keep unit tests out of the developer's home directory

The marketplace installer and the skill security cache resolve paths from
os.homedir() at import time, so npm run test wrote fixtures into the real
~/.waggle/security-cache and ~/.waggle/plugins/registry.json. Point HOME
and USERPROFILE at a temporary directory per worker and silence npm's
update notice that a fresh home triggers (UF-022). Log the four test
files that fail on macOS (UF-023).
This commit is contained in:
shumeiko.it
2026-10-15 18:35:39 +02:00
parent 214c6e66b5
commit 2346cf3ca4
2 changed files with 36 additions and 2 deletions

View File

@@ -3,8 +3,22 @@
* that need DATABASE_URL, REDIS_URL, CLERK_SECRET_KEY, etc.
* No external dependencies (no dotenv required).
*/
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import { mkdtempSync, readFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
// Tests must never write to the developer's real ~/.waggle or ~/.claude. Some
// modules resolve paths from os.homedir() at import time (the marketplace
// installer's plugin registry and the skill security cache), so point HOME and
// USERPROFILE at one temporary directory per worker before any test module loads.
if (!process.env.WAGGLE_TEST_HOME) {
process.env.WAGGLE_TEST_HOME = mkdtempSync(join(tmpdir(), 'waggle-test-home-'));
}
process.env.HOME = process.env.WAGGLE_TEST_HOME;
process.env.USERPROFILE = process.env.WAGGLE_TEST_HOME;
// A fresh home has no npm update-check stamp, so npm would print an update
// notice into the output of CLI subprocess tests.
process.env.npm_config_update_notifier = 'false';
// Phase 5 canary — pin to 0 (canary OFF) for tests. Production code-default
// post-kick-off (2026-04-30) is 10; tests need explicit OFF so shape-selection