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 }); +});