mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 18:44:31 +00:00
test: migrate suites to e2e coverage layout
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
import type { AgentTool, AgentToolResult } from "@mariozechner/pi-agent-core";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { filterToolsByPolicy, isToolAllowedByPolicyName } from "./pi-tools.policy.js";
|
||||
|
||||
function createStubTool(name: string): AgentTool<unknown, unknown> {
|
||||
return {
|
||||
name,
|
||||
label: name,
|
||||
description: "",
|
||||
parameters: {},
|
||||
execute: async () => ({}) as AgentToolResult<unknown>,
|
||||
};
|
||||
}
|
||||
|
||||
describe("pi-tools.policy", () => {
|
||||
it("treats * in allow as allow-all", () => {
|
||||
const tools = [createStubTool("read"), createStubTool("exec")];
|
||||
const filtered = filterToolsByPolicy(tools, { allow: ["*"] });
|
||||
expect(filtered.map((tool) => tool.name)).toEqual(["read", "exec"]);
|
||||
});
|
||||
|
||||
it("treats * in deny as deny-all", () => {
|
||||
const tools = [createStubTool("read"), createStubTool("exec")];
|
||||
const filtered = filterToolsByPolicy(tools, { deny: ["*"] });
|
||||
expect(filtered).toEqual([]);
|
||||
});
|
||||
|
||||
it("supports wildcard allow/deny patterns", () => {
|
||||
expect(isToolAllowedByPolicyName("web_fetch", { allow: ["web_*"] })).toBe(true);
|
||||
expect(isToolAllowedByPolicyName("web_search", { deny: ["web_*"] })).toBe(false);
|
||||
});
|
||||
|
||||
it("keeps apply_patch when exec is allowlisted", () => {
|
||||
expect(isToolAllowedByPolicyName("apply_patch", { allow: ["exec"] })).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user