@@ -8,26 +8,25 @@ import { createOpenClawCodingTools } from "./pi-tools.js";
88import { expectReadWriteEditTools } from "./test-helpers/pi-tools-fs-helpers.js" ;
99
1010describe ( "createOpenClawCodingTools" , ( ) => {
11- it ( "accepts Claude Code parameter aliases for read/write/edit" , async ( ) => {
12- const tmpDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-alias -" ) ) ;
11+ it ( "accepts canonical parameters for read/write/edit" , async ( ) => {
12+ const tmpDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-canonical -" ) ) ;
1313 try {
1414 const tools = createOpenClawCodingTools ( { workspaceDir : tmpDir } ) ;
1515 const { readTool, writeTool, editTool } = expectReadWriteEditTools ( tools ) ;
1616
17- const filePath = "alias -test.txt" ;
18- await writeTool ?. execute ( "tool-alias -1" , {
19- file_path : filePath ,
17+ const filePath = "canonical -test.txt" ;
18+ await writeTool ?. execute ( "tool-canonical -1" , {
19+ path : filePath ,
2020 content : "hello world" ,
2121 } ) ;
2222
23- await editTool ?. execute ( "tool-alias-2" , {
24- file_path : filePath ,
25- old_string : "world" ,
26- new_string : "universe" ,
23+ await editTool ?. execute ( "tool-canonical-2" , {
24+ path : filePath ,
25+ edits : [ { oldText : "world" , newText : "universe" } ] ,
2726 } ) ;
2827
29- const result = await readTool ?. execute ( "tool-alias -3" , {
30- file_path : filePath ,
28+ const result = await readTool ?. execute ( "tool-canonical -3" , {
29+ path : filePath ,
3130 } ) ;
3231
3332 const textBlocks = result ?. content ?. filter ( ( block ) => block . type === "text" ) as
@@ -40,62 +39,59 @@ describe("createOpenClawCodingTools", () => {
4039 }
4140 } ) ;
4241
43- it ( "accepts broader file/edit alias variants " , async ( ) => {
44- const tmpDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-alias-broad -" ) ) ;
42+ it ( "rejects legacy alias parameters " , async ( ) => {
43+ const tmpDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-legacy-alias -" ) ) ;
4544 try {
4645 const tools = createOpenClawCodingTools ( { workspaceDir : tmpDir } ) ;
4746 const { readTool, writeTool, editTool } = expectReadWriteEditTools ( tools ) ;
4847
49- await writeTool ?. execute ( "tool-alias-broad-1" , {
50- file : "broad-alias.txt" ,
51- content : "hello old value ",
52- } ) ;
53-
54- await editTool ?. execute ( "tool-alias-broad-2" , {
55- filePath : "broad-alias.txt" ,
56- old_text : "old" ,
57- newString : "new" ,
58- } ) ;
59-
60- const result = await readTool ?. execute ( "tool-alias-broad-3" , {
61- file : "broad-alias.txt" ,
62- } ) ;
63-
64- const textBlocks = result ?. content ?. filter ( ( block ) => block . type === "text" ) as
65- | Array < { text ?: string } >
66- | undefined ;
67- const combinedText = textBlocks ?. map ( ( block ) => block . text ?? "" ) . join ( "\n" ) ;
68- expect ( combinedText ) . toContain ( "hello new value" ) ;
48+ await expect (
49+ writeTool ?. execute ( "tool-legacy-write" , {
50+ file : "legacy.txt ",
51+ content : "hello old value" ,
52+ } ) ,
53+ ) . rejects . toThrow ( / M i s s i n g r e q u i r e d p a r a m e t e r : p a t h / ) ;
54+
55+ await expect (
56+ editTool ?. execute ( "tool-legacy-edit" , {
57+ filePath : "legacy.txt" ,
58+ old_text : "old" ,
59+ newString : "new" ,
60+ } ) ,
61+ ) . rejects . toThrow ( / M i s s i n g r e q u i r e d p a r a m e t e r s : p a t h , e d i t s / ) ;
62+
63+ await expect (
64+ readTool ?. execute ( "tool-legacy-read" , {
65+ file_path : "legacy.txt" ,
66+ } ) ,
67+ ) . rejects . toThrow ( / M i s s i n g r e q u i r e d p a r a m e t e r : p a t h / ) ;
6968 } finally {
7069 await fs . rm ( tmpDir , { recursive : true , force : true } ) ;
7170 }
7271 } ) ;
7372
74- it ( "coerces structured content blocks for write" , async ( ) => {
73+ it ( "rejects structured content blocks for write" , async ( ) => {
7574 const tmpDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-structured-write-" ) ) ;
7675 try {
7776 const tools = createOpenClawCodingTools ( { workspaceDir : tmpDir } ) ;
7877 const writeTool = tools . find ( ( tool ) => tool . name === "write" ) ;
7978 expect ( writeTool ) . toBeDefined ( ) ;
8079
81- await writeTool ?. execute ( "tool-structured-write" , {
82- path : "structured-write.js" ,
83- content : [
84- { type : "text" , text : "const path = require('path');\n" } ,
85- { type : "input_text" , text : "const root = path.join(process.env.HOME, 'clawd');\n" } ,
86- ] ,
87- } ) ;
88-
89- const written = await fs . readFile ( path . join ( tmpDir , "structured-write.js" ) , "utf8" ) ;
90- expect ( written ) . toBe (
91- "const path = require('path');\nconst root = path.join(process.env.HOME, 'clawd');\n" ,
92- ) ;
80+ await expect (
81+ writeTool ?. execute ( "tool-structured-write" , {
82+ path : "structured-write.js" ,
83+ content : [
84+ { type : "text" , text : "const path = require('path');\n" } ,
85+ { type : "input_text" , text : "const root = path.join(process.env.HOME, 'clawd');\n" } ,
86+ ] ,
87+ } ) ,
88+ ) . rejects . toThrow ( / M i s s i n g r e q u i r e d p a r a m e t e r : c o n t e n t / ) ;
9389 } finally {
9490 await fs . rm ( tmpDir , { recursive : true , force : true } ) ;
9591 }
9692 } ) ;
9793
98- it ( "coerces structured old/new text blocks for edit" , async ( ) => {
94+ it ( "rejects structured edit payloads " , async ( ) => {
9995 const tmpDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-structured-edit-" ) ) ;
10096 try {
10197 const filePath = path . join ( tmpDir , "structured-edit.js" ) ;
@@ -105,14 +101,17 @@ describe("createOpenClawCodingTools", () => {
105101 const editTool = tools . find ( ( tool ) => tool . name === "edit" ) ;
106102 expect ( editTool ) . toBeDefined ( ) ;
107103
108- await editTool ?. execute ( "tool-structured-edit" , {
109- file_path : "structured-edit.js" ,
110- old_string : [ { type : "text" , text : "old" } ] ,
111- new_string : [ { kind : "text" , value : "new" } ] ,
112- } ) ;
113-
114- const edited = await fs . readFile ( filePath , "utf8" ) ;
115- expect ( edited ) . toBe ( "const value = 'new';\n" ) ;
104+ await expect (
105+ editTool ?. execute ( "tool-structured-edit" , {
106+ path : "structured-edit.js" ,
107+ edits : [
108+ {
109+ oldText : [ { type : "text" , text : "old" } ] ,
110+ newText : [ { kind : "text" , value : "new" } ] ,
111+ } ,
112+ ] ,
113+ } ) ,
114+ ) . rejects . toThrow ( / M i s s i n g r e q u i r e d p a r a m e t e r : e d i t s / ) ;
116115 } finally {
117116 await fs . rm ( tmpDir , { recursive : true , force : true } ) ;
118117 }
0 commit comments