@@ -62,6 +62,7 @@ const tinyPngBuffer = Buffer.from(
6262 "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO2f7z8AAAAASUVORK5CYII=" ,
6363 "base64" ,
6464) ;
65+ const avifHeaderBuffer = Buffer . from ( "00000018667479706176696600000000617669666d696631" , "hex" ) ;
6566const tempDirs = useAutoCleanupTempDirTracker ( afterEach ) ;
6667const XAI_UNSUPPORTED_SCHEMA_KEYWORDS = new Set ( [ "minContains" , "maxContains" ] ) ;
6768function collectActionValues ( schema : unknown , values : Set < string > ) : void {
@@ -2684,6 +2685,39 @@ describe("createOpenClawCodingTools read behavior", () => {
26842685 expect ( readFile ) . not . toHaveBeenCalled ( ) ;
26852686 } ) ;
26862687
2688+ it ( "resolves Unicode-equivalent filenames through sandbox operations" , async ( ) => {
2689+ const tmpDir = tempDirs . make ( "openclaw-sbx-unicode-" ) ;
2690+ const storedName = "re\u0301sume\u0301 3.04\u202fPM d\u2019accord.txt" ;
2691+ await fs . writeFile ( path . join ( tmpDir , storedName ) , "sandbox match" ) ;
2692+ const readTool = createSandboxedReadTool ( {
2693+ root : tmpDir ,
2694+ bridge : createHostSandboxFsBridge ( tmpDir ) ,
2695+ } ) ;
2696+
2697+ const result = await readTool . execute ( "sandbox-unicode" , {
2698+ path : "r\u00e9sum\u00e9 3.04 PM d'accord.txt" ,
2699+ } ) ;
2700+
2701+ expect ( extractToolText ( result ) ) . toContain ( "Resolved filename" ) ;
2702+ expect ( extractToolText ( result ) ) . toContain ( "sandbox match" ) ;
2703+ } ) ;
2704+
2705+ it ( "classifies sandbox AVIF reads from the already-read buffer" , async ( ) => {
2706+ const tmpDir = tempDirs . make ( "openclaw-sbx-avif-" ) ;
2707+ await fs . writeFile ( path . join ( tmpDir , "photo.bin" ) , avifHeaderBuffer ) ;
2708+ const hostBridge = createHostSandboxFsBridge ( tmpDir ) ;
2709+ const readFile = vi . fn ( hostBridge . readFile . bind ( hostBridge ) ) ;
2710+ const readTool = createSandboxedReadTool ( {
2711+ root : tmpDir ,
2712+ bridge : { ...hostBridge , readFile } ,
2713+ } ) ;
2714+
2715+ const result = await readTool . execute ( "sandbox-avif" , { path : "photo.bin" } ) ;
2716+
2717+ expect ( extractToolText ( result ) ) . toContain ( "Read image file [image/avif]" ) ;
2718+ expect ( readFile ) . toHaveBeenCalledTimes ( 1 ) ;
2719+ } ) ;
2720+
26872721 it ( "auto-pages read output across chunks when context window budget allows" , async ( ) => {
26882722 const tmpDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-read-autopage-" ) ) ;
26892723 const filePath = path . join ( tmpDir , "big.txt" ) ;
@@ -2752,7 +2786,7 @@ describe("createOpenClawCodingTools read behavior", () => {
27522786 }
27532787 } ) ;
27542788
2755- it ( "returns empty content for explicit offsets beyond EOF" , async ( ) => {
2789+ it ( "describes explicit offsets beyond EOF" , async ( ) => {
27562790 const tmpDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-read-offset-eof-" ) ) ;
27572791 await fs . writeFile ( path . join ( tmpDir , "notes.txt" ) , "one\ntwo\nthree" , "utf8" ) ;
27582792 try {
@@ -2766,13 +2800,15 @@ describe("createOpenClawCodingTools read behavior", () => {
27662800 limit : 10 ,
27672801 } ) ;
27682802
2769- expect ( extractToolText ( result ) ) . toBe ( "" ) ;
2803+ expect ( extractToolText ( result ) ) . toBe (
2804+ "Offset 99 is beyond end of file (3 lines total). Retry with offset <= 3." ,
2805+ ) ;
27702806 } finally {
27712807 await fs . rm ( tmpDir , { recursive : true , force : true } ) ;
27722808 }
27732809 } ) ;
27742810
2775- it ( "returns empty content for adaptive offsets beyond EOF" , async ( ) => {
2811+ it ( "ignores a trailing newline when describing offsets beyond EOF" , async ( ) => {
27762812 const tmpDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-read-offset-adaptive-" ) ) ;
27772813 await fs . writeFile ( path . join ( tmpDir , "notes.txt" ) , "one\ntwo\nthree\n" , "utf8" ) ;
27782814 try {
@@ -2785,13 +2821,15 @@ describe("createOpenClawCodingTools read behavior", () => {
27852821 offset : 99 ,
27862822 } ) ;
27872823
2788- expect ( extractToolText ( result ) ) . toBe ( "" ) ;
2824+ expect ( extractToolText ( result ) ) . toBe (
2825+ "Offset 99 is beyond end of file (3 lines total). Retry with offset <= 3." ,
2826+ ) ;
27892827 } finally {
27902828 await fs . rm ( tmpDir , { recursive : true , force : true } ) ;
27912829 }
27922830 } ) ;
27932831
2794- it ( "returns already-read adaptive content when pagination reaches EOF" , async ( ) => {
2832+ it ( "stops adaptive pagination when the current page reaches EOF" , async ( ) => {
27952833 const readResult : AgentToolResult < unknown > = {
27962834 content : [
27972835 {
@@ -2803,14 +2841,12 @@ describe("createOpenClawCodingTools read behavior", () => {
28032841 truncation : {
28042842 truncated : true ,
28052843 outputLines : 1 ,
2844+ totalLines : 1 ,
28062845 firstLineExceedsLimit : false ,
28072846 } ,
28082847 } ,
28092848 } ;
2810- const execute = vi
2811- . fn ( )
2812- . mockResolvedValueOnce ( readResult )
2813- . mockRejectedValueOnce ( new Error ( "Offset 2 is beyond end of file (1 lines total)" ) ) ;
2849+ const execute = vi . fn ( ) . mockResolvedValue ( readResult ) ;
28142850 const readTool = createOpenClawReadTool ( {
28152851 name : "read" ,
28162852 label : "read" ,
@@ -2828,7 +2864,7 @@ describe("createOpenClawCodingTools read behavior", () => {
28282864 } ) ;
28292865
28302866 expect ( extractToolText ( result ) ) . toBe ( "one" ) ;
2831- expect ( execute ) . toHaveBeenCalledTimes ( 2 ) ;
2867+ expect ( execute ) . toHaveBeenCalledTimes ( 1 ) ;
28322868 } ) ;
28332869
28342870 it ( "keeps unrelated read failures loud" , async ( ) => {
0 commit comments