Files
oh-my-pi/packages/coding-agent/test/install-command.test.ts
T
roboomp db525316ab fix(discovery): wire extension package sub-dirs into discovery + add top-level install command
Bug 1: capability loaders in src/discovery/builtin.ts only walked
.omp/ and ~/.omp/agent/, so extension packages registered via
extensions: in settings or --extension on the CLI shipped their
skills/, hooks/pre|post/, tools/, commands/, rules/, prompts/, and
.mcp.json silently — the docs at omp.sh/docs/extension-authoring
advertise the opposite. Add a new omp-plugins discovery provider that
scans every configured extension package directory for those
sub-trees, plus a small omp-extension-roots helper that resolves the
union of settings-driven and CLI-injected roots. main.ts injects CLI
extension paths via injectOmpExtensionCliRoots before any capability
load.

Bug 2: install was never registered as a top-level subcommand, so
`omp install ./my-extension` was rewritten to `launch install
./my-extension` and forwarded to the LLM as an initial prompt. Add a
top-level install command that routes local paths to plugin link and
remote specs to plugin install. Extract the command table into
src/cli-commands.ts so tests can introspect registered subcommands
without triggering cli.ts's top-level await.

Fixes #1496
2026-05-29 06:16:32 +00:00

66 lines
2.6 KiB
TypeScript

/**
* Regression test for #1496 (bug 2): `omp install ./my-extension` used to be
* silently rewritten to `launch install ./my-extension` and forwarded to the
* LLM as an initial prompt because no top-level `install` subcommand existed.
*
* These tests pin two invariants:
*
* 1. `install` is registered in the CLI command table, so the runner does
* not prepend `launch` and the args never reach the model.
* 2. The local-path heuristic that routes `install ./foo` to `plugin link`
* while routing remote specs to `plugin install` is correct for the
* shapes users actually type.
*/
import { describe, expect, test } from "bun:test";
import * as fs from "node:fs";
import * as os from "node:os";
import * as path from "node:path";
import { looksLikeLocalPath } from "@oh-my-pi/pi-coding-agent/commands/install";
describe("install command is registered as a top-level subcommand", () => {
test("CLI runner sees `install` as a known command", async () => {
const cli = await import("@oh-my-pi/pi-coding-agent/cli-commands");
expect(cli.commands.some(c => c.name === "install")).toBe(true);
expect(cli.isSubcommand("install")).toBe(true);
});
});
describe("looksLikeLocalPath", () => {
test("explicit relative paths are local", () => {
expect(looksLikeLocalPath("./my-extension")).toBe(true);
expect(looksLikeLocalPath("../sibling")).toBe(true);
expect(looksLikeLocalPath(".")).toBe(true);
});
test("absolute and home-relative paths are local", () => {
expect(looksLikeLocalPath("/usr/local/share/ext")).toBe(true);
expect(looksLikeLocalPath("~/extensions/foo")).toBe(true);
});
test("Windows drive-prefixed paths are local", () => {
expect(looksLikeLocalPath("C:\\extensions\\foo")).toBe(true);
expect(looksLikeLocalPath("D:/extensions/foo")).toBe(true);
});
test("npm specs and marketplace refs are remote", () => {
expect(looksLikeLocalPath("@oh-my-pi/exa")).toBe(false);
expect(looksLikeLocalPath("my-pkg")).toBe(false);
expect(looksLikeLocalPath("my-pkg@1.2.3")).toBe(false);
expect(looksLikeLocalPath("name@marketplace")).toBe(false);
});
test("bare names that exist as a local directory are treated as local", () => {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "omp-install-test-"));
const cwd = process.cwd();
try {
process.chdir(tempDir);
fs.mkdirSync(path.join(tempDir, "vendored-ext"));
expect(looksLikeLocalPath("vendored-ext")).toBe(true);
expect(looksLikeLocalPath("missing-pkg")).toBe(false);
} finally {
process.chdir(cwd);
fs.rmSync(tempDir, { recursive: true, force: true });
}
});
});