From 097e2be7e823b972d3d1a44f57bfc731882f0a74 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Thu, 26 Mar 2026 12:59:46 +0900 Subject: [PATCH] fix(slashcommand): discover nested opencode commands with slash names Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- ...opencode-project-command-discovery.test.ts | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/tools/slashcommand/opencode-project-command-discovery.test.ts diff --git a/src/tools/slashcommand/opencode-project-command-discovery.test.ts b/src/tools/slashcommand/opencode-project-command-discovery.test.ts new file mode 100644 index 000000000..f845d9b93 --- /dev/null +++ b/src/tools/slashcommand/opencode-project-command-discovery.test.ts @@ -0,0 +1,60 @@ +import { execFileSync } from "node:child_process" +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 { discoverCommandsSync } from "./command-discovery" + +function writeCommand(path: string, description: string, body: string): void { + mkdirSync(join(path, ".."), { recursive: true }) + writeFileSync(path, `---\ndescription: ${description}\n---\n${body}\n`) +} + +describe("opencode project command discovery", () => { + let tempDir = "" + + beforeEach(() => { + tempDir = mkdtempSync(join(tmpdir(), "omo-opencode-project-command-discovery-")) + }) + + afterEach(() => { + rmSync(tempDir, { recursive: true, force: true }) + }) + + it("discovers ancestor opencode commands with slash-separated nested names and worktree boundaries", () => { + // given + const repositoryDir = join(tempDir, "repo") + const nestedDirectory = join(repositoryDir, "packages", "app", "src") + + mkdirSync(nestedDirectory, { recursive: true }) + execFileSync("git", ["init"], { + cwd: repositoryDir, + stdio: ["ignore", "ignore", "ignore"], + }) + + writeCommand( + join(repositoryDir, ".opencode", "commands", "deploy", "staging.md"), + "Deploy to staging", + "Run the staged deploy.", + ) + writeCommand( + join(repositoryDir, ".opencode", "command", "release.md"), + "Release command", + "Run the release.", + ) + writeCommand( + join(tempDir, ".opencode", "commands", "outside.md"), + "Outside command", + "Should not be discovered.", + ) + + // when + const names = discoverCommandsSync(nestedDirectory).map(command => command.name) + + // then + expect(names).toContain("deploy/staging") + expect(names).toContain("release") + expect(names).not.toContain("deploy:staging") + expect(names).not.toContain("outside") + }) +})