Skip to content

fix(run): exit 3 when a passed test's cleanup failed - #1233

Merged
okwasniewski merged 7 commits into
e2e-inc:mainfrom
Varshith-Kali:fix/cleanup-failure-exit-code-1231
Oct 28, 2026
Merged

okwasniewski merged 7 commits into
e2e-inc:mainfrom
Varshith-Kali:fix/cleanup-failure-exit-code-1231

Conversation

@Varshith-Kali

@Varshith-Kali Varshith-Kali commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

#1231: a run whose tests all pass but whose required video cannot be finalized exits 0, with the loss visible only as an attempt-level cleanup: "failed" and a secondary error. The exit-code fold never looked at cleanup state.

  • verdictExitCodes (packages/e2e/src/run/runner.ts) now folds an attempt's failed cleanup into the exit code, for ordinary and serial-group attempts alike: the cleanup-phase secondary error's category, defaulting to infrastructure (exit 3) when the record carries none.
  • A forced cleanup (cleanup: "forced") is untouched: the interrupt already sets 130.
  • Docs (docs/reference/errors.mdx) note the new rule under exit codes; changeset added.

This covers both producers of cleanup: "failed": stopVideo for a required recording (packages/e2e/src/run/execute.ts) and the session-close path, plus the standalone attempt's close. Best-effort recordings still fail quietly by design.

Verified

Ran it locally: yes, at the unit level (a real video-finalization failure needs a browser; the regression test drives the exact record shape from the issue: status: "passed", cleanup: "failed", a CLEANUP_TIMEOUT cleanup-phase secondary error).

  • New packages/e2e/tests/unit/runner-exit-codes.test.ts (8 tests): all fail on main, all pass here.
  • Full unit suite: 185 files, 2750 tests, 0 failures.
  • tsc --noEmit: no new errors (only the pre-existing @e2e-dev/web resolution errors this env has on main); oxlint: clean.
main this branch
passed attempt + failed required-video cleanup folds to 0 folds to 3 (infrastructure), run status error

Closes #1231

View guided diff

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 4 files

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

View guided diff | Re-trigger cubic

Comment thread packages/e2e/src/run/runner.ts Resolved
Comment thread docs/reference/errors.mdx Resolved
@Varshith-Kali

Copy link
Copy Markdown
Contributor Author

Hi, this PR is ready for review. Its CI runs are parked at the first-time-contributor approval gate (action_required), so the checks cannot start until a maintainer approves the run. Could you approve it when you have a moment? Thanks!

@okwasniewski okwasniewski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Varshith-Kali. Exit 3 here is the right call: docs/reference/cli.mdx (exit-code table) already lists "artifact, or cleanup infrastructure failure" under 3, so the run was breaking its own documented contract. The fold is small and covers serial groups too. Two things block it, though.

Must fix

  1. The PR breaks an existing integration test, and fork CI hasn't run yet, so nothing caught it. packages/e2e/tests/integration/engine-contract.test.ts:491 ("a failing endAttempt marks cleanup failed ... but keeps the test passed") asserts outcome.exitCode is 0 at line 507. On this branch it gets 3 (expected 3 to be +0). With the runner.ts change reverted and dist rebuilt, it passes. Flip that assertion to 3 and rename the test so it states the new contract. Note that integration tests run against dist, so build e2e and @e2e-dev/web before you run them.

  2. The terminal still says everything passed, and then the process exits 3. I ran a fake-engine project whose endAttempt throws, with the list reporter on. The output was ✓ taps a node, Test Files 1 passed, Tests 1 passed, then exit 3 with nothing explaining why. report.json has run.status: "error". A CI user sees a red job under a green summary. Please make the list reporter show the cleanup failure (code + message) under the passed test or in the summary (packages/e2e/src/report/list.ts), and add an integration test that checks the output.

  3. verdictExitCodes is exported only so the new unit test can import it (packages/e2e/src/run/runner.ts:1264). AGENTS.md: "An export whose only consumer is a test is dead production API - make it module-private or move it." The integration test from point 1 already pins this behavior through the real runner. Please keep the function private and drop tests/unit/runner-exit-codes.test.ts, or replace it with a fake-engine integration test where a required video's stop fails (createFakeEngine({ video: true, ... }) with video: 'on'), which is the exact #1231 scenario.

Nits

  1. runner.ts:1284: the cleanupErrors.length === 0 fallback can't fire. Every place that sets cleanup = 'failed' on the run path also pushes a phase: 'cleanup' secondary error (execute.ts closeSession and stopVideo). Dropping the branch leaves one loop: push exitCodeForCategory(error.category) for each cleanup-phase secondary error of an attempt whose cleanup === 'failed'. The "no recorded secondary error" unit test builds a record the runner never produces.
  2. runner.ts:1257-1263: the new JSDoc paragraph argues the design. Shorten it to one line, e.g. "An attempt whose cleanup failed adds its cleanup errors' codes, even when the test passed."
  3. docs/reference/errors.mdx:44-48: per the docs style, keep it to what users need, e.g. "A passed test whose cleanup failed (a required video that was not finalized, a session that did not close) exits with that cleanup error's code, usually 3." Drop the "its loss is not a success" rationale.
  4. tests/unit/runner-exit-codes.test.ts:3 uses an em dash. Use a plain hyphen.
  5. The changeset is fine as a patch. Two sentences are enough: what changed and what it means for CI.

For the maintainer

  • With this change a flaky result (documented as exit 0) exits 3 if an earlier, failed attempt lost its required video. The loop covers every attempt, not just the final one. That matches "a requested artifact was lost", but please confirm it's intended.

This was an automated review.

Varshith-Kali added a commit to Varshith-Kali/e2e that referenced this pull request Oct 26, 2026
The CHANGES_REQUESTED review on e2e-inc#1233 asked for eight changes, all implemented here.

The endAttempt integration test now asserts exit 3 and is renamed to state the new contract. The list reporter shows each cleanup failure (code and message) under its passed or flaky test and adds a Cleanup row to the final summary, so a run that exits 3 no longer prints a green summary. verdictExitCodes is module-private again and its unit test is gone, replaced by a fake-engine integration test in which a required video's stop fails, the exact e2e-inc#1231 scenario; the fake engine gained an onStopVideo hook to make that failure expressible. The unreachable no-secondary-error fallback is dropped, leaving one loop over the cleanup-phase secondary errors of every attempt whose cleanup failed. The JSDoc paragraph is one line, the errors.mdx paragraph keeps to what users need, and the changeset is two sentences as a patch.

Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
@mintlify

mintlify Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 3b19749.

Approve preview

The exit-code fold only looked at verdict statuses and run errors, so a
run whose tests all passed but whose required video could not be
finalized exited 0 with the report's attempt-level cleanup failure as the
only trace. A cleanup failure is an artifact/infrastructure failure the
run asked for: verdictExitCodes now folds in the cleanup-phase secondary
error's category (infrastructure, exit 3, when the record carries none),
for ordinary and serial-group attempts alike. Forced cleanups stay on
the interrupt's code.

Closes e2e-inc#1231

Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
…irst

verdictExitCodes used find() for the cleanup-phase secondary error, so when
an attempt recorded more than one (a required video that would not finalize
plus a session that would not close), a later higher-precedence category
such as internal was dropped before combineExitCodes ran. Fold in each
cleanup error's category instead, keeping the infrastructure fallback when
the record carries none. Adds a regression test for the multi-error case.

Also corrects the exit-code reference: the run exits with the cleanup
error's category code, defaulting to 3, rather than unconditionally 3.

Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
The CHANGES_REQUESTED review on e2e-inc#1233 asked for eight changes, all implemented here.

The endAttempt integration test now asserts exit 3 and is renamed to state the new contract. The list reporter shows each cleanup failure (code and message) under its passed or flaky test and adds a Cleanup row to the final summary, so a run that exits 3 no longer prints a green summary. verdictExitCodes is module-private again and its unit test is gone, replaced by a fake-engine integration test in which a required video's stop fails, the exact e2e-inc#1231 scenario; the fake engine gained an onStopVideo hook to make that failure expressible. The unreachable no-secondary-error fallback is dropped, leaving one loop over the cleanup-phase secondary errors of every attempt whose cleanup failed. The JSDoc paragraph is one line, the errors.mdx paragraph keeps to what users need, and the changeset is two sentences as a patch.

Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
@Varshith-Kali
Varshith-Kali force-pushed the fix/cleanup-failure-exit-code-1231 branch from fc85df1 to 19e55fe Compare October 26, 2026 01:11
@Varshith-Kali

Copy link
Copy Markdown
Contributor Author

Thanks for the review. All eight points are addressed in 19e55fe. One note on the push: main had moved since the last head, so I rebased onto current main. The rebase resolved a single conflict hunk in list.ts, keeping both upstream's new Left out field and this change's new Cleanup field; nothing else in the change was altered by it.

  1. Fixed: the engine-contract test now asserts exit 3, and is renamed to "a failing endAttempt marks cleanup failed with a secondary error and exits 3 even though the test passed".
  2. Fixed: the list reporter prints a yellow glance line under a passed or flaky test, e.g. "cleanup failed: ENGINE_FAILURE: attempt end failed: close exploded", and adds a Cleanup row to the final summary naming the failure and its code. A new test in list-reporter.test.ts captures stdout and asserts both lines plus exit 3. The Test Files and Tests counters still say passed, which is accurate: the test passed, its cleanup failed, and the Cleanup row is what explains the exit code.
  3. Chose the replacement option: verdictExitCodes is module-private again, tests/unit/runner-exit-codes.test.ts is deleted, and the behavior is pinned by a new fake-engine integration test where a required video's stop fails (createFakeEngine({ video: true }) with run video "on"). That needed a small onStopVideo hook in the fake-engine test helper, since the helper previously had no way to fail stopVideo. The new test asserts status passed, cleanup failed, a cleanup-phase secondary error, and exit 3.
  4. Fixed: the cleanupErrors.length === 0 fallback is gone. One loop now pushes exitCodeForCategory for each cleanup-phase secondary error of an attempt whose cleanup failed. I verified execute.ts closeSession and stopVideo both push a phase "cleanup" secondary error whenever they set cleanup to failed.
  5. Fixed: the JSDoc paragraph is now one line: "An attempt whose cleanup failed adds its cleanup errors' codes, even when the test passed."
  6. Fixed: errors.mdx now reads: "A passed test whose cleanup failed (a required video that was not finalized, a session that did not close) exits with that cleanup error's code, usually 3." The "its loss is not a success" rationale is dropped.
  7. Moot: the file is deleted, and none of the lines added by this change use an em dash (checked).
  8. Fixed: the changeset stays a patch and is now two sentences: what changed, and what it means for CI (the reporter names the missing artifact instead of printing a green summary).

For the maintainer, confirming explicitly: yes, the loop covering every attempt, not just the final one, is intended. verdictExitCodes iterates every attempt of every verdict, so a flaky result whose earlier failed attempt lost its required video exits 3, matching "a requested artifact was lost". The earlier attempt's cleanup failure is a cleanup-phase secondary error on that attempt, and the fold picks it up exactly like a final attempt's.

Verified locally against fresh dist builds of e2e and @e2e-dev/web: typecheck clean, oxlint clean, report-list unit 80 passed, list-reporter integration 2 passed, engine-contract integration 43 passed.

The cleanup fold covers every attempt, so a skipped test whose
endAttempt throws is a run level infrastructure failure, not a
passing run. The test keeps asserting the result stays skipped.

Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
@Varshith-Kali

Copy link
Copy Markdown
Contributor Author

Thanks, this was the same miss as point 1, in a second file. The missed test is tests/integration/skip-after-failure.test.ts, formerly "does not turn post-skip cleanup diagnostics into a test failure": a clean skip with failOnSkippedFailure: true whose engine endAttempt throws.

Decision: update the test, not the fold. The fold in verdictExitCodes sits outside the verdict status switch and covers every attempt whose cleanup is failed, and closeSession marks any endAttempt throw that way with a phase cleanup secondary error. A skipped test whose session did not close is the same case as the passed test in point 1, and the exit code table lists cleanup infrastructure failure under 3 without qualifying it by verdict. Exit 3 here is a run level failure, not a test failure: the result stays skipped and no "Skipped After Failure" section appears.

Change in d8307a6: renamed the test to "exits 3 when a skipped test cleanup fails, keeping the test skipped", flipped the assertion from 0 to 3, and added an assertion that the result status stays skipped. I also checked the other tests that pin a failed cleanup: the engine-contract passed test and the required video test already assert 3, and no other test asserts exit 0 under a cleanup failure.

Verified locally against the built dist (which already carries the fold, so no rebuild was needed): skip-after-failure.test.ts 7/7 passed, engine-contract.test.ts 43/43 passed, oxlint clean on the changed file. CI on the new head is pending.

@okwasniewski

Copy link
Copy Markdown
Member

Thanks @Varshith-Kali. All 8 points from the last review are in at d8307a6. CI is fully green.

What I checked:

  • The skip-after-failure.test.ts change is sound. The test now expects exit 3, which was 0 before. It still asserts that the result stays skipped and that the output has no "Skipped After Failure". I made failureBeforeSkip count cleanup errors (records.ts, run.secondaryErrors[0]) and the test failed on the "Skipped After Failure" output check, so the fix(runner): preserve failures when tests skip #741 guard still holds.
  • I reverted the runner.ts fold and rebuilt. 4 tests failed: list-reporter, engine-contract endAttempt, the Run exits 0 with passed tests when requested video fails cleanup #1231 video stop test and skip-after-failure. Restored, all 52 tests in those three suites pass. pnpm check is clean.

Nits

  1. The cleanup-error predicate exists twice: cleanupErrorsOf in packages/e2e/src/report/list.ts:141 and the loop in packages/e2e/src/run/runner.ts:1410-1415. Please move one cleanupErrorsOf(attempts) into run/records.ts, next to failureBeforeSkip, and use it in both places.
  2. runner.ts:1388-1390: the old paragraph is still there next to the new line at 1391. Keep just the one line.
  3. docs/reference/errors.mdx:44 and the changeset say "A passed test". Since d8307a6, a skipped test whose cleanup failed also exits 3, so "A test whose cleanup failed ..." is more accurate.
  4. list.ts:902-905: the cleanupLines JSDoc explains the reasoning. One line saying what it renders is enough.

This was an automated review.

@okwasniewski okwasniewski added the Ready for Human Review Green, conflict-free, every thread handled. Waiting on a maintainer. label Oct 26, 2026
@okwasniewski
okwasniewski dismissed their stale review October 26, 2026 22:14

All asks addressed at d8307a6 (automated review).

Address review nits on e2e-inc#1233: move cleanupErrorsOf into run/records.ts next to failureBeforeSkip and use it in both the list reporter and verdictExitCodes; drop the stale JSDoc paragraph in runner.ts; fix the passed-test wording in errors.mdx and the changeset since a skipped test whose cleanup failed also exits 3; trim the cleanupLines JSDoc to one line.

Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
@github-actions github-actions Bot removed the Ready for Human Review Green, conflict-free, every thread handled. Waiting on a maintainer. label Oct 27, 2026
@Varshith-Kali

Copy link
Copy Markdown
Contributor Author

All 4 nits are in at 06ca585:

  1. cleanupErrorsOf now lives in run/records.ts next to failureBeforeSkip, and both the list reporter and verdictExitCodes use it.
  2. The stale paragraph is gone from the verdictExitCodes doc comment; only the one line remains.
  3. errors.mdx and the changeset now say a test whose cleanup failed, since a skipped test with a failed cleanup also exits 3.
  4. The cleanupLines doc comment is one line.

Verified: skip-after-failure integration suite 7/7 green, e2e unit suite 200 files / 3034 tests green, oxlint clean on the touched files. The package typecheck shows the same 5 pre-existing @e2e-dev/web resolution errors as the base head, none in the touched files.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 5 files (changes from recent commits).

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

View guided diff | Re-trigger cubic

Comment thread .changeset/cleanup-failure-exit-code.md Resolved
Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
@Varshith-Kali

Copy link
Copy Markdown
Contributor Author

Replying to the cubic P3 on the changeset (review 5661122207): fixed as 6ce8945. The changeset now says a CI job that goes red names the cleanup failure instead of reporting a green summary. You were right that not every cleanup failure on this path is a missing artifact (session-close and other engine cleanup errors take the same path), so the note no longer implies that.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name=".changeset/cleanup-failure-exit-code.md">

<violation number="1" location=".changeset/cleanup-failure-exit-code.md:5">
P3: The changeset overstates list-reporter output for skipped tests: their cleanup failure appears in the summary but not under the test row. Say this is shown under passed or flaky tests, or update the reporter to render cleanup lines for skipped tests.</violation>
</file>

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

View guided diff | Re-trigger cubic

Comment thread .changeset/cleanup-failure-exit-code.md Outdated
"e2e": patch
---

A run now exits with the cleanup error's code, usually 3, when a test's cleanup failed. The list reporter shows the cleanup failure under the test and in the summary, so a CI job that goes red names the cleanup failure instead of reporting a green summary.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The changeset overstates list-reporter output for skipped tests: their cleanup failure appears in the summary but not under the test row. Say this is shown under passed or flaky tests, or update the reporter to render cleanup lines for skipped tests.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At .changeset/cleanup-failure-exit-code.md, line 5:

<comment>The changeset overstates list-reporter output for skipped tests: their cleanup failure appears in the summary but not under the test row. Say this is shown under passed or flaky tests, or update the reporter to render cleanup lines for skipped tests.</comment>

<file context>
@@ -2,4 +2,4 @@
 ---
 
-A run now exits with the cleanup error's code, usually 3, when a test's cleanup failed. The list reporter shows the cleanup failure under the test and in the summary, so a CI job that goes red names the missing artifact instead of reporting a green summary.
+A run now exits with the cleanup error's code, usually 3, when a test's cleanup failed. The list reporter shows the cleanup failure under the test and in the summary, so a CI job that goes red names the cleanup failure instead of reporting a green summary.
</file context>
Suggested change
A run now exits with the cleanup error's code, usually 3, when a test's cleanup failed. The list reporter shows the cleanup failure under the test and in the summary, so a CI job that goes red names the cleanup failure instead of reporting a green summary.
A run now exits with the cleanup error's code, usually 3, when a test's cleanup failed. The list reporter shows the cleanup failure under passed or flaky tests and in the summary, so a CI job that goes red names the cleanup failure instead of reporting a green summary.

…y tests

Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
@Varshith-Kali

Copy link
Copy Markdown
Contributor Author

Fixed, thanks. The finding was real: the changeset claimed the cleanup failure shows "under the test and in the summary", but the list reporter only renders cleanup lines under passed and flaky rows (testLine in packages/e2e/src/report/list.ts), while skipped rows render no cleanup lines. The summary line does cover every status, since testFinished records cleanup failures regardless of status.

Fixed as 3b19749: the changeset now says the reporter shows the cleanup failure "in the summary and under the test for passed and flaky tests". No code change, the wording now matches the reporter exactly.

@okwasniewski

Copy link
Copy Markdown
Member

Thanks @Varshith-Kali. I re-checked at 3b19749 and all 4 nits are done:

  1. cleanupErrorsOf now lives once in packages/e2e/src/run/records.ts:212, and runner.ts and list.ts both use it. The runner loop gives the same result as before.
  2. The old verdictExitCodes paragraph is gone.
  3. docs/reference/errors.mdx:44 and the changeset now say "A test whose cleanup failed". The changeset also matches what the reporter shows: the cleanup line goes under passed and flaky tests, and every status gets it in the summary.
  4. The cleanupLines JSDoc is down to one line.

CI is fully green. Nothing left from my side.

This was an automated review.

@okwasniewski okwasniewski added the Ready for Human Review Green, conflict-free, every thread handled. Waiting on a maintainer. label Oct 27, 2026
@Varshith-Kali

Copy link
Copy Markdown
Contributor Author

Thanks for re-checking, and for confirming CI is fully green with nothing left from your side. The PR is ready on my side whenever you want to take it forward.

@okwasniewski
okwasniewski merged commit 34287cf into e2e-inc:main Oct 28, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for Human Review Green, conflict-free, every thread handled. Waiting on a maintainer.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Run exits 0 with passed tests when requested video fails cleanup

2 participants