From c10d759c444fc10aeca462faf4a74912d231c44d Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Mon, 26 Jan 2026 22:20:39 -0800 Subject: [PATCH] fix(test): reset A2UI cache between tests to prevent CI flakiness --- src/canvas-host/a2ui.ts | 6 ++++++ src/canvas-host/server.test.ts | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/canvas-host/a2ui.ts b/src/canvas-host/a2ui.ts index 876436c57..bc33144f9 100644 --- a/src/canvas-host/a2ui.ts +++ b/src/canvas-host/a2ui.ts @@ -12,6 +12,12 @@ export const CANVAS_WS_PATH = "/__clawdbot/ws"; let cachedA2uiRootReal: string | null | undefined; let resolvingA2uiRoot: Promise | null = null; +/** Reset the A2UI root cache (for testing). */ +export function resetA2uiCache(): void { + cachedA2uiRootReal = undefined; + resolvingA2uiRoot = null; +} + async function resolveA2uiRoot(): Promise { const here = path.dirname(fileURLToPath(import.meta.url)); const candidates = [ diff --git a/src/canvas-host/server.test.ts b/src/canvas-host/server.test.ts index f51e2f5e0..0bd6bbffc 100644 --- a/src/canvas-host/server.test.ts +++ b/src/canvas-host/server.test.ts @@ -3,14 +3,22 @@ import { createServer } from "node:http"; import type { AddressInfo } from "node:net"; import os from "node:os"; import path from "node:path"; -import { describe, expect, it, vi } from "vitest"; +import { beforeEach, describe, expect, it, vi } from "vitest"; import { WebSocket } from "ws"; import { rawDataToString } from "../infra/ws.js"; import { defaultRuntime } from "../runtime.js"; -import { CANVAS_HOST_PATH, CANVAS_WS_PATH, injectCanvasLiveReload } from "./a2ui.js"; +import { + CANVAS_HOST_PATH, + CANVAS_WS_PATH, + injectCanvasLiveReload, + resetA2uiCache, +} from "./a2ui.js"; import { createCanvasHostHandler, startCanvasHost } from "./server.js"; describe("canvas host", () => { + beforeEach(() => { + resetA2uiCache(); + }); it("injects live reload script", () => { const out = injectCanvasLiveReload("Hello"); expect(out).toContain(CANVAS_WS_PATH);