mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-30 01:08:33 +00:00
The sidebar and header were still keyed on legacy ?page= ids and mapped back and forth through MIGRATED_PAGES, legacyPageHref and legacyKeyForPathname. Leaves are now plain Next links to their path route, the active item and breadcrumb come from usePathname, and the setPage/defaultSelectedKey prop chain is gone. The id-to-route table moves next to the dashboard root page as its only consumer. That redirect now forwards the remaining query params instead of dropping them, so deep links such as the proxy's MCP env-var setup link (?page=mcp-servers&fill_env_vars=) no longer rely on the target page reading the pre-redirect URL during its first render. The proxy builds that link as /ui/mcp-servers?fill_env_vars= directly, and the Playground warnings link to the real routes instead of relative ?page= URLs. migratedHref is renamed uiHref, the /ui base-path helper it always was.
55 lines
1.9 KiB
TypeScript
55 lines
1.9 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { setServerRootPath } from "@/lib/serverRootPath";
|
|
import { routeSegmentForPathname, uiHref } from "./uiHref";
|
|
|
|
afterEach(() => {
|
|
setServerRootPath("/");
|
|
vi.unstubAllEnvs();
|
|
});
|
|
|
|
describe("uiHref", () => {
|
|
it("builds a /ui-rooted path when serverRootPath is /", () => {
|
|
expect(uiHref("api-reference")).toBe("/ui/api-reference");
|
|
});
|
|
|
|
it("prefixes a non-root serverRootPath without duplicating slashes", () => {
|
|
setServerRootPath("/team-x/");
|
|
expect(uiHref("api-reference")).toBe("/team-x/ui/api-reference");
|
|
});
|
|
|
|
it("tolerates a leading slash in the route segment", () => {
|
|
expect(uiHref("/api-reference")).toBe("/ui/api-reference");
|
|
});
|
|
|
|
it("stays root-relative under next dev, which serves the app at /", () => {
|
|
vi.stubEnv("NODE_ENV", "development");
|
|
expect(uiHref("logs")).toBe("/logs");
|
|
});
|
|
});
|
|
|
|
describe("routeSegmentForPathname", () => {
|
|
it("strips the /ui base and any trailing slash", () => {
|
|
expect(routeSegmentForPathname("/ui/api-reference")).toBe("api-reference");
|
|
expect(routeSegmentForPathname("/ui/api-reference/")).toBe("api-reference");
|
|
});
|
|
|
|
it("returns an empty segment for the dashboard root", () => {
|
|
expect(routeSegmentForPathname("/ui/")).toBe("");
|
|
expect(routeSegmentForPathname("/ui")).toBe("");
|
|
});
|
|
|
|
it("keeps only the first segment of a nested path", () => {
|
|
expect(routeSegmentForPathname("/ui/models-and-endpoints/anything")).toBe("models-and-endpoints");
|
|
});
|
|
|
|
it("strips a non-root serverRootPath too", () => {
|
|
setServerRootPath("/team-x/");
|
|
expect(routeSegmentForPathname("/team-x/ui/guardrails")).toBe("guardrails");
|
|
});
|
|
|
|
it("reads the segment straight after / under next dev", () => {
|
|
vi.stubEnv("NODE_ENV", "development");
|
|
expect(routeSegmentForPathname("/logs")).toBe("logs");
|
|
expect(routeSegmentForPathname("/")).toBe("");
|
|
});
|
|
});
|