From a3ece09d19b9c7ae2a0bbeafce46f859d8d4f070 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 13 Mar 2026 17:54:52 +0000 Subject: [PATCH] refactor: share control ui hardlink asset setup --- src/gateway/control-ui.http.test.ts | 228 +++++++++++++--------------- 1 file changed, 104 insertions(+), 124 deletions(-) diff --git a/src/gateway/control-ui.http.test.ts b/src/gateway/control-ui.http.test.ts index 54cf972e7..e6b74c3d1 100644 --- a/src/gateway/control-ui.http.test.ts +++ b/src/gateway/control-ui.http.test.ts @@ -40,25 +40,6 @@ describe("handleControlUiHttpRequest", () => { expect(params.end).toHaveBeenCalledWith("Not Found"); } - function expectUnhandledRoutes(params: { - urls: string[]; - method: "GET" | "POST"; - rootPath: string; - basePath?: string; - expectationLabel: string; - }) { - for (const url of params.urls) { - const { handled, end } = runControlUiRequest({ - url, - method: params.method, - rootPath: params.rootPath, - ...(params.basePath ? { basePath: params.basePath } : {}), - }); - expect(handled, `${params.expectationLabel}: ${url}`).toBe(false); - expect(end, `${params.expectationLabel}: ${url}`).not.toHaveBeenCalled(); - } - } - function runControlUiRequest(params: { url: string; method: "GET" | "HEAD" | "POST"; @@ -104,6 +85,13 @@ describe("handleControlUiHttpRequest", () => { return { assetsDir, filePath }; } + async function createHardlinkedAssetFile(rootPath: string) { + const { filePath } = await writeAssetFile(rootPath, "app.js", "console.log('hi');"); + const hardlinkPath = path.join(path.dirname(filePath), "app.hl.js"); + await fs.link(filePath, hardlinkPath); + return hardlinkPath; + } + async function withBasePathRootFixture(params: { siblingDir: string; fn: (paths: { root: string; sibling: string }) => Promise; @@ -166,80 +154,53 @@ describe("handleControlUiHttpRequest", () => { }); }); - it.each([ - { - name: "at root", - url: CONTROL_UI_BOOTSTRAP_CONFIG_PATH, - expectedBasePath: "", - assistantName: ".png", - expectedAvatarUrl: "/avatar/main", - }, - { - name: "under basePath", - url: `/openclaw${CONTROL_UI_BOOTSTRAP_CONFIG_PATH}`, - basePath: "/openclaw", - expectedBasePath: "/openclaw", - assistantName: "Ops", - assistantAvatar: "ops.png", - expectedAvatarUrl: "/openclaw/avatar/main", - }, - ])("serves bootstrap config JSON $name", async (testCase) => { + it("serves bootstrap config JSON", async () => { await withControlUiRoot({ fn: async (tmp) => { const { res, end } = makeMockHttpResponse(); const handled = handleControlUiHttpRequest( - { url: testCase.url, method: "GET" } as IncomingMessage, + { url: CONTROL_UI_BOOTSTRAP_CONFIG_PATH, method: "GET" } as IncomingMessage, res, { - ...(testCase.basePath ? { basePath: testCase.basePath } : {}), root: { kind: "resolved", path: tmp }, config: { agents: { defaults: { workspace: tmp } }, - ui: { - assistant: { - name: testCase.assistantName, - avatar: testCase.assistantAvatar, - }, - }, + ui: { assistant: { name: ".png" } }, }, }, ); expect(handled).toBe(true); const parsed = parseBootstrapPayload(end); - expect(parsed.basePath).toBe(testCase.expectedBasePath); - expect(parsed.assistantName).toBe(testCase.assistantName); - expect(parsed.assistantAvatar).toBe(testCase.expectedAvatarUrl); + expect(parsed.basePath).toBe(""); + expect(parsed.assistantName).toBe("