Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(spaces-web): Machines health check waits for the store; full test suite green under load (#6062)

dduponteafd24eaae8b
diff --git a/apps/cua-spaces-web/src/__tests__/app-harness.tsx b/apps/cua-spaces-web/src/__tests__/app-harness.tsx
index 8ebdd3af4f..3175930dbd 100644
--- a/apps/cua-spaces-web/src/__tests__/app-harness.tsx
+++ b/apps/cua-spaces-web/src/__tests__/app-harness.tsx
@@ -8,7 +8,7 @@
import { createMemoryHistory, createRouter, RouterProvider } from "@tanstack/react-router";
import { render } from "@testing-library/react";
-import { afterEach, beforeEach } from "vitest";
+import { afterEach, beforeAll, beforeEach } from "vitest";
import type { DataAdapter } from "@/bridge/adapter";
import type { MachinesView } from "@/bridge/contracts/host";
import type { CreatingElsewhere, ListStatus } from "@/bridge/contracts/spaces";
@@ -61,6 +61,19 @@ export interface TestHost {
demo?: DemoOptions;
}
+/**
+ * Every page's code, once per test file, before its tests: routes are split
+ * into chunks (autoCodeSplitting), and a file's first import of one is a
+ * cold transform. With every worker starting at once on a loaded machine,
+ * those took longer than a test's waitFor (5 s), and a test that visits
+ * three pages longer than its own timeout. Loaded here, they never count
+ * against what a test waits for; a hook has its own budget for it.
+ */
+beforeAll(async () => {
+ const router = createRouter({ routeTree, history: createMemoryHistory({ initialEntries: ["/"] }) });
+ await Promise.all(Object.values(router.routesById).map((route) => router.loadRouteChunk(route as never)));
+}, 120_000);
+
/** The routers mounted by the running test: a navigation the app started (a
* create that finishes sends the person to the new Space) may still be
* loading when the test ends, and a router that settles after jsdom is gone
@@ -105,6 +118,13 @@ export async function mountApp(path: string, host: TestHost = { failsCreates: tr
};
const router = createRouter({ routeTree, history: createMemoryHistory({ initialEntries: [path] }) });
mounted.push(router);
+ // The first page's code before it renders, as the app has it from its
+ // bundle: routes are split into chunks (autoCodeSplitting), and a test
+ // file's first import of one is a cold transform that, with every worker
+ // starting at once on a loaded machine, took longer than a test's
+ // waitFor (5 s) by itself. Loading it here keeps that out of what tests
+ // wait for: they wait only for what the page does.
+ await router.load();
const hooks = {} as { spaces: SpacesHook; machines: ReturnType<typeof useMachines>; core: ReturnType<typeof useBridge>["core"] };
function Probe() {
hooks.spaces = useSpaces();
diff --git a/apps/cua-spaces-web/src/__tests__/electron-parity-lows.test.tsx b/apps/cua-spaces-web/src/__tests__/electron-parity-lows.test.tsx
index 06fe6b340e..c103e7275e 100644
--- a/apps/cua-spaces-web/src/__tests__/electron-parity-lows.test.tsx
+++ b/apps/cua-spaces-web/src/__tests__/electron-parity-lows.test.tsx
@@ -49,8 +49,9 @@ describe.skipIf(!wasmBuilt)("Electron parity, the small things", () => {
for (const host of ["electron", "demo"] as const) {
await mount("/settings/experiments", host);
await waitFor(() => expect(q("[data-settings-tab=advanced]")).not.toBeNull(), { timeout: 8000 });
+ // The tab draws before the host's experiments answer: wait for its rows.
+ await waitFor(() => expect(document.querySelectorAll("[data-setting-row^='experiment:']").length).toBeGreaterThan(0));
expect(q('[data-setting-row="experiment:classic_ui"]')).toBeNull();
- expect(document.querySelectorAll("[data-setting-row^='experiment:']").length).toBeGreaterThan(0);
cleanup();
}
});
diff --git a/apps/cua-spaces-web/src/bridge/BridgeProvider.tsx b/apps/cua-spaces-web/src/bridge/BridgeProvider.tsx
index e36ced783a..d82d30f8af 100644
--- a/apps/cua-spaces-web/src/bridge/BridgeProvider.tsx
+++ b/apps/cua-spaces-web/src/bridge/BridgeProvider.tsx
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: FSL-1.1-MIT
// Copyright (c) 2026 Cua AI, Inc.
-import { createContext, useEffect, useState, type ReactNode } from "react";
+import { createContext, useEffect, useRef, useState, type ReactNode } from "react";
import type { BridgeMode, DataAdapter } from "./adapter";
import { createAdapter } from "./adapters";
import { loadCore, unavailableCore, type CoreClient } from "./core";
@@ -43,8 +43,13 @@ function deferred<T>() {
* its children at once; hooks report `isLoading` until data arrives.
*/
export function BridgeProvider({ children, mode, adapter, core, storeOptions }: BridgeProviderProps) {
+ // The first render's `ready` is the one the first store resolves: a
+ // child's effect (it runs before this provider's) may already be waiting
+ // on it (the Machines page's first health check).
+ const firstReady = useRef<ReturnType<typeof deferred<BridgeStore>> | null>(null);
const [value, setValue] = useState<BridgeContextValue>(() => {
const d = deferred<BridgeStore>();
+ firstReady.current = d;
return {
mode: adapter?.mode ?? mode ?? detectMode(),
core: core ?? unavailableCore("loading", "loading"),
@@ -56,7 +61,8 @@ export function BridgeProvider({ children, mode, adapter, core, storeOptions }:
useEffect(() => {
let live = true;
- const d = deferred<BridgeStore>();
+ const d = firstReady.current ?? deferred<BridgeStore>();
+ firstReady.current = null;
const data = adapter ?? createAdapter(mode ?? detectMode());
let store: BridgeStore | null = null;
let uninstallParity = () => {};
diff --git a/apps/cua-spaces-web/src/bridge/hooks.ts b/apps/cua-spaces-web/src/bridge/hooks.ts
index ff57ce068f..3b778a488c 100644
--- a/apps/cua-spaces-web/src/bridge/hooks.ts
+++ b/apps/cua-spaces-web/src/bridge/hooks.ts
@@ -230,8 +230,12 @@ export function useMachines(): MachinesHook {
view: ctx.store?.machinesView ?? null,
rename: (id, name) => run((s) => s.renameMachine(id, name)),
remove: (machine, device) => run((s) => s.removeMachine(machine, device)),
+ // The page asks once on opening, which can be before the store is up
+ // (the core still loading): wait for it rather than skip the check
+ // until the next minute's.
checkHealth: async () => {
- await ctx.store?.checkMachinesHealth().catch(() => undefined);
+ const store = ctx.store ?? (await ctx.ready.catch(() => null));
+ await store?.checkMachinesHealth().catch(() => undefined);
},
};
}