From c2d290a8ddab9fce73d3d0a699a70d9c6a57eee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 27 Oct 2026 17:02:18 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20test:=20browser=20smoke=20check=20c?= =?UTF-8?q?licks=20a=20link=20and=20a=20form=20button=20with=20nav.js=20li?= =?UTF-8?q?ve=20and=20fails=20on=20any=20page=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +++ scripts/smoke/bun.lock | 15 +++++++++++++ scripts/smoke/package.json | 8 +++++++ scripts/smoke/run.sh | 45 ++++++++++++++++++++++++++++++++++++++ scripts/smoke/smoke.mjs | 34 ++++++++++++++++++++++++++++ 5 files changed, 105 insertions(+) create mode 100644 scripts/smoke/bun.lock create mode 100644 scripts/smoke/package.json create mode 100755 scripts/smoke/run.sh create mode 100644 scripts/smoke/smoke.mjs diff --git a/.gitignore b/.gitignore index 619dff1..65ebc47 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,6 @@ ssh_host_ed25519_key # local config; copy config/forge.example.toml /config/forge.toml .~lock.*# + +# smoke check deps +/scripts/smoke/node_modules diff --git a/scripts/smoke/bun.lock b/scripts/smoke/bun.lock new file mode 100644 index 0000000..5a99734 --- /dev/null +++ b/scripts/smoke/bun.lock @@ -0,0 +1,15 @@ +{ + "lockfileVersion": 2, + "configVersion": 1, + "workspaces": { + "": { + "name": "forge-smoke", + "dependencies": { + "playwright-core": "1.64.1", + }, + }, + }, + "packages": { + "playwright-core": ["playwright-core@1.64.1", "", { "bin": { "playwright-core": "cli.js" } }, "sha512-BC4s8y6SEVA6Q1rSxZTto8hI1KUI3xXlHGZgvGqP4IqPdI/a6FX9H29IDNz7vKo9l21b6LfYosScPL6M3xxyDQ=="], + } +} diff --git a/scripts/smoke/package.json b/scripts/smoke/package.json new file mode 100644 index 0000000..e7e5d90 --- /dev/null +++ b/scripts/smoke/package.json @@ -0,0 +1,8 @@ +{ + "name": "forge-smoke", + "private": true, + "type": "module", + "dependencies": { + "playwright-core": "1.64.1" + } +} diff --git a/scripts/smoke/run.sh b/scripts/smoke/run.sh new file mode 100755 index 0000000..0722a3f --- /dev/null +++ b/scripts/smoke/run.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +# Browser smoke check: starts forge on a throwaway data dir and clicks through it with nav.js live. +# Usage: scripts/smoke/run.sh [--no-build] +# Env: SMOKE_PORT=17670 forge port (user content +1, ssh +2) +set -euo pipefail + +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" +HERE="$ROOT/scripts/smoke" +OUT="$ROOT/target/smoke" +PORT="${SMOKE_PORT:-17670}" +BIN="$ROOT/target/debug/forge" + +[[ "${1:-}" == --no-build ]] || (cd "$ROOT" && cargo build -q -p forge-web) +[[ -x $BIN ]] || { echo "[smoke] missing $BIN" >&2; exit 1; } +(cd "$HERE" && bun install --silent && bunx playwright-core install chromium-headless-shell >/dev/null) + +pkill -f -- "--config $OUT/forge.toml" 2>/dev/null || true +rm -rf "$OUT" && mkdir -p "$OUT/data" +cat > "$OUT/forge.toml" < "$OUT/forge.log" 2>&1 & +PID=$! +trap 'kill $PID 2>/dev/null || true; wait $PID 2>/dev/null || true' EXIT INT TERM +for _ in $(seq 60); do + curl -fsS "http://127.0.0.1:$PORT/healthz" >/dev/null 2>&1 && break + sleep 0.5 +done +curl -fsS "http://127.0.0.1:$PORT/healthz" >/dev/null || { echo "[smoke] forge did not start, see $OUT/forge.log" >&2; exit 1; } + +bun "$HERE/smoke.mjs" "http://127.0.0.1:$PORT" diff --git a/scripts/smoke/smoke.mjs b/scripts/smoke/smoke.mjs new file mode 100644 index 0000000..33783ce --- /dev/null +++ b/scripts/smoke/smoke.mjs @@ -0,0 +1,34 @@ +// Clicks through a running forge with nav.js live and fails on any page error, or when a link or a +// form button does nothing. Catches what the HTTP-only e2e tests cannot: a broken nav.js. +// Usage: bun smoke.mjs [base-url] (default http://127.0.0.1:17670) +import { chromium } from 'playwright-core'; + +const base = process.argv[2] || 'http://127.0.0.1:17670'; +const errors = []; +const fail = (msg) => { console.error('[smoke] FAIL ' + msg); process.exitCode = 1; }; + +const browser = await chromium.launch({ headless: true }); +try { + const page = await browser.newPage(); + page.on('pageerror', (e) => errors.push(e.message)); + + await page.goto(base + '/', { waitUntil: 'networkidle' }); + if (!(await page.evaluate(() => document.documentElement.classList.contains('js')))) { + fail('nav.js did not run (no html.js)'); + } + + // A form button: the theme toggle posts and the page comes back in the other theme. + const before = await page.evaluate(() => document.documentElement.dataset.theme); + await page.click('.theme-form button'); + await page.waitForFunction((t) => document.documentElement.dataset.theme !== t, before, { timeout: 5000 }) + .catch(() => fail('theme button did nothing')); + + // A link: a soft navigation lands on the explore page. + await page.click('a.topbar-link[href="/explore"]'); + await page.waitForURL(base + '/explore', { timeout: 5000 }).catch(() => fail('explore link did nothing')); +} finally { + await browser.close(); +} + +for (const e of errors) { fail('page error: ' + e); } +if (!process.exitCode) { console.log('[smoke] ok'); }