From dca0fcb9749d05294c3b954bff4349dc65f152a4 Mon Sep 17 00:00:00 2001 From: can1357 Date: Wed, 1 Apr 2026 15:31:46 +0200 Subject: [PATCH] fix(coding-agent): validate plugin scope flag --- packages/coding-agent/src/commands/plugin.ts | 5 ++++- .../coding-agent/test/plugin-command.test.ts | 22 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 packages/coding-agent/test/plugin-command.test.ts diff --git a/packages/coding-agent/src/commands/plugin.ts b/packages/coding-agent/src/commands/plugin.ts index f674977c5..9fed148a6 100644 --- a/packages/coding-agent/src/commands/plugin.ts +++ b/packages/coding-agent/src/commands/plugin.ts @@ -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 { diff --git a/packages/coding-agent/test/plugin-command.test.ts b/packages/coding-agent/test/plugin-command.test.ts new file mode 100644 index 000000000..709ac52a6 --- /dev/null +++ b/packages/coding-agent/test/plugin-command.test.ts @@ -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/); + }); +});