fix(coding-agent): disambiguate duplicate slash commands, fixes #1061
This commit is contained in:
@@ -345,9 +345,10 @@ describe("ExtensionRunner", () => {
|
||||
|
||||
expect(commands.length).toBe(2);
|
||||
expect(commands.map((c) => c.name).sort()).toEqual(["cmd-a", "cmd-b"]);
|
||||
expect(commands.map((c) => c.invocationName).sort()).toEqual(["cmd-a", "cmd-b"]);
|
||||
});
|
||||
|
||||
it("gets command by name", async () => {
|
||||
it("gets command by invocation name", async () => {
|
||||
const cmdCode = `
|
||||
export default function(pi) {
|
||||
pi.registerCommand("my-cmd", {
|
||||
@@ -364,13 +365,14 @@ describe("ExtensionRunner", () => {
|
||||
const cmd = runner.getCommand("my-cmd");
|
||||
expect(cmd).toBeDefined();
|
||||
expect(cmd?.name).toBe("my-cmd");
|
||||
expect(cmd?.invocationName).toBe("my-cmd");
|
||||
expect(cmd?.description).toBe("My command");
|
||||
|
||||
const missing = runner.getCommand("not-exists");
|
||||
expect(missing).toBeUndefined();
|
||||
});
|
||||
|
||||
it("filters out duplicate extension commands", async () => {
|
||||
it("suffixes duplicate extension commands in insertion order", async () => {
|
||||
const cmdCode = (description: string) => `
|
||||
export default function(pi) {
|
||||
pi.registerCommand("shared-cmd", {
|
||||
@@ -382,22 +384,18 @@ describe("ExtensionRunner", () => {
|
||||
fs.writeFileSync(path.join(extensionsDir, "cmd-a.ts"), cmdCode("First command"));
|
||||
fs.writeFileSync(path.join(extensionsDir, "cmd-b.ts"), cmdCode("Second command"));
|
||||
|
||||
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
||||
|
||||
const result = await discoverAndLoadExtensions([], tempDir, tempDir);
|
||||
const runner = new ExtensionRunner(result.extensions, result.runtime, tempDir, sessionManager, modelRegistry);
|
||||
const commands = runner.getRegisteredCommands();
|
||||
const diagnostics = runner.getCommandDiagnostics();
|
||||
|
||||
expect(commands).toHaveLength(1);
|
||||
expect(commands[0]?.name).toBe("shared-cmd");
|
||||
expect(commands[0]?.description).toBe("First command");
|
||||
|
||||
expect(diagnostics).toHaveLength(1);
|
||||
expect(diagnostics[0]?.path).toEqual(path.join(extensionsDir, "cmd-b.ts"));
|
||||
|
||||
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining("conflicts with"));
|
||||
warnSpy.mockRestore();
|
||||
expect(commands).toHaveLength(2);
|
||||
expect(commands.map((command) => command.name)).toEqual(["shared-cmd", "shared-cmd"]);
|
||||
expect(commands.map((command) => command.invocationName)).toEqual(["shared-cmd:1", "shared-cmd:2"]);
|
||||
expect(commands.map((command) => command.description)).toEqual(["First command", "Second command"]);
|
||||
expect(diagnostics).toEqual([]);
|
||||
expect(runner.getCommand("shared-cmd:1")?.description).toBe("First command");
|
||||
expect(runner.getCommand("shared-cmd:2")?.description).toBe("Second command");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user