mirror of
https://github.com/modelstudioai/cli.git
synced 2026-09-14 19:49:23 +08:00
84805f287c
- preserve custom gateway path prefixes - strip query, fragment, trailing slash, and known SDK suffixes - normalize flag, environment, config, and fallback sources - normalize auth and config writes before persistence - add resolver, login, config, and UI coverage
33 lines
1.4 KiB
TypeScript
33 lines
1.4 KiB
TypeScript
import { expect, test } from "vite-plus/test";
|
|
import { BailianError } from "../src/errors/base.ts";
|
|
import { normalizeModelBaseUrl } from "../src/config/model-base-url.ts";
|
|
|
|
test("normalizeModelBaseUrl removes URL noise and known API base suffixes", () => {
|
|
expect(normalizeModelBaseUrl(" https://dashscope.aliyuncs.com/?region=cn#docs ")).toBe(
|
|
"https://dashscope.aliyuncs.com",
|
|
);
|
|
expect(
|
|
normalizeModelBaseUrl("https://token-plan.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/"),
|
|
).toBe("https://token-plan.cn-beijing.maas.aliyuncs.com");
|
|
expect(
|
|
normalizeModelBaseUrl("https://token-plan.cn-beijing.maas.aliyuncs.com/apps/anthropic"),
|
|
).toBe("https://token-plan.cn-beijing.maas.aliyuncs.com");
|
|
});
|
|
|
|
test("normalizeModelBaseUrl preserves ports and custom gateway prefixes", () => {
|
|
expect(normalizeModelBaseUrl("http://localhost:8080/bailian/")).toBe(
|
|
"http://localhost:8080/bailian",
|
|
);
|
|
expect(
|
|
normalizeModelBaseUrl("https://proxy.example.com/bailian/compatible-mode/v1?tenant=one"),
|
|
).toBe("https://proxy.example.com/bailian");
|
|
expect(normalizeModelBaseUrl("https://proxy.example.com/custom/apps/anthropic#section")).toBe(
|
|
"https://proxy.example.com/custom",
|
|
);
|
|
});
|
|
|
|
test("normalizeModelBaseUrl rejects non-http and malformed URLs", () => {
|
|
expect(() => normalizeModelBaseUrl("not a url")).toThrow(BailianError);
|
|
expect(() => normalizeModelBaseUrl("ftp://example.com/path")).toThrow(/Invalid model base URL/);
|
|
});
|