Skip to content

Commit 9cbc130

Browse files
authored
test(qa): prove plugin tool ownership in gateway flow (#118958)
1 parent 76cc60a commit 9cbc130

3 files changed

Lines changed: 111 additions & 3 deletions

File tree

‎extensions/qa-lab/src/tool-search-gateway.fixture.test.ts‎

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,25 @@ describe("tool search gateway e2e lane result", () => {
257257
]),
258258
);
259259
vi.stubGlobal("fetch", fetchMock);
260+
const gatewayCall = vi.fn(async () => ({
261+
groups: [
262+
{
263+
tools: [
264+
{
265+
id: "fake_plugin_tool_17",
266+
source: "plugin",
267+
pluginId: "tool-search-e2e-fixture",
268+
},
269+
],
270+
},
271+
],
272+
}));
260273
const env: QaSuiteRuntimeEnv = {
261274
alternateModel: "openai/gpt-5.6-luna",
262275
cfg: {},
263276
gateway: {
264277
baseUrl: "http://gateway.test",
265-
call: async () => undefined,
278+
call: gatewayCall,
266279
restartAfterStateMutation: async (mutateState) => {
267280
await mutateState({
268281
configPath,
@@ -293,7 +306,16 @@ describe("tool search gateway e2e lane result", () => {
293306
expect(result.providerInputSnippet).toBe(inputPrefix);
294307
expect(result.providerToolOutputSnippet).toBe(toolOutputPrefix);
295308
expect(result.providerDirectoryContainsTarget).toBe(true);
309+
expect(result.targetToolIdentity).toEqual({
310+
source: "plugin",
311+
pluginId: "tool-search-e2e-fixture",
312+
});
296313
expect(fetchMock).toHaveBeenCalledTimes(3);
314+
expect(gatewayCall).toHaveBeenCalledWith(
315+
"tools.effective",
316+
{ sessionKey: "tool-search-gateway-code" },
317+
{ timeoutMs: expect.any(Number) },
318+
);
297319
const laneConfig = JSON.parse(await fs.readFile(configPath, "utf8")) as {
298320
memory?: { search?: Record<string, unknown> };
299321
};
@@ -334,6 +356,10 @@ describe("qa fixture response helpers", () => {
334356

335357
describe("tool search gateway e2e lane assertions", () => {
336358
const targetTool = "fake_plugin_tool_17";
359+
const targetToolIdentity = {
360+
source: "plugin",
361+
pluginId: "tool-search-e2e-fixture",
362+
};
337363
const normal = {
338364
gatewayOutputText: `FAKE_PLUGIN_OK ${targetTool}`,
339365
providerDeclaredToolCount: 36,
@@ -343,6 +369,7 @@ describe("tool search gateway e2e lane assertions", () => {
343369
sessionLogToolMentions: {
344370
[targetTool]: 1,
345371
},
372+
targetToolIdentity,
346373
};
347374

348375
it("accepts code lane proof only when the target plugin tool output is present", () => {
@@ -351,6 +378,7 @@ describe("tool search gateway e2e lane assertions", () => {
351378
normal,
352379
targetTool,
353380
code: {
381+
targetToolIdentity,
354382
gatewayOutputText: `FAKE_PLUGIN_OK ${targetTool}`,
355383
providerDeclaredToolCount: 1,
356384
providerDirectoryContainsTarget: true,
@@ -377,6 +405,7 @@ describe("tool search gateway e2e lane assertions", () => {
377405
gatewayOutputText: `${normalOutput}😀tail`,
378406
},
379407
code: {
408+
targetToolIdentity,
380409
gatewayOutputText: `${codeOutput}😀tail`,
381410
providerDeclaredToolCount: 1,
382411
providerDirectoryContainsTarget: true,
@@ -399,6 +428,7 @@ describe("tool search gateway e2e lane assertions", () => {
399428
normal,
400429
targetTool,
401430
code: {
431+
targetToolIdentity,
402432
gatewayOutputText: targetTool,
403433
providerDeclaredToolCount: 1,
404434
providerDirectoryContainsTarget: true,
@@ -419,6 +449,7 @@ describe("tool search gateway e2e lane assertions", () => {
419449
normal,
420450
targetTool,
421451
code: {
452+
targetToolIdentity,
422453
gatewayOutputText: `FAKE_PLUGIN_OK ${targetTool}`,
423454
providerDeclaredToolCount: 2,
424455
providerDirectoryContainsTarget: true,
@@ -444,6 +475,7 @@ describe("tool search gateway e2e lane assertions", () => {
444475
},
445476
},
446477
code: {
478+
targetToolIdentity,
447479
gatewayOutputText: `FAKE_PLUGIN_OK ${targetTool}`,
448480
providerDeclaredToolCount: 1,
449481
providerDirectoryContainsTarget: true,
@@ -471,6 +503,7 @@ describe("tool search gateway e2e lane assertions", () => {
471503
},
472504
},
473505
code: {
506+
targetToolIdentity,
474507
gatewayOutputText: `FAKE_PLUGIN_OK ${targetTool}`,
475508
providerDeclaredToolCount: 1,
476509
providerDirectoryContainsTarget: true,
@@ -491,6 +524,7 @@ describe("tool search gateway e2e lane assertions", () => {
491524
normal,
492525
targetTool,
493526
code: {
527+
targetToolIdentity,
494528
gatewayOutputText: `FAKE_PLUGIN_OK ${targetTool}`,
495529
providerDeclaredToolCount: 1,
496530
providerDirectoryContainsTarget: false,
@@ -511,6 +545,7 @@ describe("tool search gateway e2e lane assertions", () => {
511545
normal: { ...normal, providerDirectoryContainsTarget: true },
512546
targetTool,
513547
code: {
548+
targetToolIdentity,
514549
gatewayOutputText: `FAKE_PLUGIN_OK ${targetTool}`,
515550
providerDeclaredToolCount: 1,
516551
providerDirectoryContainsTarget: true,
@@ -524,4 +559,28 @@ describe("tool search gateway e2e lane assertions", () => {
524559
}),
525560
).toThrow("normal lane unexpectedly advertised a Tool Search capability directory");
526561
});
562+
563+
it("rejects tools.effective ownership that does not identify the fixture plugin", () => {
564+
expect(() =>
565+
assertToolSearchLaneResults({
566+
normal: {
567+
...normal,
568+
targetToolIdentity: { source: "core", pluginId: "" },
569+
},
570+
targetTool,
571+
code: {
572+
targetToolIdentity,
573+
gatewayOutputText: `FAKE_PLUGIN_OK ${targetTool}`,
574+
providerDeclaredToolCount: 1,
575+
providerDirectoryContainsTarget: true,
576+
providerPlannedTools: ["tool_search_code"],
577+
providerRawBytes: 4_000,
578+
sessionLogToolMentions: {
579+
tool_search_code: 1,
580+
[targetTool]: 1,
581+
},
582+
},
583+
}),
584+
).toThrow(`tools.effective did not attribute ${targetTool} to plugin tool-search-e2e-fixture`);
585+
});
527586
});

‎extensions/qa-lab/src/tool-search-gateway.fixture.ts‎

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ type LaneResult = {
3838
gatewayOutputToolNames: string[];
3939
gatewayOutputText: string;
4040
sessionLogToolMentions: Record<string, number>;
41+
targetToolIdentity: {
42+
source: string;
43+
pluginId: string;
44+
};
4145
};
4246

4347
type LaneResultSummary = Pick<
@@ -48,6 +52,7 @@ type LaneResultSummary = Pick<
4852
| "providerRawBytes"
4953
| "gatewayOutputText"
5054
| "sessionLogToolMentions"
55+
| "targetToolIdentity"
5156
> & {
5257
providerInputSnippet?: string;
5358
providerToolOutputSnippet?: string;
@@ -332,6 +337,33 @@ async function configureLane(params: {
332337
});
333338
}
334339

340+
async function readTargetToolIdentity(params: {
341+
env: QaSuiteRuntimeEnv;
342+
sessionKey: string;
343+
targetTool: string;
344+
}) {
345+
const payload = (await params.env.gateway.call(
346+
"tools.effective",
347+
{ sessionKey: params.sessionKey },
348+
{ timeoutMs: liveTurnTimeoutMs(params.env, 90_000) },
349+
)) as {
350+
groups?: Array<{
351+
tools?: Array<{ id?: string; source?: string; pluginId?: string }>;
352+
}>;
353+
};
354+
for (const group of payload.groups ?? []) {
355+
for (const tool of group.tools ?? []) {
356+
if (tool.id === params.targetTool) {
357+
return {
358+
source: tool.source?.trim() ?? "",
359+
pluginId: tool.pluginId?.trim() ?? "",
360+
};
361+
}
362+
}
363+
}
364+
throw new Error(`tools.effective did not report ${params.targetTool}`);
365+
}
366+
335367
export async function stageToolSearchGatewayFixture(params: {
336368
env: QaSuiteRuntimeEnv;
337369
targetTool?: string;
@@ -366,6 +398,7 @@ export async function runToolSearchGatewayLane(params: {
366398
const requestCursorBefore = readQaMockRequestCursor(
367399
await fetchJson(qaMockRequestCursorUrl(providerBaseUrl)),
368400
);
401+
const sessionKey = `tool-search-gateway-${params.lane}`;
369402
const response = await fetchJson(
370403
`${params.env.gateway.baseUrl}/v1/responses`,
371404
{
@@ -375,7 +408,7 @@ export async function runToolSearchGatewayLane(params: {
375408
"content-type": "application/json",
376409
"x-openclaw-scopes": "operator.write",
377410
"x-openclaw-agent": "qa",
378-
"x-openclaw-session-key": `tool-search-gateway-${params.lane}`,
411+
"x-openclaw-session-key": sessionKey,
379412
},
380413
body: JSON.stringify({
381414
model: "openclaw/qa",
@@ -415,6 +448,11 @@ export async function runToolSearchGatewayLane(params: {
415448
.filter((value): value is string => typeof value === "string")
416449
.join("\n");
417450
const responseStatus = (response as { status?: unknown }).status;
451+
const targetToolIdentity = await readTargetToolIdentity({
452+
env: params.env,
453+
sessionKey,
454+
targetTool: params.fixture.targetTool,
455+
});
418456
const mentionCountsAfter = await countToolSearchSessionLogMentions({
419457
stateDir,
420458
targetTool: params.fixture.targetTool,
@@ -442,6 +480,7 @@ export async function runToolSearchGatewayLane(params: {
442480
gatewayOutputToolNames: outputToolNames(response),
443481
gatewayOutputText: outputText(response),
444482
sessionLogToolMentions: subtractMentionCounts(mentionCountsAfter, mentionCountsBefore),
483+
targetToolIdentity,
445484
};
446485
}
447486

@@ -519,4 +558,11 @@ export function assertToolSearchLaneResults(params: {
519558
!normal.providerPlannedTools.includes("tool_search_code"),
520559
"normal lane unexpectedly used Tool Search bridge",
521560
);
561+
for (const lane of [normal, code]) {
562+
assert(
563+
lane.targetToolIdentity.source === "plugin" &&
564+
lane.targetToolIdentity.pluginId === FAKE_PLUGIN_ID,
565+
`tools.effective did not attribute ${targetTool} to plugin ${FAKE_PLUGIN_ID}: ${laneDebug()}`,
566+
);
567+
}
522568
}

‎qa/scenarios/runtime/tool-search-gateway-e2e.yaml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ scenario:
66
coverage:
77
primary:
88
- agent-runtime.hosted-tool-use
9-
secondary:
109
- plugins.plugin-tools
10+
secondary:
1111
- plugins.tool-plugin-invocation
1212
objective: Verify the Tool Search gateway QA Lab flow keeps a large plugin-owned tool catalog behind the compact bridge while still invoking the selected plugin tool.
1313
successCriteria:
1414
- Direct mode exposes the fake plugin tool schemas and calls the selected plugin tool.
15+
- Both lanes report the selected tool through tools.effective with source=plugin and pluginId=tool-search-e2e-fixture.
1516
- Tool Search code mode exposes only the compact bridge to the provider.
1617
- Tool Search code mode automatically advertises the selected tool in its bounded system-prompt directory.
1718
- The compact bridge calls the same selected plugin tool and records bridge plus target tool mentions in session logs.
@@ -94,4 +95,6 @@ flow:
9495
compactPlannedTools: codeLane.providerPlannedTools,
9596
directMentions: normalLane.sessionLogToolMentions,
9697
compactMentions: codeLane.sessionLogToolMentions,
98+
directEffectiveTool: normalLane.targetToolIdentity,
99+
compactEffectiveTool: codeLane.targetToolIdentity,
97100
})

0 commit comments

Comments
 (0)