@@ -141,6 +141,55 @@ async function waitForRead(client: ReturnType<typeof OpenCode.make>, sessionID:
141141 throw new Error ( `Terminal ${ ptyID } did not become current for ${ sessionID } ` )
142142}
143143
144+ smoke (
145+ "rejects a cwd that is missing or not a directory without starting a shell" ,
146+ ( ) =>
147+ Effect . gen ( function * ( ) {
148+ const fixture = yield * testDirectory ( )
149+ const server = yield * ServerProcess . start < never , never > ( {
150+ hostname : "127.0.0.1" ,
151+ port : 0 ,
152+ password : "secret" ,
153+ app : { version : "test-version" } ,
154+ database : { path : fixture . database } ,
155+ pty : { root : fixture . directory } ,
156+ fs : { filewatcher : false } ,
157+ } )
158+ const base = HttpServer . formatAddress ( server . address )
159+ const createPath = "/api/experimental/session/ses_invalid_cwd/terminal"
160+ const file = path . join ( fixture . root , "file.txt" )
161+ yield * Effect . promise ( ( ) => fs . writeFile ( file , "" ) )
162+ for ( const cwd of [ path . join ( fixture . root , "missing" ) , file ] ) {
163+ const response = yield * Effect . promise ( async ( ) => {
164+ const response = await fetch ( new URL ( createPath , base ) , {
165+ method : "POST" ,
166+ headers : { authorization : `Basic ${ btoa ( "opencode:secret" ) } ` , "content-type" : "application/json" } ,
167+ body : JSON . stringify ( { command : "/bin/sh" , args : [ ] , cwd, title : "invalid" , env : { } } ) ,
168+ } )
169+ return { status : response . status , body : await response . json ( ) }
170+ } )
171+ expect ( response ) . toEqual ( {
172+ status : 400 ,
173+ body : {
174+ _tag : "InvalidRequestError" ,
175+ message : `cwd is not a directory: ${ cwd } ` ,
176+ kind : "invalid_cwd" ,
177+ field : "cwd" ,
178+ } ,
179+ } )
180+ }
181+ // The daemon is never started, so no shell can have been spawned.
182+ expect ( existsSync ( fixture . directory ) ) . toBeFalse ( )
183+ expect ( ( yield * request ( base , "GET" , createPath ) ) . data ) . toEqual ( [ ] )
184+ const valid = { command : "/bin/sh" , args : [ ] , cwd : fixture . root , title : "valid" , env : { } }
185+ const created = yield * request ( base , "POST" , createPath , valid )
186+ const terminal = Schema . decodeUnknownSync ( PersistentPty . Info ) ( created . data )
187+ expect ( terminal . cwd ) . toBe ( fixture . root )
188+ yield * request ( base , "POST" , "/api/experimental/persistent-pty/shutdown" )
189+ } ) ,
190+ 20_000 ,
191+ )
192+
144193smoke (
145194 "creates two persistent terminals for one session through the client API" ,
146195 ( ) =>
0 commit comments