File tree Expand file tree Collapse file tree
packages/opencode/test/tool Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { describe , expect , test } from "bun:test"
2+ import os from "os"
23import path from "path"
34import { BashTool } from "../../src/tool/bash"
45import { Instance } from "../../src/project/instance"
@@ -138,14 +139,14 @@ describe("tool.bash permissions", () => {
138139 await bash . execute (
139140 {
140141 command : "ls" ,
141- workdir : "/tmp" ,
142- description : "List /tmp " ,
142+ workdir : os . tmpdir ( ) ,
143+ description : "List temp dir " ,
143144 } ,
144145 testCtx ,
145146 )
146147 const extDirReq = requests . find ( ( r ) => r . permission === "external_directory" )
147148 expect ( extDirReq ) . toBeDefined ( )
148- expect ( extDirReq ! . patterns ) . toContain ( "/tmp/*" )
149+ expect ( extDirReq ! . patterns ) . toContain ( path . join ( os . tmpdir ( ) , "*" ) )
149150 } ,
150151 } )
151152 } )
@@ -366,7 +367,8 @@ describe("tool.bash truncation", () => {
366367 ctx ,
367368 )
368369 expect ( ( result . metadata as any ) . truncated ) . toBe ( false )
369- expect ( result . output ) . toBe ( "hello\n" )
370+ const eol = process . platform === "win32" ? "\r\n" : "\n"
371+ expect ( result . output ) . toBe ( `hello${ eol } ` )
370372 } ,
371373 } )
372374 } )
Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ describe("tool.assertExternalDirectory", () => {
6565
6666 const directory = "/tmp/project"
6767 const target = "/tmp/outside/file.txt"
68- const expected = path . join ( path . dirname ( target ) , "*" )
68+ const expected = path . join ( path . dirname ( target ) , "*" ) . replaceAll ( "\\" , "/" )
6969
7070 await Instance . provide ( {
7171 directory,
@@ -91,7 +91,7 @@ describe("tool.assertExternalDirectory", () => {
9191
9292 const directory = "/tmp/project"
9393 const target = "/tmp/outside"
94- const expected = path . join ( target , "*" )
94+ const expected = path . join ( target , "*" ) . replaceAll ( "\\" , "/" )
9595
9696 await Instance . provide ( {
9797 directory,
Original file line number Diff line number Diff line change @@ -293,19 +293,26 @@ describe("tool.write", () => {
293293 } )
294294
295295 describe ( "error handling" , ( ) => {
296- test ( "throws error for paths outside project " , async ( ) => {
296+ test ( "throws error when OS denies write access " , async ( ) => {
297297 await using tmp = await tmpdir ( )
298- const outsidePath = "/etc/passwd"
298+ const readonlyPath = path . join ( tmp . path , "readonly.txt" )
299+
300+ // Create a read-only file
301+ await fs . writeFile ( readonlyPath , "test" , "utf-8" )
302+ await fs . chmod ( readonlyPath , 0o444 )
299303
300304 await Instance . provide ( {
301305 directory : tmp . path ,
302306 fn : async ( ) => {
307+ const { FileTime } = await import ( "../../src/file/time" )
308+ FileTime . read ( ctx . sessionID , readonlyPath )
309+
303310 const write = await WriteTool . init ( )
304311 await expect (
305312 write . execute (
306313 {
307- filePath : outsidePath ,
308- content : "test " ,
314+ filePath : readonlyPath ,
315+ content : "new content " ,
309316 } ,
310317 ctx ,
311318 ) ,
You can’t perform that action at this time.
0 commit comments