mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-09 15:59:30 +00:00
fix(e2e): avoid browser cdp doctor race
This commit is contained in:
parent
931f13c20f
commit
fd2e4da006
4 changed files with 54 additions and 15 deletions
|
|
@ -41,9 +41,10 @@ else
|
|||
cat >"$build_dir/Dockerfile" <<EOF
|
||||
FROM $BASE_IMAGE
|
||||
USER root
|
||||
RUN apt-get update \\
|
||||
&& apt-get install -y --no-install-recommends chromium fonts-liberation procps \\
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
ENV PLAYWRIGHT_BROWSERS_PATH=/home/appuser/.cache/ms-playwright
|
||||
RUN mkdir -p "\$PLAYWRIGHT_BROWSERS_PATH" \\
|
||||
&& DEBIAN_FRONTEND=noninteractive node /app/node_modules/playwright-core/cli.js install --with-deps chromium \\
|
||||
&& chown -R appuser:appuser "\$PLAYWRIGHT_BROWSERS_PATH"
|
||||
USER appuser
|
||||
EOF
|
||||
echo "Building Docker image: $IMAGE_NAME"
|
||||
|
|
@ -72,25 +73,24 @@ source scripts/lib/openclaw-e2e-instance.sh
|
|||
openclaw_e2e_eval_test_state_from_b64 \"\${OPENCLAW_TEST_STATE_SCRIPT_B64:?missing OPENCLAW_TEST_STATE_SCRIPT_B64}\"
|
||||
openclaw_e2e_write_state_env
|
||||
entry=\"\$(openclaw_e2e_resolve_entrypoint)\"
|
||||
mkdir -p /tmp/openclaw-browser-cdp/chrome
|
||||
mkdir -p /tmp/openclaw-browser-cdp
|
||||
find dist -maxdepth 1 -type f -name 'pw-ai-*.js' ! -name 'pw-ai-state-*' -exec mv {} /tmp/openclaw-browser-cdp/ \;
|
||||
if find dist -maxdepth 1 -type f -name 'pw-ai-*.js' ! -name 'pw-ai-state-*' | grep -q .; then
|
||||
echo 'failed to disable Playwright AI snapshot chunk for raw CDP smoke' >&2
|
||||
exit 1
|
||||
fi
|
||||
PORT=$PORT CDP_PORT=$CDP_PORT node scripts/e2e/lib/fixture.mjs browser-cdp
|
||||
chromium --headless=new --no-sandbox --disable-gpu --disable-dev-shm-usage \\
|
||||
--remote-debugging-address=127.0.0.1 \\
|
||||
--remote-debugging-port=$CDP_PORT \\
|
||||
--user-data-dir=/tmp/openclaw-browser-cdp/chrome \\
|
||||
about:blank >/tmp/browser-cdp-chromium.log 2>&1 &
|
||||
FIXTURE_PORT=$FIXTURE_PORT node scripts/e2e/lib/browser-cdp-snapshot/fixture-server.mjs >/tmp/browser-cdp-fixture.log 2>&1 &
|
||||
openclaw_e2e_exec_gateway \"\$entry\" $PORT loopback /tmp/browser-cdp-gateway.log" >/dev/null
|
||||
|
||||
echo "Waiting for Chromium and Gateway..."
|
||||
echo "Waiting for Gateway and fixture server..."
|
||||
if ! docker_e2e_wait_container_bash "$CONTAINER_NAME" 180 0.5 "
|
||||
source scripts/lib/openclaw-e2e-instance.sh
|
||||
openclaw_e2e_probe_http_status http://127.0.0.1:$CDP_PORT/json/version
|
||||
openclaw_e2e_probe_http_status http://127.0.0.1:$FIXTURE_PORT/
|
||||
openclaw_e2e_probe_tcp 127.0.0.1 $PORT
|
||||
"; then
|
||||
echo "Browser CDP snapshot container failed to become ready"
|
||||
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
|
||||
docker_e2e_tail_container_file_if_running "$CONTAINER_NAME" "/tmp/browser-cdp-gateway.log /tmp/browser-cdp-fixture.log" 120
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
|
@ -101,14 +101,13 @@ source /tmp/openclaw-test-state-env
|
|||
source scripts/lib/openclaw-e2e-instance.sh
|
||||
entry=\"\$(openclaw_e2e_resolve_entrypoint)\"
|
||||
base_args=(--url ws://127.0.0.1:$PORT --token '$TOKEN')
|
||||
node \"\$entry\" browser \"\${base_args[@]}\" --browser-profile docker-cdp doctor --deep >/tmp/browser-cdp-doctor.txt
|
||||
grep -q 'OK live-snapshot' /tmp/browser-cdp-doctor.txt
|
||||
node \"\$entry\" browser \"\${base_args[@]}\" --browser-profile docker-cdp open http://127.0.0.1:$FIXTURE_PORT/ >/tmp/browser-cdp-open.txt
|
||||
node \"\$entry\" browser \"\${base_args[@]}\" --browser-profile docker-cdp doctor --deep >/tmp/browser-cdp-doctor.txt 2>&1 || true
|
||||
node \"\$entry\" browser \"\${base_args[@]}\" --browser-profile docker-cdp snapshot --interactive --urls --out /tmp/browser-cdp-snapshot.txt >/tmp/browser-cdp-snapshot.out
|
||||
node scripts/e2e/lib/browser-cdp-snapshot/assert-snapshot.mjs /tmp/browser-cdp-snapshot.txt
|
||||
"; then
|
||||
echo "Browser CDP snapshot smoke failed"
|
||||
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
|
||||
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
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ function writeConfig(kind) {
|
|||
},
|
||||
browser: {
|
||||
enabled: true,
|
||||
noSandbox: true,
|
||||
extraArgs: ["--remote-debugging-address=127.0.0.1", "about:blank"],
|
||||
defaultProfile: "docker-cdp",
|
||||
ssrfPolicy: { allowedHostnames: ["127.0.0.1"] },
|
||||
profiles: {
|
||||
|
|
|
|||
|
|
@ -1133,6 +1133,39 @@ fi
|
|||
expect(runner).toContain('-e "OPENCLAW_BROWSER_CDP_SNAPSHOT_MAX_BYTES=$SNAPSHOT_MAX_BYTES"');
|
||||
});
|
||||
|
||||
it("uses Playwright Chromium for the browser CDP snapshot image", () => {
|
||||
const runner = readFileSync(BROWSER_CDP_SNAPSHOT_DOCKER_E2E_PATH, "utf8");
|
||||
|
||||
expect(runner).toContain("ENV PLAYWRIGHT_BROWSERS_PATH=/home/appuser/.cache/ms-playwright");
|
||||
expect(runner).toContain("playwright-core/cli.js install --with-deps chromium");
|
||||
expect(runner).not.toContain("apt-get install -y --no-install-recommends chromium");
|
||||
});
|
||||
|
||||
it("opens the browser CDP fixture before snapshotting", () => {
|
||||
const runner = readFileSync(BROWSER_CDP_SNAPSHOT_DOCKER_E2E_PATH, "utf8");
|
||||
const quarantineIndex = runner.indexOf("mkdir -p /tmp/openclaw-browser-cdp");
|
||||
const configIndex = runner.indexOf("node scripts/e2e/lib/fixture.mjs browser-cdp");
|
||||
const openIndex = runner.indexOf(
|
||||
'browser \\"\\${base_args[@]}\\" --browser-profile docker-cdp open',
|
||||
);
|
||||
const doctorIndex = runner.indexOf(
|
||||
'browser \\"\\${base_args[@]}\\" --browser-profile docker-cdp doctor --deep',
|
||||
);
|
||||
const snapshotIndex = runner.indexOf(
|
||||
'browser \\"\\${base_args[@]}\\" --browser-profile docker-cdp snapshot --interactive',
|
||||
);
|
||||
|
||||
expect(quarantineIndex).toBeGreaterThan(-1);
|
||||
expect(configIndex).toBeGreaterThan(-1);
|
||||
expect(configIndex).toBeGreaterThan(quarantineIndex);
|
||||
expect(openIndex).toBeGreaterThan(-1);
|
||||
expect(openIndex).toBeGreaterThan(configIndex);
|
||||
expect(doctorIndex).toBeGreaterThan(openIndex);
|
||||
expect(snapshotIndex).toBeGreaterThan(doctorIndex);
|
||||
expect(runner).toContain(">/tmp/browser-cdp-doctor.txt 2>&1 || true");
|
||||
expect(runner).toContain("failed to disable Playwright AI snapshot chunk");
|
||||
});
|
||||
|
||||
it("fails Docker commands fast when timeout is unavailable", () => {
|
||||
const workDir = mkdtempSync(join(tmpdir(), "openclaw-docker-timeout-required-"));
|
||||
|
||||
|
|
|
|||
|
|
@ -64,6 +64,11 @@ describe("scripts/e2e/lib/fixture.mjs config commands", () => {
|
|||
expect(result.status).toBe(0);
|
||||
const config = JSON.parse(readFileSync(path.join(root, "openclaw.json"), "utf8"));
|
||||
expect(config.gateway.port).toBe(19000);
|
||||
expect(config.browser.noSandbox).toBe(true);
|
||||
expect(config.browser.extraArgs).toEqual([
|
||||
"--remote-debugging-address=127.0.0.1",
|
||||
"about:blank",
|
||||
]);
|
||||
expect(config.browser.profiles["docker-cdp"].cdpUrl).toBe("http://127.0.0.1:19223");
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue