mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 14:51:24 +00:00
test: strengthen ports, tool policy, and note wrapping
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { AnyAgentTool } from "./tools/common.js";
|
||||
import { TOOL_POLICY_CONFORMANCE } from "./tool-policy.conformance.js";
|
||||
import { expandToolGroups, resolveToolProfilePolicy, TOOL_GROUPS } from "./tool-policy.js";
|
||||
import {
|
||||
applyOwnerOnlyToolPolicy,
|
||||
expandToolGroups,
|
||||
isOwnerOnlyToolName,
|
||||
normalizeToolName,
|
||||
resolveToolProfilePolicy,
|
||||
TOOL_GROUPS,
|
||||
} from "./tool-policy.js";
|
||||
|
||||
describe("tool-policy", () => {
|
||||
it("expands groups and normalizes aliases", () => {
|
||||
@@ -28,6 +36,53 @@ describe("tool-policy", () => {
|
||||
expect(group).toContain("subagents");
|
||||
expect(group).toContain("session_status");
|
||||
});
|
||||
|
||||
it("normalizes tool names and aliases", () => {
|
||||
expect(normalizeToolName(" BASH ")).toBe("exec");
|
||||
expect(normalizeToolName("apply-patch")).toBe("apply_patch");
|
||||
expect(normalizeToolName("READ")).toBe("read");
|
||||
});
|
||||
|
||||
it("identifies owner-only tools", () => {
|
||||
expect(isOwnerOnlyToolName("whatsapp_login")).toBe(true);
|
||||
expect(isOwnerOnlyToolName("read")).toBe(false);
|
||||
});
|
||||
|
||||
it("strips owner-only tools for non-owner senders", async () => {
|
||||
const tools = [
|
||||
{
|
||||
name: "read",
|
||||
// oxlint-disable-next-line typescript/no-explicit-any
|
||||
execute: async () => ({ content: [], details: {} }) as any,
|
||||
},
|
||||
{
|
||||
name: "whatsapp_login",
|
||||
// oxlint-disable-next-line typescript/no-explicit-any
|
||||
execute: async () => ({ content: [], details: {} }) as any,
|
||||
},
|
||||
] as unknown as AnyAgentTool[];
|
||||
|
||||
const filtered = applyOwnerOnlyToolPolicy(tools, false);
|
||||
expect(filtered.map((t) => t.name)).toEqual(["read"]);
|
||||
});
|
||||
|
||||
it("keeps owner-only tools for the owner sender", async () => {
|
||||
const tools = [
|
||||
{
|
||||
name: "read",
|
||||
// oxlint-disable-next-line typescript/no-explicit-any
|
||||
execute: async () => ({ content: [], details: {} }) as any,
|
||||
},
|
||||
{
|
||||
name: "whatsapp_login",
|
||||
// oxlint-disable-next-line typescript/no-explicit-any
|
||||
execute: async () => ({ content: [], details: {} }) as any,
|
||||
},
|
||||
] as unknown as AnyAgentTool[];
|
||||
|
||||
const filtered = applyOwnerOnlyToolPolicy(tools, true);
|
||||
expect(filtered.map((t) => t.name)).toEqual(["read", "whatsapp_login"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("TOOL_POLICY_CONFORMANCE", () => {
|
||||
|
||||
Reference in New Issue
Block a user