fix(core): cancel running calls by name when a session closes

Merged
OK
8d ago
+181-18
  • Closing an @e2e-dev/core session or host while calls still run on it is how a program cancels. Core treated it as a missing await, because launchAttempt ran the runner's abandonRunning() for core sessions too.
  • Each running step now fails with CANCELLED and a message that names it, with the stack of the call. close() does not fail for them.
  • Only a session opened with cancelsOnClose takes the new path, which is core's launch (packages/core/src/run/standalone-attempt.ts). Runner attempts and MCP sessions keep STEP_NOT_AWAITED.
  • StepRecorder.nameRunning(reason, error) registers each running step's error right before the abort. A step that failed on its own, or that another abort reached first, keeps that failure.
const open = session.app.open('/slow');
await session.close(); // resolves
await open; // CANCELLED: the session closed while app.open "/slow" was running

Why

A nightly report showed a program dying with a bare E2EError: the session is closed and blamed a concurrent launch() of two engines. Hosts turned out to be independent: the report's script passed 8 of 8 runs here, and a failing mobile launch left a concurrent web session untouched. The trace is what a call left running at session disposal produces, and it named neither the call nor its line.

For the reviewer to decide

A call that nothing awaits rejects unhandled when its session closes, so Node.js ends the program during the close and the host is never disposed.

  • On main that already happened for calls an async method wraps (waitFor, scrollUntilVisible).
  • For calls that return the step's own promise (tap, app.open), main observed the rejection, finished the close, and threw the test body returned before ... finished from close(). This PR makes them end the program too, with the named error.
  • Keeping the old behavior for those calls means close() fails on every deliberate cancel, Ctrl-C included.
  • The alternative that keeps teardown is what the runner does: an unhandledRejection listener while a host is open. It is a process-wide hook in a library, so it is not in this PR.

Not in this PR

  • Reads (textContent(), count()) and saveState() are not steps. One cut mid-flight still fails with operation cancelled.
  • A program with no finally and no await using around a running call still exits 1 on Ctrl-C without disposing its host, as on main.

Verified

Ran it locally: yes

  • Scratch programs on the built packages, @e2e-dev/web on Chromium against https://books.toscrape.com, each run on main and on this branch.
  • The new tests in core.test.ts, core-signals.test.ts, and step-name-running.test.ts fail on main and pass here.
Programmainthis branch
await using session, locator.waitFor() not awaitedE2EError: the session is closed at Object.closed (launch.js:141), exit 1E2EError: the session closed while locator.waitFor "getByText("this text is not on the page") → visible" was running at runWeb (signature3.ts:20), exit 1
app.open("/") awaited, session.close() called 300 ms inopen: CANCELLED the session is closed; close throws the test body returned before app.open "/" finished; put await in front of every step callopen: CANCELLED the session closed while app.open "/" was running; close resolves
SIGINT during an awaited app.open("/")stderr @e2e-dev/core: closing a host on SIGINT failed: closing the host failed: the test body returned before app.open "/" finished; ..., exit 130empty stderr, exit 130