From 7fc3bdb5942d248674047c54b1118c12af159d01 Mon Sep 17 00:00:00 2001 From: Behruz Nassre Esfahani <20915308+behruznassre@users.noreply.github.com> Date: Mon, 26 Oct 2026 10:57:42 -0700 Subject: [PATCH] test: run unit tests against a throwaway home Plugin state defaults to ~/.codex, and several unit tests create jobs and stop-review history without overriding HOME or CODEX_HOME, so every local `npm test` left fixtures in the developer's real plugin data. Some stay in running or cancelling state, and data written to the legacy `cc` namespace is merged into the installed plugin's namespace on its next run. Preload a small module with `node --import` in the unit test scripts. node --test applies it to each test file's process, which gets its own temporary HOME/USERPROFILE with CODEX_HOME cleared, removed on exit. Tests that spawn hooks with their own HOME keep working unchanged. The integration and e2e suites already set CODEX_HOME themselves. Fixes #127 Co-Authored-By: Claude Opus 5.5 --- package.json | 4 ++-- tests/support/isolated-codex-home.mjs | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 tests/support/isolated-codex-home.mjs diff --git a/package.json b/package.json index bf8873c..762d2e0 100644 --- a/package.json +++ b/package.json @@ -50,8 +50,8 @@ "install:codex": "node scripts/installer-cli.mjs install", "prepack": "npm run check:version-sync && npm run check:changelog", "setup:git-hooks": "node scripts/setup-git-hooks.mjs", - "test": "node --test tests/*.test.mjs", - "test:cross-platform": "node --test tests/args.test.mjs tests/changelog.test.mjs tests/claude-cli.test.mjs tests/fs.test.mjs tests/prompts.test.mjs tests/render.test.mjs tests/sandbox-modes.test.mjs tests/skills-contracts.test.mjs tests/structured-output.test.mjs tests/version-sync.test.mjs", + "test": "node --import ./tests/support/isolated-codex-home.mjs --test tests/*.test.mjs", + "test:cross-platform": "node --import ./tests/support/isolated-codex-home.mjs --test tests/args.test.mjs tests/changelog.test.mjs tests/claude-cli.test.mjs tests/fs.test.mjs tests/prompts.test.mjs tests/render.test.mjs tests/sandbox-modes.test.mjs tests/skills-contracts.test.mjs tests/structured-output.test.mjs tests/version-sync.test.mjs", "test:integration": "node --test tests/integration/*.test.mjs", "test:e2e": "node --test tests/e2e/*.test.mjs", "uninstall:codex": "node scripts/installer-cli.mjs uninstall", diff --git a/tests/support/isolated-codex-home.mjs b/tests/support/isolated-codex-home.mjs new file mode 100644 index 0000000..8da145a --- /dev/null +++ b/tests/support/isolated-codex-home.mjs @@ -0,0 +1,21 @@ +/** + * Copyright 2026 Sendbird, Inc. + * SPDX-License-Identifier: Apache-2.0 + */ +// Preloaded by the unit test scripts with `node --import`, which also applies it +// to every test file's process. Plugin state defaults to ~/.codex, so without +// this the tests that create jobs write into the developer's real Codex plugin +// data. Each process gets its own throwaway home. Tests that need a specific +// layout still pass their own HOME or CODEX_HOME to the processes they spawn. +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; +import process from "node:process"; + +const home = fs.mkdtempSync(path.join(os.tmpdir(), "cc-plugin-codex-test-home-")); +process.env.HOME = home; +process.env.USERPROFILE = home; +delete process.env.CODEX_HOME; +process.on("exit", () => { + fs.rmSync(home, { recursive: true, force: true }); +});