test(slashcommand): isolate command discovery mocks

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-04-27 13:24:50 +09:00
parent ecce65bb67
commit a2c3804b5f
4 changed files with 22 additions and 11 deletions
@@ -1,8 +1,9 @@
/// <reference types="bun-types" />
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<typeof import("./executor").executeSlashCommand>): ReturnType<typeof import("./executor").executeSlashCommand> {
const module = await import(`./executor?test=${Date.now()}-${Math.random()}`)
return module.executeSlashCommand(...args)
}
afterEach(restoreExecutorSpies)
function createRestrictedSkill(): LoadedSkill {
+4 -6
View File
@@ -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<CommandInfo[]> {
const discoveredCommands = discoverCommandsSync(options?.directory ?? process.cwd(), {
const discoveredCommands = commandDiscovery.discoverCommandsSync(options?.directory ?? process.cwd(), {
pluginsEnabled: options?.pluginsEnabled,
enabledPluginsOverride: options?.enabledPluginsOverride,
})
@@ -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"
+4 -3
View File
@@ -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 {