fix(slashcommand): support parent config dirs in command execution path to match discovery

This commit is contained in:
YeonGyu-Kim
2026-03-13 10:54:15 +09:00
parent e3f6c12347
commit cbe113ebab
2 changed files with 85 additions and 113 deletions
@@ -0,0 +1,63 @@
import { afterEach, beforeEach, describe, expect, it } from "bun:test"
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs"
import { tmpdir } from "node:os"
import { join } from "node:path"
import { executeSlashCommand } from "../../hooks/auto-slash-command/executor"
import { discoverCommandsSync } from "./command-discovery"
describe("slashcommand discovery and execution compatibility", () => {
let tempDir = ""
let originalWorkingDirectory = ""
let originalOpencodeConfigDir: string | undefined
beforeEach(() => {
tempDir = mkdtempSync(join(tmpdir(), "omo-slashcommand-compat-test-"))
originalWorkingDirectory = process.cwd()
originalOpencodeConfigDir = process.env.OPENCODE_CONFIG_DIR
})
afterEach(() => {
process.chdir(originalWorkingDirectory)
if (originalOpencodeConfigDir === undefined) {
delete process.env.OPENCODE_CONFIG_DIR
} else {
process.env.OPENCODE_CONFIG_DIR = originalOpencodeConfigDir
}
rmSync(tempDir, { recursive: true, force: true })
})
it("executes commands discovered from a parent opencode config dir", async () => {
// given
const projectDir = join(tempDir, "project")
const opencodeRootDir = join(tempDir, "opencode-root")
const profileConfigDir = join(opencodeRootDir, "profiles", "codex")
const parentCommandDir = join(opencodeRootDir, "command")
const commandName = "parent-only-command"
mkdirSync(projectDir, { recursive: true })
mkdirSync(profileConfigDir, { recursive: true })
mkdirSync(parentCommandDir, { recursive: true })
writeFileSync(
join(parentCommandDir, `${commandName}.md`),
`---\ndescription: Parent config command\n---\nExecute from parent config.\n`,
)
process.env.OPENCODE_CONFIG_DIR = profileConfigDir
process.chdir(projectDir)
expect(discoverCommandsSync(projectDir).some(command => command.name === commandName)).toBe(true)
// when
const result = await executeSlashCommand({
command: commandName,
args: "",
raw: `/${commandName}`,
}, { skills: [] })
// then
expect(result.success).toBe(true)
expect(result.replacementText).toContain("Execute from parent config.")
expect(result.replacementText).toContain("**Scope**: opencode")
})
})