Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11), free to diverge. Tree copied sans upstream .git; upstream remote added for future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19. Preserves docs/ARCHITECTURE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
686 lines
19 KiB
TypeScript
686 lines
19 KiB
TypeScript
// @vitest-environment node
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { createImportedCustomThemeFixture } from "../test-helpers/custom-theme.ts";
|
|
import { createStorageMock } from "../test-helpers/storage.ts";
|
|
import {
|
|
loadLocalUserIdentity,
|
|
loadSettings,
|
|
saveLocalUserIdentity,
|
|
saveSettings,
|
|
} from "./settings.ts";
|
|
|
|
function setTestLocation(params: { protocol: string; host: string; pathname: string }) {
|
|
vi.stubGlobal("location", {
|
|
protocol: params.protocol,
|
|
host: params.host,
|
|
hostname: params.host.replace(/:\d+$/, ""),
|
|
pathname: params.pathname,
|
|
} as Location);
|
|
}
|
|
|
|
function setControlUiBasePath(value: string | undefined) {
|
|
type TestWindow = Window & typeof globalThis & { [key: string]: unknown };
|
|
if (typeof window === "undefined") {
|
|
vi.stubGlobal(
|
|
"window",
|
|
value == null
|
|
? ({} as TestWindow)
|
|
: ({ __OPENCLAW_CONTROL_UI_BASE_PATH__: value } as unknown as TestWindow),
|
|
);
|
|
return;
|
|
}
|
|
if (value == null) {
|
|
delete (window as TestWindow)["__OPENCLAW_CONTROL_UI_BASE_PATH__"];
|
|
return;
|
|
}
|
|
Object.defineProperty(window, "__OPENCLAW_CONTROL_UI_BASE_PATH__", {
|
|
value,
|
|
writable: true,
|
|
configurable: true,
|
|
});
|
|
}
|
|
|
|
function expectedGatewayUrl(basePath: string): string {
|
|
const proto = location.protocol === "https:" ? "wss" : "ws";
|
|
return `${proto}://${location.host}${basePath}`;
|
|
}
|
|
|
|
describe("loadSettings default gateway URL derivation", () => {
|
|
beforeEach(() => {
|
|
vi.stubGlobal("localStorage", createStorageMock());
|
|
vi.stubGlobal("sessionStorage", createStorageMock());
|
|
vi.stubGlobal("navigator", { language: "en-US" } as Navigator);
|
|
localStorage.clear();
|
|
sessionStorage.clear();
|
|
setControlUiBasePath(undefined);
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
setControlUiBasePath(undefined);
|
|
vi.unstubAllGlobals();
|
|
});
|
|
|
|
it("uses configured base path and normalizes trailing slash", () => {
|
|
setTestLocation({
|
|
protocol: "https:",
|
|
host: "gateway.example:8443",
|
|
pathname: "/ignored/path",
|
|
});
|
|
setControlUiBasePath(" /openclaw/ ");
|
|
|
|
expect(loadSettings().gatewayUrl).toBe(expectedGatewayUrl("/openclaw"));
|
|
});
|
|
|
|
it("defaults chat auto-scroll to near-bottom", () => {
|
|
setTestLocation({
|
|
protocol: "https:",
|
|
host: "gateway.example:8443",
|
|
pathname: "/",
|
|
});
|
|
|
|
expect(loadSettings().chatAutoScroll).toBe("near-bottom");
|
|
});
|
|
|
|
it("infers base path from nested pathname when configured base path is not set", () => {
|
|
setTestLocation({
|
|
protocol: "http:",
|
|
host: "gateway.example:18789",
|
|
pathname: "/apps/openclaw/chat",
|
|
});
|
|
|
|
expect(loadSettings().gatewayUrl).toBe(expectedGatewayUrl("/apps/openclaw"));
|
|
});
|
|
|
|
it("skips node sessionStorage accessors that warn without a storage file", () => {
|
|
vi.unstubAllGlobals();
|
|
vi.stubGlobal("localStorage", createStorageMock());
|
|
vi.stubGlobal("navigator", { language: "en-US" } as Navigator);
|
|
setTestLocation({
|
|
protocol: "https:",
|
|
host: "gateway.example:8443",
|
|
pathname: "/",
|
|
});
|
|
setControlUiBasePath(undefined);
|
|
const warningSpy = vi.spyOn(process, "emitWarning").mockImplementation(() => undefined);
|
|
|
|
const settings = loadSettings();
|
|
expect(settings.gatewayUrl).toBe(expectedGatewayUrl(""));
|
|
expect(settings.token).toBe("");
|
|
expect(
|
|
warningSpy.mock.calls.some(
|
|
([message]) => message === "`--localstorage-file` was provided without a valid path",
|
|
),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("ignores and scrubs legacy persisted tokens", () => {
|
|
setTestLocation({
|
|
protocol: "https:",
|
|
host: "gateway.example:8443",
|
|
pathname: "/",
|
|
});
|
|
sessionStorage.setItem("openclaw.control.token.v1", "legacy-session-token");
|
|
localStorage.setItem(
|
|
"openclaw.control.settings.v1",
|
|
JSON.stringify({
|
|
gatewayUrl: "wss://gateway.example:8443/openclaw",
|
|
token: "persisted-token",
|
|
sessionKey: "agent",
|
|
}),
|
|
);
|
|
|
|
const settings = loadSettings();
|
|
expect(settings.gatewayUrl).toBe("wss://gateway.example:8443/openclaw");
|
|
expect(settings.token).toBe("");
|
|
expect(settings.sessionKey).toBe("agent");
|
|
const scopedKey = "openclaw.control.settings.v1:wss://gateway.example:8443/openclaw";
|
|
expect(JSON.parse(localStorage.getItem(scopedKey) ?? "{}")).toEqual({
|
|
gatewayUrl: "wss://gateway.example:8443/openclaw",
|
|
theme: "claw",
|
|
themeMode: "system",
|
|
chatShowThinking: true,
|
|
chatShowToolCalls: true,
|
|
chatPersistCommentary: false,
|
|
chatAutoScroll: "near-bottom",
|
|
splitRatio: 0.6,
|
|
navCollapsed: false,
|
|
navWidth: 220,
|
|
navGroupsCollapsed: {},
|
|
recentSessionsCollapsed: false,
|
|
borderRadius: 50,
|
|
textScale: 100,
|
|
sessionsByGateway: {
|
|
"wss://gateway.example:8443/openclaw": {
|
|
sessionKey: "agent",
|
|
lastActiveSessionKey: "agent",
|
|
},
|
|
},
|
|
});
|
|
expect(sessionStorage.length).toBe(0);
|
|
});
|
|
|
|
it("loads the current-tab token from sessionStorage", () => {
|
|
setTestLocation({
|
|
protocol: "https:",
|
|
host: "gateway.example:8443",
|
|
pathname: "/",
|
|
});
|
|
|
|
const gwUrl = expectedGatewayUrl("");
|
|
saveSettings({
|
|
gatewayUrl: gwUrl,
|
|
token: "session-token",
|
|
sessionKey: "main",
|
|
lastActiveSessionKey: "main",
|
|
theme: "claw",
|
|
themeMode: "system",
|
|
chatShowThinking: true,
|
|
chatShowToolCalls: true,
|
|
chatAutoScroll: "near-bottom",
|
|
splitRatio: 0.6,
|
|
navCollapsed: false,
|
|
navWidth: 220,
|
|
navGroupsCollapsed: {},
|
|
borderRadius: 50,
|
|
textScale: 100,
|
|
});
|
|
|
|
const settings = loadSettings();
|
|
expect(settings.gatewayUrl).toBe(gwUrl);
|
|
expect(settings.token).toBe("session-token");
|
|
});
|
|
|
|
it("does not reuse a session token for a different gatewayUrl", () => {
|
|
setTestLocation({
|
|
protocol: "https:",
|
|
host: "gateway.example:8443",
|
|
pathname: "/",
|
|
});
|
|
|
|
const gwUrl = expectedGatewayUrl("");
|
|
const otherUrl = "wss://other-gateway.example:8443";
|
|
saveSettings({
|
|
gatewayUrl: gwUrl,
|
|
token: "gateway-a-token",
|
|
sessionKey: "main",
|
|
lastActiveSessionKey: "main",
|
|
theme: "claw",
|
|
themeMode: "system",
|
|
chatShowThinking: true,
|
|
chatShowToolCalls: true,
|
|
chatAutoScroll: "near-bottom",
|
|
splitRatio: 0.6,
|
|
navCollapsed: false,
|
|
navWidth: 220,
|
|
navGroupsCollapsed: {},
|
|
borderRadius: 50,
|
|
});
|
|
|
|
saveSettings({
|
|
gatewayUrl: otherUrl,
|
|
token: "",
|
|
sessionKey: "main",
|
|
lastActiveSessionKey: "main",
|
|
theme: "claw",
|
|
themeMode: "system",
|
|
chatShowThinking: true,
|
|
chatShowToolCalls: true,
|
|
chatAutoScroll: "near-bottom",
|
|
splitRatio: 0.6,
|
|
navCollapsed: false,
|
|
navWidth: 220,
|
|
navGroupsCollapsed: {},
|
|
borderRadius: 50,
|
|
});
|
|
|
|
const settings = loadSettings();
|
|
expect(settings.gatewayUrl).toBe(gwUrl);
|
|
expect(settings.token).toBe("gateway-a-token");
|
|
});
|
|
|
|
it("does not persist gateway tokens when saving settings", () => {
|
|
setTestLocation({
|
|
protocol: "https:",
|
|
host: "gateway.example:8443",
|
|
pathname: "/",
|
|
});
|
|
|
|
const gwUrl = expectedGatewayUrl("");
|
|
saveSettings({
|
|
gatewayUrl: gwUrl,
|
|
token: "memory-only-token",
|
|
sessionKey: "main",
|
|
lastActiveSessionKey: "main",
|
|
theme: "claw",
|
|
themeMode: "system",
|
|
chatShowThinking: true,
|
|
chatShowToolCalls: true,
|
|
splitRatio: 0.6,
|
|
navCollapsed: false,
|
|
navWidth: 220,
|
|
navGroupsCollapsed: {},
|
|
borderRadius: 50,
|
|
});
|
|
const settings = loadSettings();
|
|
expect(settings.gatewayUrl).toBe(gwUrl);
|
|
expect(settings.token).toBe("memory-only-token");
|
|
|
|
const scopedKey = `openclaw.control.settings.v1:${gwUrl}`;
|
|
expect(JSON.parse(localStorage.getItem(scopedKey) ?? "{}")).toEqual({
|
|
gatewayUrl: gwUrl,
|
|
theme: "claw",
|
|
themeMode: "system",
|
|
chatShowThinking: true,
|
|
chatShowToolCalls: true,
|
|
chatPersistCommentary: false,
|
|
chatAutoScroll: "near-bottom",
|
|
splitRatio: 0.6,
|
|
navCollapsed: false,
|
|
navWidth: 220,
|
|
navGroupsCollapsed: {},
|
|
recentSessionsCollapsed: false,
|
|
borderRadius: 50,
|
|
textScale: 100,
|
|
sessionsByGateway: {
|
|
[gwUrl]: {
|
|
sessionKey: "main",
|
|
lastActiveSessionKey: "main",
|
|
},
|
|
},
|
|
});
|
|
expect(sessionStorage.length).toBe(1);
|
|
});
|
|
|
|
it("persists recent sessions collapse state across save and load", () => {
|
|
setTestLocation({
|
|
protocol: "https:",
|
|
host: "gateway.example:8443",
|
|
pathname: "/",
|
|
});
|
|
|
|
const gwUrl = expectedGatewayUrl("");
|
|
saveSettings({
|
|
gatewayUrl: gwUrl,
|
|
token: "",
|
|
sessionKey: "main",
|
|
lastActiveSessionKey: "main",
|
|
theme: "claw",
|
|
themeMode: "system",
|
|
chatShowThinking: true,
|
|
chatShowToolCalls: true,
|
|
chatAutoScroll: "near-bottom",
|
|
splitRatio: 0.6,
|
|
navCollapsed: false,
|
|
navWidth: 220,
|
|
navGroupsCollapsed: {},
|
|
recentSessionsCollapsed: true,
|
|
borderRadius: 50,
|
|
textScale: 100,
|
|
});
|
|
|
|
expect(loadSettings().recentSessionsCollapsed).toBe(true);
|
|
|
|
saveSettings({
|
|
gatewayUrl: gwUrl,
|
|
token: "",
|
|
sessionKey: "main",
|
|
lastActiveSessionKey: "main",
|
|
theme: "claw",
|
|
themeMode: "system",
|
|
chatShowThinking: true,
|
|
chatShowToolCalls: true,
|
|
chatAutoScroll: "near-bottom",
|
|
splitRatio: 0.6,
|
|
navCollapsed: false,
|
|
navWidth: 220,
|
|
navGroupsCollapsed: {},
|
|
recentSessionsCollapsed: false,
|
|
borderRadius: 50,
|
|
textScale: 100,
|
|
});
|
|
|
|
const scopedKey = `openclaw.control.settings.v1:${gwUrl}`;
|
|
const persisted = JSON.parse(localStorage.getItem(scopedKey) ?? "{}") as Record<
|
|
string,
|
|
unknown
|
|
>;
|
|
expect(persisted.recentSessionsCollapsed).toBe(false);
|
|
expect(loadSettings().recentSessionsCollapsed).toBe(false);
|
|
});
|
|
|
|
it("normalizes persisted text scale to the nearest supported stop", () => {
|
|
setTestLocation({
|
|
protocol: "https:",
|
|
host: "gateway.example:8443",
|
|
pathname: "/",
|
|
});
|
|
|
|
const gwUrl = expectedGatewayUrl("");
|
|
localStorage.setItem(
|
|
`openclaw.control.settings.v1:${gwUrl}`,
|
|
JSON.stringify({
|
|
gatewayUrl: gwUrl,
|
|
textScale: 123,
|
|
}),
|
|
);
|
|
|
|
expect(loadSettings().textScale).toBe(125);
|
|
});
|
|
|
|
it("loads valid chat auto-scroll modes and normalizes invalid values", () => {
|
|
setTestLocation({
|
|
protocol: "https:",
|
|
host: "gateway.example:8443",
|
|
pathname: "/",
|
|
});
|
|
|
|
const gwUrl = expectedGatewayUrl("");
|
|
localStorage.setItem(
|
|
`openclaw.control.settings.v1:${gwUrl}`,
|
|
JSON.stringify({
|
|
gatewayUrl: gwUrl,
|
|
chatAutoScroll: "off",
|
|
}),
|
|
);
|
|
expect(loadSettings().chatAutoScroll).toBe("off");
|
|
|
|
localStorage.setItem(
|
|
`openclaw.control.settings.v1:${gwUrl}`,
|
|
JSON.stringify({
|
|
gatewayUrl: gwUrl,
|
|
chatAutoScroll: "disabled",
|
|
}),
|
|
);
|
|
expect(loadSettings().chatAutoScroll).toBe("near-bottom");
|
|
});
|
|
|
|
it("clears the current-tab token when saving an empty token", () => {
|
|
setTestLocation({
|
|
protocol: "https:",
|
|
host: "gateway.example:8443",
|
|
pathname: "/",
|
|
});
|
|
|
|
const gwUrl = expectedGatewayUrl("");
|
|
saveSettings({
|
|
gatewayUrl: gwUrl,
|
|
token: "stale-token",
|
|
sessionKey: "main",
|
|
lastActiveSessionKey: "main",
|
|
theme: "claw",
|
|
themeMode: "system",
|
|
chatShowThinking: true,
|
|
chatShowToolCalls: true,
|
|
splitRatio: 0.6,
|
|
navCollapsed: false,
|
|
navWidth: 220,
|
|
navGroupsCollapsed: {},
|
|
borderRadius: 50,
|
|
});
|
|
saveSettings({
|
|
gatewayUrl: gwUrl,
|
|
token: "",
|
|
sessionKey: "main",
|
|
lastActiveSessionKey: "main",
|
|
theme: "claw",
|
|
themeMode: "system",
|
|
chatShowThinking: true,
|
|
chatShowToolCalls: true,
|
|
splitRatio: 0.6,
|
|
navCollapsed: false,
|
|
navWidth: 220,
|
|
navGroupsCollapsed: {},
|
|
borderRadius: 50,
|
|
});
|
|
|
|
expect(loadSettings().token).toBe("");
|
|
expect(sessionStorage.length).toBe(0);
|
|
});
|
|
|
|
it("persists themeMode and navWidth alongside the selected theme", () => {
|
|
setTestLocation({
|
|
protocol: "https:",
|
|
host: "gateway.example:8443",
|
|
pathname: "/",
|
|
});
|
|
|
|
const gwUrl = expectedGatewayUrl("");
|
|
saveSettings({
|
|
gatewayUrl: gwUrl,
|
|
token: "",
|
|
sessionKey: "main",
|
|
lastActiveSessionKey: "main",
|
|
theme: "dash",
|
|
themeMode: "light",
|
|
chatShowThinking: true,
|
|
chatShowToolCalls: true,
|
|
splitRatio: 0.6,
|
|
navCollapsed: false,
|
|
navWidth: 320,
|
|
navGroupsCollapsed: {},
|
|
borderRadius: 50,
|
|
});
|
|
|
|
const scopedKey = `openclaw.control.settings.v1:${gwUrl}`;
|
|
const persisted = JSON.parse(localStorage.getItem(scopedKey) ?? "{}") as Record<
|
|
string,
|
|
unknown
|
|
>;
|
|
expect(persisted.theme).toBe("dash");
|
|
expect(persisted.themeMode).toBe("light");
|
|
expect(persisted.navWidth).toBe(320);
|
|
});
|
|
|
|
it("persists the browser-local custom theme payload when present", () => {
|
|
setTestLocation({
|
|
protocol: "https:",
|
|
host: "gateway.example:8443",
|
|
pathname: "/",
|
|
});
|
|
|
|
const gwUrl = expectedGatewayUrl("");
|
|
const customTheme = createImportedCustomThemeFixture();
|
|
saveSettings({
|
|
gatewayUrl: gwUrl,
|
|
token: "",
|
|
sessionKey: "main",
|
|
lastActiveSessionKey: "main",
|
|
theme: "custom",
|
|
themeMode: "system",
|
|
chatShowThinking: true,
|
|
chatShowToolCalls: true,
|
|
splitRatio: 0.6,
|
|
navCollapsed: false,
|
|
navWidth: 220,
|
|
navGroupsCollapsed: {},
|
|
borderRadius: 50,
|
|
customTheme,
|
|
});
|
|
|
|
const settings = loadSettings();
|
|
expect(settings.theme).toBe("custom");
|
|
expect(settings.customTheme?.label).toBe("Light Green");
|
|
expect(settings.customTheme?.themeId).toBe("cmlhfpjhw000004l4f4ax3m7z");
|
|
});
|
|
|
|
it("falls back to claw when persisted custom theme data is invalid", () => {
|
|
setTestLocation({
|
|
protocol: "https:",
|
|
host: "gateway.example:8443",
|
|
pathname: "/",
|
|
});
|
|
|
|
const gwUrl = expectedGatewayUrl("");
|
|
localStorage.setItem(
|
|
`openclaw.control.settings.v1:${gwUrl}`,
|
|
JSON.stringify({
|
|
gatewayUrl: gwUrl,
|
|
theme: "custom",
|
|
themeMode: "dark",
|
|
chatShowThinking: true,
|
|
chatShowToolCalls: true,
|
|
splitRatio: 0.6,
|
|
navCollapsed: false,
|
|
navWidth: 220,
|
|
navGroupsCollapsed: {},
|
|
borderRadius: 50,
|
|
customTheme: {
|
|
sourceUrl: "https://tweakcn.com/themes/broken",
|
|
themeId: "broken",
|
|
label: "Broken",
|
|
importedAt: "2026-04-22T00:00:00.000Z",
|
|
light: {},
|
|
dark: {},
|
|
},
|
|
sessionsByGateway: {
|
|
[gwUrl]: {
|
|
sessionKey: "main",
|
|
lastActiveSessionKey: "main",
|
|
},
|
|
},
|
|
}),
|
|
);
|
|
|
|
const settings = loadSettings();
|
|
expect(settings.theme).toBe("claw");
|
|
expect(settings.themeMode).toBe("dark");
|
|
});
|
|
|
|
it("scopes persisted session selection per gateway", () => {
|
|
setTestLocation({
|
|
protocol: "https:",
|
|
host: "gateway-a.example:8443",
|
|
pathname: "/",
|
|
});
|
|
|
|
const gwUrl = expectedGatewayUrl("");
|
|
saveSettings({
|
|
gatewayUrl: gwUrl,
|
|
token: "",
|
|
sessionKey: "agent:test_old:main",
|
|
lastActiveSessionKey: "agent:test_old:main",
|
|
theme: "claw",
|
|
themeMode: "system",
|
|
chatShowThinking: true,
|
|
chatShowToolCalls: true,
|
|
splitRatio: 0.6,
|
|
navCollapsed: false,
|
|
navWidth: 220,
|
|
navGroupsCollapsed: {},
|
|
borderRadius: 50,
|
|
});
|
|
|
|
const settings = loadSettings();
|
|
expect(settings.gatewayUrl).toBe(gwUrl);
|
|
expect(settings.sessionKey).toBe("agent:test_old:main");
|
|
expect(settings.lastActiveSessionKey).toBe("agent:test_old:main");
|
|
});
|
|
|
|
it("caps persisted session scopes to the most recent gateways", () => {
|
|
setTestLocation({
|
|
protocol: "https:",
|
|
host: "gateway.example:8443",
|
|
pathname: "/",
|
|
});
|
|
|
|
const gwUrl = expectedGatewayUrl("");
|
|
const scopedKey = `openclaw.control.settings.v1:wss://gateway.example:8443`;
|
|
|
|
// Pre-seed sessionsByGateway with 11 stale gateway entries so the next
|
|
// saveSettings call pushes the total to 12 and triggers the cap (10).
|
|
const staleEntries: Record<string, { sessionKey: string; lastActiveSessionKey: string }> = {};
|
|
for (let i = 0; i < 11; i += 1) {
|
|
staleEntries[`wss://stale-${i}.example:8443`] = {
|
|
sessionKey: `agent:stale_${i}:main`,
|
|
lastActiveSessionKey: `agent:stale_${i}:main`,
|
|
};
|
|
}
|
|
localStorage.setItem(scopedKey, JSON.stringify({ sessionsByGateway: staleEntries }));
|
|
|
|
saveSettings({
|
|
gatewayUrl: gwUrl,
|
|
token: "",
|
|
sessionKey: "agent:current:main",
|
|
lastActiveSessionKey: "agent:current:main",
|
|
theme: "claw",
|
|
themeMode: "system",
|
|
chatShowThinking: true,
|
|
chatShowToolCalls: true,
|
|
splitRatio: 0.6,
|
|
navCollapsed: false,
|
|
navWidth: 220,
|
|
navGroupsCollapsed: {},
|
|
borderRadius: 50,
|
|
});
|
|
|
|
const persisted = JSON.parse(localStorage.getItem(scopedKey) ?? "{}");
|
|
|
|
const scopedSessions = persisted.sessionsByGateway as Record<
|
|
string,
|
|
{ sessionKey: string; lastActiveSessionKey: string }
|
|
>;
|
|
expect(scopedSessions["wss://gateway.example:8443"]).toEqual({
|
|
sessionKey: "agent:current:main",
|
|
lastActiveSessionKey: "agent:current:main",
|
|
});
|
|
expect(Object.keys(scopedSessions)).toEqual([
|
|
"wss://stale-2.example:8443",
|
|
"wss://stale-3.example:8443",
|
|
"wss://stale-4.example:8443",
|
|
"wss://stale-5.example:8443",
|
|
"wss://stale-6.example:8443",
|
|
"wss://stale-7.example:8443",
|
|
"wss://stale-8.example:8443",
|
|
"wss://stale-9.example:8443",
|
|
"wss://stale-10.example:8443",
|
|
"wss://gateway.example:8443",
|
|
]);
|
|
});
|
|
|
|
it("persists local user identity separately from gateway settings", () => {
|
|
setTestLocation({
|
|
protocol: "https:",
|
|
host: "gateway.example:8443",
|
|
pathname: "/",
|
|
});
|
|
|
|
saveLocalUserIdentity({ name: "Buns", avatar: "🦞" });
|
|
|
|
expect(loadLocalUserIdentity()).toEqual({
|
|
name: "Buns",
|
|
avatar: "🦞",
|
|
});
|
|
expect(JSON.parse(localStorage.getItem("openclaw.control.user.v1") ?? "{}")).toEqual({
|
|
name: "Buns",
|
|
avatar: "🦞",
|
|
});
|
|
});
|
|
|
|
it("normalizes invalid local user identity values on load", () => {
|
|
localStorage.setItem(
|
|
"openclaw.control.user.v1",
|
|
JSON.stringify({
|
|
name: " ",
|
|
avatar: "https://example.com/avatar.png",
|
|
}),
|
|
);
|
|
|
|
expect(loadLocalUserIdentity()).toEqual({
|
|
name: null,
|
|
avatar: null,
|
|
});
|
|
});
|
|
|
|
it("removes the persisted local user identity when cleared", () => {
|
|
saveLocalUserIdentity({ name: "Buns", avatar: "data:image/png;base64,AAA" });
|
|
saveLocalUserIdentity({ name: null, avatar: null });
|
|
|
|
expect(loadLocalUserIdentity()).toEqual({
|
|
name: null,
|
|
avatar: null,
|
|
});
|
|
expect(localStorage.getItem("openclaw.control.user.v1")).toBeNull();
|
|
});
|
|
});
|