@@ -9,6 +9,7 @@ import path from "node:path";
99import type { AgentTool , AgentToolResult } from "openclaw/plugin-sdk/agent-core" ;
1010import { Type } from "typebox" ;
1111import { afterEach , describe , expect , it , vi } from "vitest" ;
12+ import { useAutoCleanupTempDirTracker } from "../../test/helpers/temp-dir.js" ;
1213import { replaceSessionEntry } from "../config/sessions/session-accessor.js" ;
1314import type { SessionEntry } from "../config/sessions/types.js" ;
1415import type { OpenClawConfig } from "../config/types.openclaw.js" ;
@@ -57,6 +58,7 @@ const tinyPngBuffer = Buffer.from(
5758 "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO2f7z8AAAAASUVORK5CYII=" ,
5859 "base64" ,
5960) ;
61+ const tempDirs = useAutoCleanupTempDirTracker ( afterEach ) ;
6062const XAI_UNSUPPORTED_SCHEMA_KEYWORDS = new Set ( [ "minContains" , "maxContains" ] ) ;
6163function collectActionValues ( schema : unknown , values : Set < string > ) : void {
6264 if ( ! schema || typeof schema !== "object" ) {
@@ -2573,6 +2575,23 @@ describe("createOpenClawCodingTools read behavior", () => {
25732575 }
25742576 } ) ;
25752577
2578+ it ( "rejects sandbox directory reads before calling the bridge read operation" , async ( ) => {
2579+ const tmpDir = tempDirs . make ( "openclaw-sbx-directory-" ) ;
2580+ const directoryName = "notes" ;
2581+ await fs . mkdir ( path . join ( tmpDir , directoryName ) ) ;
2582+ const hostBridge = createHostSandboxFsBridge ( tmpDir ) ;
2583+ const readFile = vi . fn ( hostBridge . readFile . bind ( hostBridge ) ) ;
2584+ const readTool = createSandboxedReadTool ( {
2585+ root : tmpDir ,
2586+ bridge : { ...hostBridge , readFile } ,
2587+ } ) ;
2588+
2589+ await expect ( readTool . execute ( "sandbox-directory" , { path : directoryName } ) ) . rejects . toThrow (
2590+ `Read requires a file path, but ${ directoryName } is a directory. List the directory, then read a specific file.` ,
2591+ ) ;
2592+ expect ( readFile ) . not . toHaveBeenCalled ( ) ;
2593+ } ) ;
2594+
25762595 it ( "auto-pages read output across chunks when context window budget allows" , async ( ) => {
25772596 const tmpDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-read-autopage-" ) ) ;
25782597 const filePath = path . join ( tmpDir , "big.txt" ) ;
0 commit comments