1+ import { httpTransport } from "bailian-cli-core" ;
12import { BailianError , ExitCode , type Identity , type Settings } from "bailian-cli-core" ;
23import { expect , test } from "vite-plus/test" ;
34import {
@@ -105,9 +106,9 @@ test("显式 Base URL 只校验指定站点,并根据 Key 类型选择 /models
105106} ) ;
106107
107108test ( "Token Plan 多地区并行校验选择实际接受 Key 的国际站点" , async ( ) => {
108- const originalFetch = globalThis . fetch ;
109+ const originalFetch = httpTransport . fetch ;
109110 const requests : Array < { authorization : string ; url : string } > = [ ] ;
110- globalThis . fetch = async ( input , init ) => {
111+ httpTransport . fetch = async ( input , init ) => {
111112 const url = requestUrl ( input ) ;
112113 requests . push ( {
113114 authorization : new Headers ( init ?. headers ) . get ( "authorization" ) ?? "" ,
@@ -135,30 +136,30 @@ test("Token Plan 多地区并行校验选择实际接受 Key 的国际站点", a
135136 } ,
136137 ] ) ;
137138 } finally {
138- globalThis . fetch = originalFetch ;
139+ httpTransport . fetch = originalFetch ;
139140 }
140141} ) ;
141142
142143test ( "所有候选站点明确拒绝 Key 时返回 AUTH 校验失败" , async ( ) => {
143- const originalFetch = globalThis . fetch ;
144- globalThis . fetch = async ( ) =>
144+ const originalFetch = httpTransport . fetch ;
145+ httpTransport . fetch = async ( ) =>
145146 jsonResponse ( { code : "InvalidApiKey" , message : "invalid key" } , 401 ) ;
146147
147148 try {
148149 const error = await captureValidationError ( "sk-sp-placeholder" ) ;
149150 expect ( error . exitCode ) . toBe ( ExitCode . AUTH ) ;
150151 expect ( error . message ) . toMatch ( / A P I k e y v a l i d a t i o n f a i l e d / ) ;
151152 } finally {
152- globalThis . fetch = originalFetch ;
153+ httpTransport . fetch = originalFetch ;
153154 }
154155} ) ;
155156
156157test . each ( [
157158 { name : "5xx" , status : 503 , message : "temporary outage" } ,
158159 { name : "429" , status : 429 , message : "too many requests" } ,
159160] ) ( "存在 $name 时校验结论不确定,不误报 Key 无效" , async ( { status, message } ) => {
160- const originalFetch = globalThis . fetch ;
161- globalThis . fetch = async ( input ) => {
161+ const originalFetch = httpTransport . fetch ;
162+ httpTransport . fetch = async ( input ) => {
162163 if ( requestUrl ( input ) . startsWith ( "https://dashscope.aliyuncs.com/" ) ) {
163164 return jsonResponse ( { code : "TemporaryFailure" , message } , status ) ;
164165 }
@@ -170,6 +171,6 @@ test.each([
170171 expect ( error . exitCode ) . toBe ( ExitCode . GENERAL ) ;
171172 expect ( error . message ) . toBe ( message ) ;
172173 } finally {
173- globalThis . fetch = originalFetch ;
174+ httpTransport . fetch = originalFetch ;
174175 }
175176} ) ;
0 commit comments