Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/app-command-exit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"e2e": patch
---

Fail `e2e run` when an app command exits unexpectedly after readiness.
Report its exit code or signal and redacted log tail.
Interrupt active tests and skip queued tests only for targets that depend on that command.
Ignore command exits after those targets finish their work.
Comment thread
samanyudas marked this conversation as resolved.
Resolved
An exit with code 0 also fails the run, so a command that starts the app in the background and then exits, such as `docker compose up -d --wait`, now fails.
Keep the app in the foreground instead, for example `docker compose up` without `-d`.
22 changes: 15 additions & 7 deletions docs/reference/config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -518,14 +518,22 @@ command: {
is dropped.
- `startupTimeout` is the budget of the [`readyUrl`](#readyurl) probe.
- `shutdownTimeout` is the grace period before force-kill.
- In `e2e run`, a command that exits after readiness fails the run with `APP_UNREACHABLE` if a dependent target has unfinished work.
This includes exit code 0 and termination by a signal.
The runner interrupts active tests and skips queued tests only for those targets.
Targets that have finished their work ignore the exit.
- `log` receives the process's stdout and stderr, appended, resolved from the
project root. It must stay inside the project root.
- With a `log`, a failure after the command started quotes the lines any
process appended since then, with `command.env` and `inheritEnv` values of
at least four characters replaced by `<secret:NAME>` markers. A log of up to
40 lines inside 8 KiB is quoted whole. Otherwise the quote keeps up to 20
lines from each end, with `[startup output omitted]` between them, and for a
log past 8 KiB those lines come from its first and last 4 KiB.
- With a `log`, startup timeouts and command exits quote the lines appended
since the command started. A log of up to 40 lines inside 8 KiB is quoted
whole. Otherwise the quote keeps up to 20 lines from each end, with
`[startup output omitted]` between them, and for a log past 8 KiB those
lines come from its first and last 4 KiB.
An empty or unreadable log produces `no output in <log>`.
A shared log can include lines from other processes.
The quote replaces `command.env` and `inheritEnv` values of at least 4 characters with `<secret:NAME>` markers.
Without `log`, these errors ask you to set one.
A command that fails to spawn reports the spawn error instead.
- `reuseExisting`: when the readiness URL already answers before the command
starts, the runner uses that process. It starts nothing and stops nothing.
CI ignores it, with a notice, and always starts the command.
Expand All @@ -540,7 +548,7 @@ command: {
| `INVALID_CONFIG` | `reuseExisting` on an app whose `url` asks for port 0: a process already running cannot serve the port the run assigns. |
| `APP_URL_REQUIRED` | An `app.command` with neither `app.url` nor `app.readyUrl`, at config load. |
| `APP_ALREADY_RUNNING` | Without `reuseExisting`, a `readyUrl` that already answers. |
| `APP_UNREACHABLE` | `startupTimeout` expires. |
| `APP_UNREACHABLE` | The command fails to spawn, its `log` cannot be opened, `startupTimeout` expires, the command exits before readiness, or it exits unexpectedly during `e2e run`. |

<Warning>
`log` holds the raw, unredacted output. Keep it in an ignored directory.
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/errors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ category a blocked verdict reports as the obstacle.
| `AUTOMATION_UNSUPPORTED` | The step needs an interaction the available toolset cannot perform, such as drag-and-drop (blocked: automation) | test | 1 |
| `MODEL_UNAVAILABLE` | No model configured: the built-in agent's `agents.<name>.model` holds no AI SDK model instance (the message names the selected agent), or GitHub Copilot does not serve the configured model to this account (`model_not_supported`; the message names the model). Recorded once as a run-level error, and the run stops. In a test run, a missing model is found when the `agent` fixture is first acquired, and an unserved model at its first call. `e2e explore` runs the built-in agent, so it checks for a missing model before anything starts, a custom executor's entry included. A custom executor without a model is not checked: its `act` and `assert` steps run, and `waitFor` or `extract` fails with this code on its first call. Evicts no [recording](/cache). | configuration | 2 |
| `POLICY_DENIED` | The security policy refused an operation: a denied destination, a forbidden fill, `vision: 'only'` without pixels, or a read from a secure field. [Policy denials](/reference/security#policy-denials) lists every case. An unknown tool or an undeclared field goes back to the model as the call's result, never as this code | configuration | 2 |
| `APP_UNREACHABLE` | The app URL could not be reached, or an app command exited early or exceeded `startupTimeout`. With a `log`, the startup error quotes the log's output since the command started, `command.env` values redacted, or says there was none. The quote keeps the first and last lines of a long log, with `[startup output omitted]` between them. Without a `log`, the message says to set one. A command that fails to spawn reports the spawn error. Under the agent, also any engine fault with no more specific code. On a device, a busy or wedged iOS automation runner reports here; the message names the runner, the session and device, and the recovery. See [Mobile](/mobile#troubleshooting) | infrastructure | 3 |
| `APP_UNREACHABLE` | The app URL could not be reached, or an app command exited or exceeded `startupTimeout`. An exit after readiness during `e2e run` interrupts active tests and skips queued tests only for dependent targets with unfinished work. See [app commands](/reference/config#command) for diagnostics. Under the agent, also any engine fault with no more specific code. On a device, the message can identify a busy or wedged iOS automation runner and its recovery. See [Mobile](/mobile#troubleshooting). | infrastructure | 3 |
| `APP_ALREADY_RUNNING` | `readyUrl` answered before the target's `app.command` was spawned, and `reuseExisting` was not in effect. Stop that process, or set `reuseExisting: true` locally | infrastructure | 3 |
| `MODEL_PROVIDER_FAILED` | Provider transport failure (network error, 5xx, rate limit, or no response within 120 s) after the adapter's transport retries: up to 5 per model call, honoring `retry-after`, within the remaining step timeout. A stalled request is aborted at 120 s and sent again; an `agent.act` step's `--debug` transcript notes it. The 120 s covers the whole request, so a model that needs longer for one answer fails here too. An error body the provider package cannot read shows as the HTTP status and the body, secrets redacted, cut at 1 KB. Also a call the provider ended on an `error` finish, whatever text came with it, and an `e2e doctor --check-model` call with no answer within 1 minute. Evicts no [recording](/cache) | infrastructure | 3 |
| `CANCELLED` | The runner cancelled the operation without a process signal: an `e2e mcp` `open_session` cut short by a client cancel, a closed connection, or the server's shutdown, after it stopped what it had started, or a `run_tests` cancelled before it started or called while the server shuts down | infrastructure | 3 |
Expand Down
2 changes: 1 addition & 1 deletion docs/web.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ variables, `inheritEnv`, and `env`.
| Option | Purpose |
| --- | --- |
| `reuseExisting: true` | Use a server that already runs, such as one an [MCP session](/mcp-server#run-tests-next-to-a-session) started. In CI, e2e ignores it, and a server that already answers is `APP_ALREADY_RUNNING`. |
| `log` | Save the app's stdout and stderr to a project-relative file. A startup error quotes the lines any process appended to the file since the command started. A log of up to 40 lines inside 8 KiB is quoted whole; otherwise the quote keeps up to 20 lines from each end, with `[startup output omitted]` between them, and for a log past 8 KiB those lines come from its first and last 4 KiB. `command.env` and `inheritEnv` values of at least four characters are redacted from the quote. The file itself is not redacted. |
| `log` | Save the app's stdout and stderr to a project-relative file. A startup error, or an unexpected exit during `e2e run`, quotes the lines any process appended to the file since the command started. A log of up to 40 lines inside 8 KiB is quoted whole; otherwise the quote keeps up to 20 lines from each end, with `[startup output omitted]` between them, and for a log past 8 KiB those lines come from its first and last 4 KiB. `command.env` and `inheritEnv` values of at least four characters are redacted from the quote. The file itself is not redacted. |
| `env` | Environment variables for the app. |
| `inheritEnv` | Host variables to pass through when set, by name or prefix: `['DATABASE_URL', 'STRIPE_*']`. `env` wins over them. |
| `startupTimeout` | How long to wait for the app to answer. Default 60 seconds. |
Expand Down
13 changes: 7 additions & 6 deletions packages/e2e/src/run/declared-processes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@ export interface DeclaredCommand {
readonly readyUrl: string;
/** The command's identity: how it spawns, not where it is probed. A URL declared with port 0 spawns with its allocated port, so each allocation is its own. */
readonly key: string;
/** Every target whose work depends on this command. */
readonly targetNames: readonly string[];
}

/** Every distinct app command in target order; identity is the command alone, not where it is probed. */
export function declaredCommands(targets: readonly ResolvedTarget[]): readonly DeclaredCommand[] {
const commands: DeclaredCommand[] = [];
const keys = new Set<string>();
const commands = new Map<string, DeclaredCommand & { targetNames: string[] }>();
for (const target of targets) {
const { command, readyUrl } = target.app;
if (command === undefined || readyUrl === undefined) continue;
const key = canonicalDigest(command);
if (keys.has(key)) continue;
keys.add(key);
commands.push({ label: `target "${target.name}" command`, command, readyUrl, key });
const existing = commands.get(key);
if (existing !== undefined) existing.targetNames.push(target.name);
else commands.set(key, { label: `target "${target.name}" command`, command, readyUrl, key, targetNames: [target.name] });
}
return commands;
return [...commands.values()];
}
22 changes: 14 additions & 8 deletions packages/e2e/src/run/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
} from '../locator/screen.ts';
import { engineAppInfo } from '../config/app.ts';
import type { ResolvedAgentConfig, ResolvedConfig, ResolvedTarget } from '../config/resolve.ts';
import type { Agent, App, Expectable, RecordingOptions, SetupSession, TestFixtures } from '../types.ts';
import type { Agent, App, CommandConfig, Expectable, RecordingOptions, SetupSession, TestFixtures } from '../types.ts';
import type { StepRecord, StepRecorder } from './steps.ts';

export interface ArtifactSink {
Expand Down Expand Up @@ -450,17 +450,23 @@ const NOTHING_LISTENING =
/ERR_CONNECTION_REFUSED|ECONNREFUSED|ERR_NAME_NOT_RESOLVED|ENOTFOUND|ERR_ADDRESS_UNREACHABLE|EHOSTUNREACH|ERR_CONNECTION_TIMED_OUT|ETIMEDOUT/;

/**
* A navigation the network refused means the app is down, which is the
* first thing a new project runs into and the last thing an engine failure
* message suggests. Named by its own code, with the URL and the three ways
* to fix it.
* Adds a recovery hint to navigation connection errors using the target's
* command configuration. A `reuseExisting` command may have attached to a
* process the runner did not start, whose output `app.command.log` never
* holds, so its hint does not promise that output.
*/
function unreachableApp(cause: unknown, url: string): InfrastructureError | undefined {
function unreachableApp(cause: unknown, url: string, command: CommandConfig | undefined): InfrastructureError | undefined {
const match = NOTHING_LISTENING.exec(errorMessage(cause));
if (match === null) return undefined;
const hint =
command === undefined
? "start the app there, point the target's app.url at where it runs, or give the target an app.command so the runner starts it"
: command.reuseExisting === true
? "check that the process serving the target's app.url still runs. With reuseExisting the runner may use a process it did not start, and app.command.log captures only a command the runner started"
: "check the target's app.command output and app.url. Set app.command.log if output is not captured";
return new InfrastructureError(
'APP_UNREACHABLE',
`nothing answered at ${url} (${match[0]}); start the app there, point the target's app.url at where it runs, or give the target an app.command so the runner starts it`,
`nothing answered at ${url} (${match[0]}); ${hint}`,
{ cause },
);
}
Expand All @@ -475,7 +481,7 @@ function createApp(environment: AttemptEnvironment, engine: LocatorEngine): App
try {
await engine.session.app.open(resolved, engine.operation(timeoutMs));
} catch (cause) {
throw unreachableApp(cause, resolved) ?? cause;
throw unreachableApp(cause, resolved, target.app.command) ?? cause;
}
};

Expand Down
11 changes: 11 additions & 0 deletions packages/e2e/src/run/managed-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ export interface ManagedProcessHooks {
readonly starting?: (label: string, url: string | undefined) => void;
/** `reused` when the process attached to one already serving the URL instead of spawning. */
readonly ready?: (label: string, url: string | undefined, durationMs: number, reused: boolean) => void;
/** The owned command exited after URL readiness and before `stop` was requested. */
readonly unexpectedExit?: (cause: InfrastructureError) => void;
}

/**
Expand All @@ -155,6 +157,7 @@ export interface ManagedProcessHooks {
*/
export class ManagedProcess {
private child: ChildProcess | null = null;
private watching = false;
private reusedExisting = false;
private spawnedProcess = false;
/** Hides `command.env` and `inheritEnv` values in a quoted startup failure; built at spawn. */
Expand Down Expand Up @@ -268,6 +271,11 @@ export class ManagedProcess {
child.once('exit', (code, exitSignal) => {
exit = { code, signal: exitSignal };
resolve();
const unexpected = this.watching;
this.watching = false;
if (unexpected) {
this.hooks.unexpectedExit?.(this.unreachable(`${this.label} ${describeExit(exit)} after becoming ready`, logOffset));
}
});
});

Expand Down Expand Up @@ -318,6 +326,8 @@ export class ManagedProcess {
readyUrl !== undefined &&
(await answers(readyUrl, Math.min(READY_PROBE_TIMEOUT_MS, remaining, untilHalf), signal))
) {
if (exit !== undefined || aborted()) continue;
this.watching = true;
return;
}
// The exit event wakes the wait early so an exit is seen at once, not on the next poll.
Expand Down Expand Up @@ -419,6 +429,7 @@ export class ManagedProcess {
/** Gracefully terminates the whole process group, then force-kills. A reused process was never ours to stop. */
async stop(): Promise<void> {
if (this.reusedExisting) return;
this.watching = false;
const child = this.child;
this.child = null;
if (child === null) return;
Expand Down
14 changes: 10 additions & 4 deletions packages/e2e/src/run/provision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ export class PreparedEngines {
}

/** The hooks the app commands report through; a run narrates each as a setup step. */
export type ProcessHooks = () => ManagedProcessHooks;
export interface ProcessHooks extends Omit<ManagedProcessHooks, 'unexpectedExit'> {
/** An owned app command exited; every declaring target depends on it. */
readonly commandExited?: (targetNames: readonly string[], cause: InfrastructureError) => void;
}

/**
* Starts every distinct app command the targets declare, in target order,
Expand All @@ -240,12 +243,15 @@ export async function startDeclaredProcesses(
},
};
// A cleanup failure after a failed start is a notice at most: the startup failure is the one reported.
const onCleanupFailure = (failure: unknown): void => hooks().notice?.(`cleanup after a failed start: ${String(failure)}`);
const onCleanupFailure = (failure: unknown): void => hooks.notice?.(`cleanup after a failed start: ${String(failure)}`);
try {
for (const { label, command, readyUrl, key } of declaredCommands(targets)) {
for (const { label, command, readyUrl, key, targetNames } of declaredCommands(targets)) {
if (signal.aborted) return processes;
const start = async (scope: AbortSignal): Promise<AppProcesses> => {
const app = new ManagedProcess(label, command, projectRoot, { readyUrl }, hooks());
const app = new ManagedProcess(label, command, projectRoot, { readyUrl }, {
...hooks,
unexpectedExit: (cause) => hooks.commandExited?.(targetNames, cause),
});
const stop: AppProcesses['stop'] = async (onFailure) => {
try {
await app.stop();
Expand Down
Loading
Loading