@@ -804,6 +804,81 @@ it.layer(layer)("OpenCodeDriver runtime selection", (it) => {
804804 } ) . pipe ( Effect . scoped , Effect . provide ( TestClock . layer ( ) ) ) ,
805805 ) ;
806806
807+ it . effect . each ( [
808+ { status : 200 , data : null , reason : "unsupported" } ,
809+ { status : 404 , data : null , reason : "unsupported" } ,
810+ { status : 503 , data : null , reason : "probeFailed" } ,
811+ {
812+ status : 200 ,
813+ data : {
814+ workspace : {
815+ id : "remote-workspace" ,
816+ name : "Remote workspace" ,
817+ usageURL : "https://opencode.ai/console/remote-workspace" ,
818+ } ,
819+ budgets : [
820+ {
821+ id : "all" ,
822+ limit : 20 ,
823+ spent : 15 ,
824+ scope : "combined" ,
825+ per : "set" ,
826+ coverage : "all" ,
827+ models : [ ] ,
828+ shared : true ,
829+ resetsAt : 1793491200000 ,
830+ } ,
831+ ] ,
832+ } ,
833+ reason : undefined ,
834+ } ,
835+ ] ) (
836+ "reads external workspace usage without local credentials, HTTP $status, $reason" ,
837+ ( scenario ) =>
838+ Effect . gen ( function * ( ) {
839+ const requested : string [ ] = [ ] ;
840+ const replay = replayOpenCodeServer ( OPENCODE_2_RESPONSES , "secret" , requested ) ;
841+ const server = HttpClient . make ( ( request ) => {
842+ assert . notInclude ( request . url , "opencode.ai/zen" ) ;
843+ if ( request . url . endsWith ( "/api/experimental/usage/limits" ) ) {
844+ assert . strictEqual ( request . headers . authorization , "Basic b3BlbmNvZGU6c2VjcmV0" ) ;
845+ return Effect . succeed (
846+ HttpClientResponse . fromWeb (
847+ request ,
848+ Response . json (
849+ {
850+ location : { directory : "/work" } ,
851+ data : scenario . data ,
852+ } ,
853+ { status : scenario . status } ,
854+ ) ,
855+ ) ,
856+ ) ;
857+ }
858+ return replay . execute ( request ) ;
859+ } ) ;
860+ const instance = yield * create (
861+ { serverUrl : "https://remote.example" , serverPassword : "secret" } ,
862+ server ,
863+ ) ;
864+ const [ snapshot ] = Array . from (
865+ yield * instance . snapshot . streamChanges . pipe (
866+ Stream . filter ( ( snapshot ) => snapshot . usageLimits !== undefined ) ,
867+ Stream . take ( 1 ) ,
868+ Stream . runCollect ,
869+ ) ,
870+ ) ;
871+ assert . strictEqual ( snapshot ?. usageLimits ?. unavailable ?. reason , scenario . reason ) ;
872+ if ( scenario . reason === undefined ) {
873+ assert . strictEqual ( snapshot ?. usageLimits ?. windows [ 0 ] ?. usedPercent , 75 ) ;
874+ assert . strictEqual ( snapshot ?. usageLimits ?. externalUsage ?. label , "Remote workspace" ) ;
875+ assert . deepStrictEqual ( snapshot ?. usageLimits ?. windows [ 0 ] ?. providerIds , [ ] ) ;
876+ } else {
877+ assert . deepStrictEqual ( snapshot ?. usageLimits ?. windows , [ ] ) ;
878+ }
879+ } ) . pipe ( Effect . scoped ) ,
880+ ) ;
881+
807882 it . effect . each (
808883 [
809884 { name : "recovers" } ,
@@ -843,6 +918,10 @@ it.layer(layer)("OpenCodeDriver runtime selection", (it) => {
843918 ) ;
844919 }
845920 const path = new URL ( request . url ) . pathname ;
921+ if ( path === "/api/experimental/usage/limits" )
922+ return Effect . succeed (
923+ HttpClientResponse . fromWeb ( request , new Response ( null , { status : 404 } ) ) ,
924+ ) ;
846925 if ( path === "/api/model" ) modelReads += 1 ;
847926 const body =
848927 path === "/api/info"
0 commit comments