@@ -2,28 +2,27 @@ import { expect, test } from "vite-plus/test";
22import { BailianError } from "../src/errors/base.ts" ;
33import { normalizeModelBaseUrl } from "../src/config/model-base-url.ts" ;
44
5- test ( "normalizeModelBaseUrl removes URL noise and known API base suffixes " , ( ) => {
5+ test ( "normalizeModelBaseUrl keeps only the URL origin " , ( ) => {
66 expect ( normalizeModelBaseUrl ( " https://dashscope.aliyuncs.com/?region=cn#docs " ) ) . toBe (
77 "https://dashscope.aliyuncs.com" ,
88 ) ;
99 expect (
10- normalizeModelBaseUrl ( "https://token-plan.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/" ) ,
10+ normalizeModelBaseUrl (
11+ "https://token-plan.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/chat/completions" ,
12+ ) ,
1113 ) . toBe ( "https://token-plan.cn-beijing.maas.aliyuncs.com" ) ;
14+ expect ( normalizeModelBaseUrl ( "https://example.com/api/v1/agentstudio" ) ) . toBe (
15+ "https://example.com" ,
16+ ) ;
1217 expect (
13- normalizeModelBaseUrl ( "https://token-plan.cn-beijing.maas.aliyuncs.com/apps/anthropic" ) ,
14- ) . toBe ( "https://token-plan.cn-beijing.maas.aliyuncs.com" ) ;
18+ normalizeModelBaseUrl (
19+ "https://example.com/api/v1/services/aigc/image-generation/generation?model=qwen#docs" ,
20+ ) ,
21+ ) . toBe ( "https://example.com" ) ;
1522} ) ;
1623
17- test ( "normalizeModelBaseUrl preserves ports and custom gateway prefixes" , ( ) => {
18- expect ( normalizeModelBaseUrl ( "http://localhost:8080/bailian/" ) ) . toBe (
19- "http://localhost:8080/bailian" ,
20- ) ;
21- expect (
22- normalizeModelBaseUrl ( "https://proxy.example.com/bailian/compatible-mode/v1?tenant=one" ) ,
23- ) . toBe ( "https://proxy.example.com/bailian" ) ;
24- expect ( normalizeModelBaseUrl ( "https://proxy.example.com/custom/apps/anthropic#section" ) ) . toBe (
25- "https://proxy.example.com/custom" ,
26- ) ;
24+ test ( "normalizeModelBaseUrl preserves explicit ports while removing paths" , ( ) => {
25+ expect ( normalizeModelBaseUrl ( "http://localhost:8080/bailian/" ) ) . toBe ( "http://localhost:8080" ) ;
2726} ) ;
2827
2928test ( "normalizeModelBaseUrl rejects non-http and malformed URLs" , ( ) => {
0 commit comments