33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { test } from "node:test";
|
|
import {
|
|
cfgFromSettings,
|
|
escapeXml,
|
|
normalizeBaseUrl,
|
|
shorten,
|
|
} from "../src/lib/util";
|
|
|
|
test("normalizeBaseUrl strips trailing slashes", () => {
|
|
assert.equal(normalizeBaseUrl("http://localhost:9292/"), "http://localhost:9292");
|
|
assert.equal(normalizeBaseUrl("http://localhost:9292"), "http://localhost:9292");
|
|
});
|
|
|
|
test("cfgFromSettings defaults baseUrl and omits empty apiKey", () => {
|
|
const cfg = cfgFromSettings({});
|
|
assert.equal(cfg.baseUrl, "http://localhost:9292");
|
|
assert.equal(cfg.apiKey, undefined);
|
|
assert.deepEqual(cfgFromSettings({ baseUrl: "http://x/", apiKey: "abc" }), {
|
|
baseUrl: "http://x",
|
|
apiKey: "abc",
|
|
});
|
|
});
|
|
|
|
test("shorten keeps short names and truncates long ones", () => {
|
|
assert.equal(shorten("Qwen3.8-27B"), "Qwen3.8-27B");
|
|
assert.equal(shorten("DeepSeek-V4-Flash-0731"), "DeepSeek-…0731");
|
|
});
|
|
|
|
test("escapeXml escapes XML special characters", () => {
|
|
assert.equal(escapeXml(`A&B <C> "D" 'E'`), "A&B <C> "D" 'E'");
|
|
});
|