test: tighten agent tool assertions

This commit is contained in:
Peter Steinberger
2026-05-09 14:53:03 +01:00
parent 8afbe42258
commit d7d53004a9
8 changed files with 38 additions and 50 deletions

View File

@@ -197,9 +197,7 @@ describe("TOOL_POLICY_CONFORMANCE", () => {
it("is JSON-serializable", () => {
const serialized = JSON.stringify(TOOL_POLICY_CONFORMANCE);
expect(JSON.parse(serialized)).toMatchObject({
toolGroups: TOOL_GROUPS,
});
expect(JSON.parse(serialized)).toEqual({ toolGroups: TOOL_GROUPS });
});
});

View File

@@ -401,11 +401,12 @@ describe("resolveEffectiveToolInventory", () => {
modelId: "grok-test",
});
expect(createToolsMock).toHaveBeenCalledWith(
expect.objectContaining({
allowGatewaySubagentBinding: true,
modelCompat: { supportsTools: true, nativeWebSearchTool: true },
}),
);
expect(createToolsMock).toHaveBeenCalledTimes(1);
const createToolsOptions = createToolsMock.mock.calls[0]?.[0];
expect(createToolsOptions?.allowGatewaySubagentBinding).toBe(true);
expect(createToolsOptions?.modelCompat).toEqual({
supportsTools: true,
nativeWebSearchTool: true,
});
});
});

View File

@@ -58,19 +58,15 @@ function expectAllowedApply(
describe("gateway config mutation guard coverage", () => {
it("keeps a narrow allowlist of agent-tunable config paths", () => {
expect(ALLOWED_GATEWAY_CONFIG_PATHS_FOR_TEST).toEqual(
expect.arrayContaining([
"agents.defaults.systemPromptOverride",
"agents.defaults.model",
"agents.defaults.subagents.thinking",
"agents.list[].id",
"agents.list[].model",
"agents.list[].subagents.thinking",
"channels.*.requireMention",
"messages.visibleReplies",
"messages.groupChat.visibleReplies",
]),
);
expect(ALLOWED_GATEWAY_CONFIG_PATHS_FOR_TEST).toContain("agents.defaults.systemPromptOverride");
expect(ALLOWED_GATEWAY_CONFIG_PATHS_FOR_TEST).toContain("agents.defaults.model");
expect(ALLOWED_GATEWAY_CONFIG_PATHS_FOR_TEST).toContain("agents.defaults.subagents.thinking");
expect(ALLOWED_GATEWAY_CONFIG_PATHS_FOR_TEST).toContain("agents.list[].id");
expect(ALLOWED_GATEWAY_CONFIG_PATHS_FOR_TEST).toContain("agents.list[].model");
expect(ALLOWED_GATEWAY_CONFIG_PATHS_FOR_TEST).toContain("agents.list[].subagents.thinking");
expect(ALLOWED_GATEWAY_CONFIG_PATHS_FOR_TEST).toContain("channels.*.requireMention");
expect(ALLOWED_GATEWAY_CONFIG_PATHS_FOR_TEST).toContain("messages.visibleReplies");
expect(ALLOWED_GATEWAY_CONFIG_PATHS_FOR_TEST).toContain("messages.groupChat.visibleReplies");
});
it("allows documented subagent thinking default edits via config.patch", () => {

View File

@@ -182,7 +182,7 @@ describe("createSessionVisibilityGuard", () => {
a2aPolicy: createAgentToAgentPolicy({} as unknown as OpenClawConfig),
});
expect(guard.check("agent:codex:acp:child-1")).toMatchObject({ allowed: false });
expect(guard.check("agent:codex:acp:child-1").allowed).toBe(false);
expect(callGateway).not.toHaveBeenCalled();
sessionsResolutionTesting.setDepsForTest();

View File

@@ -190,13 +190,12 @@ describe("sessions-list-tool", () => {
const result = await tool.execute("call-3", {});
const details = getSessionsListDetails(result);
expect(details.sessions?.[0]).toMatchObject({
thinkingLevel: "high",
fastMode: true,
verboseLevel: "on",
reasoningLevel: "deep",
elevatedLevel: "on",
responseUsage: "full",
});
const session = details.sessions?.[0];
expect(session?.thinkingLevel).toBe("high");
expect(session?.fastMode).toBe(true);
expect(session?.verboseLevel).toBe("on");
expect(session?.reasoningLevel).toBe("deep");
expect(session?.elevatedLevel).toBe("on");
expect(session?.responseUsage).toBe("full");
});
});

View File

@@ -25,11 +25,8 @@ describe("web_search signal plumbing", () => {
await tool?.execute("call-search", { query: "openclaw" }, controller.signal);
expect(mocks.runWebSearch).toHaveBeenCalledWith(
expect.objectContaining({
args: { query: "openclaw" },
signal: controller.signal,
}),
);
expect(mocks.runWebSearch).toHaveBeenCalledTimes(1);
expect(mocks.runWebSearch.mock.calls[0]?.[0]?.args).toEqual({ query: "openclaw" });
expect(mocks.runWebSearch.mock.calls[0]?.[0]?.signal).toBe(controller.signal);
});
});

View File

@@ -180,11 +180,9 @@ describe("web_fetch extraction fallbacks", () => {
expect(details.text).toMatch(/<<<EXTERNAL_UNTRUSTED_CONTENT id="[a-f0-9]{16}">>>/);
expect(details.text).toContain("Ignore previous instructions");
expect(details.externalContent).toMatchObject({
untrusted: true,
source: "web_fetch",
wrapped: true,
});
expect(details.externalContent?.untrusted).toBe(true);
expect(details.externalContent?.source).toBe("web_fetch");
expect(details.externalContent?.wrapped).toBe(true);
// contentType is protocol metadata, not user content - should NOT be wrapped
expect(details.contentType).toBe("text/plain");
expect(details.length).toBe(details.text?.length);

View File

@@ -106,14 +106,13 @@ describe("video generation task status", () => {
expect(buildVideoGenerationTaskStatusText(activeTask, { duplicateGuard: true })).toContain(
"Do not call video_generate again for this request.",
);
expect(buildVideoGenerationTaskStatusDetails(activeTask)).toMatchObject({
active: true,
existingTask: true,
status: "running",
taskKind: VIDEO_GENERATION_TASK_KIND,
provider: "openai",
progressSummary: "Generating video",
});
const details = buildVideoGenerationTaskStatusDetails(activeTask);
expect(details.active).toBe(true);
expect(details.existingTask).toBe(true);
expect(details.status).toBe("running");
expect(details.taskKind).toBe(VIDEO_GENERATION_TASK_KIND);
expect(details.provider).toBe("openai");
expect(details.progressSummary).toBe("Generating video");
});
it("builds prompt context for active session work", () => {