The fastest browser for AI agents to run browser automation, built for sharing your logged-in browser state with your AI agents, like Codex or Claude Code, without disturbing you. Zero cost, zero config.
JavaScript agent-skillsai-agentautomationbrowserbrowser-automationclaude-codecodexhermes-agentskillsskills-sh
feat(tools): let the bot run E2E without known-failing cases before it pushes
Zhuowei Wang7343b3cf6b04
diff --git a/tools/linear-autofix/README.md b/tools/linear-autofix/README.mdindex 4f4b5df..da8c8f5 100644--- a/tools/linear-autofix/README.md+++ b/tools/linear-autofix/README.md@@ -92,6 +92,7 @@ mkdir -p ~/.config/linear-autofixcat > ~/.config/linear-autofix/env <<'ENV'export LINEAR_API_KEY=lin_api_…# export AUTOFIX_LOG_ISSUE=CITRO-4786 # where tick logs are posted (default)+export AUTOFIX_E2E_KNOWN_FAILURES="Page keyboard interface" # browser-side paste bug, see below# export AUTOFIX_MAX_IMPLEMENTING=2ENVchmod 600 ~/.config/linear-autofix/env@@ -144,22 +145,23 @@ the ticket stays readable. Set `AUTOFIX_LOG_ISSUE=` (empty) to disable.## Configuration-| Variable | Default | Meaning |-| --------------------------- | ----------------------------------------- | ------------------------------------------------------- |-| `LINEAR_API_KEY` | — | required |-| `AUTOFIX_REPO` | this checkout | repository the worktrees are created from |-| `AUTOFIX_STATE_DIR` | `~/.local/state/linear-autofix` | records, runs, worktrees, lock, STOP |-| `AUTOFIX_LINEAR_STATES` | `Backlog,Todo,In Progress,Pending Review` | states polled |-| `AUTOFIX_BASE_BRANCH` | `dev` | PR base and worktree base |-| `AUTOFIX_MAX_IMPLEMENTING` | `2` | bot PRs allowed in review at once |-| `AUTOFIX_MAX_REVIEW_ROUNDS` | `5` | fix rounds per PR before escalating |-| `AUTOFIX_*_BUDGET_USD` | triage 2 / implement 25 / review 15 | `--max-budget-usd` per Claude run |-| `AUTOFIX_*_TIMEOUT_MS` | triage 10 min / implement 90 / review 60 | wall-clock limit per Claude run |-| `AUTOFIX_PUSH_TIMEOUT_MS` | 45 min | covers the pre-push E2E suite |-| `AUTOFIX_CLAUDE_MODEL` | Claude Code default | `--model` |-| `AUTOFIX_LOG_ISSUE` | `CITRO-4786` | Linear ticket that receives one comment per active tick |-| `AUTOFIX_DRY_RUN` | unset | `1`: no Linear/GitHub writes, no push |-| `AUTOFIX_ISSUE` | unset | restrict a tick to one identifier |+| Variable | Default | Meaning |+| ---------------------------- | ----------------------------------------- | ------------------------------------------------------------ |+| `LINEAR_API_KEY` | — | required |+| `AUTOFIX_REPO` | this checkout | repository the worktrees are created from |+| `AUTOFIX_STATE_DIR` | `~/.local/state/linear-autofix` | records, runs, worktrees, lock, STOP |+| `AUTOFIX_LINEAR_STATES` | `Backlog,Todo,In Progress,Pending Review` | states polled |+| `AUTOFIX_BASE_BRANCH` | `dev` | PR base and worktree base |+| `AUTOFIX_MAX_IMPLEMENTING` | `2` | bot PRs allowed in review at once |+| `AUTOFIX_MAX_REVIEW_ROUNDS` | `5` | fix rounds per PR before escalating |+| `AUTOFIX_*_BUDGET_USD` | triage 2 / implement 25 / review 15 | `--max-budget-usd` per Claude run |+| `AUTOFIX_*_TIMEOUT_MS` | triage 10 min / implement 90 / review 60 | wall-clock limit per Claude run |+| `AUTOFIX_PUSH_TIMEOUT_MS` | 45 min | covers the pre-push E2E suite |+| `AUTOFIX_CLAUDE_MODEL` | Claude Code default | `--model` |+| `AUTOFIX_E2E_KNOWN_FAILURES` | (empty) | E2E cases the bot leaves out, pushing with the hook excluded |+| `AUTOFIX_LOG_ISSUE` | `CITRO-4786` | Linear ticket that receives one comment per active tick |+| `AUTOFIX_DRY_RUN` | unset | `1`: no Linear/GitHub writes, no push |+| `AUTOFIX_ISSUE` | unset | restrict a tick to one identifier |## Review-loop termination@@ -176,6 +178,17 @@ escalates instead of pushing again. A round whose outcome is `disputed`produces a PR comment and no commit; the next tick sees the same findings andescalates, which is intended: a dispute needs a human.+## Known-failing E2E cases++Some real-browser E2E cases fail for reasons outside this repository (today:+`Page keyboard interface`, whose paste assertion hits a browser-side clipboard+race). Left alone, that blocks every bot push that touches+`package/ego-browser/`. Name such cases in `AUTOFIX_E2E_KNOWN_FAILURES`+(comma-separated). When the diff is inside the E2E scope, the bot then runs the+suite itself with those cases left out (`EGO_BROWSER_REAL_E2E_ONLY`) and pushes+with `LEFTHOOK_EXCLUDE=e2e-test`; the PR body names the excluded cases. Remove+a name as soon as the underlying bug ships, so the case guards again.+## When a push fails`git push` runs the pre-push hook, which runs the real-browser E2E suite ondiff --git a/tools/linear-autofix/src/config.mjs b/tools/linear-autofix/src/config.mjsindex 5bd1bd8..5f8ddf3 100644--- a/tools/linear-autofix/src/config.mjs+++ b/tools/linear-autofix/src/config.mjs@@ -45,6 +45,10 @@ export const config = Object.freeze({remote: process.env.AUTOFIX_REMOTE ?? "origin",baseBranch: process.env.AUTOFIX_BASE_BRANCH ?? "dev",packageDir: "package/ego-browser",+ // Real-browser E2E cases known to fail on this host for reasons outside the+ // SDK (browser-side bugs). With this set, the bot runs the suite itself+ // without them and pushes with the pre-push hook excluded; the PR body says so.+ e2eKnownFailures: list("AUTOFIX_E2E_KNOWN_FAILURES", []),maxImplementing: num("AUTOFIX_MAX_IMPLEMENTING", 2),maxReviewRounds: num("AUTOFIX_MAX_REVIEW_ROUNDS", 5),diff --git a/tools/linear-autofix/src/e2e.mjs b/tools/linear-autofix/src/e2e.mjsnew file mode 100644index 0000000..5004708--- /dev/null+++ b/tools/linear-autofix/src/e2e.mjs@@ -0,0 +1,89 @@+import fs from "node:fs";+import path from "node:path";+import { pathToFileURL } from "node:url";+import { config } from "./config.mjs";+import * as git from "./git.mjs";+import { run } from "./proc.mjs";++const E2E_SCOPE = /^(package\/ego-browser\/|skills\/ego-browser\/)/;++/** Paths whose change makes the pre-push hook run the real-browser E2E suite. */+export function touchesE2eScope(changedFiles) {+ return changedFiles.some((f) => E2E_SCOPE.test(f));+}++/**+ * Split the suite into the cases to run and the known-failing names that do+ * not exist (a typo, or a case that was renamed). Pure.+ */+export function selectE2eCases(allCases, knownFailures) {+ const known = new Set(knownFailures);+ const all = new Set(allCases);+ return {+ only: allCases.filter((name) => !known.has(name)),+ excluded: allCases.filter((name) => known.has(name)),+ unknown: knownFailures.filter((name) => !all.has(name)),+ };+}++async function listE2eCases(dir) {+ const file = path.join(+ dir,+ config.packageDir,+ "scripts/real-browser-e2e/cases/index.mjs",+ );+ if (!fs.existsSync(file))+ throw new Error(`E2E case index not found at ${file}`);+ const mod = await import(`${pathToFileURL(file).href}?t=${Date.now()}`);+ return mod.e2eCases.map((c) => c.name);+}++/**+ * Push the worktree branch through the E2E gate.+ *+ * Without known-failing cases the pre-push hook runs the full suite as usual.+ * With `AUTOFIX_E2E_KNOWN_FAILURES` set and the diff inside the E2E scope, the+ * bot runs the suite itself with those cases left out and pushes with the hook+ * excluded, so one browser-side bug does not block every PR. Returns the+ * excluded case names (empty when the hook ran the full suite).+ */+export async function gatedPush(dir, branch) {+ const base = `${config.remote}/${config.baseBranch}`;+ const changed = await git.changedFiles(dir, base);+ const known = config.e2eKnownFailures;+ if (!known.length || !touchesE2eScope(changed)) {+ await git.push(dir, branch);+ return { excluded: [], ran: known.length ? "not needed" : "hook" };+ }+ const { only, excluded, unknown } = selectE2eCases(+ await listE2eCases(dir),+ known,+ );+ if (unknown.length)+ console.warn(+ `AUTOFIX_E2E_KNOWN_FAILURES names unknown cases: ${unknown.join(", ")}`,+ );+ if (!only.length)+ throw new Error("AUTOFIX_E2E_KNOWN_FAILURES excludes every E2E case");+ if (config.dryRun) {+ console.log(`[dry-run] would run E2E without: ${excluded.join(", ")}`);+ } else {+ await run("npm", ["run", "e2e"], {+ cwd: path.join(dir, config.packageDir),+ timeoutMs: config.pushTimeoutMs,+ env: { EGO_BROWSER_REAL_E2E_ONLY: JSON.stringify(only) },+ });+ }+ await git.push(dir, branch, { skipHookE2e: true });+ return { excluded, ran: "bot" };+}++/** The sentence the PR body carries about how E2E was run. */+export function e2eNote(gate) {+ if (gate.ran === "bot") {+ return `The real-browser E2E suite ran on the bot machine before this push, excluding known-failing cases: ${gate.excluded.map((n) => `\`${n}\``).join(", ")} (AUTOFIX_E2E_KNOWN_FAILURES).`;+ }+ if (gate.ran === "not needed")+ return "No E2E-scoped files changed; the pre-push E2E hook did not run.";+ return "The pre-push real-browser E2E suite ran on the bot machine before this push.";+}diff --git a/tools/linear-autofix/src/e2e.test.mjs b/tools/linear-autofix/src/e2e.test.mjsnew file mode 100644index 0000000..822c864--- /dev/null+++ b/tools/linear-autofix/src/e2e.test.mjs@@ -0,0 +1,37 @@+import assert from "node:assert/strict";+import { test } from "node:test";+import { e2eNote, selectE2eCases, touchesE2eScope } from "./e2e.mjs";++test("touchesE2eScope matches the paths the pre-push hook watches", () => {+ assert.equal(+ touchesE2eScope(["tools/linear-autofix/src/cli.mjs", "README.md"]),+ false,+ );+ assert.equal(touchesE2eScope(["package/ego-browser/src/cdp-eval.ts"]), true);+ assert.equal(touchesE2eScope(["skills/ego-browser/SKILL.md"]), true);+ assert.equal(+ touchesE2eScope(["plugins/ego/skills/ego-browser/SKILL.md"]),+ false,+ );+});++test("selectE2eCases leaves out known failures and reports unknown names", () => {+ const all = ["Environment", "Page keyboard interface", "Pointer"];+ const r = selectE2eCases(all, ["Page keyboard interface", "Gone case"]);+ assert.deepEqual(r.only, ["Environment", "Pointer"]);+ assert.deepEqual(r.excluded, ["Page keyboard interface"]);+ assert.deepEqual(r.unknown, ["Gone case"]);+ assert.deepEqual(selectE2eCases(all, []).only, all);+});++test("e2eNote says which cases were excluded", () => {+ assert.match(+ e2eNote({ ran: "bot", excluded: ["Page keyboard interface"] }),+ /excluding known-failing cases: `Page keyboard interface`/,+ );+ assert.match(+ e2eNote({ ran: "hook", excluded: [] }),+ /pre-push real-browser E2E suite ran/,+ );+ assert.match(e2eNote({ ran: "not needed", excluded: [] }), /did not run/);+});diff --git a/tools/linear-autofix/src/git.mjs b/tools/linear-autofix/src/git.mjsindex 92792e4..179244a 100644--- a/tools/linear-autofix/src/git.mjs+++ b/tools/linear-autofix/src/git.mjs@@ -111,14 +111,30 @@ export async function recentLog(dir, ref) {return (await gitIn(dir, ["log", "--oneline", `${ref}..HEAD`])).stdout.trim();}-/** Push the branch. The pre-push hook runs the real-browser E2E suite here. */-export async function push(dir, branch) {+/** Files changed on the branch relative to `ref`. */+export async function changedFiles(dir, ref) {+ const { stdout } = await gitIn(dir, ["diff", "--name-only", `${ref}...HEAD`]);+ return stdout+ .split("\n")+ .map((l) => l.trim())+ .filter(Boolean);+}++/**+ * Push the branch. The pre-push hook runs the real-browser E2E suite here+ * unless `skipHookE2e` is set, which the E2E gate does after running the suite+ * itself (see e2e.mjs).+ */+export async function push(dir, branch, { skipHookE2e = false } = {}) {if (config.dryRun) {- console.log(`[dry-run] git push ${config.remote} ${branch} (from ${dir})`);+ console.log(+ `[dry-run] git push ${config.remote} ${branch} (from ${dir}${skipHookE2e ? ", hook E2E excluded" : ""})`,+ );return;}await gitIn(dir, ["push", "--set-upstream", config.remote, branch], {timeoutMs: config.pushTimeoutMs,+ env: skipHookE2e ? { LEFTHOOK_EXCLUDE: "e2e-test" } : {},});}diff --git a/tools/linear-autofix/src/implement.mjs b/tools/linear-autofix/src/implement.mjsindex f70bb42..098b07b 100644--- a/tools/linear-autofix/src/implement.mjs+++ b/tools/linear-autofix/src/implement.mjs@@ -8,6 +8,7 @@ import * as linear from "./linear.mjs";import { note, runDir, transition, worktreePath } from "./state.mjs";import { escalate, FOOTER } from "./actions.mjs";import { bothTails } from "./proc.mjs";+import { e2eNote, gatedPush } from "./e2e.mjs";/*** Tools the implementer and the review fixer may use. The list keeps Claude on@@ -163,8 +164,9 @@ export async function publish(record) {return escalate(record, `分支上没有领先 ${base} 的提交,无法 publish。`);}+ let gate;try {- await git.push(dir, record.branch);+ gate = await gatedPush(dir, record.branch);} catch (err) {const logDir =record.implement?.runDir ?? runDir(record.identifier, "publish");@@ -176,7 +178,7 @@ export async function publish(record) {const excerpt = bothTails(err.stdout, err.stderr, 60).slice(-2200);return escalate(record,- `push 失败(pre-push 会跑真浏览器 E2E,通常是 E2E 未通过):\n\n\`\`\`\n${excerpt}\n\`\`\`\n\n完整输出:\`${log}\`\nworktree: \`${dir}\`\n\n修好环境后运行 \`linear-autofix publish ${record.identifier}\` 只重跑 push 和开 PR,不会重新实现。`,+ `push 或推送前的 E2E 失败(通常是 E2E 用例未通过):\n\n\`\`\`\n${excerpt}\n\`\`\`\n\n完整输出:\`${log}\`\nworktree: \`${dir}\`\n\n修好环境后运行 \`linear-autofix publish ${record.identifier}\` 只重跑 push 和开 PR,不会重新实现。`,);}note(record, "pushed", await git.recentLog(dir, base));@@ -193,8 +195,7 @@ export async function publish(record) {body: pr.body,identifier: record.identifier,draft,- e2eNote:- "The pre-push real-browser E2E suite ran on the bot machine before this push.",+ e2eNote: e2eNote(gate),}),draft,});diff --git a/tools/linear-autofix/src/review.mjs b/tools/linear-autofix/src/review.mjsindex 88a1350..edf3e76 100644--- a/tools/linear-autofix/src/review.mjs+++ b/tools/linear-autofix/src/review.mjs@@ -14,6 +14,7 @@ import { note, runDir, transition, worktreePath } from "./state.mjs";import { actionableThreads, renderThreads } from "./threads.mjs";import { escalate, FOOTER } from "./actions.mjs";import { CODE_TOOLS, readJson } from "./implement.mjs";+import { gatedPush } from "./e2e.mjs";// After a push, Codex's review takes up to 30 minutes. Wait this long for a// review of the current head before proceeding on CI and human threads alone.@@ -202,11 +203,11 @@ export async function review(issue, record) {}if (committed) {try {- await git.push(dir, record.branch);+ await gatedPush(dir, record.branch);} catch (err) {return escalate(record,- `review 修复后 push 失败:\n\n\`\`\`\n${String(err.message).slice(0, 2500)}\n\`\`\``,+ `review 修复后 push 或推送前的 E2E 失败:\n\n\`\`\`\n${String(err.message).slice(0, 2500)}\n\`\`\``,);}note(record, "pushed review fix", await git.recentLog(dir, before));