Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
test: 等待 Cloud 工作区和浏览器切换完成
Zhehui Bi2dbb68802fa1
diff --git a/scripts/testing/one-workspace-fixture.ts b/scripts/testing/one-workspace-fixture.tsindex f0b17ec411..2698768cab 100644--- a/scripts/testing/one-workspace-fixture.ts+++ b/scripts/testing/one-workspace-fixture.ts@@ -37,6 +37,7 @@ import { createHomeWindow, installHomeWindowIpc, HOME_SCREEN_PATH } from "../../import { createStartupScreen } from "../../electron/startup-screen.mjs";import { packageUrlFromDeepLink } from "../../electron/package-link.mjs";import { WELCOME_VERSION } from "../../electron/onboarding-record.mjs";+import { freePortBlock } from "../../server/testing/ports.ts";import { SPOTLIGHTS } from "../../src/lib/first-conversation.ts";import { TOUR_STEPS } from "../../src/lib/guided-tour.ts";import { NOTICES } from "../../src/lib/notices.ts";@@ -303,11 +304,15 @@ async function vite(port: number, host: string, plugin: (server: ViteDevServer)return server;}-/** `chrome`: the pinned Chrome for Testing; `ports`: two free pairs (each Vite server takes its port and the next). */-export async function launchHomeWorld(fx: CloudSendFixture, { chrome, ports, versionEveryMs = 1_000, quietMs = 1_500, profiles = false }: {- chrome: string; ports: [number, number, number, number]; versionEveryMs?: number; quietMs?: number; profiles?: boolean;+export async function launchHomeWorld(fx: CloudSendFixture, { chrome, versionEveryMs = 1_000, quietMs = 1_500, profiles = false }: {+ chrome: string; versionEveryMs?: number; quietMs?: number; profiles?: boolean;}): Promise<HomeWorld> {- const [cloudPort, localPort, ipcPort, teamPort] = ports;+ const [cloudPort, localPort, ipcPort, teamPort] = await Promise.all([+ freePortBlock([0, 1], 19_616, 768),+ freePortBlock([0, 1], 20_384, 768),+ freePortBlock([0], 21_152, 768),+ freePortBlock([0, 1], 21_920, 768),+ ]);const cloudOrigin = `http://localhost:${cloudPort}`;const localOrigin = `http://127.0.0.1:${localPort}`;const ipcBase = `http://127.0.0.1:${ipcPort}`;diff --git a/scripts/testing/one-workspace-ui.e2e.test.ts b/scripts/testing/one-workspace-ui.e2e.test.tsindex 1883bf6d87..d29d8f11d1 100644--- a/scripts/testing/one-workspace-ui.e2e.test.ts+++ b/scripts/testing/one-workspace-ui.e2e.test.ts@@ -6,7 +6,6 @@ import { join } from "node:path";import { afterAll, beforeAll, describe, expect, it } from "vitest";import { resolveAgentBrowserBinary } from "../../server/browser-engine.ts";import { hostTimeout } from "../../server/testing/host-timeout.ts";-import { freePortBlock } from "../../server/testing/ports.ts";import { launchCloudSendFixture, type CloudSendFixture } from "./cloud-send-fixture.ts";import { ensureUiBrowser, UI_TOOLS_DIR } from "./control-omb-ui.ts";import { launchHomeWorld, shotsDir, welcomed, type HomeWorld } from "./one-workspace-fixture.ts";@@ -37,7 +36,10 @@ const PAIR_FORM = "Boolean(document.querySelector('form input') && /pairing codeconst onCloudPage = () => until(() => page<boolean>("Boolean(document.querySelector('textarea[aria-label^=\"Message\"]'))"), Boolean, 60_000, "My Cloud's page").then(() => expect(new URL(world.window.url).origin).toBe(world.cloudOrigin));const screen = () => page<string | null>("document.querySelector('[data-home-screen]')?.dataset.homeScreen ?? null");- const blank = async () => { await world.window.loadURL("about:blank"); await new Promise((resolve) => setTimeout(resolve, 200)); };+ const blank = async () => {+ await world.window.loadURL("about:blank");+ await until(async () => world.window.url === "about:blank" && await page("location.href") === "about:blank", Boolean, 10_000, "the blank page");+ };beforeAll(async () => {fx = await launchCloudSendFixture({ onePasswordToken: `ops_fake-window-${randomBytes(12).toString("hex")}` });@@ -45,8 +47,7 @@ const PAIR_FORM = "Boolean(document.querySelector('form input') && /pairing codenova = (await fx.onCloud("POST", "/api/bots", { name: "Nova", modelSelection: { instanceId: "claude", model: "claude-sonnet-5" } })).body.bot.id;const tools = await ensureUiBrowser(process.env);if (!tools.chrome) throw new Error("This harness needs the pinned Chrome for Testing");- const ports = await Promise.all([freePortBlock([0, 1]), freePortBlock([0, 1]), freePortBlock([0]), freePortBlock([0, 1])]) as [number, number, number, number];- world = await launchHomeWorld(fx, { chrome: tools.chrome, ports });+ world = await launchHomeWorld(fx, { chrome: tools.chrome });shots = shotsDir(fx.root);// Each page's dev server bundles what it imports on the first visit, then reloads it once: done before anything counts.for (const url of [`${world.localOrigin}/`, `${world.cloudOrigin}/`, `${world.teamOrigin}/`]) {diff --git a/scripts/testing/rail-profile-ui.e2e.test.ts b/scripts/testing/rail-profile-ui.e2e.test.tsindex 6eed74838a..d51fdca4b9 100644--- a/scripts/testing/rail-profile-ui.e2e.test.ts+++ b/scripts/testing/rail-profile-ui.e2e.test.ts@@ -15,7 +15,6 @@ import { cleanWorkspaceConfig, profileDir, profilesDir } from "../../electron/climport { parseCloudList } from "../../electron/cloud-list.mjs";import { resolveAgentBrowserBinary } from "../../server/browser-engine.ts";import { hostTimeout } from "../../server/testing/host-timeout.ts";-import { freePortBlock } from "../../server/testing/ports.ts";import { launchCloudSendFixture, type CloudSendFixture } from "./cloud-send-fixture.ts";import { ensureUiBrowser, UI_TOOLS_DIR } from "./control-omb-ui.ts";import { launchHomeWorld, shotsDir, welcomed, type HomeWorld } from "./one-workspace-fixture.ts";@@ -98,8 +97,11 @@ function harness(get: () => { world: HomeWorld; shots: string }) {const onCloud = () => until(() => page<string>("document.body.innerText"), (text) => new URL(world.window.url).origin === world.cloudOrigin && text.includes("Atlas"), 60_000, "My Cloud's page with its bots");const lentCount = async () => ((await fx.onCloud("GET", "/api/shared-computers")).body?.computers ?? []).filter((computer: { online?: boolean }) => computer.online !== false).length;const current = async () => (await tiles()).find((tile) => tile.current)?.id ?? null;- const shown = (id: string, text?: string) => until(async () => ({ current: await current(), local: onLocal(), body: await page<string>("document.body.innerText") }),- (seen) => seen.current === id && (id === cloudEntry ? !seen.local : seen.local) && (!text || seen.body.includes(text)), 90_000, `${id} on screen${text ? ` with ${text}` : ""}`);+ const shown = (id: string, text?: string) => until(async () => ({+ current: await current(), local: onLocal(), running: world.running(), body: await page<string>("document.body.innerText"),+ }), (seen) => seen.current === id+ && (id === cloudEntry ? !seen.local : seen.local && seen.running === profileDir(fx.desktopDataDir, id.slice("profile:".length)))+ && (!text || seen.body.includes(text)), 90_000, `${id} on screen${text ? ` with ${text}` : ""}`);const lineOf = () => page<string | null>("document.querySelector('[data-home-line]')?.textContent ?? null");const workId = () => world.registry!.list().find((entry) => entry.name === "Work")?.id ?? "work";@@ -114,8 +116,7 @@ function harness(get: () => { world: HomeWorld; shots: string }) {}const tools = await ensureUiBrowser(process.env);if (!tools.chrome) throw new Error("This harness needs the pinned Chrome for Testing");- const ports = await Promise.all([freePortBlock([0, 1]), freePortBlock([0, 1]), freePortBlock([0]), freePortBlock([0, 1])]) as [number, number, number, number];- world = await launchHomeWorld(fx, { chrome: tools.chrome, ports, profiles: true });+ world = await launchHomeWorld(fx, { chrome: tools.chrome, profiles: true });shots = shotsDir(fx.root);await world.setSize(WIDTH, HEIGHT);// The session lists My Cloud as the person's own, as the Admin does: so its circle is a rail even alone, for +.@@ -427,8 +428,7 @@ function harness(get: () => { world: HomeWorld; shots: string }) {await fx.local("POST", "/api/bots", { name: "Atlas", modelSelection: { instanceId: "claude", model: "claude-sonnet-5" } });const tools = await ensureUiBrowser(process.env);if (!tools.chrome) throw new Error("This harness needs the pinned Chrome for Testing");- const ports = await Promise.all([freePortBlock([0, 1]), freePortBlock([0, 1]), freePortBlock([0]), freePortBlock([0, 1])]) as [number, number, number, number];- world = await launchHomeWorld(fx, { chrome: tools.chrome, ports, profiles: true });+ world = await launchHomeWorld(fx, { chrome: tools.chrome, profiles: true });shots = shotsDir(fx.root);await world.setSize(WIDTH, HEIGHT);world.moved = false;