fix: apply server preference deltas after read-only edits

This commit is contained in:
Shakker
2026-08-06 17:40:28 +01:00
parent 54e2ab545f
commit e118e607bc
2 changed files with 32 additions and 0 deletions
+29
View File
@@ -670,6 +670,35 @@ describe("pushServerUiPrefs", () => {
expect(request).not.toHaveBeenCalled();
});
it("applies the first server delta after a post-snapshot read-only edit", () => {
const scope = "ws://read-only";
const initial = configWithPrefs({ theme: "claw" });
applyServerUiPrefs(initial, { scope, onApplied: vi.fn() });
patchSettings({ theme: "knot" });
pushServerUiPrefs(
createClient(vi.fn(), scope, true, { ok: true }, false),
{ theme: "knot" },
{
afterCommit: ({ retainedLocal }) => {
expect(retainedLocal).toBe(true);
expect(applyServerUiPrefs(initial, { scope, onApplied: vi.fn() })).toBe(false);
},
},
);
expect(
localStorage.getItem(`openclaw.control.serverPrefs.retained-local.v1:${scope}`),
).toBeNull();
expect(
applyServerUiPrefs(configWithPrefs({ theme: "dash" }), {
scope,
onApplied: vi.fn(),
}),
).toBe(true);
expect(loadSettings().theme).toBe("dash");
});
it("keeps offline intent through read-only reconnect and replays it after authorization", async () => {
const scope = "ws://read-only";
const request = vi.fn<(method: string, params?: unknown) => Promise<unknown>>(async () => ({}));
+3
View File
@@ -504,6 +504,9 @@ export function applyServerUiPrefs(
const key = JSON.stringify(prefs);
const lastSeenRaw = readStorage(LAST_SEEN_KEY, scope);
if (key === lastSeenRaw) {
if (retainedLocalKeys.size) {
updateRetainedLocalKeys(scope, [...retainedLocalKeys], false);
}
recordReconciledObject();
return false;
}