Files
openclaw-zero-token/gateway/control-ui-routing.test.ts
sjhu 571e14a236 feat: upgrade to upstream v2026.3.28
Major upgrade from e26988a38 to upstream v2026.3.28 (f9b107928).
Key changes:
- Upstream src/, ui/, extensions/ (89 bundled extensions)
- Zero-token web providers preserved in src/zero-token/
- AskOnce plugin restored and registered as CLI command
- Added missing packages: @anthropic-ai/vertex-sdk, @modelcontextprotocol/sdk
- Fixed tsconfig rootDir, skipLibCheck for plugin-sdk DTS build
- Added askonce to bundled plugin metadata and package.json exports
- Fixed AskOnce CLI command registration (missing commands metadata)
- Restored AskOnce adapter imports (correct 5-level relative paths)
- Removed stale migration artifacts from root directory
2026-03-30 17:58:12 +08:00

116 lines
3.3 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { classifyControlUiRequest } from "./control-ui-routing.js";
describe("classifyControlUiRequest", () => {
describe("root-mounted control ui", () => {
it.each([
{
name: "serves the root entrypoint",
pathname: "/",
method: "GET",
expected: { kind: "serve" as const },
},
{
name: "serves other read-only SPA routes",
pathname: "/chat",
method: "HEAD",
expected: { kind: "serve" as const },
},
{
name: "keeps health probes outside the SPA catch-all",
pathname: "/healthz",
method: "GET",
expected: { kind: "not-control-ui" as const },
},
{
name: "keeps readiness probes outside the SPA catch-all",
pathname: "/ready",
method: "HEAD",
expected: { kind: "not-control-ui" as const },
},
{
name: "keeps plugin routes outside the SPA catch-all",
pathname: "/plugins/webhook",
method: "GET",
expected: { kind: "not-control-ui" as const },
},
{
name: "keeps API routes outside the SPA catch-all",
pathname: "/api/sessions",
method: "GET",
expected: { kind: "not-control-ui" as const },
},
{
name: "returns not-found for legacy ui routes",
pathname: "/ui/settings",
method: "GET",
expected: { kind: "not-found" as const },
},
{
name: "falls through non-read requests",
pathname: "/bluebubbles-webhook",
method: "POST",
expected: { kind: "not-control-ui" as const },
},
])("$name", ({ pathname, method, expected }) => {
expect(
classifyControlUiRequest({
basePath: "",
pathname,
search: "",
method,
}),
).toEqual(expected);
});
});
describe("basePath-mounted control ui", () => {
it.each([
{
name: "redirects the basePath entrypoint",
pathname: "/openclaw",
search: "?foo=1",
method: "GET",
expected: { kind: "redirect" as const, location: "/openclaw/?foo=1" },
},
{
name: "serves nested read-only routes",
pathname: "/openclaw/chat",
search: "",
method: "HEAD",
expected: { kind: "serve" as const },
},
{
name: "falls through unmatched paths",
pathname: "/elsewhere/chat",
search: "",
method: "GET",
expected: { kind: "not-control-ui" as const },
},
{
name: "falls through write requests to the basePath entrypoint",
pathname: "/openclaw",
search: "",
method: "POST",
expected: { kind: "not-control-ui" as const },
},
...["PUT", "DELETE", "PATCH", "OPTIONS"].map((method) => ({
name: `falls through ${method} subroute requests`,
pathname: "/openclaw/webhook",
search: "",
method,
expected: { kind: "not-control-ui" as const },
})),
])("$name", ({ pathname, search, method, expected }) => {
expect(
classifyControlUiRequest({
basePath: "/openclaw",
pathname,
search,
method,
}),
).toEqual(expected);
});
});
});