@@ -127,6 +127,25 @@ describe("e2e: Sandbox shared base URL resolution", () => {
127127 } ) ;
128128
129129 test ( "auth login persists a base URL that Sandbox uses without a workspace flag" , async ( ) => {
130+ const requests : Array < { authorization ?: string ; method ?: string ; path ?: string } > = [ ] ;
131+ const server = createServer ( ( request , response ) => {
132+ request . resume ( ) ;
133+ requests . push ( {
134+ authorization : request . headers . authorization ,
135+ method : request . method ,
136+ path : request . url ,
137+ } ) ;
138+ response . writeHead ( 200 , { "content-type" : "application/json" } ) ;
139+ response . end ( JSON . stringify ( { data : [ { id : "qwen-plus" } ] } ) ) ;
140+ } ) ;
141+ await new Promise < void > ( ( resolve , reject ) => {
142+ server . once ( "error" , reject ) ;
143+ server . listen ( 0 , "127.0.0.1" , resolve ) ;
144+ } ) ;
145+ servers . push ( server ) ;
146+ const address = server . address ( ) ;
147+ if ( ! address || typeof address === "string" ) throw new Error ( "Expected a local TCP server." ) ;
148+ const origin = `http://127.0.0.1:${ address . port } ` ;
130149 const env = makeConfigEnv ( ) ;
131150 const login = await runCommandE2e (
132151 ROUTES ,
@@ -138,14 +157,21 @@ describe("e2e: Sandbox shared base URL resolution", () => {
138157 "--api-key" ,
139158 "sk-login-test" ,
140159 "--base-url" ,
141- "https://login.example.test/ api/v1/agentstudio/sandbox/" ,
160+ ` ${ origin } / api/v1/agentstudio/sandbox/` ,
142161 ] ,
143162 env ,
144163 ) ;
145164 expect ( login . exitCode , login . stderr ) . toBe ( 0 ) ;
165+ expect ( requests ) . toEqual ( [
166+ {
167+ authorization : "Bearer sk-login-test" ,
168+ method : "GET" ,
169+ path : "/api/v1/models?page_no=1&page_size=1" ,
170+ } ,
171+ ] ) ;
146172 const stored = JSON . parse ( readFileSync ( join ( env . BAILIAN_CONFIG_DIR ! , "config.json" ) , "utf8" ) ) ;
147173 expect ( stored . active_config ) . toBe ( "sandbox-test" ) ;
148- expect ( stored [ "sandbox-test" ] . base_url ) . toBe ( "https://login.example.test" ) ;
174+ expect ( stored [ "sandbox-test" ] . base_url ) . toBe ( origin ) ;
149175
150176 const result = await runCommandE2e (
151177 ROUTES ,
@@ -154,7 +180,7 @@ describe("e2e: Sandbox shared base URL resolution", () => {
154180 ) ;
155181 expect ( result . exitCode , result . stderr ) . toBe ( 0 ) ;
156182 expect ( parseStdoutJson ( result . stdout ) ) . toMatchObject ( {
157- endpoint : `https://login.example.test ${ API_PATH } /sandboxes/sbx-test/pause` ,
183+ endpoint : `${ origin } ${ API_PATH } /sandboxes/sbx-test/pause` ,
158184 } ) ;
159185 } ) ;
160186} ) ;
0 commit comments