fix(coding-agent): attach source info to resources and commands, fixes #1734
This commit is contained in:
@@ -370,32 +370,33 @@ describe("ExtensionRunner", () => {
|
||||
expect(missing).toBeUndefined();
|
||||
});
|
||||
|
||||
it("filters out commands conflict with reseved", async () => {
|
||||
const cmdCode = (name: string) => `
|
||||
it("filters out duplicate extension commands", async () => {
|
||||
const cmdCode = (description: string) => `
|
||||
export default function(pi) {
|
||||
pi.registerCommand("${name}", {
|
||||
description: "Test command",
|
||||
pi.registerCommand("shared-cmd", {
|
||||
description: "${description}",
|
||||
handler: async () => {},
|
||||
});
|
||||
}
|
||||
`;
|
||||
fs.writeFileSync(path.join(extensionsDir, "cmd-a.ts"), cmdCode("cmd-a"));
|
||||
fs.writeFileSync(path.join(extensionsDir, "cmd-b.ts"), cmdCode("cmd-b"));
|
||||
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(new Set(["cmd-a"]));
|
||||
const commands = runner.getRegisteredCommands();
|
||||
const diagnostics = runner.getCommandDiagnostics();
|
||||
|
||||
expect(commands.length).toBe(1);
|
||||
expect(commands.map((c) => c.name).sort()).toEqual(["cmd-b"]);
|
||||
expect(commands).toHaveLength(1);
|
||||
expect(commands[0]?.name).toBe("shared-cmd");
|
||||
expect(commands[0]?.description).toBe("First command");
|
||||
|
||||
expect(diagnostics.length).toBe(1);
|
||||
expect(diagnostics[0].path).toEqual(path.join(extensionsDir, "cmd-a.ts"));
|
||||
expect(diagnostics).toHaveLength(1);
|
||||
expect(diagnostics[0]?.path).toEqual(path.join(extensionsDir, "cmd-b.ts"));
|
||||
|
||||
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining("conflicts with built-in command"));
|
||||
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining("conflicts with"));
|
||||
warnSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -346,14 +346,16 @@ Extra prompt content`,
|
||||
});
|
||||
|
||||
const { skills } = loader.getSkills();
|
||||
expect(skills.some((skill) => skill.name === "extra-skill")).toBe(true);
|
||||
const loadedSkill = skills.find((skill) => skill.name === "extra-skill");
|
||||
expect(loadedSkill).toBeDefined();
|
||||
expect(loadedSkill?.sourceInfo?.source).toBe("extension:extra");
|
||||
expect(loadedSkill?.sourceInfo?.path).toBe(skillPath);
|
||||
|
||||
const { prompts } = loader.getPrompts();
|
||||
expect(prompts.some((prompt) => prompt.name === "extra")).toBe(true);
|
||||
|
||||
const metadata = loader.getPathMetadata();
|
||||
expect(metadata.get(skillPath)?.source).toBe("extension:extra");
|
||||
expect(metadata.get(promptPath)?.source).toBe("extension:extra");
|
||||
const loadedPrompt = prompts.find((prompt) => prompt.name === "extra");
|
||||
expect(loadedPrompt).toBeDefined();
|
||||
expect(loadedPrompt?.sourceInfo?.source).toBe("extension:extra");
|
||||
expect(loadedPrompt?.sourceInfo?.path).toBe(promptPath);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -156,7 +156,6 @@ function createMinimalResourceLoader(systemPrompt: string): ResourceLoader {
|
||||
getAgentsFiles: () => ({ agentsFiles: [] }),
|
||||
getSystemPrompt: () => systemPrompt,
|
||||
getAppendSystemPrompt: () => [],
|
||||
getPathMetadata: () => new Map(),
|
||||
extendResources: () => {},
|
||||
reload: async () => {},
|
||||
};
|
||||
|
||||
@@ -58,7 +58,6 @@ This is a test skill.
|
||||
getAgentsFiles: () => ({ agentsFiles: [] }),
|
||||
getSystemPrompt: () => undefined,
|
||||
getAppendSystemPrompt: () => [],
|
||||
getPathMetadata: () => new Map(),
|
||||
extendResources: () => {},
|
||||
reload: async () => {},
|
||||
};
|
||||
@@ -92,7 +91,6 @@ This is a test skill.
|
||||
getAgentsFiles: () => ({ agentsFiles: [] }),
|
||||
getSystemPrompt: () => undefined,
|
||||
getAppendSystemPrompt: () => [],
|
||||
getPathMetadata: () => new Map(),
|
||||
extendResources: () => {},
|
||||
reload: async () => {},
|
||||
};
|
||||
|
||||
@@ -184,7 +184,6 @@ export function createTestResourceLoader(): ResourceLoader {
|
||||
getAgentsFiles: () => ({ agentsFiles: [] }),
|
||||
getSystemPrompt: () => undefined,
|
||||
getAppendSystemPrompt: () => [],
|
||||
getPathMetadata: () => new Map(),
|
||||
extendResources: () => {},
|
||||
reload: async () => {},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user