Files
DeepTutor/web/tests/api-resolve-base.test.ts
Bingxi Zhao (Frank) 4b7d24d33e release: v1.2.3 — document attachments, thinking blocks, provider core refactor
- Chat document attachments (PDF/DOCX/XLSX/PPTX) with text extraction
- Reasoning model <think> block display as collapsible cards
- Tri-state send_dimensions toggle for embeddings (#368)
- LLM provider_core module refactor + context_window detection
- Soul template editor (PR #373), Co-Writer save-to-notebook
- Knowledge Base drag-and-drop upload, delete resilience (#370),
  progress persistence, supported-file-types endpoint
- Question generation language fidelity via shared prompt directives
- Settings tour redesign, CLI notebook add-md/replace-md
- Bug fixes: CJK bot name slug, I18nProvider init, Skills default off,
  Moonshot base URL, version badge
- Provider registry: custom_anthropic, thinking_style, alias expansion
- +1900 test lines across 15 new/expanded test files

Made-with: Cursor
2026-04-24 22:36:32 +08:00

69 lines
2.4 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
// Must be set before importing the module under test, since API_BASE_URL is
// read at module-load time and the module throws if it's missing.
process.env.NEXT_PUBLIC_API_BASE = "http://localhost:8001/api";
let apiModulePromise: Promise<typeof import("../lib/api")> | null = null;
async function loadApiModule(): Promise<typeof import("../lib/api")> {
apiModulePromise ??= import("../lib/api");
return apiModulePromise;
}
function setWindow(hostname: string | undefined): void {
if (hostname === undefined) {
delete (globalThis as { window?: unknown }).window;
return;
}
(globalThis as { window?: unknown }).window = {
location: { hostname },
} as unknown;
}
test("resolveBase returns the build-time base in SSR (no window)", async () => {
const { resolveBase } = await loadApiModule();
setWindow(undefined);
assert.equal(resolveBase(), "http://localhost:8001/api");
});
test("resolveBase returns base unchanged when client is also on localhost", async () => {
const { resolveBase } = await loadApiModule();
setWindow("localhost");
assert.equal(resolveBase(), "http://localhost:8001/api");
});
test("resolveBase rewrites loopback hostname to remote LAN host and preserves path", async () => {
const { resolveBase } = await loadApiModule();
setWindow("192.168.1.10");
assert.equal(resolveBase(), "http://192.168.1.10:8001/api");
});
test("resolveBase treats IPv6 loopback as loopback (no swap when client is also ::1)", async () => {
const { resolveBase } = await loadApiModule();
setWindow("::1");
assert.equal(resolveBase(), "http://localhost:8001/api");
});
test("apiUrl composes correctly after rewrite, without losing the base path", async () => {
const { apiUrl } = await loadApiModule();
setWindow("10.0.0.5");
assert.equal(
apiUrl("/api/v1/knowledge/list"),
"http://10.0.0.5:8001/api/api/v1/knowledge/list",
);
});
test("wsUrl converts http to ws and respects rewritten host", async () => {
const { wsUrl } = await loadApiModule();
setWindow("10.0.0.5");
assert.equal(wsUrl("/api/v1/ws"), "ws://10.0.0.5:8001/api/api/v1/ws");
});
test("wsUrl keeps original loopback when client is also loopback", async () => {
const { wsUrl } = await loadApiModule();
setWindow("127.0.0.1");
assert.equal(wsUrl("/api/v1/ws"), "ws://localhost:8001/api/api/v1/ws");
});