mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 12:24:59 +00:00
refactor: eliminate remaining duplicate blocks across draft streams and tests
This commit is contained in:
@@ -7,6 +7,11 @@ import { createOpenClawCodingTools } from "./pi-tools.js";
|
||||
import type { SandboxContext } from "./sandbox.js";
|
||||
import type { SandboxFsBridge, SandboxResolvedPath } from "./sandbox/fs-bridge.js";
|
||||
import { createSandboxFsBridgeFromResolver } from "./test-helpers/host-sandbox-fs-bridge.js";
|
||||
import {
|
||||
expectReadWriteEditTools,
|
||||
expectReadWriteTools,
|
||||
getTextContent,
|
||||
} from "./test-helpers/pi-tools-fs-helpers.js";
|
||||
import { createPiToolsSandboxContext } from "./test-helpers/pi-tools-sandbox-context.js";
|
||||
|
||||
vi.mock("../infra/shell-env.js", async (importOriginal) => {
|
||||
@@ -14,11 +19,6 @@ vi.mock("../infra/shell-env.js", async (importOriginal) => {
|
||||
return { ...mod, getShellPathFromLoginShell: () => null };
|
||||
});
|
||||
|
||||
function getTextContent(result?: { content?: Array<{ type: string; text?: string }> }) {
|
||||
const textBlock = result?.content?.find((block) => block.type === "text");
|
||||
return textBlock?.text ?? "";
|
||||
}
|
||||
|
||||
function createUnsafeMountedBridge(params: {
|
||||
root: string;
|
||||
agentHostRoot: string;
|
||||
@@ -96,10 +96,7 @@ describe("tools.fs.workspaceOnly", () => {
|
||||
await fs.writeFile(path.join(agentRoot, "secret.txt"), "shh", "utf8");
|
||||
|
||||
const tools = createOpenClawCodingTools({ sandbox, workspaceDir: sandboxRoot });
|
||||
const readTool = tools.find((tool) => tool.name === "read");
|
||||
const writeTool = tools.find((tool) => tool.name === "write");
|
||||
expect(readTool).toBeDefined();
|
||||
expect(writeTool).toBeDefined();
|
||||
const { readTool, writeTool } = expectReadWriteTools(tools);
|
||||
|
||||
const readResult = await readTool?.execute("t1", { path: "/agent/secret.txt" });
|
||||
expect(getTextContent(readResult)).toContain("shh");
|
||||
@@ -115,12 +112,7 @@ describe("tools.fs.workspaceOnly", () => {
|
||||
|
||||
const cfg = { tools: { fs: { workspaceOnly: true } } } as unknown as OpenClawConfig;
|
||||
const tools = createOpenClawCodingTools({ sandbox, workspaceDir: sandboxRoot, config: cfg });
|
||||
const readTool = tools.find((tool) => tool.name === "read");
|
||||
const writeTool = tools.find((tool) => tool.name === "write");
|
||||
const editTool = tools.find((tool) => tool.name === "edit");
|
||||
expect(readTool).toBeDefined();
|
||||
expect(writeTool).toBeDefined();
|
||||
expect(editTool).toBeDefined();
|
||||
const { readTool, writeTool, editTool } = expectReadWriteEditTools(tools);
|
||||
|
||||
await expect(readTool?.execute("t1", { path: "/agent/secret.txt" })).rejects.toThrow(
|
||||
/Path escapes sandbox root/i,
|
||||
|
||||
Reference in New Issue
Block a user