From 23582ea9a5038844644032966791a0aca6cb4085 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Sun, 5 Apr 2026 11:34:24 +0900 Subject: [PATCH] fix(test): isolate discovery tests from global env var contamination The discovery.test.ts was using process.env.CLAUDE_PLUGINS_HOME to set the plugins directory, but this global state could be affected by other tests running in parallel, causing flaky failures with errors like: Expected: "oh-my-openagent" Received: "demo" Changes: - Added pluginsHomeOverride option to PluginLoaderOptions type - Modified discoverInstalledPlugins to accept optional pluginsHomeOverride - Modified loadInstalledPlugins to accept optional pluginsBaseDir - Updated all 3 discovery tests to use pluginsHomeOverride instead of relying on global process.env.CLAUDE_PLUGINS_HOME This makes the tests properly isolated and deterministic regardless of test execution order or parallelization. Fixes CI failure on dev branch. --- .../claude-code-plugin-loader/discovery.test.ts | 6 +++--- src/features/claude-code-plugin-loader/discovery.ts | 12 +++++++----- src/features/claude-code-plugin-loader/types.ts | 6 ++++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/features/claude-code-plugin-loader/discovery.test.ts b/src/features/claude-code-plugin-loader/discovery.test.ts index d42286579..c7569d39f 100644 --- a/src/features/claude-code-plugin-loader/discovery.test.ts +++ b/src/features/claude-code-plugin-loader/discovery.test.ts @@ -59,7 +59,7 @@ describe("discoverInstalledPlugins", () => { ) //#when - const discovered = discoverInstalledPlugins() + const discovered = discoverInstalledPlugins({ pluginsHomeOverride: pluginsHome }) //#then expect(discovered.errors).toHaveLength(0) @@ -94,7 +94,7 @@ describe("discoverInstalledPlugins", () => { ) //#when - const discovered = discoverInstalledPlugins() + const discovered = discoverInstalledPlugins({ pluginsHomeOverride: pluginsHome }) //#then expect(discovered.errors).toHaveLength(0) @@ -129,7 +129,7 @@ describe("discoverInstalledPlugins", () => { ) //#when - const discovered = discoverInstalledPlugins() + const discovered = discoverInstalledPlugins({ pluginsHomeOverride: pluginsHome }) //#then expect(discovered.errors).toHaveLength(0) diff --git a/src/features/claude-code-plugin-loader/discovery.ts b/src/features/claude-code-plugin-loader/discovery.ts index d4d9bb577..6ee463849 100644 --- a/src/features/claude-code-plugin-loader/discovery.ts +++ b/src/features/claude-code-plugin-loader/discovery.ts @@ -23,12 +23,12 @@ function getPluginsBaseDir(): string { return join(homedir(), ".claude", "plugins") } -function getInstalledPluginsPath(): string { - return join(getPluginsBaseDir(), "installed_plugins.json") +function getInstalledPluginsPath(pluginsBaseDir?: string): string { + return join(pluginsBaseDir ?? getPluginsBaseDir(), "installed_plugins.json") } -function loadInstalledPlugins(): InstalledPluginsDatabase | null { - const dbPath = getInstalledPluginsPath() +function loadInstalledPlugins(pluginsBaseDir?: string): InstalledPluginsDatabase | null { + const dbPath = getInstalledPluginsPath(pluginsBaseDir) if (!existsSync(dbPath)) { return null } @@ -163,7 +163,9 @@ function extractPluginEntries( } export function discoverInstalledPlugins(options?: PluginLoaderOptions): PluginLoadResult { - const db = loadInstalledPlugins() + // Allow overriding the plugins base directory for testing + const pluginsBaseDir = options?.pluginsHomeOverride ?? getPluginsBaseDir() + const db = loadInstalledPlugins(pluginsBaseDir) const settings = loadClaudeSettings() const plugins: LoadedPlugin[] = [] const errors: PluginLoadError[] = [] diff --git a/src/features/claude-code-plugin-loader/types.ts b/src/features/claude-code-plugin-loader/types.ts index 9a6d5ee1c..14ca32c43 100644 --- a/src/features/claude-code-plugin-loader/types.ts +++ b/src/features/claude-code-plugin-loader/types.ts @@ -221,6 +221,12 @@ export interface ClaudeSettings { * Plugin loader options */ export interface PluginLoaderOptions { + /** + * Override the plugins home directory for testing. + * If not provided, uses CLAUDE_PLUGINS_HOME env var or ~/.claude/plugins + */ + pluginsHomeOverride?: string + /** * Override enabled plugins from oh-my-opencode config. * Key format: "pluginName@marketplace" (e.g., "shell-scripting@claude-code-workflows")