Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
test(browser): the S4 tab tests and the v1 live view wait for Chrome, not a fixed sleep (#3823)
Milind Soni58c892684beb
diff --git a/scripts/testing/ci-retry-list.json b/scripts/testing/ci-retry-list.jsonindex 60e762da81..04661f68f6 100644--- a/scripts/testing/ci-retry-list.json+++ b/scripts/testing/ci-retry-list.json@@ -56,6 +56,13 @@"owner": "milind-soni","reason": "Failed 8 runs (7 branches, 2 main runs) since Sep 24, Windows; same commit later green.","since": "2026-10-08"+ },+ {+ "file": "server/browser/viewers/viewers.e2e.test.ts",+ "test": "a phone's v1 live view on real Chrome > sends the events and fields the agent-browser engine sent, step for step",+ "owner": "milind-soni",+ "reason": "Failed 11 times since Oct 26 in browser driver S4 (ubuntu-latest), on the host and in the container; five of the six logged failures are one stall of about 50 s in which navigate through tab-new get no picture. Not reproduced in 72 runs on ubuntu-latest on Oct 29. Each attempt starts its own Chrome.",+ "since": "2026-10-29"}]}diff --git a/server/browser/cdp/s4-pages.e2e.test.ts b/server/browser/cdp/s4-pages.e2e.test.tsindex aa19317124..af4e520f43 100644--- a/server/browser/cdp/s4-pages.e2e.test.ts+++ b/server/browser/cdp/s4-pages.e2e.test.ts@@ -160,7 +160,8 @@ suite("S4 pages, tabs and page state on real Chrome", () => {await page.click({ selector: "#o" });expect(run.browser.activePage).toBe(page);await popup.close();- await page.waitFor({ ms: 200 });+ // Chrome reports the closed tab with an event after Target.closeTarget has answered.+ for (const until = Date.now() + hostTimeout(5_000); run.browser.pages().includes(popup) && Date.now() < until;) await page.waitFor({ ms: 25 });expect(run.browser.pages()).not.toContain(popup);});@@ -194,7 +195,7 @@ suite("S4 pages, tabs and page state on real Chrome", () => {await second.click({ selector: "#b" });expect(await read(`document.getElementById("b").textContent`, second)).toBe("two");await second.close();- await page.waitFor({ ms: 200 });+ for (const until = Date.now() + hostTimeout(5_000); run.browser.pages().includes(second) && Date.now() < until;) await page.waitFor({ ms: 25 });expect(run.browser.pages()).toEqual([page]);await expect(second.click({ selector: "#b" })).rejects.toMatchObject({ code: "closed" });});diff --git a/server/browser/viewers/testing/v1-compare.ts b/server/browser/viewers/testing/v1-compare.tsindex ad2eab5a41..b48467a5fb 100644--- a/server/browser/viewers/testing/v1-compare.ts+++ b/server/browser/viewers/testing/v1-compare.ts@@ -42,17 +42,35 @@ export function v1Differences(actual: Array<Record<string, unknown>>): string[]for (const expected of V1_GOLDEN) {const got = (actual as unknown as Step[]).find((step) => step.step === expected.step);if (!got) { problems.push(`no step ${expected.step}`); continue; }+ if (failedInGolden(expected)) continue;const answer = expected.answer as Record<string, unknown> | string;- if (typeof answer === "object" && "error" in answer) continue;if (JSON.stringify(answer) !== JSON.stringify(got.answer)) problems.push(`${expected.step}: answered ${JSON.stringify(got.answer)}, the contract ${JSON.stringify(answer)}`);- if (expected.control && JSON.stringify(expected.control) !== JSON.stringify(got.control)) problems.push(`${expected.step}: control ${JSON.stringify(got.control)}, expected ${JSON.stringify(expected.control)}`);- if (expected.tabs) {- const want = expected.tabs.map((tab) => `${tab.url}${tab.active ? "*" : ""}`).join(" ");- const have = (got.tabs ?? []).map((tab) => `${tab.url}${tab.active ? "*" : ""}`).join(" ");- if (want !== have) problems.push(`${expected.step}: tabs ${have}, expected ${want}`);- }- if (expected.url && expected.url !== got.url) problems.push(`${expected.step}: address ${String(got.url)}, expected ${expected.url}`);- if (expected.frameFormat && got.frameFormat !== expected.frameFormat) problems.push(`${expected.step}: no ${expected.frameFormat} picture came`);+ problems.push(...shownDifferences(expected, got));+ }+ return problems;+}++/** A step the old engine failed when the golden was recorded holds nothing to the contract. */+function failedInGolden(step: Step): boolean {+ return typeof step.answer === "object" && step.answer !== null && "error" in step.answer;+}++/** What a phone acts on after one step: who controls, the tabs, the address, and that a picture came. */+function shownDifferences(expected: Step, got: Step): string[] {+ const problems: string[] = [];+ if (expected.control && JSON.stringify(expected.control) !== JSON.stringify(got.control)) problems.push(`${expected.step}: control ${JSON.stringify(got.control)}, expected ${JSON.stringify(expected.control)}`);+ if (expected.tabs) {+ const want = expected.tabs.map((tab) => `${tab.url}${tab.active ? "*" : ""}`).join(" ");+ const have = (got.tabs ?? []).map((tab) => `${tab.url}${tab.active ? "*" : ""}`).join(" ");+ if (want !== have) problems.push(`${expected.step}: tabs ${have}, expected ${want}`);}+ if (expected.url && expected.url !== got.url) problems.push(`${expected.step}: address ${String(got.url)}, expected ${expected.url}`);+ if (expected.frameFormat && got.frameFormat !== expected.frameFormat) problems.push(`${expected.step}: no ${expected.frameFormat} picture came`);return problems;}++/** True once a normalized step shows a phone everything the golden's same step showed it. */+export function v1StepShown(step: Record<string, unknown>): boolean {+ const expected = V1_GOLDEN.find((candidate) => candidate.step === step.step);+ return !expected || failedInGolden(expected) || shownDifferences(expected, step as unknown as Step).length === 0;+}diff --git a/server/browser/viewers/testing/v1-session.ts b/server/browser/viewers/testing/v1-session.tsindex 97309bd325..91cfc89cbe 100644--- a/server/browser/viewers/testing/v1-session.ts+++ b/server/browser/viewers/testing/v1-session.ts@@ -56,8 +56,11 @@ export interface StepRecord {const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));-/** Runs every step, acking each frame as a phone does, and returns the events each step brought. */-export async function runV1Session(driver: LiveDriver, origin: string, { settleMs = 1_200 } = {}): Promise<StepRecord[]> {+/** Runs every step, acking each frame as a phone does, and returns the events each step brought. Each step waits+ * `settleMs`, then while `shown` says its events are still incomplete, at most `maxSettleMs` more. */+export async function runV1Session(driver: LiveDriver, origin: string, { settleMs = 1_200, shown, maxSettleMs = 10_000 }: {+ settleMs?: number; shown?: (record: StepRecord) => boolean; maxSettleMs?: number;+} = {}): Promise<StepRecord[]> {const sse = new SseRecorder();let viewerId = "";sse.on("event", (event: { type: string; data: Record<string, unknown> }) => {@@ -68,8 +71,10 @@ export async function runV1Session(driver: LiveDriver, origin: string, { settleMlet mark = 0;const step = async (name: string, run: () => Promise<unknown>) => {const answer = await run().catch((error: unknown) => ({ error: error instanceof Error ? error.message : String(error) }));+ const record = (): StepRecord => ({ step: name, answer, events: sse.events.slice(mark) });await sleep(settleMs);- records.push({ step: name, answer, events: sse.events.slice(mark) });+ for (const until = Date.now() + maxSettleMs; shown && !shown(record()) && Date.now() < until;) await sleep(50);+ records.push(record());mark = sse.events.length;};const act = (body: Record<string, unknown>) => driver.action(viewerId, body);diff --git a/server/browser/viewers/viewers.e2e.test.ts b/server/browser/viewers/viewers.e2e.test.tsindex 8ccc1bbf12..d4c2bc1ba0 100644--- a/server/browser/viewers/viewers.e2e.test.ts+++ b/server/browser/viewers/viewers.e2e.test.ts@@ -11,7 +11,7 @@ import type { BrowserTarget } from "../service.ts";import { jpegSize, startService, until, type RealService } from "../testing/real-service.ts";import type { Viewer, ViewerOptions, ViewerOutput } from "./core.ts";import { LiveV1 } from "./live-v1.ts";-import { v1Differences } from "./testing/v1-compare.ts";+import { v1Differences, v1StepShown } from "./testing/v1-compare.ts";import { normalizeV1, runV1Session, startV1Pages } from "./testing/v1-session.ts";const suite = CHROME ? describe : describe.skip;@@ -280,10 +280,11 @@ suite("a phone's v1 live view on real Chrome", () => {const target = { session: "bot-golden", key: "bot:golden" };const live = new LiveV1({ service: real.service, target: () => target });try {+ // A loaded runner's Chrome can paint a step's picture after the usual settle; the step waits for it.const records = await runV1Session({open: (res) => live.open({ botId: "bot", session: target.session, owner: "local-owner", isCurrent: () => true, res }),action: (viewerId, body) => live.action({ viewerId, botId: "bot", owner: "local-owner", body }),- }, pages.origin);+ }, pages.origin, { shown: (record) => v1StepShown(normalizeV1([record], pages.origin)[0]!) });expect(v1Differences(normalizeV1(records, pages.origin))).toEqual([]);} finally {live.closeAll();