From a8450d6509c887381c71904d2bc2d947a859c863 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Sun, 5 Apr 2026 11:45:43 +0900 Subject: [PATCH] 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. --- .../claude-code-plugin-loader/discovery.test.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/features/claude-code-plugin-loader/discovery.test.ts b/src/features/claude-code-plugin-loader/discovery.test.ts index a5cb220cf..7983013fb 100644 --- a/src/features/claude-code-plugin-loader/discovery.test.ts +++ b/src/features/claude-code-plugin-loader/discovery.test.ts @@ -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(