@@ -131,6 +131,10 @@ function fixture(
131131 let closed = false ;
132132 const fileReads : { cwd ?: string ; path : string } [ ] = [ ] ;
133133 const spawn = vi . fn ( async ( _id : string , value ?: HostProcessOptions ) => {
134+ if ( _id === "workspace" ) {
135+ value ?. onStdout ?.( "/home/test/.buzz\n" ) ;
136+ return { ...process , exited : Promise . resolve ( 0 ) } ;
137+ }
134138 if ( _id === "read" ) {
135139 fileReads . push ( {
136140 ...( value ?. cwd ? { cwd : value . cwd } : { } ) ,
@@ -752,13 +756,83 @@ it("waits for terminal termination after asynchronous clean acknowledgement befo
752756
753757it ( "publishes workspace errors without starting work" , async ( ) => {
754758 const f = fixture ( ) ;
755- await f . runtime . run ( { ...f . delivery ( "hello" ) , config : { } } ) ;
759+ await f . runtime . run ( {
760+ ...f . delivery ( "hello" ) ,
761+ config : { workspace : "relative" } ,
762+ } ) ;
756763 expect ( f . publish . mock . calls [ 0 ] ?. [ 0 ] ) . toMatchObject ( {
757764 content : expect . stringContaining ( "absolute workspace" ) ,
758765 } ) ;
759766 expect ( f . spawn ) . not . toHaveBeenCalled ( ) ;
760767} ) ;
761768
769+ it . each ( [ { } , { workspace : "" } , { workspace : " " } ] ) (
770+ "runs blank workspace settings in the resolved default: %j" ,
771+ async ( config ) => {
772+ const f = fixture ( ) ;
773+ await f . runtime . run ( { ...f . delivery ( "hello" ) , config } ) ;
774+ await vi . waitFor ( ( ) => expect ( f . starts ( ) ) . toHaveLength ( 1 ) ) ;
775+ expect ( f . spawn ) . toHaveBeenCalledWith (
776+ "app-server" ,
777+ expect . objectContaining ( { cwd : "~/.buzz" } ) ,
778+ ) ;
779+ expect ( f . spawn ) . toHaveBeenCalledWith (
780+ "workspace" ,
781+ expect . objectContaining ( { cwd : "~/.buzz" } ) ,
782+ ) ;
783+ for ( const method of [ "config/read" , "thread/start" ] )
784+ expect (
785+ f . sent . find ( ( wire ) => wire . method === method ) ?. params ,
786+ ) . toMatchObject ( { cwd : "/home/test/.buzz" } ) ;
787+ f . complete ( 0 , "DONE" ) ;
788+ await vi . waitFor ( ( ) => expect ( f . publish ) . toHaveBeenCalledTimes ( 1 ) ) ;
789+ await f . runtime . run ( { ...f . delivery ( "again" ) , config } ) ;
790+ await vi . waitFor ( ( ) => expect ( f . starts ( ) ) . toHaveLength ( 2 ) ) ;
791+ expect (
792+ f . sent . find ( ( wire ) => wire . method === "thread/resume" ) ?. params ,
793+ ) . toMatchObject ( { cwd : "/home/test/.buzz" } ) ;
794+ f . complete ( 1 , "DONE AGAIN" ) ;
795+ await vi . waitFor ( ( ) => expect ( f . publish ) . toHaveBeenCalledTimes ( 2 ) ) ;
796+ f . runtime . dispose ( ) ;
797+ } ,
798+ ) ;
799+
800+ it ( "reports a default workspace resolution failure without starting a turn" , async ( ) => {
801+ const f = fixture ( ) ;
802+ const spawn = f . spawn . getMockImplementation ( ) ;
803+ if ( ! spawn ) throw new Error ( "Missing spawn fixture" ) ;
804+ f . spawn . mockImplementation ( async ( id , options ) =>
805+ id === "workspace"
806+ ? { ...f . process , exited : Promise . resolve ( 1 ) }
807+ : spawn ( id , options ) ,
808+ ) ;
809+ await f . runtime . run ( { ...f . delivery ( "hello" ) , config : { } } ) ;
810+ await vi . waitFor ( ( ) => expect ( f . publish ) . toHaveBeenCalledTimes ( 1 ) ) ;
811+ expect ( f . publish . mock . calls [ 0 ] ?. [ 0 ] ) . toMatchObject ( {
812+ content : expect . stringContaining (
813+ "Could not resolve the default Codex workspace" ,
814+ ) ,
815+ } ) ;
816+ expect ( f . starts ( ) ) . toHaveLength ( 0 ) ;
817+ } ) ;
818+
819+ it ( "uses the default after changing away from a custom workspace on an existing server" , async ( ) => {
820+ const f = fixture ( ) ;
821+ await f . runtime . run ( f . delivery ( "custom" ) ) ;
822+ await vi . waitFor ( ( ) => expect ( f . starts ( ) ) . toHaveLength ( 1 ) ) ;
823+ f . complete ( 0 , "CUSTOM" ) ;
824+ await vi . waitFor ( ( ) => expect ( f . publish ) . toHaveBeenCalledTimes ( 1 ) ) ;
825+ await f . runtime . run ( { ...f . delivery ( "default" ) , config : { } } ) ;
826+ await vi . waitFor ( ( ) => expect ( f . starts ( ) ) . toHaveLength ( 2 ) ) ;
827+ const threads = f . sent . filter ( ( wire ) => wire . method === "thread/start" ) ;
828+ expect ( threads . map ( ( wire ) => ( wire . params as { cwd : string } ) . cwd ) ) . toEqual ( [
829+ "/tmp/codex-test" ,
830+ "/home/test/.buzz" ,
831+ ] ) ;
832+ f . complete ( 1 , "DEFAULT" ) ;
833+ await vi . waitFor ( ( ) => expect ( f . publish ) . toHaveBeenCalledTimes ( 2 ) ) ;
834+ } ) ;
835+
762836it ( "posts tool-sent parts and never duplicates native assistant text" , async ( ) => {
763837 const f = fixture ( ) ;
764838 await f . runtime . run ( f . delivery ( "work" ) ) ;
0 commit comments