mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-08-28 08:35:57 +00:00
fix(tool-search): avoid blocking known group activation
This commit is contained in:
@@ -5,7 +5,7 @@ import { join } from "node:path";
|
||||
import test from "node:test";
|
||||
|
||||
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
||||
import toolSearchExtension from "../extensions/index.ts";
|
||||
import toolSearchExtension, { platformToolPolicy } from "../extensions/index.ts";
|
||||
|
||||
interface ToolSearchResult {
|
||||
details: {
|
||||
@@ -249,3 +249,76 @@ test("uses the precomputed bundle groups without calling a model", async () => {
|
||||
await rm(agentDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("keeps PowerShell with Bash only on Windows", () => {
|
||||
const definitions = [
|
||||
sourceTool("bash", "Run Bash commands"),
|
||||
sourceTool("powershell", "Run PowerShell commands"),
|
||||
sourceTool("read", "Read a file"),
|
||||
];
|
||||
|
||||
const nonWindows = platformToolPolicy(definitions, "darwin");
|
||||
assert.deepEqual(nonWindows.tools.map((tool) => tool.name), ["bash", "read"]);
|
||||
assert.ok(nonWindows.coreTools.includes("bash"));
|
||||
assert.ok(!nonWindows.coreTools.includes("powershell"));
|
||||
|
||||
const windows = platformToolPolicy(definitions, "win32");
|
||||
assert.deepEqual(windows.tools.map((tool) => tool.name), ["bash", "powershell", "read"]);
|
||||
assert.ok(windows.coreTools.includes("bash"));
|
||||
assert.ok(windows.coreTools.includes("powershell"));
|
||||
});
|
||||
|
||||
test("loads an exact known group without waiting for unknown-tool model enrichment", async () => {
|
||||
const agentDir = await mkdtemp(join(tmpdir(), "my-pi-tool-search-fast-path-"));
|
||||
const previousAgentDir = process.env.PI_CODING_AGENT_DIR;
|
||||
process.env.PI_CODING_AGENT_DIR = agentDir;
|
||||
|
||||
try {
|
||||
const handlers = new Map<string, (...args: any[]) => unknown>();
|
||||
const registered = new Map<string, RegisteredTool>();
|
||||
let modelCalls = 0;
|
||||
const sourceTools = [
|
||||
sourceTool("read", "Read a file"),
|
||||
sourceTool("tavily_web_search", "Search broadly for current web sources"),
|
||||
sourceTool("tavily_web_fetch", "Fetch a selected Tavily source"),
|
||||
sourceTool("unrecognized_extra", "An unrecognized third-party capability"),
|
||||
];
|
||||
const api = {
|
||||
getAllTools: () => sourceTools,
|
||||
registerTool: (definition: unknown) => {
|
||||
const tool = definition as RegisteredTool & { name: string };
|
||||
registered.set(tool.name, tool);
|
||||
},
|
||||
registerCommand: () => {},
|
||||
setActiveTools: () => {},
|
||||
on: (event: string, handler: (...args: any[]) => unknown) => handlers.set(event, handler),
|
||||
} as unknown as ExtensionAPI;
|
||||
toolSearchExtension(api);
|
||||
const ctx = testContext({
|
||||
model: { provider: "test", id: "catalog-model" } as ExtensionContext["model"],
|
||||
modelRegistry: {
|
||||
hasConfiguredAuth: () => true,
|
||||
complete: async () => {
|
||||
modelCalls += 1;
|
||||
throw new Error("an exact known group must not wait for model enrichment");
|
||||
},
|
||||
} as unknown as ExtensionContext["modelRegistry"],
|
||||
});
|
||||
handlers.get("session_start")?.({}, ctx);
|
||||
|
||||
const result = await registered.get("tool_search")?.execute(
|
||||
"call-1",
|
||||
{ group: "web-tavily" },
|
||||
undefined,
|
||||
undefined,
|
||||
ctx,
|
||||
);
|
||||
assert.equal(result?.details.loadedGroup, "web-tavily");
|
||||
assert.equal(result?.details.catalogSource, "hybrid");
|
||||
assert.equal(modelCalls, 0);
|
||||
} finally {
|
||||
if (previousAgentDir === undefined) delete process.env.PI_CODING_AGENT_DIR;
|
||||
else process.env.PI_CODING_AGENT_DIR = previousAgentDir;
|
||||
await rm(agentDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user