From a2c3804b5f7adcfbaa8cd67b0c1184dd1033af6c Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Mon, 27 Apr 2026 13:24:50 +0900 Subject: [PATCH] test(slashcommand): isolate command discovery mocks Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- .../auto-slash-command/executor-resolution.test.ts | 10 ++++++++-- src/hooks/auto-slash-command/executor.ts | 10 ++++------ src/tools/slashcommand/command-discovery-deps.ts | 6 ++++++ src/tools/slashcommand/command-discovery.ts | 7 ++++--- 4 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 src/tools/slashcommand/command-discovery-deps.ts diff --git a/src/hooks/auto-slash-command/executor-resolution.test.ts b/src/hooks/auto-slash-command/executor-resolution.test.ts index 45c905467..82d924902 100644 --- a/src/hooks/auto-slash-command/executor-resolution.test.ts +++ b/src/hooks/auto-slash-command/executor-resolution.test.ts @@ -1,8 +1,9 @@ +/// + import { afterEach, describe, expect, it, spyOn } from "bun:test" import type { LoadedSkill } from "../../features/opencode-skill-loader" import * as shared from "../../shared" -import * as slashcommand from "../../tools/slashcommand" -import { executeSlashCommand } from "./executor" +import * as slashcommand from "../../tools/slashcommand/command-discovery" let resolveCommandsInTextSpy: { mockRestore: () => void } | undefined let resolveFileReferencesInTextSpy: { mockRestore: () => void } | undefined @@ -38,6 +39,11 @@ function restoreExecutorSpies(): void { discoverCommandsSyncSpy = undefined } +async function executeSlashCommand(...args: Parameters): ReturnType { + const module = await import(`./executor?test=${Date.now()}-${Math.random()}`) + return module.executeSlashCommand(...args) +} + afterEach(restoreExecutorSpies) function createRestrictedSkill(): LoadedSkill { diff --git a/src/hooks/auto-slash-command/executor.ts b/src/hooks/auto-slash-command/executor.ts index eedd8881f..0b5c7ceb9 100644 --- a/src/hooks/auto-slash-command/executor.ts +++ b/src/hooks/auto-slash-command/executor.ts @@ -1,10 +1,8 @@ import { dirname } from "path" -import { - resolveCommandsInText, - resolveFileReferencesInText, -} from "../../shared" +import { resolveCommandsInText } from "../../shared/command-executor/resolve-commands-in-text" +import { resolveFileReferencesInText } from "../../shared/file-reference-resolver" import { discoverAllSkills, type LoadedSkill, type LazyContentLoader } from "../../features/opencode-skill-loader" -import { discoverCommandsSync } from "../../tools/slashcommand" +import * as commandDiscovery from "../../tools/slashcommand/command-discovery" import type { CommandInfo as DiscoveredCommandInfo, CommandMetadata } from "../../tools/slashcommand/types" import type { ParsedSlashCommand } from "./types" @@ -47,7 +45,7 @@ export interface ExecutorOptions { async function discoverAllCommands(options?: ExecutorOptions): Promise { - const discoveredCommands = discoverCommandsSync(options?.directory ?? process.cwd(), { + const discoveredCommands = commandDiscovery.discoverCommandsSync(options?.directory ?? process.cwd(), { pluginsEnabled: options?.pluginsEnabled, enabledPluginsOverride: options?.enabledPluginsOverride, }) diff --git a/src/tools/slashcommand/command-discovery-deps.ts b/src/tools/slashcommand/command-discovery-deps.ts new file mode 100644 index 000000000..5465e0dfc --- /dev/null +++ b/src/tools/slashcommand/command-discovery-deps.ts @@ -0,0 +1,6 @@ +export { EXCLUDED_DIRS } from "../../shared/excluded-dirs" +export { parseFrontmatter } from "../../shared/frontmatter" +export { sanitizeModelField } from "../../shared/model-sanitizer" +export { getOpenCodeCommandDirs } from "../../shared/opencode-command-dirs" +export { discoverPluginCommandDefinitions } from "../../shared/plugin-command-discovery" +export { findProjectOpencodeCommandDirs } from "../../shared/project-discovery-dirs" diff --git a/src/tools/slashcommand/command-discovery.ts b/src/tools/slashcommand/command-discovery.ts index 855f6dc28..0900dec42 100644 --- a/src/tools/slashcommand/command-discovery.ts +++ b/src/tools/slashcommand/command-discovery.ts @@ -7,11 +7,12 @@ import { getOpenCodeCommandDirs, discoverPluginCommandDefinitions, EXCLUDED_DIRS, -} from "../../shared" +} from "./command-discovery-deps" import type { CommandFrontmatter } from "../../features/claude-code-command-loader/types" import { isMarkdownFile } from "../../shared/file-utils" -import { getClaudeConfigDir, log } from "../../shared" -import { loadBuiltinCommands } from "../../features/builtin-commands" +import { getClaudeConfigDir } from "../../shared/claude-config-dir" +import { log } from "../../shared/logger" +import { loadBuiltinCommands } from "../../features/builtin-commands/commands" import type { CommandInfo, CommandMetadata, CommandScope } from "./types" export interface CommandDiscoveryOptions {