@@ -73,25 +73,82 @@ test("普通 Key 优先使用已保存地址,再尝试 Workspace 专属地址
7373 } ) ,
7474 ) . toEqual ( [
7575 "https://stored.example.com/api/v1/models?page_no=1&page_size=1" ,
76- "https://llm-test-workspace.cn-beijing.maas.aliyuncs.com/api /v1/models?page_no=1&page_size=1 " ,
77- "https://llm-test-workspace.ap-southeast-1.maas.aliyuncs.com/api /v1/models?page_no=1&page_size=1 " ,
78- "https://llm-test-workspace.cn-hongkong.maas.aliyuncs.com/api /v1/models?page_no=1&page_size=1 " ,
79- "https://llm-test-workspace.ap-northeast-1.maas.aliyuncs.com/api /v1/models?page_no=1&page_size=1 " ,
80- "https://llm-test-workspace.eu-central-1.maas.aliyuncs.com/api /v1/models?page_no=1&page_size=1 " ,
81- "https://llm-test-workspace.us-east-1.maas.aliyuncs.com/api /v1/models?page_no=1&page_size=1 " ,
76+ "https://llm-test-workspace.cn-beijing.maas.aliyuncs.com/compatible-mode /v1/models" ,
77+ "https://llm-test-workspace.ap-southeast-1.maas.aliyuncs.com/compatible-mode /v1/models" ,
78+ "https://llm-test-workspace.cn-hongkong.maas.aliyuncs.com/compatible-mode /v1/models" ,
79+ "https://llm-test-workspace.ap-northeast-1.maas.aliyuncs.com/compatible-mode /v1/models" ,
80+ "https://llm-test-workspace.eu-central-1.maas.aliyuncs.com/compatible-mode /v1/models" ,
81+ "https://llm-test-workspace.us-east-1.maas.aliyuncs.com/compatible-mode /v1/models" ,
8282 "https://dashscope.aliyuncs.com/api/v1/models?page_no=1&page_size=1" ,
8383 "https://dashscope-intl.aliyuncs.com/api/v1/models?page_no=1&page_size=1" ,
8484 "https://dashscope-us.aliyuncs.com/api/v1/models?page_no=1&page_size=1" ,
8585 "https://cn-hongkong.dashscope.aliyuncs.com/api/v1/models?page_no=1&page_size=1" ,
8686 ] ) ;
8787} ) ;
8888
89+ test ( "已保存的 Workspace MaaS 地址使用 Compatible /models" , ( ) => {
90+ expect (
91+ candidateUrls ( "sk-ws-placeholder" , {
92+ storedBaseUrl : "https://ws-stored.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1" ,
93+ } ) ,
94+ ) . toEqual ( [
95+ "https://ws-stored.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/models" ,
96+ "https://dashscope.aliyuncs.com/api/v1/models?page_no=1&page_size=1" ,
97+ "https://dashscope-intl.aliyuncs.com/api/v1/models?page_no=1&page_size=1" ,
98+ "https://dashscope-us.aliyuncs.com/api/v1/models?page_no=1&page_size=1" ,
99+ "https://cn-hongkong.dashscope.aliyuncs.com/api/v1/models?page_no=1&page_size=1" ,
100+ ] ) ;
101+ } ) ;
102+
103+ test ( "Workspace 地域候选先于公共站点选择首个成功地域" , async ( ) => {
104+ const originalFetch = httpTransport . fetch ;
105+ const workspaceOrigin = "https://llm-test-workspace.ap-southeast-1.maas.aliyuncs.com" ;
106+ httpTransport . fetch = async ( input ) => {
107+ const url = requestUrl ( input ) ;
108+ if ( url === `${ workspaceOrigin } /compatible-mode/v1/models` ) {
109+ return jsonResponse ( { object : "list" , data : [ { id : "workspace-model" } ] } ) ;
110+ }
111+ if ( url . startsWith ( "https://dashscope-intl.aliyuncs.com/" ) ) {
112+ return jsonResponse ( { data : [ { id : "public-model" } ] } ) ;
113+ }
114+ const status = url . includes ( ".maas.aliyuncs.com/" ) ? 404 : 401 ;
115+ return jsonResponse ( { code : "Rejected" , message : "candidate rejected" } , status ) ;
116+ } ;
117+
118+ try {
119+ await expect (
120+ validateApiKey ( { identity, settings } , "sk-ws-placeholder" , {
121+ workspaceId : "llm-test-workspace" ,
122+ } ) ,
123+ ) . resolves . toEqual ( {
124+ baseUrl : workspaceOrigin ,
125+ kind : "ordinary" ,
126+ } ) ;
127+ } finally {
128+ httpTransport . fetch = originalFetch ;
129+ }
130+ } ) ;
131+
89132test ( "其他格式 Key 不限制端点类型" , ( ) => {
90133 expect (
91134 apiKeyValidationCandidates ( "custom-key-placeholder" , { } ) . map ( ( candidate ) => candidate . kind ) ,
92135 ) . toEqual ( [ "ordinary" , "ordinary" , "ordinary" , "ordinary" , "token-plan" , "token-plan" ] ) ;
93136} ) ;
94137
138+ test ( "未知格式 Key 指向 Token Plan host 时保留 Token Plan kind" , ( ) => {
139+ expect (
140+ apiKeyValidationCandidates ( "custom-key-placeholder" , {
141+ explicitBaseUrl : "https://token-plan.ap-southeast-1.maas.aliyuncs.com" ,
142+ } ) ,
143+ ) . toEqual ( [
144+ {
145+ baseUrl : "https://token-plan.ap-southeast-1.maas.aliyuncs.com" ,
146+ kind : "token-plan" ,
147+ modelsUrl : "https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/models" ,
148+ } ,
149+ ] ) ;
150+ } ) ;
151+
95152test ( "显式 Base URL 只校验指定站点,并根据 Key 类型选择 /models 路径" , ( ) => {
96153 expect (
97154 candidateUrls ( "sk-sp-placeholder" , {
@@ -103,6 +160,11 @@ test("显式 Base URL 只校验指定站点,并根据 Key 类型选择 /models
103160 explicitBaseUrl : "https://workspace.example.com/compatible-mode/v1" ,
104161 } ) ,
105162 ) . toEqual ( [ "https://workspace.example.com/api/v1/models?page_no=1&page_size=1" ] ) ;
163+ expect (
164+ candidateUrls ( "sk-ws-placeholder" , {
165+ explicitBaseUrl : "https://ws-explicit.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1" ,
166+ } ) ,
167+ ) . toEqual ( [ "https://ws-explicit.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/models" ] ) ;
106168} ) ;
107169
108170test ( "Token Plan 多地区并行校验选择实际接受 Key 的国际站点" , async ( ) => {
0 commit comments