fix(plugins): isolate cached tool runtime siblings

This commit is contained in:
Vincent Koc
2026-06-01 02:05:23 +01:00
committed by GitHub
parent 53990d5bbf
commit 570e2db252
2 changed files with 35 additions and 2 deletions

View File

@@ -2061,6 +2061,39 @@ describe("resolvePluginTools optional tools", () => {
expect(factory).toHaveBeenCalledTimes(2);
});
it("executes cached healthy tools when a runtime sibling is malformed", async () => {
const factory = vi.fn(() => [
createMalformedTool("fuzz_move_angles"),
{
...makeTool("mockplugin_status"),
async execute() {
return { content: [{ type: "text", text: "mock-status-ok" }] };
},
},
]);
setRegistry([
{
pluginId: "fuzzplugin",
optional: false,
source: "/tmp/fuzzplugin.js",
names: ["mockplugin_status"],
factory,
},
]);
const first = resolvePluginTools(createResolveToolsParams());
const second = resolvePluginTools(createResolveToolsParams());
const statusTool = second.find((tool) => tool.name === "mockplugin_status");
expectResolvedToolNames(first, ["mockplugin_status"]);
expectResolvedToolNames(second, ["mockplugin_status"]);
expect(factory).toHaveBeenCalledTimes(1);
await expect(statusTool?.execute("call", {}, undefined)).resolves.toEqual({
content: [{ type: "text", text: "mock-status-ok" }],
});
expect(factory).toHaveBeenCalledTimes(2);
});
it("reuses cached plugin tool descriptors across session identity changes", async () => {
const factory = vi.fn((rawCtx: unknown) => {
const ctx = rawCtx as { sessionId?: string };

View File

@@ -692,10 +692,10 @@ function createCachedDescriptorPluginTool(params: {
for (const toolRaw of listRaw) {
const malformedReason = describeMalformedPluginTool(toolRaw);
if (malformedReason) {
throw new Error(`plugin tool is malformed (${pluginId}): ${malformedReason}`);
continue;
}
const runtimeTool = toolRaw as AnyAgentTool;
if (normalizeToolName(runtimeTool.name) === requestedToolName) {
if (normalizeToolName(readPluginToolName(runtimeTool)) === requestedToolName) {
return runtimeTool;
}
}