From bce02d7a9e88a13f30c56c0e5ec23190e043bfc6 Mon Sep 17 00:00:00 2001 From: Vignesh Natarajan Date: Sat, 14 Feb 2026 19:51:24 -0800 Subject: [PATCH] test (tools): cover structured block params for write/edit --- ...ses-schemas-without-dropping-f.e2e.test.ts | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/agents/pi-tools.create-openclaw-coding-tools.adds-claude-style-aliases-schemas-without-dropping-f.e2e.test.ts b/src/agents/pi-tools.create-openclaw-coding-tools.adds-claude-style-aliases-schemas-without-dropping-f.e2e.test.ts index ef653c5bddf..2db54ddc0b1 100644 --- a/src/agents/pi-tools.create-openclaw-coding-tools.adds-claude-style-aliases-schemas-without-dropping-f.e2e.test.ts +++ b/src/agents/pi-tools.create-openclaw-coding-tools.adds-claude-style-aliases-schemas-without-dropping-f.e2e.test.ts @@ -120,4 +120,51 @@ describe("createOpenClawCodingTools", () => { await fs.rm(tmpDir, { recursive: true, force: true }); } }); + + it("coerces structured content blocks for write", async () => { + const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-structured-write-")); + try { + const tools = createOpenClawCodingTools({ workspaceDir: tmpDir }); + const writeTool = tools.find((tool) => tool.name === "write"); + expect(writeTool).toBeDefined(); + + await writeTool?.execute("tool-structured-write", { + path: "structured-write.js", + content: [ + { type: "text", text: "const path = require('path');\n" }, + { type: "input_text", text: "const root = path.join(process.env.HOME, 'clawd');\n" }, + ], + }); + + const written = await fs.readFile(path.join(tmpDir, "structured-write.js"), "utf8"); + expect(written).toBe( + "const path = require('path');\nconst root = path.join(process.env.HOME, 'clawd');\n", + ); + } finally { + await fs.rm(tmpDir, { recursive: true, force: true }); + } + }); + + it("coerces structured old/new text blocks for edit", async () => { + const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-structured-edit-")); + try { + const filePath = path.join(tmpDir, "structured-edit.js"); + await fs.writeFile(filePath, "const value = 'old';\n", "utf8"); + + const tools = createOpenClawCodingTools({ workspaceDir: tmpDir }); + const editTool = tools.find((tool) => tool.name === "edit"); + expect(editTool).toBeDefined(); + + await editTool?.execute("tool-structured-edit", { + file_path: "structured-edit.js", + old_string: [{ type: "text", text: "old" }], + new_string: [{ kind: "text", value: "new" }], + }); + + const edited = await fs.readFile(filePath, "utf8"); + expect(edited).toBe("const value = 'new';\n"); + } finally { + await fs.rm(tmpDir, { recursive: true, force: true }); + } + }); });