The one and only agent harness for complex codebases. Project memory, planning, execution, and verified completion inside Codex.
JavaScript aiai-agentsclaudeclaude-codeclicodexdeveloper-toolslazylazycodexoh-my-openagentomoopenaiorchestrationtypescript
ci(web): gate Lighthouse on real Chrome
YeonGyu-Kim43f0ad72ff93
diff --git a/.github/workflows/web-ci.yml b/.github/workflows/web-ci.ymlindex 87effb9b..eef97e3a 100644--- a/.github/workflows/web-ci.yml+++ b/.github/workflows/web-ci.yml@@ -74,15 +74,9 @@ jobs:CI: "true"NODE_OPTIONS: "--no-deprecation"- - name: Lighthouse audits (non-blocking)- # Playwright-Chromium-CDP-Lighthouse hits NO_FCP intermittently in headless- # environments (both Ubuntu CI and macOS local). Live URL scoring is- # gated by PageSpeed Insights in web-deploy.yml. Reports still upload- # for inspection.- continue-on-error: true+ - name: Lighthouse audits (real Chrome)run: pnpm exec playwright test --grep "@lighthouse"env:- CI: "true"NODE_OPTIONS: "--no-deprecation"- name: Upload Lighthouse reportsdiff --git a/.github/workflows/web-deploy.yml b/.github/workflows/web-deploy.ymlindex a6fe83bc..964eb868 100644--- a/.github/workflows/web-deploy.yml+++ b/.github/workflows/web-deploy.yml@@ -90,34 +90,10 @@ jobs:echo "$loc" | grep -qE '^https://lazycodex\.ai/?$'echo "::endgroup::"- - name: PageSpeed Insights — Lighthouse 100/100/100/100 (live URL)- continue-on-error: true # PSI shared quota throttles on frequent CI runs; Playwright Lighthouse in web-ci.yml is the gating check.- run: |- set -euo pipefail- # Google PageSpeed Insights audits the live URL from Google's servers- # — the canonical Lighthouse measurement (immune to any local/CI- # rendering quirks). No API key needed for occasional invocations,- # but shared quota gets hit on frequent CI; non-blocking here.- for strategy in mobile desktop; do- echo "::group::PSI ${strategy}"- json=$(curl -sfG \- --data-urlencode "url=https://lazycodex.ai/" \- --data-urlencode "strategy=${strategy}" \- --data-urlencode "category=performance" \- --data-urlencode "category=accessibility" \- --data-urlencode "category=best-practices" \- --data-urlencode "category=seo" \- "https://www.googleapis.com/pagespeedonline/v5/runPagespeed")- python3 - <<PY- import json, sys- d = json.loads(r'''$json''')- cats = d['lighthouseResult']['categories']- scores = {k: round((cats[k]['score'] or 0) * 100) for k in ('performance','accessibility','best-practices','seo')}- print('strategy=${strategy}', scores)- fails = {k: v for k, v in scores.items() if v < 100}- if fails:- print('FAIL: scores below 100:', fails)- sys.exit(1)- PY- echo "::endgroup::"- done+ - name: Install Google Chrome stable+ uses: browser-actions/setup-chrome@v2+ with:+ chrome-version: stable++ - name: Live Lighthouse audits (real Chrome)+ run: pnpm run test:lighthouse:livediff --git a/packages/web/package.json b/packages/web/package.jsonindex c36265e2..857ac0ed 100644--- a/packages/web/package.json+++ b/packages/web/package.json@@ -18,6 +18,7 @@"type-check": "tsc --noEmit","test:e2e": "NODE_OPTIONS=--no-deprecation playwright test","test:lighthouse": "NODE_OPTIONS=--no-deprecation playwright test --grep @lighthouse",+ "test:lighthouse:live": "NODE_OPTIONS=--no-deprecation node ./scripts/lighthouse-live.mjs https://lazycodex.ai/","preview": "opennextjs-cloudflare build && opennextjs-cloudflare preview","deploy": "opennextjs-cloudflare build && opennextjs-cloudflare deploy","cf-typegen": "wrangler types --env-interface CloudflareEnv cloudflare-env.d.ts"diff --git a/packages/web/scripts/lighthouse-live.mjs b/packages/web/scripts/lighthouse-live.mjsnew file mode 100644index 00000000..c387dcac--- /dev/null+++ b/packages/web/scripts/lighthouse-live.mjs@@ -0,0 +1,126 @@+import { chromium } from "@playwright/test"+import lighthouse from "lighthouse"+import { createServer } from "node:net"++const url = process.argv[2] ?? "https://lazycodex.ai/"+const categoryKeys = ["performance", "accessibility", "best-practices", "seo"]++function findFreePort() {+ return new Promise((resolve, reject) => {+ const server = createServer()+ server.unref()+ server.on("error", reject)+ server.listen(0, "127.0.0.1", () => {+ const address = server.address()+ if (!address || typeof address === "string") {+ server.close()+ reject(new Error("Unable to allocate a CDP port"))+ return+ }+ const { port } = address+ server.close((error) => (error ? reject(error) : resolve(port)))+ })+ })+}++function settingsFor(formFactor) {+ if (formFactor === "mobile") {+ return {+ formFactor: "mobile",+ disableStorageReset: true,+ throttlingMethod: "provided",+ screenEmulation: {+ mobile: true,+ width: 412,+ height: 823,+ deviceScaleFactor: 1.75,+ disabled: false,+ },+ }+ }++ return {+ formFactor: "desktop",+ disableStorageReset: true,+ throttlingMethod: "provided",+ screenEmulation: {+ mobile: false,+ width: 1350,+ height: 940,+ deviceScaleFactor: 1,+ disabled: false,+ },+ throttling: {+ rttMs: 40,+ throughputKbps: 10240,+ cpuSlowdownMultiplier: 1,+ requestLatencyMs: 0,+ downloadThroughputKbps: 0,+ uploadThroughputKbps: 0,+ },+ }+}++async function audit(formFactor) {+ const cdpPort = await findFreePort()+ const browser = await chromium.launch({+ channel: "chrome",+ headless: true,+ args: [`--remote-debugging-port=${cdpPort}`, "--no-sandbox", "--disable-dev-shm-usage"],+ })++ try {+ const context = await browser.newContext()+ const page = await context.newPage()+ await page.goto(url, { waitUntil: "networkidle", timeout: 60_000 })+ await page.goto("about:blank")++ const result = await lighthouse(+ url,+ {+ port: cdpPort,+ output: ["json"],+ logLevel: "error",+ onlyCategories: categoryKeys,+ },+ {+ extends: "lighthouse:default",+ settings: settingsFor(formFactor),+ },+ )++ if (!result || result.lhr.runtimeError) {+ const runtimeError = result?.lhr.runtimeError+ const message = runtimeError ? `${runtimeError.code}: ${runtimeError.message}` : "no result"+ throw new Error(`Lighthouse ${formFactor} failed: ${message}`)+ }++ const scores = Object.fromEntries(+ categoryKeys.map((key) => [key, Math.round((result.lhr.categories[key].score ?? 0) * 100)]),+ )+ console.log(+ `[live Lighthouse ${formFactor}] url=${url} perf=${scores.performance} a11y=${scores.accessibility} bp=${scores["best-practices"]} seo=${scores.seo}`,+ )++ const failingAudits = Object.values(result.lhr.audits)+ .filter((audit) => audit.score !== null && audit.score < 1)+ .map((audit) => ` - ${audit.id}: score=${audit.score} (${audit.title})`)+ .slice(0, 30)+ if (failingAudits.length > 0) {+ console.warn(`[live Lighthouse ${formFactor}] Failing audits:\n${failingAudits.join("\n")}`)+ }++ const failingScores = Object.entries(scores).filter(([, score]) => score < 100)+ if (failingScores.length > 0) {+ throw new Error(`Lighthouse ${formFactor} scores below 100: ${JSON.stringify(Object.fromEntries(failingScores))}`)+ }+ } finally {+ await browser.close()+ }+}++for (const formFactor of ["mobile", "desktop"]) {+ await audit(formFactor)+}++console.log("cleanup: closed Playwright Chrome browsers; no Lighthouse CLI used")