@@ -253,6 +253,7 @@ describe("OpenCode2Client usage limits", () => {
253253 it . effect ( "reads the connected workspace and maps Go and Console budgets" , ( ) =>
254254 Effect . gen ( function * ( ) {
255255 let workspace = "wrk_remote" ;
256+ let usageURL : string | undefined ;
256257 const transport = HttpClient . make ( ( request ) => {
257258 assert . strictEqual ( request . headers . authorization , utf8Basic ( "remote-password" ) ) ;
258259 assert . deepStrictEqual ( Array . from ( request . urlParams ) , [
@@ -286,7 +287,7 @@ describe("OpenCode2Client usage limits", () => {
286287 workspace : {
287288 id : workspace ,
288289 name : workspace ,
289- usageURL : "https://opencode.ai/console/" + workspace ,
290+ usageURL : usageURL ?? "https://opencode.ai/console/" + workspace ,
290291 } ,
291292 go : {
292293 rolling : { percent : 23 , limited : false , resetsAt : 1793491200000 } ,
@@ -381,6 +382,19 @@ describe("OpenCode2Client usage limits", () => {
381382 const next = yield * api . usageLimits ( "/remote/project" ) ;
382383 assert . strictEqual ( next ?. externalUsage ?. label , "wrk_switched" ) ;
383384 assert . strictEqual ( next ?. externalUsage ?. url , "https://opencode.ai/console/wrk_switched" ) ;
385+ for ( const url of [
386+ "not a URL" ,
387+ "javascript:alert(1)" ,
388+ "custom-app://usage" ,
389+ "file:///tmp/usage" ,
390+ ] ) {
391+ usageURL = url ;
392+ const invalid = yield * api . usageLimits ( "/remote/project" ) ;
393+ assert . strictEqual ( invalid ?. externalUsage , undefined ) ;
394+ assert . deepStrictEqual ( invalid ?. windows , next ?. windows ) ;
395+ }
396+ usageURL = "http://console.example/workspace/usage" ;
397+ assert . strictEqual ( ( yield * api . usageLimits ( "/remote/project" ) ) ?. externalUsage ?. url , usageURL ) ;
384398 } ) ,
385399 ) ;
386400
0 commit comments