Skip to content

Commit fd2e4da

Browse files
committed
fix(e2e): avoid browser cdp doctor race
1 parent 931f13c commit fd2e4da

4 files changed

Lines changed: 54 additions & 15 deletions

File tree

scripts/e2e/browser-cdp-snapshot-docker.sh

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ else
4141
cat >"$build_dir/Dockerfile" <<EOF
4242
FROM $BASE_IMAGE
4343
USER root
44-
RUN apt-get update \\
45-
&& apt-get install -y --no-install-recommends chromium fonts-liberation procps \\
46-
&& rm -rf /var/lib/apt/lists/*
44+
ENV PLAYWRIGHT_BROWSERS_PATH=/home/appuser/.cache/ms-playwright
45+
RUN mkdir -p "\$PLAYWRIGHT_BROWSERS_PATH" \\
46+
&& DEBIAN_FRONTEND=noninteractive node /app/node_modules/playwright-core/cli.js install --with-deps chromium \\
47+
&& chown -R appuser:appuser "\$PLAYWRIGHT_BROWSERS_PATH"
4748
USER appuser
4849
EOF
4950
echo "Building Docker image: $IMAGE_NAME"
@@ -72,25 +73,24 @@ source scripts/lib/openclaw-e2e-instance.sh
7273
openclaw_e2e_eval_test_state_from_b64 \"\${OPENCLAW_TEST_STATE_SCRIPT_B64:?missing OPENCLAW_TEST_STATE_SCRIPT_B64}\"
7374
openclaw_e2e_write_state_env
7475
entry=\"\$(openclaw_e2e_resolve_entrypoint)\"
75-
mkdir -p /tmp/openclaw-browser-cdp/chrome
76+
mkdir -p /tmp/openclaw-browser-cdp
7677
find dist -maxdepth 1 -type f -name 'pw-ai-*.js' ! -name 'pw-ai-state-*' -exec mv {} /tmp/openclaw-browser-cdp/ \;
78+
if find dist -maxdepth 1 -type f -name 'pw-ai-*.js' ! -name 'pw-ai-state-*' | grep -q .; then
79+
echo 'failed to disable Playwright AI snapshot chunk for raw CDP smoke' >&2
80+
exit 1
81+
fi
7782
PORT=$PORT CDP_PORT=$CDP_PORT node scripts/e2e/lib/fixture.mjs browser-cdp
78-
chromium --headless=new --no-sandbox --disable-gpu --disable-dev-shm-usage \\
79-
--remote-debugging-address=127.0.0.1 \\
80-
--remote-debugging-port=$CDP_PORT \\
81-
--user-data-dir=/tmp/openclaw-browser-cdp/chrome \\
82-
about:blank >/tmp/browser-cdp-chromium.log 2>&1 &
8383
FIXTURE_PORT=$FIXTURE_PORT node scripts/e2e/lib/browser-cdp-snapshot/fixture-server.mjs >/tmp/browser-cdp-fixture.log 2>&1 &
8484
openclaw_e2e_exec_gateway \"\$entry\" $PORT loopback /tmp/browser-cdp-gateway.log" >/dev/null
8585

86-
echo "Waiting for Chromium and Gateway..."
86+
echo "Waiting for Gateway and fixture server..."
8787
if ! docker_e2e_wait_container_bash "$CONTAINER_NAME" 180 0.5 "
8888
source scripts/lib/openclaw-e2e-instance.sh
89-
openclaw_e2e_probe_http_status http://127.0.0.1:$CDP_PORT/json/version
89+
openclaw_e2e_probe_http_status http://127.0.0.1:$FIXTURE_PORT/
9090
openclaw_e2e_probe_tcp 127.0.0.1 $PORT
9191
"; then
9292
echo "Browser CDP snapshot container failed to become ready"
93-
docker_e2e_tail_container_file_if_running "$CONTAINER_NAME" "/tmp/browser-cdp-chromium.log /tmp/browser-cdp-gateway.log /tmp/browser-cdp-fixture.log" 120
93+
docker_e2e_tail_container_file_if_running "$CONTAINER_NAME" "/tmp/browser-cdp-gateway.log /tmp/browser-cdp-fixture.log" 120
9494
exit 1
9595
fi
9696

@@ -101,14 +101,13 @@ source /tmp/openclaw-test-state-env
101101
source scripts/lib/openclaw-e2e-instance.sh
102102
entry=\"\$(openclaw_e2e_resolve_entrypoint)\"
103103
base_args=(--url ws://127.0.0.1:$PORT --token '$TOKEN')
104-
node \"\$entry\" browser \"\${base_args[@]}\" --browser-profile docker-cdp doctor --deep >/tmp/browser-cdp-doctor.txt
105-
grep -q 'OK live-snapshot' /tmp/browser-cdp-doctor.txt
106104
node \"\$entry\" browser \"\${base_args[@]}\" --browser-profile docker-cdp open http://127.0.0.1:$FIXTURE_PORT/ >/tmp/browser-cdp-open.txt
105+
node \"\$entry\" browser \"\${base_args[@]}\" --browser-profile docker-cdp doctor --deep >/tmp/browser-cdp-doctor.txt 2>&1 || true
107106
node \"\$entry\" browser \"\${base_args[@]}\" --browser-profile docker-cdp snapshot --interactive --urls --out /tmp/browser-cdp-snapshot.txt >/tmp/browser-cdp-snapshot.out
108107
node scripts/e2e/lib/browser-cdp-snapshot/assert-snapshot.mjs /tmp/browser-cdp-snapshot.txt
109108
"; then
110109
echo "Browser CDP snapshot smoke failed"
111-
docker_e2e_tail_container_file_if_running "$CONTAINER_NAME" "/tmp/browser-cdp-doctor.txt /tmp/browser-cdp-open.txt /tmp/browser-cdp-snapshot.out /tmp/browser-cdp-snapshot.txt /tmp/browser-cdp-chromium.log /tmp/browser-cdp-gateway.log /tmp/browser-cdp-fixture.log" 200
110+
docker_e2e_tail_container_file_if_running "$CONTAINER_NAME" "/tmp/browser-cdp-doctor.txt /tmp/browser-cdp-open.txt /tmp/browser-cdp-snapshot.out /tmp/browser-cdp-snapshot.txt /tmp/browser-cdp-gateway.log /tmp/browser-cdp-fixture.log" 200
112111
exit 1
113112
fi
114113

scripts/e2e/lib/fixtures/config.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ function writeConfig(kind) {
3232
},
3333
browser: {
3434
enabled: true,
35+
noSandbox: true,
36+
extraArgs: ["--remote-debugging-address=127.0.0.1", "about:blank"],
3537
defaultProfile: "docker-cdp",
3638
ssrfPolicy: { allowedHostnames: ["127.0.0.1"] },
3739
profiles: {

test/scripts/docker-build-helper.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,39 @@ fi
11331133
expect(runner).toContain('-e "OPENCLAW_BROWSER_CDP_SNAPSHOT_MAX_BYTES=$SNAPSHOT_MAX_BYTES"');
11341134
});
11351135

1136+
it("uses Playwright Chromium for the browser CDP snapshot image", () => {
1137+
const runner = readFileSync(BROWSER_CDP_SNAPSHOT_DOCKER_E2E_PATH, "utf8");
1138+
1139+
expect(runner).toContain("ENV PLAYWRIGHT_BROWSERS_PATH=/home/appuser/.cache/ms-playwright");
1140+
expect(runner).toContain("playwright-core/cli.js install --with-deps chromium");
1141+
expect(runner).not.toContain("apt-get install -y --no-install-recommends chromium");
1142+
});
1143+
1144+
it("opens the browser CDP fixture before snapshotting", () => {
1145+
const runner = readFileSync(BROWSER_CDP_SNAPSHOT_DOCKER_E2E_PATH, "utf8");
1146+
const quarantineIndex = runner.indexOf("mkdir -p /tmp/openclaw-browser-cdp");
1147+
const configIndex = runner.indexOf("node scripts/e2e/lib/fixture.mjs browser-cdp");
1148+
const openIndex = runner.indexOf(
1149+
'browser \\"\\${base_args[@]}\\" --browser-profile docker-cdp open',
1150+
);
1151+
const doctorIndex = runner.indexOf(
1152+
'browser \\"\\${base_args[@]}\\" --browser-profile docker-cdp doctor --deep',
1153+
);
1154+
const snapshotIndex = runner.indexOf(
1155+
'browser \\"\\${base_args[@]}\\" --browser-profile docker-cdp snapshot --interactive',
1156+
);
1157+
1158+
expect(quarantineIndex).toBeGreaterThan(-1);
1159+
expect(configIndex).toBeGreaterThan(-1);
1160+
expect(configIndex).toBeGreaterThan(quarantineIndex);
1161+
expect(openIndex).toBeGreaterThan(-1);
1162+
expect(openIndex).toBeGreaterThan(configIndex);
1163+
expect(doctorIndex).toBeGreaterThan(openIndex);
1164+
expect(snapshotIndex).toBeGreaterThan(doctorIndex);
1165+
expect(runner).toContain(">/tmp/browser-cdp-doctor.txt 2>&1 || true");
1166+
expect(runner).toContain("failed to disable Playwright AI snapshot chunk");
1167+
});
1168+
11361169
it("fails Docker commands fast when timeout is unavailable", () => {
11371170
const workDir = mkdtempSync(join(tmpdir(), "openclaw-docker-timeout-required-"));
11381171

test/scripts/fixture-config.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ describe("scripts/e2e/lib/fixture.mjs config commands", () => {
6464
expect(result.status).toBe(0);
6565
const config = JSON.parse(readFileSync(path.join(root, "openclaw.json"), "utf8"));
6666
expect(config.gateway.port).toBe(19000);
67+
expect(config.browser.noSandbox).toBe(true);
68+
expect(config.browser.extraArgs).toEqual([
69+
"--remote-debugging-address=127.0.0.1",
70+
"about:blank",
71+
]);
6772
expect(config.browser.profiles["docker-cdp"].cdpUrl).toBe("http://127.0.0.1:19223");
6873
} finally {
6974
rmSync(root, { recursive: true, force: true });

0 commit comments

Comments
 (0)