Skip to content

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.

feat(tools): report failed E2E cases on the PR instead of stopping the push

Zhuowei Wang5f4a8eff3850
diff --git a/package/ego-browser/scripts/real-browser-e2e/runner.mjs b/package/ego-browser/scripts/real-browser-e2e/runner.mjs
index 2e497d1..e29bca0 100644
--- a/package/ego-browser/scripts/real-browser-e2e/runner.mjs
+++ b/package/ego-browser/scripts/real-browser-e2e/runner.mjs
@@ -145,7 +145,9 @@ export async function runRealBrowserE2e() {
);
} catch (error) {
const durationMs = Date.now() - startedAt;
- const message = error?.message || String(error);
+ const message =
+ extractCaseError(error?.stdout, error?.stderr) ??
+ (error?.message || String(error));
const assertions =
extractAssertionCount(error?.stdout, error?.stderr) ?? 0;
recordResult(name, "fail", durationMs, assertions, message);
@@ -329,6 +331,16 @@ export async function runRealBrowserE2e() {
passed = caseResults.every((r) => r.status !== "fail");
printSummary(caseResults, Date.now() - totalStartedAt);
+ // For callers that act on individual cases (tools/linear-autofix). Written
+ // only when every case ran, so its absence means the suite did not finish.
+ if (process.env.EGO_BROWSER_REAL_E2E_RESULTS) {
+ await writeFile(
+ process.env.EGO_BROWSER_REAL_E2E_RESULTS,
+ JSON.stringify({ cases: caseResults }, null, 2),
+ "utf8",
+ );
+ }
+
if (!passed) {
process.exitCode = 1;
} else if (isFullRun) {
@@ -398,15 +410,15 @@ async function initializeE2eEnvironment(context, tempDir) {
);
}
-function extractAssertionCount(...outputs) {
- // Find the last JSON line with "assertions" from cliLog output
+/** The last JSON line with an assertion count from a case's cliLog output. */
+function lastCaseReport(outputs) {
const lines = outputs.filter(Boolean).join("\n").split("\n");
for (let i = lines.length - 1; i >= 0; i--) {
const line = lines[i].trim();
if (line.startsWith("{") && line.includes("assertions")) {
try {
const parsed = JSON.parse(line);
- if (typeof parsed.assertions === "number") return parsed.assertions;
+ if (typeof parsed.assertions === "number") return parsed;
} catch {
// not valid JSON, keep looking
}
@@ -415,6 +427,19 @@ function extractAssertionCount(...outputs) {
return null;
}
+function extractAssertionCount(...outputs) {
+ return lastCaseReport(outputs)?.assertions ?? null;
+}
+
+/**
+ * The reason a case reported for failing, or null. The process error only says
+ * which command exited non-zero, which does not tell one case from another.
+ */
+export function extractCaseError(...outputs) {
+ const error = lastCaseReport(outputs)?.error;
+ return typeof error === "string" && error ? error : null;
+}
+
function formatDuration(ms) {
if (ms < 1000) return `${ms}ms`;
return `${(ms / 1000).toFixed(1)}s`;
diff --git a/package/ego-browser/src/real-browser-runner.test.mjs b/package/ego-browser/src/real-browser-runner.test.mjs
index 6b960f4..30c5cce 100644
--- a/package/ego-browser/src/real-browser-runner.test.mjs
+++ b/package/ego-browser/src/real-browser-runner.test.mjs
@@ -7,7 +7,10 @@ import {
} from "../scripts/real-browser-e2e/ego-browser-cli.mjs";
import { pageActionabilityCase } from "../scripts/real-browser-e2e/cases/page-actionability.mjs";
import { pageScrolledScreenshotCase } from "../scripts/real-browser-e2e/cases/page-screenshot.mjs";
-import { parseOnlyCases } from "../scripts/real-browser-e2e/runner.mjs";
+import {
+ extractCaseError,
+ parseOnlyCases,
+} from "../scripts/real-browser-e2e/runner.mjs";
test("real-browser E2E honors an explicit Ego Lite CLI", () => {
assert.equal(
@@ -91,6 +94,18 @@ test("real-browser E2E rejects an explicitly empty selection", () => {
);
});
+test("real-browser E2E reports the reason a case logged for failing", () => {
+ const stdout = [
+ "[ego-browser:notice] an update is available",
+ '{"ok":false,"assertions":15,"error":"page.click timed out"}',
+ "",
+ "ego's nodejs process exited with code 1.",
+ ].join("\n");
+ assert.equal(extractCaseError(stdout, ""), "page.click timed out");
+ assert.equal(extractCaseError('{"ok":true,"assertions":3}'), null);
+ assert.equal(extractCaseError(undefined, "plain stack trace"), null);
+});
+
test("the scrolled screenshot fixture is larger than the live viewport", () => {
const source = pageScrolledScreenshotCase();
diff --git a/tools/linear-autofix/README.md b/tools/linear-autofix/README.md
index 889514d..52867b8 100644
--- a/tools/linear-autofix/README.md
+++ b/tools/linear-autofix/README.md
@@ -20,15 +20,16 @@ new ──triage (claude, read-only)──► skipped (browser_side / needs_inf
│ design_decision / duplicate / already_fixed)
└─ verdict fix ──► triaged
│ implement (claude in a worktree; failing test → fix → npm test → commit)
- │ git push (pre-push runs the real-browser E2E on this machine)
+ │ real-browser E2E on this machine, then git push (failed cases do not block)
│ gh pr create --base dev (draft when the ticket needs Windows verification)
+ │ PR comment listing the failed E2E cases, if any
▼
in_review ──► every tick: CI status + Codex comment for HEAD + unresolved threads
│ nothing left → done (Linear → Pending Review); human merges
│ findings → claude review-fix → commit → push → reply/resolve
▼
- escalated (round limit, same findings twice, merge conflict, push/E2E
- failure, Claude says blocked, 3 consecutive errors)
+ escalated (round limit, same findings twice, merge conflict, push failure,
+ E2E suite did not finish, Claude says blocked, 3 consecutive errors)
```
Per-ticket state lives in `~/.local/state/linear-autofix/issues/<ID>.json`;
@@ -66,7 +67,7 @@ Prerequisites on the host:
- macOS with a logged-in GUI session that stays up: enable automatic login,
disable the screen saver and screen lock, and keep the machine awake
- (`sudo pmset -a sleep 0 displaysleep 0`). The pre-push E2E drives ego lite
+ (`sudo pmset -a sleep 0 displaysleep 0`). The bot's E2E run drives ego lite
windows, and background or locked windows break it.
- ego lite installed at `/Applications/ego lite.app` and running. The E2E
runner uses the CLI bundled inside the app. Nobody takes manual control of
@@ -141,7 +142,7 @@ Operations:
node src/cli.mjs status
node src/cli.mjs stop # STOP file: running tick finishes its step, later ticks exit
node src/cli.mjs resume
-node src/cli.mjs publish CITRO-2908 # push failed (E2E)? fix the host, then redo only push + PR
+node src/cli.mjs publish CITRO-2908 # push failed or E2E did not finish? fix the host, then redo only E2E + push + PR
node src/cli.mjs retry CITRO-2908 # start over: re-triage and re-implement (keeps worktree and branch)
node src/cli.mjs reset CITRO-2908 --remote # forget the ticket entirely: record, worktree, branches, bot labels
launchctl bootout gui/$(id -u)/com.citrolabs.linear-autofix # uninstall the schedule
@@ -167,24 +168,24 @@ 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` | `10` | fix rounds per PR before escalating |
-| `AUTOFIX_INTERVAL_MS` | `600000` (10 min) | pause between ticks in `daemon` mode |
-| `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 |
+| 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` | `10` | fix rounds per PR before escalating |
+| `AUTOFIX_INTERVAL_MS` | `600000` (10 min) | pause between ticks in `daemon` mode |
+| `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 | limit for the E2E suite, and for the push |
+| `AUTOFIX_CLAUDE_MODEL` | Claude Code default | `--model` |
+| `AUTOFIX_E2E_KNOWN_FAILURES` | (empty) | E2E cases the bot leaves out of its run and its comments |
+| `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 |
## What counts as review feedback
@@ -224,33 +225,42 @@ 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 and
escalates, which is intended: a dispute needs a human.
-## Known-failing E2E cases
+## E2E failures
-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.
+Whenever the branch changes `package/ego-browser/` or `skills/ego-browser/`, the
+bot runs the real-browser E2E suite on this host before every push, and pushes
+with `LEFTHOOK_EXCLUDE=e2e-test` so the pre-push hook does not run it again.
+
+A failed case does not stop the bot. It pushes, opens the PR as usual, and
+comments on the PR with each failed case and its error. A later push whose run
+passes says so in another comment. The bot does not try to fix these failures,
+and they do not hold back `done`: E2E only runs on this host, so a human judges
+them. The Linear comments for the PR warn about them while they apply to the
+current head.
+
+Some cases fail for reasons outside this repository (today: `Page keyboard
+interface`, whose paste assertion hits a browser-side clipboard race). Name them
+in `AUTOFIX_E2E_KNOWN_FAILURES` (comma-separated) to leave them out of the run
+(`EGO_BROWSER_REAL_E2E_ONLY`), so they do not repeat in every PR's comment; 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 on
-this host whenever `package/ego-browser/` or `skills/ego-browser/` changed.
-A failed push escalates the ticket with the last lines of the hook output; the
-full output is in `runs/<ID>/<timestamp>-implement/push.log`. The commits stay
-in `worktrees/<ID>`. To see the failure directly:
+A failed push escalates the ticket, and so does an E2E run without a usable
+result: it did not finish (build error, timeout) or no case passed (CLI missing,
+browser down, unusable build). The escalation carries the last lines of the output;
+the full output is in `runs/<ID>/<timestamp>-implement/push.log`. The commits
+stay in `worktrees/<ID>`. To see the failure directly:
```sh
cd ~/.local/state/linear-autofix/worktrees/CITRO-2908
-git push -u origin zhuoweiwang/citro-2908 # or: (cd package/ego-browser && npm run e2e)
+(cd package/ego-browser && npm run e2e) # or: git push -u origin zhuoweiwang/citro-2908
```
Once the host is fixed (ego lite running and in the foreground, nobody
-controlling it), `node src/cli.mjs publish CITRO-2908` redoes only the push
-and the PR; the review loop takes over from there.
+controlling it), `node src/cli.mjs publish CITRO-2908` redoes only E2E, the
+push and the PR; the review loop takes over from there.
## Limitations
diff --git a/tools/linear-autofix/src/config.mjs b/tools/linear-autofix/src/config.mjs
index 91fdec4..f432bb9 100644
--- a/tools/linear-autofix/src/config.mjs
+++ b/tools/linear-autofix/src/config.mjs
@@ -46,8 +46,8 @@ export const config = Object.freeze({
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.
+ // SDK (browser-side bugs). The bot's E2E run leaves them out, so they do not
+ // repeat in every PR's failure comment; the PR body says so.
e2eKnownFailures: list("AUTOFIX_E2E_KNOWN_FAILURES", []),
// `daemon` mode: pause between ticks.
diff --git a/tools/linear-autofix/src/e2e.mjs b/tools/linear-autofix/src/e2e.mjs
index 5004708..1a9a233 100644
--- a/tools/linear-autofix/src/e2e.mjs
+++ b/tools/linear-autofix/src/e2e.mjs
@@ -1,11 +1,15 @@
import fs from "node:fs";
+import os from "node:os";
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";
+import * as github from "./github.mjs";
+import { ProcessError, run } from "./proc.mjs";
+import { save } from "./state.mjs";
const E2E_SCOPE = /^(package\/ego-browser\/|skills\/ego-browser\/)/;
+const MAX_FAILURE_CHARS = 1500;
/** Paths whose change makes the pre-push hook run the real-browser E2E suite. */
export function touchesE2eScope(changedFiles) {
@@ -38,26 +42,74 @@ async function listE2eCases(dir) {
return mod.e2eCases.map((c) => c.name);
}
+/**
+ * The failed cases in the runner's results file, or null when no case passed.
+ * Nothing passing means the host could not run the suite (CLI missing, browser
+ * down) or the build is unusable, not a list worth reporting case by case. Pure.
+ */
+export function failedCases(results) {
+ const cases = results?.cases ?? [];
+ if (!cases.some((c) => c.status === "pass")) return null;
+ return cases
+ .filter((c) => c.status === "fail")
+ .map((c) => ({ name: c.name, message: String(c.message ?? "") }));
+}
+
+/**
+ * Run the suite and return the failed cases. Throws when it gave no usable
+ * verdict (build error, timeout, no case passing): that is for a human to look
+ * at on the host, not something to report on a PR as case failures.
+ */
+async function runSuite(dir, excluded, only) {
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "autofix-e2e-"));
+ const resultsFile = path.join(tmp, "results.json");
+ try {
+ const result = await run("npm", ["run", "e2e"], {
+ cwd: path.join(dir, config.packageDir),
+ timeoutMs: config.pushTimeoutMs,
+ allowFailure: true,
+ env: {
+ EGO_BROWSER_REAL_E2E_RESULTS: resultsFile,
+ // Without exclusions it stays a full run, which can skip an unchanged
+ // build and records a full pass.
+ ...(excluded.length
+ ? { EGO_BROWSER_REAL_E2E_ONLY: JSON.stringify(only) }
+ : {}),
+ },
+ });
+ if (result.code === 0) return [];
+ const failures = fs.existsSync(resultsFile)
+ ? failedCases(JSON.parse(fs.readFileSync(resultsFile, "utf8")))
+ : null;
+ if (!failures?.length) {
+ throw new ProcessError(
+ `E2E suite exited ${result.code} without a usable result (it did not finish, or no case passed)`,
+ result,
+ );
+ }
+ return failures;
+ } finally {
+ fs.rmSync(tmp, { recursive: true, force: true });
+ }
+}
+
/**
* 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).
+ * When the diff is inside the E2E scope the bot runs the suite itself, leaving
+ * out `AUTOFIX_E2E_KNOWN_FAILURES`, and pushes with the hook excluded. Failed
+ * cases do not stop the push: they come back in `failures` for the PR comment.
*/
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)) {
+ if (!touchesE2eScope(changed)) {
await git.push(dir, branch);
- return { excluded: [], ran: known.length ? "not needed" : "hook" };
+ return { ran: "not needed", excluded: [], failures: [] };
}
const { only, excluded, unknown } = selectE2eCases(
await listE2eCases(dir),
- known,
+ config.e2eKnownFailures,
);
if (unknown.length)
console.warn(
@@ -65,25 +117,78 @@ export async function gatedPush(dir, branch) {
);
if (!only.length)
throw new Error("AUTOFIX_E2E_KNOWN_FAILURES excludes every E2E case");
+ let failures = [];
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) },
- });
+ failures = await runSuite(dir, excluded, only);
}
await git.push(dir, branch, { skipHookE2e: true });
- return { excluded, ran: "bot" };
+ return { ran: "bot", excluded, failures };
}
-/** The sentence the PR body carries about how E2E was run. */
+/** The sentence the PR body carries about how E2E was run. Pure. */
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.";
+ return "No E2E-scoped files changed; the real-browser E2E suite did not run.";
+ const excluded = gate.excluded.length
+ ? `, excluding known-failing cases: ${gate.excluded.map((n) => `\`${n}\``).join(", ")} (AUTOFIX_E2E_KNOWN_FAILURES)`
+ : "";
+ const outcome = gate.failures.length
+ ? ` ${gate.failures.length} case(s) failed; a PR comment lists them.`
+ : "";
+ return `The real-browser E2E suite ran on the bot machine before this push${excluded}.${outcome}`;
+}
+
+/**
+ * PR comment naming the failed cases. The repository is public and the runner's
+ * messages can carry local paths, so the home directory is shortened. Pure.
+ */
+export function e2eFailureComment(gate, sha, home = os.homedir()) {
+ const cases = gate.failures.map(({ name, message }) => {
+ const text = message
+ .replaceAll(home, "~")
+ .replaceAll("```", "'''")
+ .slice(0, MAX_FAILURE_CHARS);
+ return `#### \`${name}\`\n\n\`\`\`text\n${text}\n\`\`\``;
+ });
+ const excluded = gate.excluded.length
+ ? `\n\nNot run (known failures on this host): ${gate.excluded.map((n) => `\`${n}\``).join(", ")}.`
+ : "";
+ return `### Real-browser E2E: ${gate.failures.length} case(s) failed on \`${sha.slice(0, 8)}\`\n\nThe bot pushed anyway, since a failed case does not block the PR. Check whether these failures come from this change before merging.${excluded}\n\n${cases.join("\n\n")}`;
+}
+
+/**
+ * Remember what E2E said about this head, and the PR comment that goes with it.
+ * The comment is kept on the record until it is posted, so a failed `gh` call
+ * cannot leave a PR that looks clean: the next review check posts it. A pass
+ * only needs saying when it replaces an earlier failure comment.
+ */
+export function recordE2e(record, gate, sha) {
+ let unposted;
+ if (gate.failures.length) {
+ unposted = e2eFailureComment(gate, sha);
+ } else if (gate.ran === "bot" && record.e2e?.failures?.length) {
+ unposted = `### Real-browser E2E: passes on \`${sha.slice(0, 8)}\`\n\nThe failures reported in earlier comments no longer occur.`;
+ }
+ record.e2e = {
+ sha,
+ failures: gate.failures.map((f) => f.name),
+ ...(unposted ? { unposted } : {}),
+ };
+ save(record);
+}
+
+export async function flushE2eComment(record, prNumber) {
+ if (!record.e2e?.unposted) return;
+ await github.commentOnPr(prNumber, record.e2e.unposted);
+ delete record.e2e.unposted;
+ save(record);
+}
+
+/** Warning for Linear comments that would otherwise read as all green. Pure. */
+export function e2eWarning(record, sha) {
+ const failures = record.e2e?.sha === sha ? (record.e2e.failures ?? []) : [];
+ if (!failures.length) return "";
+ return `\n\n⚠️ 这个提交上有 ${failures.length} 个 E2E 用例失败(${failures.join(", ")}),详情见 PR 评论,合并前请确认是否由本次改动引起。`;
}
diff --git a/tools/linear-autofix/src/e2e.test.mjs b/tools/linear-autofix/src/e2e.test.mjs
index 822c864..7fd679e 100644
--- a/tools/linear-autofix/src/e2e.test.mjs
+++ b/tools/linear-autofix/src/e2e.test.mjs
@@ -1,6 +1,13 @@
import assert from "node:assert/strict";
import { test } from "node:test";
-import { e2eNote, selectE2eCases, touchesE2eScope } from "./e2e.mjs";
+import {
+ e2eFailureComment,
+ e2eNote,
+ e2eWarning,
+ failedCases,
+ selectE2eCases,
+ touchesE2eScope,
+} from "./e2e.mjs";
test("touchesE2eScope matches the paths the pre-push hook watches", () => {
assert.equal(
@@ -24,14 +31,84 @@ test("selectE2eCases leaves out known failures and reports unknown names", () =>
assert.deepEqual(selectE2eCases(all, []).only, all);
});
-test("e2eNote says which cases were excluded", () => {
+test("e2eNote says what ran, what was excluded and what failed", () => {
assert.match(
- e2eNote({ ran: "bot", excluded: ["Page keyboard interface"] }),
+ e2eNote({
+ ran: "bot",
+ excluded: ["Page keyboard interface"],
+ failures: [],
+ }),
/excluding known-failing cases: `Page keyboard interface`/,
);
+ const clean = e2eNote({ ran: "bot", excluded: [], failures: [] });
+ assert.match(clean, /suite ran on the bot machine before this push\.$/);
assert.match(
- e2eNote({ ran: "hook", excluded: [] }),
- /pre-push real-browser E2E suite ran/,
+ e2eNote({
+ ran: "bot",
+ excluded: [],
+ failures: [{ name: "Pointer", message: "x" }],
+ }),
+ /1 case\(s\) failed; a PR comment lists them/,
);
- assert.match(e2eNote({ ran: "not needed", excluded: [] }), /did not run/);
+ assert.match(
+ e2eNote({ ran: "not needed", excluded: [], failures: [] }),
+ /did not run/,
+ );
+});
+
+test("failedCases keeps only failures from the runner's results", () => {
+ assert.deepEqual(
+ failedCases({
+ cases: [
+ { name: "A", status: "pass" },
+ { name: "B", status: "skip" },
+ { name: "C", status: "fail", message: "boom" },
+ ],
+ }),
+ [{ name: "C", message: "boom" }],
+ );
+ assert.deepEqual(failedCases({ cases: [{ name: "A", status: "pass" }] }), []);
+});
+
+test("failedCases refuses to report when no case passed", () => {
+ assert.equal(
+ failedCases({
+ cases: [
+ { name: "A", status: "fail", message: "CLI not found" },
+ { name: "B", status: "skip" },
+ ],
+ }),
+ null,
+ );
+ assert.equal(failedCases({ cases: [] }), null);
+ assert.equal(failedCases(null), null);
+});
+
+test("e2eFailureComment names each case and keeps local paths out", () => {
+ const body = e2eFailureComment(
+ {
+ excluded: ["Paste"],
+ failures: [
+ { name: "Pointer", message: "/Users/bot/x failed ```fence```" },
+ { name: "Long", message: "y".repeat(5000) },
+ ],
+ },
+ "0123456789abcdef",
+ "/Users/bot",
+ );
+ assert.match(body, /2 case\(s\) failed on `01234567`/);
+ assert.match(body, /Not run \(known failures on this host\): `Paste`/);
+ assert.match(body, /#### `Pointer`/);
+ assert.match(body, /~\/x failed '''fence'''/);
+ assert.doesNotMatch(body, /\/Users\/bot/);
+ assert.ok(!body.includes("y".repeat(1501)));
+ assert.equal(body.match(/```/g).length, 4);
+});
+
+test("e2eWarning only speaks about the commit E2E ran on", () => {
+ const record = { e2e: { sha: "abc", failures: ["Pointer"] } };
+ assert.match(e2eWarning(record, "abc"), /1 个 E2E 用例失败(Pointer)/);
+ assert.equal(e2eWarning(record, "def"), "");
+ assert.equal(e2eWarning({ e2e: { sha: "abc", failures: [] } }, "abc"), "");
+ assert.equal(e2eWarning({}, "abc"), "");
});
diff --git a/tools/linear-autofix/src/git.mjs b/tools/linear-autofix/src/git.mjs
index 0678909..19cd93d 100644
--- a/tools/linear-autofix/src/git.mjs
+++ b/tools/linear-autofix/src/git.mjs
@@ -170,7 +170,8 @@ export async function changedFiles(dir, ref) {
/**
* 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).
+ * itself, so failed cases can be reported instead of stopping the push (see
+ * e2e.mjs).
*/
export async function push(dir, branch, { skipHookE2e = false } = {}) {
if (config.dryRun) {
diff --git a/tools/linear-autofix/src/implement.mjs b/tools/linear-autofix/src/implement.mjs
index 414986d..32c31d1 100644
--- a/tools/linear-autofix/src/implement.mjs
+++ b/tools/linear-autofix/src/implement.mjs
@@ -8,7 +8,13 @@ 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";
+import {
+ e2eNote,
+ e2eWarning,
+ flushE2eComment,
+ gatedPush,
+ recordE2e,
+} from "./e2e.mjs";
/**
* Tools the implementer and the review fixer may use. The list keeps Claude on
@@ -188,8 +194,8 @@ export async function publish(record) {
record,
"push",
config.e2eKnownFailures.length
- ? `E2E gate: the bot runs the suite without ${config.e2eKnownFailures.join(", ")} and pushes with the hook excluded`
- : "no AUTOFIX_E2E_KNOWN_FAILURES set: the pre-push hook runs the full E2E suite",
+ ? `E2E gate: the bot runs the suite without ${config.e2eKnownFailures.join(", ")}; failed cases are reported on the PR`
+ : "E2E gate: the bot runs the full suite; failed cases are reported on the PR",
);
let gate;
try {
@@ -205,10 +211,19 @@ export async function publish(record) {
const excerpt = bothTails(err.stdout, err.stderr, 60).slice(-2200);
return escalate(
record,
- `push 或推送前的 E2E 失败(通常是 E2E 用例未通过):\n\n\`\`\`\n${excerpt}\n\`\`\`\n\n完整输出:\`${log}\`\nworktree: \`${dir}\`\n\n修好环境后运行 \`linear-autofix publish ${record.identifier}\` 只重跑 push 和开 PR,不会重新实现。`,
+ `push 失败,或推送前的 E2E 没能跑完(用例失败不会走到这里,只会评论到 PR):\n\n\`\`\`\n${excerpt}\n\`\`\`\n\n完整输出:\`${log}\`\nworktree: \`${dir}\`\n\n修好环境后运行 \`linear-autofix publish ${record.identifier}\` 只重跑 push 和开 PR,不会重新实现。`,
);
}
+ const headSha = await git.headSha(dir);
+ recordE2e(record, gate, headSha);
note(record, "pushed", await git.recentLog(dir, base));
+ if (gate.failures.length) {
+ note(
+ record,
+ "E2E failures reported on the PR",
+ gate.failures.map((f) => f.name).join(", "),
+ );
+ }
const draft = record.triage?.needs_windows === true;
// Taken before the PR exists, so no comment can slip in between creation
@@ -253,9 +268,12 @@ export async function publish(record) {
}
await linear.comment(
record,
- `**已开 PR** ${prInfo.url}${draft ? "(draft,待在 Windows 上验证后转正)" : ""}\n\n机器人会跟进 Codex review 和人工评论,直到没有新意见为止。合并由人工完成。\n\n${FOOTER}`,
+ `**已开 PR** ${prInfo.url}${draft ? "(draft,待在 Windows 上验证后转正)" : ""}\n\n机器人会跟进 Codex review 和人工评论,直到没有新意见为止。合并由人工完成。${e2eWarning(record, headSha)}\n\n${FOOTER}`,
);
transition(record, "in_review", prInfo.url);
+ // After the transition: if this fails, the next review check posts it, rather
+ // than the ticket being implemented again.
+ await flushE2eComment(record, prInfo.number);
}
/**
diff --git a/tools/linear-autofix/src/review.mjs b/tools/linear-autofix/src/review.mjs
index 9323c61..c8c421e 100644
--- a/tools/linear-autofix/src/review.mjs
+++ b/tools/linear-autofix/src/review.mjs
@@ -20,7 +20,7 @@ import {
} from "./threads.mjs";
import { escalate, FOOTER } from "./actions.mjs";
import { CODE_TOOLS, readJson } from "./implement.mjs";
-import { gatedPush } from "./e2e.mjs";
+import { e2eWarning, flushE2eComment, gatedPush, recordE2e } 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.
@@ -99,6 +99,7 @@ export async function review(issue, record) {
if (pr.state === "CLOSED") {
return transition(record, "done", `PR closed without merge ${pr.url}`);
}
+ await flushE2eComment(record, pr.number);
const sha = pr.headRefOid;
record.review ??= { rounds: 0 };
@@ -153,7 +154,7 @@ export async function review(issue, record) {
record.review.draftNotified = true;
await linear.comment(
record,
- `**Draft PR 已就绪,等待 Windows 验证** ${pr.url}\n\nCI 通过且没有未处理的评论。请在 Windows 上验证后把 PR 转为 ready for review,机器人会继续跟进 Codex review。\n\n${FOOTER}`,
+ `**Draft PR 已就绪,等待 Windows 验证** ${pr.url}\n\nCI 通过且没有未处理的评论。请在 Windows 上验证后把 PR 转为 ready for review,机器人会继续跟进 Codex review。${e2eWarning(record, sha)}\n\n${FOOTER}`,
);
}
return;
@@ -164,7 +165,7 @@ export async function review(issue, record) {
}
await linear.comment(
record,
- `**review 意见已清零** ${pr.url}\n\n${verdict.why}。等待人工合并。\n\n${FOOTER}`,
+ `**review 意见已清零** ${pr.url}\n\n${verdict.why}。等待人工合并。${e2eWarning(record, sha)}\n\n${FOOTER}`,
);
return transition(record, "done", verdict.why);
}
@@ -273,14 +274,16 @@ export async function review(issue, record) {
);
}
if (committed) {
+ let gate;
try {
- await gatedPush(dir, record.branch);
+ gate = await gatedPush(dir, record.branch);
} catch (err) {
return escalate(
record,
- `review 修复后 push 或推送前的 E2E 失败:\n\n\`\`\`\n${String(err.message).slice(0, 2500)}\n\`\`\``,
+ `review 修复后 push 失败,或推送前的 E2E 没能跑完(用例失败不会走到这里,只会评论到 PR):\n\n\`\`\`\n${String(err.message).slice(0, 2500)}\n\`\`\``,
);
}
+ recordE2e(record, gate, await git.headSha(dir));
note(record, "pushed review fix", await git.recentLog(dir, before));
}
@@ -304,4 +307,6 @@ export async function review(issue, record) {
record.review.lastFingerprint = fingerprint;
record.review.lastStatus = result.status;
note(record, `review round ${round} posted`, result.status);
+ // Last, so a failed comment is retried by the next check, not by another round.
+ await flushE2eComment(record, pr.number);
}