mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 05:37:41 +00:00
refactor: rename to openclaw
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import "./test-helpers/fast-coding-tools.js";
|
||||
import type { MoltbotConfig } from "../config/config.js";
|
||||
import { createMoltbotCodingTools } from "./pi-tools.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { createOpenClawCodingTools } from "./pi-tools.js";
|
||||
import type { SandboxDockerConfig } from "./sandbox.js";
|
||||
|
||||
describe("Agent-specific tool filtering", () => {
|
||||
it("should apply global tool policy when no agent-specific policy exists", () => {
|
||||
const cfg: MoltbotConfig = {
|
||||
const cfg: OpenClawConfig = {
|
||||
tools: {
|
||||
allow: ["read", "write"],
|
||||
deny: ["bash"],
|
||||
@@ -15,13 +15,13 @@ describe("Agent-specific tool filtering", () => {
|
||||
list: [
|
||||
{
|
||||
id: "main",
|
||||
workspace: "~/clawd",
|
||||
workspace: "~/openclaw",
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const tools = createMoltbotCodingTools({
|
||||
const tools = createOpenClawCodingTools({
|
||||
config: cfg,
|
||||
sessionKey: "agent:main:main",
|
||||
workspaceDir: "/tmp/test",
|
||||
@@ -36,7 +36,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
});
|
||||
|
||||
it("should keep global tool policy when agent only sets tools.elevated", () => {
|
||||
const cfg: MoltbotConfig = {
|
||||
const cfg: OpenClawConfig = {
|
||||
tools: {
|
||||
deny: ["write"],
|
||||
},
|
||||
@@ -44,7 +44,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
list: [
|
||||
{
|
||||
id: "main",
|
||||
workspace: "~/clawd",
|
||||
workspace: "~/openclaw",
|
||||
tools: {
|
||||
elevated: {
|
||||
enabled: true,
|
||||
@@ -56,7 +56,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
},
|
||||
};
|
||||
|
||||
const tools = createMoltbotCodingTools({
|
||||
const tools = createOpenClawCodingTools({
|
||||
config: cfg,
|
||||
sessionKey: "agent:main:main",
|
||||
workspaceDir: "/tmp/test",
|
||||
@@ -71,7 +71,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
});
|
||||
|
||||
it("should allow apply_patch when exec is allow-listed and applyPatch is enabled", () => {
|
||||
const cfg: MoltbotConfig = {
|
||||
const cfg: OpenClawConfig = {
|
||||
tools: {
|
||||
allow: ["read", "exec"],
|
||||
exec: {
|
||||
@@ -80,7 +80,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
},
|
||||
};
|
||||
|
||||
const tools = createMoltbotCodingTools({
|
||||
const tools = createOpenClawCodingTools({
|
||||
config: cfg,
|
||||
sessionKey: "agent:main:main",
|
||||
workspaceDir: "/tmp/test",
|
||||
@@ -96,7 +96,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
});
|
||||
|
||||
it("should apply agent-specific tool policy", () => {
|
||||
const cfg: MoltbotConfig = {
|
||||
const cfg: OpenClawConfig = {
|
||||
tools: {
|
||||
allow: ["read", "write", "exec"],
|
||||
deny: [],
|
||||
@@ -105,7 +105,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
list: [
|
||||
{
|
||||
id: "restricted",
|
||||
workspace: "~/clawd-restricted",
|
||||
workspace: "~/openclaw-restricted",
|
||||
tools: {
|
||||
allow: ["read"], // Agent override: only read
|
||||
deny: ["exec", "write", "edit"],
|
||||
@@ -115,7 +115,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
},
|
||||
};
|
||||
|
||||
const tools = createMoltbotCodingTools({
|
||||
const tools = createOpenClawCodingTools({
|
||||
config: cfg,
|
||||
sessionKey: "agent:restricted:main",
|
||||
workspaceDir: "/tmp/test-restricted",
|
||||
@@ -131,7 +131,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
});
|
||||
|
||||
it("should apply provider-specific tool policy", () => {
|
||||
const cfg: MoltbotConfig = {
|
||||
const cfg: OpenClawConfig = {
|
||||
tools: {
|
||||
allow: ["read", "write", "exec"],
|
||||
byProvider: {
|
||||
@@ -142,7 +142,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
},
|
||||
};
|
||||
|
||||
const tools = createMoltbotCodingTools({
|
||||
const tools = createOpenClawCodingTools({
|
||||
config: cfg,
|
||||
sessionKey: "agent:main:main",
|
||||
workspaceDir: "/tmp/test-provider",
|
||||
@@ -159,7 +159,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
});
|
||||
|
||||
it("should apply provider-specific tool profile overrides", () => {
|
||||
const cfg: MoltbotConfig = {
|
||||
const cfg: OpenClawConfig = {
|
||||
tools: {
|
||||
profile: "coding",
|
||||
byProvider: {
|
||||
@@ -170,7 +170,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
},
|
||||
};
|
||||
|
||||
const tools = createMoltbotCodingTools({
|
||||
const tools = createOpenClawCodingTools({
|
||||
config: cfg,
|
||||
sessionKey: "agent:main:main",
|
||||
workspaceDir: "/tmp/test-provider-profile",
|
||||
@@ -184,17 +184,17 @@ describe("Agent-specific tool filtering", () => {
|
||||
});
|
||||
|
||||
it("should allow different tool policies for different agents", () => {
|
||||
const cfg: MoltbotConfig = {
|
||||
const cfg: OpenClawConfig = {
|
||||
agents: {
|
||||
list: [
|
||||
{
|
||||
id: "main",
|
||||
workspace: "~/clawd",
|
||||
workspace: "~/openclaw",
|
||||
// No tools restriction - all tools available
|
||||
},
|
||||
{
|
||||
id: "family",
|
||||
workspace: "~/clawd-family",
|
||||
workspace: "~/openclaw-family",
|
||||
tools: {
|
||||
allow: ["read"],
|
||||
deny: ["exec", "write", "edit", "process"],
|
||||
@@ -205,7 +205,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
};
|
||||
|
||||
// main agent: all tools
|
||||
const mainTools = createMoltbotCodingTools({
|
||||
const mainTools = createOpenClawCodingTools({
|
||||
config: cfg,
|
||||
sessionKey: "agent:main:main",
|
||||
workspaceDir: "/tmp/test-main",
|
||||
@@ -218,7 +218,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
expect(mainToolNames).not.toContain("apply_patch");
|
||||
|
||||
// family agent: restricted
|
||||
const familyTools = createMoltbotCodingTools({
|
||||
const familyTools = createOpenClawCodingTools({
|
||||
config: cfg,
|
||||
sessionKey: "agent:family:whatsapp:group:123",
|
||||
workspaceDir: "/tmp/test-family",
|
||||
@@ -233,7 +233,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
});
|
||||
|
||||
it("should apply group tool policy overrides (group-specific beats wildcard)", () => {
|
||||
const cfg: MoltbotConfig = {
|
||||
const cfg: OpenClawConfig = {
|
||||
channels: {
|
||||
whatsapp: {
|
||||
groups: {
|
||||
@@ -248,7 +248,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
},
|
||||
};
|
||||
|
||||
const trustedTools = createMoltbotCodingTools({
|
||||
const trustedTools = createOpenClawCodingTools({
|
||||
config: cfg,
|
||||
sessionKey: "agent:main:whatsapp:group:trusted",
|
||||
messageProvider: "whatsapp",
|
||||
@@ -259,7 +259,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
expect(trustedNames).toContain("read");
|
||||
expect(trustedNames).toContain("exec");
|
||||
|
||||
const defaultTools = createMoltbotCodingTools({
|
||||
const defaultTools = createOpenClawCodingTools({
|
||||
config: cfg,
|
||||
sessionKey: "agent:main:whatsapp:group:unknown",
|
||||
messageProvider: "whatsapp",
|
||||
@@ -272,7 +272,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
});
|
||||
|
||||
it("should apply per-sender tool policies for group tools", () => {
|
||||
const cfg: MoltbotConfig = {
|
||||
const cfg: OpenClawConfig = {
|
||||
channels: {
|
||||
whatsapp: {
|
||||
groups: {
|
||||
@@ -287,7 +287,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
},
|
||||
};
|
||||
|
||||
const aliceTools = createMoltbotCodingTools({
|
||||
const aliceTools = createOpenClawCodingTools({
|
||||
config: cfg,
|
||||
sessionKey: "agent:main:whatsapp:group:family",
|
||||
senderId: "alice",
|
||||
@@ -298,7 +298,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
expect(aliceNames).toContain("read");
|
||||
expect(aliceNames).toContain("exec");
|
||||
|
||||
const bobTools = createMoltbotCodingTools({
|
||||
const bobTools = createOpenClawCodingTools({
|
||||
config: cfg,
|
||||
sessionKey: "agent:main:whatsapp:group:family",
|
||||
senderId: "bob",
|
||||
@@ -311,7 +311,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
});
|
||||
|
||||
it("should not let default sender policy override group tools", () => {
|
||||
const cfg: MoltbotConfig = {
|
||||
const cfg: OpenClawConfig = {
|
||||
channels: {
|
||||
whatsapp: {
|
||||
groups: {
|
||||
@@ -328,7 +328,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
},
|
||||
};
|
||||
|
||||
const adminTools = createMoltbotCodingTools({
|
||||
const adminTools = createOpenClawCodingTools({
|
||||
config: cfg,
|
||||
sessionKey: "agent:main:whatsapp:group:locked",
|
||||
senderId: "admin",
|
||||
@@ -341,7 +341,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
});
|
||||
|
||||
it("should resolve telegram group tool policy for topic session keys", () => {
|
||||
const cfg: MoltbotConfig = {
|
||||
const cfg: OpenClawConfig = {
|
||||
channels: {
|
||||
telegram: {
|
||||
groups: {
|
||||
@@ -353,7 +353,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
},
|
||||
};
|
||||
|
||||
const tools = createMoltbotCodingTools({
|
||||
const tools = createOpenClawCodingTools({
|
||||
config: cfg,
|
||||
sessionKey: "agent:main:telegram:group:123:topic:456",
|
||||
messageProvider: "telegram",
|
||||
@@ -366,7 +366,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
});
|
||||
|
||||
it("should inherit group tool policy for subagents from spawnedBy session keys", () => {
|
||||
const cfg: MoltbotConfig = {
|
||||
const cfg: OpenClawConfig = {
|
||||
channels: {
|
||||
whatsapp: {
|
||||
groups: {
|
||||
@@ -378,7 +378,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
},
|
||||
};
|
||||
|
||||
const tools = createMoltbotCodingTools({
|
||||
const tools = createOpenClawCodingTools({
|
||||
config: cfg,
|
||||
sessionKey: "agent:main:subagent:test",
|
||||
spawnedBy: "agent:main:whatsapp:group:trusted",
|
||||
@@ -391,7 +391,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
});
|
||||
|
||||
it("should apply global tool policy before agent-specific policy", () => {
|
||||
const cfg: MoltbotConfig = {
|
||||
const cfg: OpenClawConfig = {
|
||||
tools: {
|
||||
deny: ["browser"], // Global deny
|
||||
},
|
||||
@@ -399,7 +399,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
list: [
|
||||
{
|
||||
id: "work",
|
||||
workspace: "~/clawd-work",
|
||||
workspace: "~/openclaw-work",
|
||||
tools: {
|
||||
deny: ["exec", "process"], // Agent deny (override)
|
||||
},
|
||||
@@ -408,7 +408,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
},
|
||||
};
|
||||
|
||||
const tools = createMoltbotCodingTools({
|
||||
const tools = createOpenClawCodingTools({
|
||||
config: cfg,
|
||||
sessionKey: "agent:work:slack:dm:user123",
|
||||
workspaceDir: "/tmp/test-work",
|
||||
@@ -424,7 +424,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
});
|
||||
|
||||
it("should work with sandbox tools filtering", () => {
|
||||
const cfg: MoltbotConfig = {
|
||||
const cfg: OpenClawConfig = {
|
||||
agents: {
|
||||
defaults: {
|
||||
sandbox: {
|
||||
@@ -435,7 +435,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
list: [
|
||||
{
|
||||
id: "restricted",
|
||||
workspace: "~/clawd-restricted",
|
||||
workspace: "~/openclaw-restricted",
|
||||
sandbox: {
|
||||
mode: "all",
|
||||
scope: "agent",
|
||||
@@ -457,7 +457,7 @@ describe("Agent-specific tool filtering", () => {
|
||||
},
|
||||
};
|
||||
|
||||
const tools = createMoltbotCodingTools({
|
||||
const tools = createOpenClawCodingTools({
|
||||
config: cfg,
|
||||
sessionKey: "agent:restricted:main",
|
||||
workspaceDir: "/tmp/test-restricted",
|
||||
@@ -497,13 +497,13 @@ describe("Agent-specific tool filtering", () => {
|
||||
});
|
||||
|
||||
it("should run exec synchronously when process is denied", async () => {
|
||||
const cfg: MoltbotConfig = {
|
||||
const cfg: OpenClawConfig = {
|
||||
tools: {
|
||||
deny: ["process"],
|
||||
},
|
||||
};
|
||||
|
||||
const tools = createMoltbotCodingTools({
|
||||
const tools = createOpenClawCodingTools({
|
||||
config: cfg,
|
||||
sessionKey: "agent:main:main",
|
||||
workspaceDir: "/tmp/test-main",
|
||||
|
||||
Reference in New Issue
Block a user