Files
openclaw/ui/vitest.config.ts
Peter Steinberger cca5b14785 feat(ui): path-based session and dashboard URLs (#113883)
* feat(ui): path-based session and dashboard URLs

* docs(ui): document control UI URLs

* fix(ui): finalize session path routing

* feat(ui): anchor session URLs on stable keys

* docs(ui): clarify stable session URL identity

* fix(ui): resolve session prefixes with full prefix and pagination

Query sessions.list with the full supplied prefix instead of an eight-char
truncation, and paginate up to a bounded page count so longer disambiguation
links resolve instead of being reported ambiguous. Zero strict-prefix matches
now fall through to literal-key resolution rather than rendering an empty
ambiguity view.

Also document the ~dot/~dotdot segment escape: peer ids reach session keys
trimmed and lowercased only (src/routing/session-key.ts), so a literal '.' or
'..' segment is reachable and browsers would normalize it away.

* fix(ui): synchronize committed session routes

* test(ui): split native shell host coverage

* fix(ui): thread configured mainKey through session URL builders

Reserved-set disambiguation needs the operator-configured mainKey at runtime, so
thread it from agentsList through every session path builder and the ClickClack
control URL. Unambiguous non-hex single-segment rests now resolve literally while
short-id-shaped rests still fail closed, which restores ClickClack channel
compatibility detection and control-link reconciliation.

Also bound prefix-resolution retries, preserve catalog thread identity, and keep
draft state on ambiguous candidate links.

* fix(ui): repair session URL CI integration

* perf(ui): lazy-load session route resolution

* perf(ui): isolate session prefix resolution

* perf(ui): defer session path parsing

* perf(ui): defer session navigation startup

* fix(ui): preserve first-run and literal session navigation

* fix(ui): satisfy session routing type and export gates

* fix(clickclack): preserve unscoped control link agent

* style(ui): satisfy chat page line limit

* refactor(ui): move chat page helpers to owning modules

* fix(ui): preserve destination session route identity

* fix(ui): preserve agent identity in session routes

* fix(ui): escape dots in literal session path segments

encodeURIComponent leaves periods intact, so a literal key segment like
channel:release.js produced /chat/main/channel/release.js. In-app navigation is
intercepted by the SPA, but a refresh, an external link, or a ClickClack link
would be served as a static asset request and never reach the app.

pathForWorkboardBoard already escapes dots for this reason; mirror it in both the
session URL contract and the ClickClack encoder, route the agent id through the
same segment encoder, and pin the case in both shared vector tables.

* fix(ui): stop bootstrap after teardown race

* refactor(ui): centralize session navigation targets

* fix(ui): consume bootstrap teardown abort

* fix(ui): canonicalize configured main session routes

* fix(ui): preserve distinct session references

* fix(ui): redirect released session query links

* fix(ui): make bootstrap teardown abort-safe
2026-07-26 12:46:04 -04:00

212 lines
6.8 KiB
TypeScript

// Control UI config module wires vitest behavior.
import { spawnSync } from "node:child_process";
import { existsSync } from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { playwright } from "@vitest/browser-playwright";
import { chromium } from "playwright";
import { defineConfig, defineProject } from "vitest/config";
import {
jsdomOptimizedDeps,
resolveDefaultVitestPool,
} from "../test/vitest/vitest.shared.config.ts";
const here = path.dirname(fileURLToPath(import.meta.url));
const repoRoot = path.resolve(here, "..");
const workspaceSourceAliases = [
{
find: "@openclaw/gateway-client/browser",
replacement: path.resolve(repoRoot, "packages/gateway-client/src/browser.ts"),
},
{
find: /^@openclaw\/gateway-protocol\/(.+)$/u,
replacement: path.resolve(repoRoot, "packages/gateway-protocol/src/$1.ts"),
},
{
find: /^@openclaw\/(gateway-protocol|retry)$/u,
replacement: path.resolve(repoRoot, "packages/$1/src/index.ts"),
},
{
find: "../logging/redact.js",
replacement: path.resolve(here, "src/lib/browser-redact.ts"),
},
{
find: "openclaw/plugin-sdk/test-fixtures",
replacement: path.resolve(repoRoot, "src/plugin-sdk/test-fixtures.ts"),
},
{
find: /^@openclaw\/model-catalog-core\/(.+)$/u,
replacement: path.resolve(repoRoot, "packages/model-catalog-core/src/$1.ts"),
},
{
find: "@openclaw/model-catalog-core",
replacement: path.resolve(repoRoot, "packages/model-catalog-core/src/index.ts"),
},
{
find: /^@openclaw\/normalization-core\/(.+)$/u,
replacement: path.resolve(repoRoot, "packages/normalization-core/src/$1"),
},
{
find: "@openclaw/normalization-core",
replacement: path.resolve(repoRoot, "packages/normalization-core/src/index.ts"),
},
{
find: /^@openclaw\/media-core\/(.+)$/u,
replacement: path.resolve(repoRoot, "packages/media-core/src/$1"),
},
{
find: "@openclaw/media-core",
replacement: path.resolve(repoRoot, "packages/media-core/src/index.ts"),
},
{
find: "@openclaw/session-url-contract/parse",
replacement: path.resolve(repoRoot, "packages/session-url-contract/src/parse.ts"),
},
{
find: "@openclaw/session-url-contract",
replacement: path.resolve(repoRoot, "packages/session-url-contract/src/index.ts"),
},
{
find: "@openclaw/workboard-contract",
replacement: path.resolve(repoRoot, "packages/workboard-contract/src/index.ts"),
},
{
find: /^@openclaw\/net-policy\/(.+)$/u,
replacement: path.resolve(repoRoot, "packages/net-policy/src/$1"),
},
{
find: "@openclaw/net-policy",
replacement: path.resolve(repoRoot, "packages/net-policy/src/index.ts"),
},
];
const sharedUiTestConfig = {
isolate: false,
pool: resolveDefaultVitestPool(),
// Real-Chromium layout tests exceed Vitest's 5s default on 4vcpu CI runners;
// without this the checks-ui lane flakes on cold hover/interaction tests.
testTimeout: 60_000,
hookTimeout: 60_000,
} as const;
const nodeDrivenBrowserLayoutTests = [
"src/ui/chat/sidebar-session-picker.browser.test.ts",
"src/pages/chat/chat-responsive.browser.test.ts",
"src/components/form-controls.browser.test.ts",
"src/pages/sessions/view.browser.test.ts",
] as const;
const mockRegistryUnitTests = [
"src/components/mcp-app-view.test.ts",
"src/pages/chat/chat-page.test.ts",
] as const;
const chromiumExecutableOverrideEnvKey = "PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH";
const systemChromiumExecutableCandidates = [
"/snap/bin/chromium",
"/usr/bin/chromium-browser",
"/usr/bin/chromium",
"/usr/bin/google-chrome",
"/usr/bin/google-chrome-stable",
] as const;
function canRunChromiumExecutable(executablePath: string): boolean {
const result = spawnSync(executablePath, ["--version"], { stdio: "ignore" });
return result.status === 0;
}
function resolveChromiumLaunchOptions(): { executablePath: string } | undefined {
const override = process.env[chromiumExecutableOverrideEnvKey]?.trim();
if (override && existsSync(override) && canRunChromiumExecutable(override)) {
return { executablePath: override };
}
const defaultExecutablePath = chromium.executablePath();
if (existsSync(defaultExecutablePath) && canRunChromiumExecutable(defaultExecutablePath)) {
return undefined;
}
const systemExecutablePath = systemChromiumExecutableCandidates.find(
(candidate) => existsSync(candidate) && canRunChromiumExecutable(candidate),
);
return systemExecutablePath ? { executablePath: systemExecutablePath } : undefined;
}
const chromiumLaunchOptions = resolveChromiumLaunchOptions();
export default defineConfig({
resolve: {
alias: workspaceSourceAliases,
},
test: {
...sharedUiTestConfig,
projects: [
defineProject({
resolve: {
alias: workspaceSourceAliases,
},
test: {
...sharedUiTestConfig,
deps: jsdomOptimizedDeps,
name: "unit",
include: ["src/**/*.test.ts"],
exclude: [
"src/**/*.browser.test.ts",
"src/**/*.e2e.test.ts",
"src/**/*.node.test.ts",
...mockRegistryUnitTests,
],
environment: "jsdom",
setupFiles: ["./src/test-helpers/lit-warnings.setup.ts"],
},
}),
defineProject({
resolve: {
alias: workspaceSourceAliases,
},
test: {
...sharedUiTestConfig,
// These two tests intentionally replace module exports. Isolate only this tiny
// project so the main 339-file suite keeps its isolate:false speed contract.
isolate: true,
deps: jsdomOptimizedDeps,
name: "unit-mock-registry",
include: [...mockRegistryUnitTests],
environment: "jsdom",
setupFiles: ["./src/test-helpers/lit-warnings.setup.ts"],
},
}),
defineProject({
resolve: {
alias: workspaceSourceAliases,
},
test: {
...sharedUiTestConfig,
deps: jsdomOptimizedDeps,
name: "unit-node",
include: ["src/**/*.node.test.ts", ...nodeDrivenBrowserLayoutTests],
environment: "jsdom",
setupFiles: ["./src/test-helpers/lit-warnings.setup.ts"],
},
}),
defineProject({
resolve: {
alias: workspaceSourceAliases,
},
test: {
...sharedUiTestConfig,
name: "browser",
include: ["src/**/*.browser.test.ts"],
exclude: [...nodeDrivenBrowserLayoutTests],
setupFiles: ["./src/test-helpers/lit-warnings.setup.ts"],
browser: {
enabled: true,
provider: playwright(
chromiumLaunchOptions ? { launchOptions: chromiumLaunchOptions } : {},
),
instances: [{ browser: "chromium", name: "chromium" }],
headless: true,
ui: false,
},
},
}),
],
},
});