fix(coding-agent): validate plugin scope flag

This commit is contained in:
can1357
2026-04-01 15:31:46 +02:00
parent 5acd56a5e3
commit dca0fcb974
2 changed files with 26 additions and 1 deletions
+4 -1
View File
@@ -45,7 +45,10 @@ export default class Plugin extends Command {
enable: Flags.string({ description: "Enable a feature" }),
disable: Flags.string({ description: "Disable a feature" }),
set: Flags.string({ description: "Set plugin config (key=value)" }),
scope: Flags.string({ description: 'Install scope: "user" (default) or "project"' }),
scope: Flags.string({
description: 'Install scope: "user" (default) or "project"',
options: ["user", "project"],
}),
};
async run(): Promise<void> {
@@ -0,0 +1,22 @@
import { describe, expect, it } from "bun:test";
import type { CliConfig } from "@oh-my-pi/pi-utils/cli";
import Plugin from "../src/commands/plugin";
const TEST_CONFIG: CliConfig = {
bin: "omp",
version: "0.0.0-test",
commands: new Map(),
};
describe("Plugin command scope parsing", () => {
it("accepts project scope", async () => {
const command = new Plugin(["install", "--scope", "project"], TEST_CONFIG);
const { flags } = await command.parse(Plugin);
expect(flags.scope).toBe("project");
});
it("rejects invalid scope values", async () => {
const command = new Plugin(["install", "--scope", "porject"], TEST_CONFIG);
await expect(command.parse(Plugin)).rejects.toThrow(/Expected --scope to be one of: user, project/);
});
});