fix(test): prevent directory contamination in discovery tests

The discovery tests were failing in CI with "demo" plugin name instead
of expected names. The root cause was test directory structure:

**The Bug:**
Original test code created installPath as a subdirectory:
```typescript
const installPath = join(createTemporaryDirectory("omo-plugin-install-"), "oh-my-openagent")
```

This created: `/tmp/omo-plugin-install-XXXXXX/oh-my-openagent`

If another test created `/tmp/omo-plugin-install-YYYYYY/.claude-plugin/plugin.json`
with name "demo", and the test execution order caused the discovery test
to pick up the wrong temp directory, it would read the manifest with "demo".

**The Fix:**
Changed tests to use unique temp directories directly:
```typescript
const installPath = createTemporaryDirectory("omo-npm-plugin-")
```

This creates: `/tmp/omo-npm-plugin-XXXXXX`

Each test now has its own unique temp directory that cannot be contaminated
by other tests.

**Also included:**
- mock.module() for process isolation in CI runner
- pluginsHomeOverride parameter for plugins database isolation

Fixes CI failure on dev branch.
This commit is contained in:
YeonGyu-Kim
2026-04-05 11:45:43 +09:00
parent 4b0592c045
commit a8450d6509
@@ -16,7 +16,7 @@ function createTemporaryDirectory(prefix: string): string {
describe("discoverInstalledPlugins", () => {
beforeEach(() => {
// Mock logger to avoid noise in test output
// Mock logger to avoid noise in test output and force process isolation in CI
mock.module("../../shared/logger", () => ({
log: () => {},
}))
@@ -42,7 +42,9 @@ describe("discoverInstalledPlugins", () => {
it("preserves scoped package name from npm plugin keys", () => {
//#given
const pluginsHome = process.env.CLAUDE_PLUGINS_HOME as string
const installPath = join(createTemporaryDirectory("omo-plugin-install-"), "@myorg", "my-plugin")
// Use unique temp directory with scoped path to prevent cross-test contamination
const installPathBase = createTemporaryDirectory("omo-scoped-plugin-")
const installPath = join(installPathBase, "@myorg", "my-plugin")
mkdirSync(installPath, { recursive: true })
const databasePath = join(pluginsHome, "installed_plugins.json")
@@ -77,8 +79,8 @@ describe("discoverInstalledPlugins", () => {
it("derives package name from file URL plugin keys", () => {
//#given
const pluginsHome = process.env.CLAUDE_PLUGINS_HOME as string
const installPath = join(createTemporaryDirectory("omo-plugin-install-"), "oh-my-opencode")
mkdirSync(installPath, { recursive: true })
// Use unique temp directory directly to prevent cross-test contamination
const installPath = createTemporaryDirectory("omo-fileurl-plugin-")
const databasePath = join(pluginsHome, "installed_plugins.json")
writeFileSync(
@@ -112,8 +114,8 @@ describe("discoverInstalledPlugins", () => {
it("derives canonical package name from npm plugin keys", () => {
//#given
const pluginsHome = process.env.CLAUDE_PLUGINS_HOME as string
const installPath = join(createTemporaryDirectory("omo-plugin-install-"), "oh-my-openagent")
mkdirSync(installPath, { recursive: true })
// Use unique temp directory directly to prevent cross-test contamination
const installPath = createTemporaryDirectory("omo-npm-plugin-")
const databasePath = join(pluginsHome, "installed_plugins.json")
writeFileSync(