惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
爱范儿
爱范儿
P
Proofpoint News Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
Tailwind CSS Blog
J
Java Code Geeks
宝玉的分享
宝玉的分享
Jina AI
Jina AI
B
Blog
N
Netflix TechBlog - Medium
Recent Announcements
Recent Announcements
aimingoo的专栏
aimingoo的专栏
腾讯CDC
C
Check Point Blog
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
博客园 - Franky
罗磊的独立博客
B
Blog RSS Feed
WordPress大学
WordPress大学
小众软件
小众软件
博客园 - 叶小钗
M
MIT News - Artificial intelligence
GbyAI
GbyAI

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix: reload control ui on service worker update (#96141) ...
brokemac79 · 2026-06-26 · via Recent Commits to openclaw:main

@@ -2,26 +2,116 @@

22

import fs from "node:fs";

33

import path from "node:path";

44

import { fileURLToPath } from "node:url";

5-

import { describe, expect, it } from "vitest";

5+

import vm from "node:vm";

6+

import { describe, expect, it, vi } from "vitest";

6778

const here = path.dirname(fileURLToPath(import.meta.url));

9+

const serviceWorkerPath = path.join(here, "../../public/sw.js");

810911

describe("Control UI service worker cache versioning", () => {

1012

it("registers the service worker with a build id and bounds prior build caches", () => {

1113

const mainSource = fs.readFileSync(path.join(here, "../main.ts"), "utf8");

12-

const serviceWorkerSource = fs.readFileSync(path.join(here, "../../public/sw.js"), "utf8");

14+

const serviceWorkerSource = fs.readFileSync(serviceWorkerPath, "utf8");

1315

const viteConfigSource = fs.readFileSync(path.join(here, "../../vite.config.ts"), "utf8");

14161517

expect(mainSource).toContain('swUrl.searchParams.set("v"');

1618

expect(mainSource).toContain('updateViaCache: "none"');

19+

expect(mainSource).toContain('navigator.serviceWorker.addEventListener("message"');

20+

expect(mainSource).toContain("event.data.version !== currentControlUiBuildId");

1721

expect(serviceWorkerSource).toContain(

1822

'const EMBEDDED_CACHE_VERSION = "__OPENCLAW_CONTROL_UI_BUILD_ID__"',

1923

);

2024

expect(serviceWorkerSource).toContain("URL_CACHE_VERSION");

2125

expect(serviceWorkerSource).toContain("CONTROL_CACHE_LIMIT = 3");

2226

expect(serviceWorkerSource).toContain("slice(-priorCacheLimit)");

2327

expect(serviceWorkerSource).toContain("caches.delete");

28+

expect(serviceWorkerSource).toContain("includeUncontrolled: true");

29+

expect(serviceWorkerSource).not.toContain(

30+

'postMessage({ type: "sw-updated", version: CACHE_VERSION },',

31+

);

2432

expect(viteConfigSource).toContain("source.replace(placeholder, JSON.stringify(buildId))");

2533

expect(serviceWorkerSource).not.toContain('const CACHE_NAME = "openclaw-control-v1"');

2634

});

35+36+

it("broadcasts updated versions to uncontrolled window clients during activation", async () => {

37+

const serviceWorkerSource = fs.readFileSync(serviceWorkerPath, "utf8");

38+

const windowClient = { postMessage: vi.fn() };

39+

const matchedClients = createDeferred<Array<typeof windowClient>>();

40+

const listeners = new Map<string, Array<(event: ActivateEventStub) => void>>();

41+

const cacheDelete = vi.fn(async () => true);

42+

const clients = {

43+

claim: vi.fn(async () => undefined),

44+

matchAll: vi.fn(() => matchedClients.promise),

45+

};

46+

const caches = {

47+

delete: cacheDelete,

48+

keys: vi.fn(async () => [

49+

"openclaw-control-oldest",

50+

"openclaw-control-older",

51+

"openclaw-control-previous",

52+

"openclaw-control-new-build",

53+

"other-cache",

54+

]),

55+

open: vi.fn(),

56+

};

57+

const serviceWorkerGlobal = {

58+

addEventListener(type: string, listener: (event: ActivateEventStub) => void) {

59+

listeners.set(type, [...(listeners.get(type) ?? []), listener]);

60+

},

61+

clients,

62+

location: { href: "https://control.example/sw.js?v=new-build" },

63+

registration: { showNotification: vi.fn() },

64+

skipWaiting: vi.fn(),

65+

};

66+

const context = vm.createContext({

67+

URL,

68+

caches,

69+

fetch: vi.fn(),

70+

self: serviceWorkerGlobal,

71+

});

72+73+

new vm.Script(serviceWorkerSource, { filename: "ui/public/sw.js" }).runInContext(context);

74+75+

const activateHandler = listeners.get("activate")?.[0];

76+

expect(activateHandler).toBeDefined();

77+

let activationPromise: Promise<unknown> | undefined;

78+

activateHandler?.({

79+

waitUntil(promise: Promise<unknown>) {

80+

activationPromise = promise;

81+

},

82+

});

83+84+

let activationSettled = false;

85+

void activationPromise?.then(() => {

86+

activationSettled = true;

87+

});

88+

await Promise.resolve();

89+90+

expect(activationSettled).toBe(false);

91+

expect(windowClient.postMessage).not.toHaveBeenCalled();

92+93+

matchedClients.resolve([windowClient]);

94+

await activationPromise;

95+96+

expect(clients.matchAll).toHaveBeenCalledWith({ type: "window", includeUncontrolled: true });

97+

expect(clients.claim).toHaveBeenCalled();

98+

expect(cacheDelete).toHaveBeenCalledWith("openclaw-control-oldest");

99+

expect(windowClient.postMessage).toHaveBeenCalledWith({

100+

type: "sw-updated",

101+

version: "new-build",

102+

});

103+

expect(windowClient.postMessage.mock.calls[0]).toHaveLength(1);

104+

});

27105

});

106+107+

type ActivateEventStub = {

108+

waitUntil(promise: Promise<unknown>): void;

109+

};

110+111+

function createDeferred<T>() {

112+

let resolve!: (value: T) => void;

113+

const promise = new Promise<T>((resolvePromise) => {

114+

resolve = resolvePromise;

115+

});

116+

return { promise, resolve };

117+

}