mirror of
https://github.com/tester-army/e2e.git
synced 2026-12-04 04:56:00 +08:00
feat(run): run every test n times with --repeat-each (#391)
`e2e run --repeat-each <n>` (`RunOptions.repeatEach`) runs every selected test that many times. The repeat is a dimension of a pair's identity beside the test, the target, and the agent: `TestTargetPair.repeat`, the wire pair, the pair-start and progress messages, the scheduler's keys, and the report result and serial group all carry it, 0 for the run every test has. The first run's result id is unchanged; later runs get their own, the list reporter, JUnit, and the failure pages title them `(repeat #n)`, and their artifacts go under `repeat-<n>`. Setup tests run once; a filtered or skipped pair is reported once. Run events `test-started` and `step` carry `repeat`. `--last-failed` now keys the previous run's results by test, target, and agent, so a test is named once whichever of its repeats did not pass.
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'e2e': minor
|
||||
---
|
||||
|
||||
`e2e run --repeat-each <n>` (`RunOptions.repeatEach`) runs every selected test that many times. Each run is a result of its own: `repeat` 0 through `n - 1` on the report result and serial group (0 on every report from now on), an `id` that stays the same for the first run and differs for the later ones, a `(repeat #n)` suffix in the list reporter, JUnit, and the failure pages, and artifacts under a `repeat-<n>` directory. Setup tests run once. Run events `test-started` and `step` carry `repeat`. `--last-failed` names a test once whichever of its repeats did not pass.
|
||||
@@ -32,7 +32,7 @@ agent calls.
|
||||
| `npx playwright test tests/checkout.spec.ts:12` | `npx e2e run tests/checkout.e2e.ts:12`, the test whose `test(` call opens on that line |
|
||||
| `--project chromium` | `--target web`, the name in `targets` |
|
||||
| `--grep`, `--grep-invert` | The same, matched against the describe titles and the test title joined by spaces; tags are `--tag` and `--exclude-tag` |
|
||||
| `--headed`, `--workers`, `--retries`, `--pass-with-no-tests`, `--last-failed`, `--shard`, `--max-failures` | The same names; `--shard` keeps serial groups together |
|
||||
| `--headed`, `--workers`, `--retries`, `--pass-with-no-tests`, `--last-failed`, `--shard`, `--max-failures`, `--repeat-each` | The same names; `--shard` keeps serial groups together |
|
||||
| `--reporter junit` | `--reporter list,junit` |
|
||||
| `--ui`, `--debug` | `npx e2e mcp` gives a coding agent a live session; `--debug` prints timings and the agent step table |
|
||||
|
||||
|
||||
@@ -216,6 +216,7 @@ or every test was filtered out.
|
||||
| `--agent <names>` | comma-separated or repeated | `default` | Runs unpinned tests once per selected agent. For a test with `{ agent }`, selects the shared names when there is overlap; otherwise keeps the test's selection. An unknown name is `INVALID_CONFIG`. |
|
||||
| `--retries <n>` | integer 0-10 | config | Replaces `config.retries`. |
|
||||
| `--workers <n>` | integer 1-1024 | config | Replaces `config.workers`. |
|
||||
| `--repeat-each <n>` | integer, at least 1 | `1` | Runs every selected test this many times. Each run is a result of its own, with `repeat` 0 through `n - 1` and its own `id`; the list reporter titles the later runs `(repeat #1)`, `(repeat #2)`, and their artifacts go under a `repeat-<n>` directory. Setup tests run once. With the trace cache on, the first run records and the later ones replay, so pair it with `--no-cache` to exercise the model each time. |
|
||||
| `--max-failures <n>` | integer, at least 1 | none | Stops the run once this many tests have failed or timed out. Nothing more is dispatched, the tests running end as `interrupted`, and the tests not started are skipped with cause `failure-limit` and the reason `run stopped after 3 failures (--max-failures 3)`. The exit code is the failures' own, 1, not 130. |
|
||||
| `--reporter <ids>` | comma-separated list | config | Replaces the built-in IDs in `config.reporters`: `list`, `json`, `junit`, `markdown`. `json` with `list` is `INVALID_CONFIG`. [Reporter objects](/reference/reporters) in the config keep running. |
|
||||
| `--artifacts <dir>` | string | `.e2e/artifacts` | Relocates the report and artifact tree. |
|
||||
@@ -281,6 +282,7 @@ npx e2e run --last-failed
|
||||
npx e2e run --shard 2/3
|
||||
npx e2e run --reporter json --workers 4 --retries 2
|
||||
npx e2e run --max-failures 3
|
||||
npx e2e run --repeat-each 5 --no-cache tests/checkout.e2e.ts
|
||||
npx e2e run --reporter list,junit
|
||||
```
|
||||
|
||||
|
||||
@@ -79,8 +79,8 @@ type RunEventFact =
|
||||
| { type: 'notice'; target; message }
|
||||
| { type: 'setup'; step: SetupStep; state: 'started' }
|
||||
| { type: 'setup'; step: SetupStep; state: 'finished'; durationMs; outcome?: 'reused' }
|
||||
| { type: 'test-started'; testId; agent; title; file; serialId; target }
|
||||
| { type: 'step'; testId; agent; target; progress: StepProgress }
|
||||
| { type: 'test-started'; testId; agent; repeat; title; file; serialId; target }
|
||||
| { type: 'step'; testId; agent; repeat; target; progress: StepProgress }
|
||||
| { type: 'test-finished'; result: RunEventResult }
|
||||
| { type: 'serial-group'; group: SerialGroupRecord }
|
||||
| { type: 'explore'; progress: ExploreProgress }
|
||||
|
||||
@@ -70,6 +70,7 @@
|
||||
"targetId": "web",
|
||||
"platform": "web",
|
||||
"agent": "default",
|
||||
"repeat": 0,
|
||||
"status": "passed",
|
||||
"attempts": [
|
||||
{
|
||||
@@ -226,6 +227,7 @@
|
||||
"targetId": "web",
|
||||
"platform": "web",
|
||||
"agent": "default",
|
||||
"repeat": 0,
|
||||
"status": "skipped",
|
||||
"attempts": [
|
||||
{
|
||||
|
||||
@@ -422,6 +422,7 @@
|
||||
"targetId": { "type": "string", "minLength": 1 },
|
||||
"platform": { "type": "string", "minLength": 1 },
|
||||
"agent": { "type": "string", "minLength": 1 },
|
||||
"repeat": { "type": "integer", "minimum": 0 },
|
||||
"memberTestIds": { "type": "array", "minItems": 1, "items": { "type": "string", "minLength": 1 }, "uniqueItems": true },
|
||||
"status": { "enum": ["passed", "flaky", "failed", "timed-out", "interrupted", "skipped"] },
|
||||
"skip": { "$ref": "#/$defs/skip" },
|
||||
@@ -462,6 +463,7 @@
|
||||
"targetId": { "type": "string", "minLength": 1 },
|
||||
"platform": { "type": "string", "minLength": 1 },
|
||||
"agent": { "type": "string", "minLength": 1 },
|
||||
"repeat": { "type": "integer", "minimum": 0 },
|
||||
"tags": { "type": "array", "items": { "type": "string", "pattern": "^[^\\s,](?:[^,]*[^\\s,])?$" }, "uniqueItems": true },
|
||||
"serialGroupId": { "type": "string", "minLength": 1 },
|
||||
"status": { "enum": ["passed", "flaky", "failed", "timed-out", "interrupted", "skipped"] },
|
||||
|
||||
@@ -469,6 +469,7 @@ function createProgram(version: string, telemetry: Telemetry): Command {
|
||||
.option('--workers <n>', 'parallel workers (default: from the config)', parseNonNegativeInt)
|
||||
.option('--retries <n>', 'retries per failing test (default: from the config)', parseNonNegativeInt)
|
||||
.option('--max-failures <n>', 'stop the run once this many tests have failed; the rest are skipped', parsePositiveInt)
|
||||
.option('--repeat-each <n>', 'run every selected test this many times, each run its own result (pair with --no-cache to exercise the model each time)', parsePositiveInt)
|
||||
.option('--no-cache', 'run with the trace cache off, whatever the config says')
|
||||
.optionsGroup('Output:')
|
||||
.option('--reporter <ids>', `comma-separated reporters: ${BUILTIN_REPORTERS.join(', ')}`, parseReporters)
|
||||
@@ -491,6 +492,7 @@ function createProgram(version: string, telemetry: Telemetry): Command {
|
||||
'e2e run --shard 2/3',
|
||||
'e2e run --reporter list,junit --workers 4 --retries 2',
|
||||
'e2e run --max-failures 3',
|
||||
'e2e run --repeat-each 5 --no-cache tests/checkout.e2e.ts',
|
||||
'e2e run --agent ux tests/onboarding.e2e.ts',
|
||||
'e2e run --agent buyer,admin tests/checkout.e2e.ts',
|
||||
'AI_GATEWAY_API_KEY=... e2e run --no-cache',
|
||||
@@ -513,6 +515,7 @@ function createProgram(version: string, telemetry: Telemetry): Command {
|
||||
retries?: number;
|
||||
workers?: number;
|
||||
maxFailures?: number;
|
||||
repeatEach?: number;
|
||||
reporter?: Reporter[];
|
||||
artifacts?: string;
|
||||
/** Commander negation: `--no-cache` parses as `cache: false`. */
|
||||
@@ -535,6 +538,7 @@ function createProgram(version: string, telemetry: Telemetry): Command {
|
||||
retries: options.retries,
|
||||
workers: options.workers,
|
||||
maxFailures: options.maxFailures,
|
||||
repeatEach: options.repeatEach,
|
||||
reporters: options.reporter,
|
||||
artifactsDir: options.artifacts,
|
||||
noCache: options.cache === false,
|
||||
|
||||
@@ -46,6 +46,12 @@ export interface TestTargetPair {
|
||||
readonly target: ResolvedTarget;
|
||||
/** The configured agent this pair runs as: one of `options.agents`. */
|
||||
readonly agent: string;
|
||||
/**
|
||||
* Which run of the test this is under `--repeat-each`: 0 for the one every
|
||||
* run has, then 1 through `n - 1`. Part of the pair's identity with the
|
||||
* test, the target, and the agent.
|
||||
*/
|
||||
readonly repeat: number;
|
||||
readonly options: ResolvedTestOptions;
|
||||
/** run: execute; skip: report skipped; filtered: report as unselected. */
|
||||
readonly disposition: 'run' | 'skip' | 'filtered';
|
||||
@@ -334,6 +340,25 @@ export function select(
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The selection with every runnable ordinary pair run `times` times: the
|
||||
* pair itself, then a copy per further repeat right after it, so a test's
|
||||
* runs are adjacent in report order. Setup tests run once whatever the
|
||||
* count, and a filtered or skipped pair is reported once.
|
||||
*/
|
||||
export function repeatEach(selection: Selection, times: number): Selection {
|
||||
if (times <= 1) return selection;
|
||||
const expand = (pairs: readonly TestTargetPair[]): TestTargetPair[] =>
|
||||
pairs.flatMap((pair) => {
|
||||
if (pair.disposition !== 'run' || pair.test.kind !== 'test') return [pair];
|
||||
return Array.from({ length: times }, (_, repeat) => ({ ...pair, repeat }));
|
||||
});
|
||||
return {
|
||||
pairs: expand(selection.pairs),
|
||||
perTarget: selection.perTarget.map(({ target, pairs }) => ({ target, pairs: expand(pairs) })),
|
||||
};
|
||||
}
|
||||
|
||||
/** At most this many file names are spelled out in a `NO_TESTS` message. */
|
||||
const MAX_NAMED_FILES = 3;
|
||||
|
||||
@@ -508,7 +533,7 @@ function classifyPair(
|
||||
filters: SelectionFilters,
|
||||
tagMode: TagMode,
|
||||
): TestTargetPair {
|
||||
const base = { test, target, agent, options };
|
||||
const base = { test, target, agent, repeat: 0, options };
|
||||
|
||||
if (test.kind === 'test') {
|
||||
// A file no positional named is collected for its setup tests only; its
|
||||
|
||||
@@ -105,9 +105,15 @@ export function canonicalDigest(value: unknown): string {
|
||||
return sha256Hex(canonicalJson(value));
|
||||
}
|
||||
|
||||
/** Result ID: SHA-256/JCS of `{ testId, targetId, agent }`; a test run as several agents has one per agent. */
|
||||
export function resultId(test: string, targetId: string, agent: string): string {
|
||||
return canonicalDigest({ testId: test, targetId, agent });
|
||||
/**
|
||||
* Result ID: SHA-256/JCS of `{ testId, targetId, agent }`, with `repeat` added
|
||||
* for a run past the first under `--repeat-each`; a test run as several
|
||||
* agents has one per agent, and one per repeat. The first run's id is the
|
||||
* same with or without the repeat dimension, so ids are stable across
|
||||
* versions and runs without the flag.
|
||||
*/
|
||||
export function resultId(test: string, targetId: string, agent: string, repeat = 0): string {
|
||||
return canonicalDigest(repeat === 0 ? { testId: test, targetId, agent } : { testId: test, targetId, agent, repeat });
|
||||
}
|
||||
|
||||
/** Generates one lowercase UUIDv7 string. */
|
||||
|
||||
@@ -234,6 +234,8 @@ export interface ReportSerialGroup {
|
||||
platform: string;
|
||||
/** The configured agent this variant of the group ran as. */
|
||||
agent: string;
|
||||
/** Which run of the group this is under `--repeat-each`, 0 for the first. */
|
||||
repeat: number;
|
||||
memberTestIds: readonly string[];
|
||||
status: SerialGroupRecord['status'];
|
||||
skip?: SkipInfo | undefined;
|
||||
@@ -256,6 +258,11 @@ export interface ReportResult {
|
||||
* with its own `id`.
|
||||
*/
|
||||
agent: string;
|
||||
/**
|
||||
* Which run of the test this is under `--repeat-each`: 0 for the run
|
||||
* every test has, then 1 through `n - 1`, each a result with its own `id`.
|
||||
*/
|
||||
repeat: number;
|
||||
/** The tags the test declares; `[]` when none. */
|
||||
tags: readonly string[];
|
||||
serialGroupId?: string | undefined;
|
||||
@@ -434,6 +441,7 @@ function serializeSerialGroup(group: SerialGroupRecord): ReportSerialGroup {
|
||||
targetId: group.targetId,
|
||||
platform: group.platform,
|
||||
agent: group.agent,
|
||||
repeat: group.repeat,
|
||||
memberTestIds: group.memberTestIds,
|
||||
status: group.status,
|
||||
skip: group.status === 'skipped' ? group.skip : undefined,
|
||||
@@ -443,7 +451,7 @@ function serializeSerialGroup(group: SerialGroupRecord): ReportSerialGroup {
|
||||
|
||||
function serializeResult(config: ResolvedConfig | undefined, result: ResultRecord): ReportResult {
|
||||
return {
|
||||
id: resultId(result.test.id, result.target.name, result.agent),
|
||||
id: resultId(result.test.id, result.target.name, result.agent, result.repeat),
|
||||
testId: result.test.id,
|
||||
kind: result.test.kind,
|
||||
declarationIndex: result.test.declarationIndex,
|
||||
@@ -453,6 +461,7 @@ function serializeResult(config: ResolvedConfig | undefined, result: ResultRecor
|
||||
targetId: result.target.name,
|
||||
platform: result.target.platform,
|
||||
agent: result.agent,
|
||||
repeat: result.repeat,
|
||||
tags: result.test.tags,
|
||||
serialGroupId: result.serialGroupId,
|
||||
status: result.status,
|
||||
|
||||
@@ -12,6 +12,7 @@ import { isLoopbackHost } from '../internal/urls.ts';
|
||||
import type { StepTurn } from '../run/steps.ts';
|
||||
import type { Report1Document, ReportError, ReportResult, ReportSource, ReportStep } from './build.ts';
|
||||
import { cell, code, formatDuration, link, MAX_CELL_CHARS, MAX_ID_CHARS, MAX_LABEL_CHARS, MAX_PATH_CHARS, MAX_TITLE_CHARS, plural } from './markdown-text.ts';
|
||||
import { repeatSuffix } from './format.ts';
|
||||
import type { AttemptView, Outcome } from './outcome.ts';
|
||||
|
||||
type ReportArtifact = ReportResult['attempts'][number]['artifacts'][number];
|
||||
@@ -213,7 +214,7 @@ export function renderFailurePage(report: Report1Document, result: ReportResult,
|
||||
const run = report.run;
|
||||
const told = toldAttempt(result, final);
|
||||
const manyTargets = run.targets.length > 1;
|
||||
const title = result.titlePath.map((part) => cell(part, MAX_TITLE_CHARS)).join(' › ');
|
||||
const title = `${result.titlePath.map((part) => cell(part, MAX_TITLE_CHARS)).join(' › ')}${repeatSuffix(result.repeat)}`;
|
||||
const lines: string[] = [`# ✗ ${title}`, ''];
|
||||
const about = [
|
||||
code(result.file, MAX_PATH_CHARS),
|
||||
|
||||
@@ -268,3 +268,12 @@ export function aiSegment(usage: AiUsage): string | undefined {
|
||||
export function visibleWidth(text: string): number {
|
||||
return [...stripVTControlCharacters(text)].length;
|
||||
}
|
||||
|
||||
/**
|
||||
* The title suffix of a `--repeat-each` run past the first: ` (repeat #2)`;
|
||||
* empty for the first run, and for a report written before results carried
|
||||
* `repeat`, which the renderers may still be handed.
|
||||
*/
|
||||
export function repeatSuffix(repeat: number | undefined): string {
|
||||
return repeat === undefined || repeat === 0 ? '' : ` (repeat #${repeat})`;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { sanitizeText } from '../internal/errors.ts';
|
||||
import type { Report1Document, ReportError, ReportResult, ReportSerialGroup } from './build.ts';
|
||||
import { repeatSuffix } from './format.ts';
|
||||
import { outcome } from './outcome.ts';
|
||||
import { fileReporter } from './write.ts';
|
||||
|
||||
@@ -99,7 +100,7 @@ function renderResult(result: ReportResult, groups: ReadonlyMap<string, ReportSe
|
||||
// never names one keeps the case names its CI history is keyed on.
|
||||
const agent = result.agent === 'default' ? '' : ` [${result.agent}]`;
|
||||
const open = `<testcase ${attributes({
|
||||
name: `${result.titlePath.join(' > ')} [${result.targetId}]${agent}`,
|
||||
name: `${result.titlePath.join(' > ')}${repeatSuffix(result.repeat)} [${result.targetId}]${agent}`,
|
||||
classname: result.file,
|
||||
time: seconds(final.durationMs),
|
||||
})}`;
|
||||
|
||||
@@ -35,6 +35,7 @@ import {
|
||||
stateString,
|
||||
statusBucket,
|
||||
stepsCacheTally,
|
||||
repeatSuffix,
|
||||
stepsUsage,
|
||||
sumUsage,
|
||||
tally,
|
||||
@@ -84,10 +85,11 @@ export interface ListReporterOptions {
|
||||
|
||||
/**
|
||||
* The identity of one pair across `test-started`, `step`, and `test-finished`:
|
||||
* a test runs once per agent it is pinned to, on each target.
|
||||
* a test runs once per agent it is pinned to, on each target, and once per
|
||||
* `--repeat-each` run.
|
||||
*/
|
||||
function pairKey(testId: string, agent: string, target: string): string {
|
||||
return `${testId}@${agent}@${target}`;
|
||||
function pairKey(testId: string, agent: string, target: string, repeat: number): string {
|
||||
return `${testId}@${agent}@${target}@${repeat}`;
|
||||
}
|
||||
|
||||
/** What a test line and a failure entry need from a result's execution. */
|
||||
@@ -348,7 +350,7 @@ export class ListReporter implements Reporter {
|
||||
private testOutput(event: RunEventOf<'output'>): void {
|
||||
const { pc } = this;
|
||||
if (event.text === '') return;
|
||||
const pair = event.pair === undefined ? undefined : pairKey(event.pair.testId, event.pair.agent, event.target);
|
||||
const pair = event.pair === undefined ? undefined : pairKey(event.pair.testId, event.pair.agent, event.target, event.pair.repeat);
|
||||
const running = pair === undefined ? undefined : this.pairs.get(pair);
|
||||
const source = running === undefined ? this.badge(event.target) : `${this.badge(running.group.target)} ${bounded(running.group.file)}${this.separator}${running.title}`;
|
||||
const key = `${event.stream}\u0000${source}`;
|
||||
@@ -386,8 +388,8 @@ export class ListReporter implements Reporter {
|
||||
* `default`: a test pinned to several agents lists once per agent, and the
|
||||
* tag is what tells the lines apart.
|
||||
*/
|
||||
private titledAs(title: string, agent: string): string {
|
||||
const bare = bounded(title);
|
||||
private titledAs(title: string, agent: string, repeat: number): string {
|
||||
const bare = `${bounded(title)}${repeat === 0 ? '' : this.pc.dim(repeatSuffix(repeat))}`;
|
||||
return agent === 'default' ? bare : `${bare} ${this.pc.dim(`[${bounded(agent)}]`)}`;
|
||||
}
|
||||
|
||||
@@ -518,11 +520,11 @@ export class ListReporter implements Reporter {
|
||||
if (test.serialId === event.serialId && test.group.target === event.target) test.executing = false;
|
||||
}
|
||||
}
|
||||
const key = pairKey(event.testId, event.agent, event.target);
|
||||
const key = pairKey(event.testId, event.agent, event.target, event.repeat);
|
||||
this.pairs.set(key, {
|
||||
group: this.group(event.file, event.target),
|
||||
serialId: event.serialId,
|
||||
title: this.titledAs(event.title, event.agent),
|
||||
title: this.titledAs(event.title, event.agent, event.repeat),
|
||||
startedMs: Date.now(),
|
||||
executing: true,
|
||||
current: undefined,
|
||||
@@ -540,7 +542,7 @@ export class ListReporter implements Reporter {
|
||||
* steps are fast and many, so they only ever show in the live window.
|
||||
*/
|
||||
private step(event: RunEventOf<'step'>): void {
|
||||
const running = this.pairs.get(pairKey(event.testId, event.agent, event.target));
|
||||
const running = this.pairs.get(pairKey(event.testId, event.agent, event.target, event.repeat));
|
||||
if (running === undefined) return;
|
||||
const { progress } = event;
|
||||
switch (progress.phase) {
|
||||
@@ -622,7 +624,7 @@ export class ListReporter implements Reporter {
|
||||
// Unselected pairs are report-only: they never print and the plan never
|
||||
// counted them.
|
||||
if (!result.selected) return;
|
||||
const key = pairKey(result.test.id, result.agent, result.target.name);
|
||||
const key = pairKey(result.test.id, result.agent, result.target.name, result.repeat);
|
||||
this.flushOutput(key);
|
||||
const steps = this.pairs.get(key)?.steps ?? [];
|
||||
this.pairs.delete(key);
|
||||
@@ -630,7 +632,7 @@ export class ListReporter implements Reporter {
|
||||
const { durationMs, usage, cache, error, videos, failure, screenPath } = this.detailsOf(result);
|
||||
addUsage(this.runUsage, usage);
|
||||
addCacheTally(this.runCache, cache);
|
||||
const title = this.titledAs(result.test.titlePath.join(' > '), result.agent);
|
||||
const title = this.titledAs(result.test.titlePath.join(' > '), result.agent, result.repeat);
|
||||
if (this.explore !== undefined) {
|
||||
// The exploration's verdict is its findings; any other error is a failure of its own.
|
||||
this.explore.result(result.attempts.flatMap((attempt) => attempt.artifacts));
|
||||
|
||||
@@ -22,7 +22,7 @@ import path from 'node:path';
|
||||
import { collapseText } from '../internal/text.ts';
|
||||
import type { Report1Document, ReportError, ReportExplore, ReportExploreFinding, ReportResult, ReportStep } from './build.ts';
|
||||
import { ENDED_TEXT, orderFindings, SEVERITY_WORDS, stepCountParts } from './explore-text.ts';
|
||||
import { formatCost, formatTokens, statusBucket, tally, type Counters } from './format.ts';
|
||||
import { formatCost, formatTokens, repeatSuffix, statusBucket, tally, type Counters } from './format.ts';
|
||||
import {
|
||||
attemptsLine,
|
||||
detailLines,
|
||||
@@ -272,7 +272,7 @@ function fileLabel(file: string, target: string, manyTargets: boolean): string {
|
||||
/** `suite › title (target)`. */
|
||||
function testName(result: ReportResult, manyTargets: boolean): string {
|
||||
const title = result.titlePath.map((part) => cell(part, MAX_TITLE_CHARS)).join(' › ');
|
||||
return `${title}${manyTargets ? ` (${cell(result.targetId, MAX_ID_CHARS)})` : ''}`;
|
||||
return `${title}${repeatSuffix(result.repeat)}${manyTargets ? ` (${cell(result.targetId, MAX_ID_CHARS)})` : ''}`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -125,7 +125,7 @@ export type RunEventFact =
|
||||
*/
|
||||
readonly type: 'output';
|
||||
readonly target: string;
|
||||
readonly pair: { readonly testId: string; readonly agent: string } | undefined;
|
||||
readonly pair: { readonly testId: string; readonly agent: string; readonly repeat: number } | undefined;
|
||||
readonly stream: 'stdout' | 'stderr';
|
||||
readonly text: string;
|
||||
}
|
||||
@@ -154,6 +154,8 @@ export type RunEventFact =
|
||||
readonly testId: string;
|
||||
/** The configured agent the test runs as; a test run as several starts once per agent. */
|
||||
readonly agent: string;
|
||||
/** Which run of the test this is under `--repeat-each`, 0 for the first; each repeat starts once. */
|
||||
readonly repeat: number;
|
||||
readonly title: string;
|
||||
/** Project-root-relative test file, so reporters can group by file. */
|
||||
readonly file: string;
|
||||
@@ -169,6 +171,7 @@ export type RunEventFact =
|
||||
readonly type: 'step';
|
||||
readonly testId: string;
|
||||
readonly agent: string;
|
||||
readonly repeat: number;
|
||||
readonly target: string;
|
||||
readonly progress: StepProgress;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ import type {
|
||||
import { isFailedStatus } from './records.ts';
|
||||
import { runWithRetries } from './retry.ts';
|
||||
import { runSerialUnit, type SerialHost, type SharedSerialSession } from './serial.ts';
|
||||
import { interruptedSkip, pairKey, pairResult, unstartedResult } from './units.ts';
|
||||
import { interruptedSkip, pairKey, pairResult, repeatSegment, unstartedResult } from './units.ts';
|
||||
import { sessionSecrecy } from './secrecy.ts';
|
||||
import { SessionStaging, SessionStore, type SessionIdentity } from './sessions.ts';
|
||||
import { redactTraceArchives } from './trace-redaction.ts';
|
||||
@@ -299,11 +299,11 @@ export class TargetExecutor implements SerialHost {
|
||||
if (pair.test.serialId !== undefined) {
|
||||
// One serial unit per agent the group runs as: its members are the
|
||||
// group's pairs under that agent, in declaration order.
|
||||
const unitKey = pairKey(pair.test.serialId, pair.agent);
|
||||
const unitKey = pairKey(pair.test.serialId, pair.agent, pair.repeat);
|
||||
if (!executedSerialUnits.has(unitKey)) {
|
||||
executedSerialUnits.add(unitKey);
|
||||
const members = ordered.filter(
|
||||
(member) => member.test.serialId === pair.test.serialId && member.agent === pair.agent,
|
||||
(member) => member.test.serialId === pair.test.serialId && member.agent === pair.agent && member.repeat === pair.repeat,
|
||||
);
|
||||
// A serial group owns its realm; whatever realm ordinary tests were
|
||||
// sharing ends here, afterAll included.
|
||||
@@ -733,10 +733,11 @@ export class TargetExecutor implements SerialHost {
|
||||
artifactsRoot: this.artifactsRoot,
|
||||
// Serial members share the group's session, and therefore its artifact
|
||||
// directory; registering under their own would not resolve on disk. The
|
||||
// agent segment keeps a test run as several agents from overwriting itself.
|
||||
// agent and repeat segments keep a test run as several agents, or
|
||||
// several times, from overwriting itself.
|
||||
segments:
|
||||
shared?.artifactSegments ??
|
||||
[this.target.name, sanitizePathSegment(pair.test.id), pair.agent, `attempt-${attemptIndex}`],
|
||||
[this.target.name, sanitizePathSegment(pair.test.id), pair.agent, ...repeatSegment(pair.repeat), `attempt-${attemptIndex}`],
|
||||
attemptId,
|
||||
currentStepId: () => steps.currentStepId,
|
||||
...(this.config.artifactStore === undefined ? {} : { store: this.config.artifactStore }),
|
||||
|
||||
@@ -149,12 +149,12 @@ async function resolveFromSelection(
|
||||
): Promise<ResolvedUnitPairs> {
|
||||
const selected = selection.perTarget.find((entry) => entry.target.name === target.name);
|
||||
const available = new Map<string, TestTargetPair>();
|
||||
for (const pair of selected?.pairs ?? []) available.set(pairKey(pair.test.id, pair.agent), pair);
|
||||
for (const pair of selected?.pairs ?? []) available.set(pairKey(pair.test.id, pair.agent, pair.repeat), pair);
|
||||
|
||||
const pairs: TestTargetPair[] = [];
|
||||
const missing: WirePair[] = [];
|
||||
for (const wire of unit.pairs) {
|
||||
const pair = available.get(pairKey(wire.test.id, wire.agent));
|
||||
const pair = available.get(pairKey(wire.test.id, wire.agent, wire.repeat));
|
||||
if (pair === undefined) missing.push(wire);
|
||||
else pairs.push(pair);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { ConfigurationError, errorMessage } from '../internal/errors.ts';
|
||||
import { resultId } from '../internal/ids.ts';
|
||||
import type { Report1Document } from '../report/build.ts';
|
||||
|
||||
type ReportResult = Report1Document['run']['results'][number];
|
||||
@@ -37,9 +38,10 @@ function noLastRun(message: string, cause?: unknown): ConfigurationError {
|
||||
* report the run before wrote where this run will write its own: failed,
|
||||
* timed out, interrupted, or skipped because a setup, a serial predecessor,
|
||||
* a hook, or the worker failed. An explicit skip and a filtered test passed
|
||||
* in the sense that matters here: nothing to run again. The ids match
|
||||
* `resultId(testId, target, agent)`, so a test is named per target and agent.
|
||||
* A missing or unreadable report is `NO_LAST_RUN`.
|
||||
* in the sense that matters here: nothing to run again. The ids are
|
||||
* `resultId(testId, target, agent)`, so a test is named per target and agent
|
||||
* whichever of its `--repeat-each` runs did not pass. A missing or unreadable
|
||||
* report is `NO_LAST_RUN`.
|
||||
*/
|
||||
export async function readLastFailed(reportPath: string): Promise<ReadonlySet<string>> {
|
||||
let text: string;
|
||||
@@ -60,7 +62,7 @@ export async function readLastFailed(reportPath: string): Promise<ReadonlySet<st
|
||||
if (!isReport(document)) {
|
||||
throw noLastRun(`--last-failed needs a report-1 document at ${reportPath}, which holds something else; run once without the flag to write one`);
|
||||
}
|
||||
return new Set(document.run.results.filter(didNotPass).map((result) => result.id));
|
||||
return new Set(document.run.results.filter(didNotPass).map((result) => resultId(result.testId, result.targetId, result.agent)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -108,6 +108,8 @@ export interface SerialGroupRecord {
|
||||
platform: string;
|
||||
/** The configured agent this variant of the group ran as. */
|
||||
agent: string;
|
||||
/** Which run of the group this is under `--repeat-each`, 0 for the first. */
|
||||
repeat: number;
|
||||
memberTestIds: string[];
|
||||
status: 'passed' | 'flaky' | 'failed' | 'timed-out' | 'interrupted' | 'skipped';
|
||||
skip?: SkipInfo;
|
||||
@@ -136,6 +138,8 @@ export interface ResultRecord {
|
||||
target: ResolvedTarget;
|
||||
/** The configured agent the test ran as; with a test run as several, one record each. */
|
||||
agent: string;
|
||||
/** Which run of the test this is under `--repeat-each`, 0 for the first; one record each. */
|
||||
repeat: number;
|
||||
status: ResultStatus;
|
||||
selected: boolean;
|
||||
skip?: SkipInfo | undefined;
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
} from '../config/resolve.ts';
|
||||
import { collect, collectInMemory, type Collection } from '../collect/collect.ts';
|
||||
import type { ModuleRegistration } from '../collect/registry.ts';
|
||||
import { select, selectTargets, type Selection, type SelectionFilters, type Shard, type TagMode } from '../collect/select.ts';
|
||||
import { repeatEach, select, selectTargets, type Selection, type SelectionFilters, type Shard, type TagMode } from '../collect/select.ts';
|
||||
import {
|
||||
classifyError,
|
||||
combineExitCodes,
|
||||
@@ -83,6 +83,13 @@ export interface RunOptions {
|
||||
* `failure-limit`, and the exit code is the failures' own.
|
||||
*/
|
||||
maxFailures?: number | undefined;
|
||||
/**
|
||||
* Runs every selected test this many times (`--repeat-each`), each run a
|
||||
* result of its own with `repeat` 0 through `n - 1`. Setup tests run once.
|
||||
* With the trace cache on, the first run records and the later ones
|
||||
* replay; pair it with `noCache` to exercise the model each time.
|
||||
*/
|
||||
repeatEach?: number | undefined;
|
||||
reporters?: readonly BuiltinReporter[] | undefined;
|
||||
artifactsDir?: string | undefined;
|
||||
passWithNoTests?: boolean | undefined;
|
||||
@@ -559,11 +566,14 @@ export async function run(options: RunOptions = {}): Promise<RunOutcome> {
|
||||
options.tests === undefined
|
||||
? await collect(config, options.files)
|
||||
: collectInMemory(config.projectRoot, options.tests.file, options.tests.registration);
|
||||
const selection = select(
|
||||
collection,
|
||||
config,
|
||||
await selectionFilters(options, config),
|
||||
options.passWithNoTests !== undefined ? { passWithNoTests: options.passWithNoTests } : {},
|
||||
const selection = repeatEach(
|
||||
select(
|
||||
collection,
|
||||
config,
|
||||
await selectionFilters(options, config),
|
||||
options.passWithNoTests !== undefined ? { passWithNoTests: options.passWithNoTests } : {},
|
||||
),
|
||||
options.repeatEach ?? 1,
|
||||
);
|
||||
return { collection, selection };
|
||||
}),
|
||||
@@ -708,7 +718,7 @@ export async function run(options: RunOptions = {}): Promise<RunOutcome> {
|
||||
onTestStart: (start, targetName) =>
|
||||
emit({ type: 'test-started', ...start, target: targetName }),
|
||||
onProgress: (pair, targetName, progress) =>
|
||||
emit({ type: 'step', testId: pair.testId, agent: pair.agent, target: targetName, progress }),
|
||||
emit({ type: 'step', testId: pair.testId, agent: pair.agent, repeat: pair.repeat, target: targetName, progress }),
|
||||
onOutput: (output, targetName) => emit({ type: 'output', target: targetName, ...output }),
|
||||
onDebug: (snapshot) => debug.merge(snapshot),
|
||||
onAiTrace: (snapshot) => aiTrace?.merge(snapshot),
|
||||
@@ -866,11 +876,14 @@ async function selectionFilters(options: ListOptions, config: ResolvedConfig): P
|
||||
|
||||
/**
|
||||
* The run options the CLI parser already bounds, checked again for the SDK
|
||||
* path so `run({ maxFailures: 0 })` is `INVALID_CONFIG` rather than a run
|
||||
* that stops at its first failure.
|
||||
* path so `run({ maxFailures: 0 })` or `run({ repeatEach: 0 })` is
|
||||
* `INVALID_CONFIG` rather than a run that stops at its first failure or
|
||||
* runs each test once.
|
||||
*/
|
||||
function validateRunOptions(options: ListOptions): void {
|
||||
positiveInt((options as RunOptions).maxFailures, 'maxFailures');
|
||||
const given = options as RunOptions;
|
||||
positiveInt(given.maxFailures, 'maxFailures');
|
||||
positiveInt(given.repeatEach, 'repeatEach');
|
||||
}
|
||||
|
||||
/** Resolves the run's config: a supplied value, or the discovered file. */
|
||||
|
||||
@@ -50,8 +50,8 @@ export interface SchedulerEvents {
|
||||
onFailureLimit?(failures: number, limit: number): void;
|
||||
/** A worker began executing one test-target pair. */
|
||||
onTestStart?(start: PairStart, targetName: string): void;
|
||||
/** Live step progress of one running pair, identified by test id and agent. */
|
||||
onProgress?(pair: { testId: string; agent: string }, targetName: string, progress: StepProgress): void;
|
||||
/** Live step progress of one running pair, identified by test id, agent, and repeat. */
|
||||
onProgress?(pair: { testId: string; agent: string; repeat: number }, targetName: string, progress: StepProgress): void;
|
||||
/** Text a worker's process wrote to stdout or stderr, attributed to the pair executing when one was. */
|
||||
onOutput?(output: Omit<OutputMessage, 'type'>, targetName: string): void;
|
||||
/** Phase timings a child-process worker drained after one unit. */
|
||||
@@ -153,6 +153,7 @@ class SchedulerWorker {
|
||||
const pairs: WirePair[] = unit.pairs.map((pair) => ({
|
||||
test: pair.test,
|
||||
agent: pair.agent,
|
||||
repeat: pair.repeat,
|
||||
options: pair.options,
|
||||
}));
|
||||
this.runner.send({
|
||||
@@ -561,14 +562,14 @@ class Scheduler {
|
||||
break;
|
||||
}
|
||||
case 'pair-start': {
|
||||
worker.inFlightPair = pairKey(message.testId, message.agent);
|
||||
worker.inFlightPair = pairKey(message.testId, message.agent, message.repeat);
|
||||
const { type: _type, ...start } = message;
|
||||
this.options.events.onTestStart?.(start, worker.targetName);
|
||||
break;
|
||||
}
|
||||
case 'progress': {
|
||||
this.options.events.onProgress?.(
|
||||
{ testId: message.testId, agent: message.agent },
|
||||
{ testId: message.testId, agent: message.agent, repeat: message.repeat },
|
||||
worker.targetName,
|
||||
message.progress,
|
||||
);
|
||||
@@ -582,7 +583,7 @@ class Scheduler {
|
||||
case 'result': {
|
||||
const state = this.targetState(worker);
|
||||
const result = decodeResult(message.result, state.target);
|
||||
worker.reported.add(pairKey(result.test.id, result.agent));
|
||||
worker.reported.add(pairKey(result.test.id, result.agent, result.repeat));
|
||||
if (result.status !== 'passed' && result.status !== 'flaky' && result.status !== 'skipped') {
|
||||
worker.sawFailure = true;
|
||||
}
|
||||
@@ -687,7 +688,7 @@ class Scheduler {
|
||||
): void {
|
||||
const interrupted = this.interrupting;
|
||||
for (const pair of unit.pairs) {
|
||||
const key = pairKey(pair.test.id, pair.agent);
|
||||
const key = pairKey(pair.test.id, pair.agent, pair.repeat);
|
||||
if (worker.reported.has(key)) continue;
|
||||
if (interrupted) {
|
||||
this.report(unstartedResult(pair, this.stopSkip ?? INTERRUPTED_BEFORE_START));
|
||||
|
||||
@@ -21,7 +21,7 @@ import { findRegistered, type Realm, RealmManager } from './realm.ts';
|
||||
import type { AttemptRecord, ResultRecord, ResultStatus, SerialAttemptRecord, SerialGroupRecord, SerialMemberRecord, FailedStatus } from './records.ts';
|
||||
import { isFailedStatus } from './records.ts';
|
||||
import { runWithRetries } from './retry.ts';
|
||||
import { interruptedSkip, pairResult } from './units.ts';
|
||||
import { interruptedSkip, pairResult, repeatSegment } from './units.ts';
|
||||
|
||||
/**
|
||||
* One shared session for a serial-group attempt: members preserve app state,
|
||||
@@ -98,7 +98,10 @@ export async function runSerialUnit(
|
||||
// Every member of a unit runs as the same agent (selection guarantees it),
|
||||
// so the group is one variant of the flow and is identified as such.
|
||||
const agent = first.agent;
|
||||
const groupRecordId = canonicalDigest({ serialId, targetId: host.target.name, agent });
|
||||
const { repeat } = first;
|
||||
const groupRecordId = canonicalDigest(
|
||||
repeat === 0 ? { serialId, targetId: host.target.name, agent } : { serialId, targetId: host.target.name, agent, repeat },
|
||||
);
|
||||
|
||||
const group: SerialGroupRecord = {
|
||||
id: groupRecordId,
|
||||
@@ -109,6 +112,7 @@ export async function runSerialUnit(
|
||||
targetId: host.target.name,
|
||||
platform: host.target.platform,
|
||||
agent,
|
||||
repeat,
|
||||
memberTestIds: members.map((member) => member.test.id),
|
||||
status: 'failed',
|
||||
attempts: [],
|
||||
@@ -183,6 +187,7 @@ async function runSerialAttempt(
|
||||
host.target.name,
|
||||
sanitizePathSegment(first.test.serialId ?? first.test.id),
|
||||
first.agent,
|
||||
...repeatSegment(first.repeat),
|
||||
`attempt-${attemptIndex}`,
|
||||
];
|
||||
const artifacts = createAttemptArtifacts({
|
||||
|
||||
@@ -146,14 +146,19 @@ function isSkipInfo(value: unknown): value is SkipInfo {
|
||||
*/
|
||||
export function pairResult(
|
||||
pair: TestTargetPair,
|
||||
fields: Omit<ResultRecord, 'test' | 'target' | 'agent'>,
|
||||
fields: Omit<ResultRecord, 'test' | 'target' | 'agent' | 'repeat'>,
|
||||
): ResultRecord {
|
||||
return { test: testIdentity(pair.test), target: pair.target, agent: pair.agent, ...fields };
|
||||
return { test: testIdentity(pair.test), target: pair.target, agent: pair.agent, repeat: pair.repeat, ...fields };
|
||||
}
|
||||
|
||||
/** The identity of one pair among a unit's: a test runs once per agent it is pinned to. */
|
||||
export function pairKey(testId: string, agent: string): string {
|
||||
return `${testId}\u0000${agent}`;
|
||||
/** The artifact path segment of a `--repeat-each` run past the first; none for the first, whose paths do not change. */
|
||||
export function repeatSegment(repeat: number): readonly string[] {
|
||||
return repeat === 0 ? [] : [`repeat-${repeat}`];
|
||||
}
|
||||
|
||||
/** The identity of one pair among a unit's: a test runs once per agent it is pinned to, and once per repeat. */
|
||||
export function pairKey(testId: string, agent: string, repeat: number): string {
|
||||
return `${testId}\u0000${agent}\u0000${repeat}`;
|
||||
}
|
||||
|
||||
/** Result for a pair reported skipped or unselected without ever dispatching. */
|
||||
@@ -181,5 +186,5 @@ export function unstartedResult(pair: TestTargetPair, skip: SkipInfo): ResultRec
|
||||
|
||||
/** Result for a test that vanished between planning and execution. */
|
||||
export function disappearedResult(pair: WirePair, target: ResolvedTarget): ResultRecord {
|
||||
return { test: pair.test, target, agent: pair.agent, status: 'failed', selected: true, attempts: [] };
|
||||
return { test: pair.test, target, agent: pair.agent, repeat: pair.repeat, status: 'failed', selected: true, attempts: [] };
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ async function bootstrap(
|
||||
missing.push(wire);
|
||||
continue;
|
||||
}
|
||||
pairs.push({ test, target, agent: wire.agent, options: wire.options, disposition: 'run', skip: undefined });
|
||||
pairs.push({ test, target, agent: wire.agent, repeat: wire.repeat, options: wire.options, disposition: 'run', skip: undefined });
|
||||
}
|
||||
return { pairs, missing, registration };
|
||||
};
|
||||
|
||||
@@ -21,6 +21,8 @@ export interface WirePair {
|
||||
readonly test: TestIdentity;
|
||||
/** The configured agent this pair runs as; one test may appear once per agent. */
|
||||
readonly agent: string;
|
||||
/** Which run of the test this is under `--repeat-each`, 0 for the first; one test may appear once per repeat. */
|
||||
readonly repeat: number;
|
||||
readonly options: ResolvedTestOptions;
|
||||
}
|
||||
|
||||
@@ -116,8 +118,10 @@ export interface ReadyMessage {
|
||||
/** One pair about to execute, as reporters see it. */
|
||||
export interface PairStart {
|
||||
readonly testId: string;
|
||||
/** The configured agent the pair runs as; with the test id, the pair's identity. */
|
||||
/** The configured agent the pair runs as; with the test id and the repeat, the pair's identity. */
|
||||
readonly agent: string;
|
||||
/** Which run of the test this is under `--repeat-each`, 0 for the first. */
|
||||
readonly repeat: number;
|
||||
/** Joined title path, so reporters need no side lookup by test ID. */
|
||||
readonly title: string;
|
||||
/** Project-root-relative test file. */
|
||||
@@ -140,6 +144,7 @@ export interface ProgressMessage {
|
||||
readonly type: 'progress';
|
||||
readonly testId: string;
|
||||
readonly agent: string;
|
||||
readonly repeat: number;
|
||||
readonly progress: StepProgress;
|
||||
}
|
||||
|
||||
@@ -152,7 +157,7 @@ export interface ProgressMessage {
|
||||
*/
|
||||
export interface OutputMessage {
|
||||
readonly type: 'output';
|
||||
readonly pair: { readonly testId: string; readonly agent: string } | undefined;
|
||||
readonly pair: { readonly testId: string; readonly agent: string; readonly repeat: number } | undefined;
|
||||
readonly stream: 'stdout' | 'stderr';
|
||||
readonly text: string;
|
||||
}
|
||||
|
||||
@@ -72,10 +72,10 @@ export class TargetWorker {
|
||||
* serial group's members follow one another, so the latest start is the
|
||||
* one running.
|
||||
*/
|
||||
private inFlight: { readonly testId: string; readonly agent: string } | undefined;
|
||||
private inFlight: { readonly testId: string; readonly agent: string; readonly repeat: number } | undefined;
|
||||
|
||||
/** The pair executing now, or undefined between units. */
|
||||
get pairInFlight(): { readonly testId: string; readonly agent: string } | undefined {
|
||||
get pairInFlight(): { readonly testId: string; readonly agent: string; readonly repeat: number } | undefined {
|
||||
return this.inFlight;
|
||||
}
|
||||
/** Serializes message handling so units never overlap on one worker. */
|
||||
@@ -108,23 +108,26 @@ export class TargetWorker {
|
||||
events: {
|
||||
onResult: (result) => {
|
||||
// Teardown after the result (an afterAll) belongs to no pair.
|
||||
if (this.inFlight?.testId === result.test.id && this.inFlight.agent === result.agent) this.inFlight = undefined;
|
||||
if (this.inFlight?.testId === result.test.id && this.inFlight.agent === result.agent && this.inFlight.repeat === result.repeat) {
|
||||
this.inFlight = undefined;
|
||||
}
|
||||
this.host.emit({ type: 'result', result: encodeResult(result) });
|
||||
},
|
||||
onSerialGroup: (group) => this.host.emit({ type: 'serial-group', group }),
|
||||
onPairStart: (pair) => {
|
||||
this.inFlight = { testId: pair.test.id, agent: pair.agent };
|
||||
this.inFlight = { testId: pair.test.id, agent: pair.agent, repeat: pair.repeat };
|
||||
this.host.emit({
|
||||
type: 'pair-start',
|
||||
testId: pair.test.id,
|
||||
agent: pair.agent,
|
||||
repeat: pair.repeat,
|
||||
title: pair.test.titlePath.join(' > '),
|
||||
file: pair.test.file,
|
||||
serialId: pair.test.serialId,
|
||||
});
|
||||
},
|
||||
onProgress: (pair, progress) =>
|
||||
this.host.emit({ type: 'progress', testId: pair.test.id, agent: pair.agent, progress }),
|
||||
this.host.emit({ type: 'progress', testId: pair.test.id, agent: pair.agent, repeat: pair.repeat, progress }),
|
||||
onRunAbort: (runError) => {
|
||||
this.interruptController.abort();
|
||||
this.host.emit({ type: 'run-abort', error: runError.error });
|
||||
|
||||
@@ -81,6 +81,7 @@ export function reportResult(overrides: Partial<ReportResult> = {}): ReportResul
|
||||
targetId: 'web',
|
||||
platform: 'web',
|
||||
agent: 'default',
|
||||
repeat: 0,
|
||||
tags: [],
|
||||
status: 'passed',
|
||||
attempts: [reportAttempt()],
|
||||
|
||||
@@ -63,6 +63,7 @@ export function sampleReport(): Report1Document {
|
||||
targetId: 'web',
|
||||
platform: 'web',
|
||||
agent: 'default',
|
||||
repeat: 0,
|
||||
memberTestIds: ['tests/secret.e2e.ts::Secret%20Title::pays'],
|
||||
status: 'passed',
|
||||
attempts: [
|
||||
|
||||
@@ -3,6 +3,7 @@ import path from 'node:path';
|
||||
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
||||
import { startFixtureApp, type FixtureApp } from '../helpers/fixture-app.ts';
|
||||
import { assertValidReport } from '../helpers/report-schema.ts';
|
||||
import { resultId } from '../../src/internal/ids.ts';
|
||||
import { listProject, resultByTitle, runExisting, runProject, type RunOutcome } from '../helpers/run-project.ts';
|
||||
|
||||
describe('runner lifecycle', () => {
|
||||
@@ -683,6 +684,50 @@ test('other', { tags: ['smoke'] }, async () => {});
|
||||
120_000,
|
||||
);
|
||||
|
||||
it(
|
||||
'runs every selected test n times under --repeat-each, each run its own result, and --last-failed names a test any repeat of which failed',
|
||||
async () => {
|
||||
const files = {
|
||||
'tests/repeat.e2e.ts': `import { existsSync, writeFileSync } from 'node:fs';
|
||||
import { test } from 'e2e';
|
||||
const marker = new URL('./ran-once', import.meta.url);
|
||||
test('steady', async () => {});
|
||||
test('breaks the second time', async () => {
|
||||
if (existsSync(marker)) throw new Error('second run breaks');
|
||||
writeFileSync(marker, '');
|
||||
});
|
||||
`,
|
||||
};
|
||||
const { outcome, project } = await runProject(files, { appUrl: app.url, runOptions: { repeatEach: 3, retries: 0 } });
|
||||
expect(outcome.exitCode).toBe(1);
|
||||
const results = outcome.report.run.results.toSorted((a, b) => a.declarationIndex - b.declarationIndex || a.repeat - b.repeat);
|
||||
expect(results.map((result) => [result.titlePath[0], result.repeat, result.status])).toEqual([
|
||||
['steady', 0, 'passed'],
|
||||
['steady', 1, 'passed'],
|
||||
['steady', 2, 'passed'],
|
||||
['breaks the second time', 0, 'passed'],
|
||||
['breaks the second time', 1, 'failed'],
|
||||
['breaks the second time', 2, 'failed'],
|
||||
]);
|
||||
expect(new Set(results.map((result) => result.id)).size).toBe(6);
|
||||
expect(results[0]!.id).toBe(resultId(results[0]!.testId, 'web', 'default'));
|
||||
const paths = results[4]!.attempts[0]!.artifacts.flatMap((artifact) => (artifact.path === undefined ? [] : [artifact.path]));
|
||||
expect(paths.length).toBeGreaterThan(0);
|
||||
expect(paths.every((artifactPath) => artifactPath.includes('/repeat-1/'))).toBe(true);
|
||||
expect(outcome.report.run.summary).toMatchObject({ selected: 6, executed: 6, passed: 4, failed: 2 });
|
||||
|
||||
// Only the breaking test failed, on its later repeats; the rerun names it once and runs it once.
|
||||
const rerun = await runExisting(project, { appUrl: app.url, runOptions: { lastFailed: true } });
|
||||
expect(rerun.results.filter((result) => result.selected).map((result) => result.test.title)).toEqual(['breaks the second time']);
|
||||
|
||||
const invalid = await runExisting(project, { appUrl: app.url, runOptions: { repeatEach: 0 } });
|
||||
expect(invalid.exitCode).toBe(2);
|
||||
expect(invalid.report.run.errors.map((error) => error.message)).toEqual(['repeatEach must be a positive safe integer, got 0']);
|
||||
project.cleanup();
|
||||
},
|
||||
120_000,
|
||||
);
|
||||
|
||||
it(
|
||||
'stops at --max-failures: the rest is skipped with the reason and the exit code is the failures\' own',
|
||||
async () => {
|
||||
|
||||
@@ -293,6 +293,8 @@ projectAgent.options = {};
|
||||
declare const report: Report;
|
||||
// Every result carries its tags, an empty list when the test declares none.
|
||||
report.run.results[0]!.tags satisfies readonly string[];
|
||||
// Every result says which `--repeat-each` run it is, 0 without the flag.
|
||||
report.run.results[0]!.repeat satisfies number;
|
||||
report.run.explore satisfies { goal: string; findings: readonly { severity: 1 | 2 | 3 | 4 | 5; artifactId?: string | undefined }[] } | undefined;
|
||||
|
||||
// An explore run's events narrow to the exploration's progress.
|
||||
|
||||
@@ -216,6 +216,16 @@ describe('e2e run argument parsing', () => {
|
||||
expect(runMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('parses --repeat-each as a positive integer', async () => {
|
||||
await invoke('run', '--repeat-each', '3');
|
||||
expect(lastRunOptions().repeatEach).toBe(3);
|
||||
runMock.mockClear();
|
||||
process.exitCode = undefined;
|
||||
await invoke('run', '--repeat-each', '0');
|
||||
expect(runMock).not.toHaveBeenCalled();
|
||||
expect(process.exitCode).toBe(2);
|
||||
});
|
||||
|
||||
it('parses --shard as index/total and --last-failed as a flag', async () => {
|
||||
await invoke('run', '--shard', '2/3', '--last-failed');
|
||||
const options = lastRunOptions();
|
||||
@@ -569,6 +579,7 @@ describe('e2e --version and --help', () => {
|
||||
'--workers',
|
||||
'--retries',
|
||||
'--max-failures',
|
||||
'--repeat-each',
|
||||
'--no-cache',
|
||||
'--reporter',
|
||||
'--artifacts',
|
||||
|
||||
@@ -92,6 +92,10 @@ describe('resultId', () => {
|
||||
expect(resultId('t.ts::a', 'web', 'default')).toBe(canonicalDigest({ testId: 't.ts::a', targetId: 'web', agent: 'default' }));
|
||||
expect(resultId('t.ts::a', 'web', 'default')).toMatch(/^[0-9a-f]{64}$/);
|
||||
expect(resultId('t.ts::a', 'web', 'buyer')).not.toBe(resultId('t.ts::a', 'web', 'admin'));
|
||||
// The first run's id ignores the repeat dimension; later runs get their own.
|
||||
expect(resultId('t.ts::a', 'web', 'default', 0)).toBe(resultId('t.ts::a', 'web', 'default'));
|
||||
expect(resultId('t.ts::a', 'web', 'default', 1)).toBe(canonicalDigest({ testId: 't.ts::a', targetId: 'web', agent: 'default', repeat: 1 }));
|
||||
expect(resultId('t.ts::a', 'web', 'default', 1)).not.toBe(resultId('t.ts::a', 'web', 'default', 2));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { afterEach, describe, expect, it } from 'vitest';
|
||||
import { resultId } from '../../src/internal/ids.ts';
|
||||
import { readLastFailed } from '../../src/run/last-run.ts';
|
||||
|
||||
let dir: string;
|
||||
@@ -18,10 +19,16 @@ function reportFile(content: string): string {
|
||||
return file;
|
||||
}
|
||||
|
||||
/** A report whose results each name a test by `id` as their test id, on target `web` as agent `default`. */
|
||||
function report(results: readonly Record<string, unknown>[]): string {
|
||||
return JSON.stringify({ schemaVersion: 'report-1', run: { results } });
|
||||
return JSON.stringify({
|
||||
schemaVersion: 'report-1',
|
||||
run: { results: results.map((result) => ({ ...result, testId: result['id'], targetId: 'web', agent: 'default' })) },
|
||||
});
|
||||
}
|
||||
|
||||
const idOf = (testId: string) => resultId(testId, 'web', 'default');
|
||||
|
||||
describe('readLastFailed', () => {
|
||||
it('collects the ids of the results that did not pass or that the run never carried out', async () => {
|
||||
const ids = await readLastFailed(
|
||||
@@ -42,11 +49,15 @@ describe('readLastFailed', () => {
|
||||
]),
|
||||
),
|
||||
);
|
||||
expect([...ids]).toEqual(['failed', 'timed-out', 'interrupted', 'setup-failed', 'predecessor', 'hook', 'worker']);
|
||||
expect([...ids]).toEqual(['failed', 'timed-out', 'interrupted', 'setup-failed', 'predecessor', 'hook', 'worker'].map(idOf));
|
||||
});
|
||||
|
||||
it('is empty when every result passed', async () => {
|
||||
it('is empty when every result passed, and names a test once however many of its repeats failed', async () => {
|
||||
expect((await readLastFailed(reportFile(report([{ id: 'a', status: 'passed' }])))).size).toBe(0);
|
||||
const repeated = await readLastFailed(
|
||||
reportFile(report([{ id: 'a', status: 'passed', repeat: 0 }, { id: 'a', status: 'failed', repeat: 1 }, { id: 'a', status: 'failed', repeat: 2 }])),
|
||||
);
|
||||
expect([...repeated]).toEqual([idOf('a')]);
|
||||
});
|
||||
|
||||
it('is NO_LAST_RUN when no report exists, with the path and the way out', async () => {
|
||||
|
||||
@@ -310,6 +310,7 @@ describe('renderJunitReport', () => {
|
||||
targetId: 'web',
|
||||
platform: 'web',
|
||||
agent: 'default',
|
||||
repeat: 0,
|
||||
memberTestIds: ['test-1', 'test-2'],
|
||||
status: 'failed',
|
||||
attempts: [
|
||||
|
||||
@@ -47,6 +47,8 @@ function result(overrides: {
|
||||
serialGroupId?: string;
|
||||
/** The agent the test ran as; `default` unless the case is about personas. */
|
||||
agent?: string;
|
||||
/** Which `--repeat-each` run this is; 0 unless the case is about repeats. */
|
||||
repeat?: number;
|
||||
}): RunEventResult {
|
||||
return {
|
||||
test: {
|
||||
@@ -57,6 +59,7 @@ function result(overrides: {
|
||||
},
|
||||
target: { name: overrides.target ?? 'chromium', platform: 'web' },
|
||||
agent: overrides.agent ?? 'default',
|
||||
repeat: overrides.repeat ?? 0,
|
||||
status: overrides.status,
|
||||
selected: overrides.selected ?? true,
|
||||
skip:
|
||||
@@ -97,6 +100,7 @@ function serialGroup(
|
||||
targetId: 'chromium',
|
||||
platform: 'web',
|
||||
agent: 'default',
|
||||
repeat: 0,
|
||||
memberTestIds: [...new Set(attempts.flatMap((entry) => entry.members.map((member) => member.testId)))],
|
||||
status: 'passed',
|
||||
attempts: attempts.map((entry, index) => ({
|
||||
@@ -173,7 +177,7 @@ function testStarted(
|
||||
file = 'tests/case.e2e.ts',
|
||||
serialId?: string,
|
||||
): RunEventFact {
|
||||
return { type: 'test-started', testId, agent: 'default', title, file, serialId, target };
|
||||
return { type: 'test-started', testId, agent: 'default', repeat: 0, title, file, serialId, target };
|
||||
}
|
||||
|
||||
function failedAttempt(message: string, stack?: string): AttemptRecord {
|
||||
@@ -273,6 +277,21 @@ describe('ListReporter', () => {
|
||||
expect(lines).toEqual(['stopped after 3 failures (--max-failures 3): the running tests end as interrupted, the rest are skipped']);
|
||||
});
|
||||
|
||||
it('titles the later runs of a repeated test and keeps each run its own line', () => {
|
||||
const { lines, output } = capture();
|
||||
const reporter = plainReporter(output);
|
||||
reporter.handle(runStarted());
|
||||
reporter.handle(plan([{ file: 'tests/checkout.e2e.ts', tests: 3 }]));
|
||||
lines.length = 0;
|
||||
for (const repeat of [0, 1, 2]) {
|
||||
reporter.handle(finished(result({ status: repeat === 1 ? 'failed' : 'passed', id: 't1', repeat, file: 'tests/checkout.e2e.ts', title: ['pays'], attempts: [attempt({ durationMs: 80 })] })));
|
||||
}
|
||||
const block = lines.join('\n');
|
||||
expect(block).toContain('pays 80ms');
|
||||
expect(block).toContain('pays (repeat #1)');
|
||||
expect(block).toContain('pays (repeat #2) 80ms');
|
||||
});
|
||||
|
||||
it('acknowledges each interrupt the moment it lands', () => {
|
||||
const { lines, output } = capture();
|
||||
const reporter = plainReporter(output);
|
||||
@@ -320,12 +339,12 @@ describe('ListReporter', () => {
|
||||
reporter.handle(runStarted());
|
||||
reporter.handle(plan([{ file: 'tests/checkout.e2e.ts', tests: 3 }]));
|
||||
lines.length = 0;
|
||||
reporter.handle({ type: 'test-started', testId: 't1', agent: 'default', title: 'checkout > pays', file: 'tests/checkout.e2e.ts', serialId: undefined, target: 'chromium' });
|
||||
reporter.handle({ type: 'test-started', testId: 't1', agent: 'buyer', title: 'checkout > pays', file: 'tests/checkout.e2e.ts', serialId: undefined, target: 'chromium' });
|
||||
reporter.handle({ type: 'test-started', testId: 't1', agent: 'admin', title: 'checkout > pays', file: 'tests/checkout.e2e.ts', serialId: undefined, target: 'chromium' });
|
||||
reporter.handle({ type: 'test-started', testId: 't1', agent: 'default', repeat: 0, title: 'checkout > pays', file: 'tests/checkout.e2e.ts', serialId: undefined, target: 'chromium' });
|
||||
reporter.handle({ type: 'test-started', testId: 't1', agent: 'buyer', repeat: 0, title: 'checkout > pays', file: 'tests/checkout.e2e.ts', serialId: undefined, target: 'chromium' });
|
||||
reporter.handle({ type: 'test-started', testId: 't1', agent: 'admin', repeat: 0, title: 'checkout > pays', file: 'tests/checkout.e2e.ts', serialId: undefined, target: 'chromium' });
|
||||
// Steps route by test id and agent, so the buyer's step stays with the buyer's line.
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'buyer', target: 'chromium', progress: { phase: 'start', kind: 'agent', api: 'agent.act', label: 'pay' } });
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'buyer', target: 'chromium', progress: { phase: 'end', kind: 'agent', api: 'agent.act', label: 'pay', status: 'passed', durationMs: 4_200, modelCalls: 3 } });
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'buyer', repeat: 0, target: 'chromium', progress: { phase: 'start', kind: 'agent', api: 'agent.act', label: 'pay' } });
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'buyer', repeat: 0, target: 'chromium', progress: { phase: 'end', kind: 'agent', api: 'agent.act', label: 'pay', status: 'passed', durationMs: 4_200, modelCalls: 3 } });
|
||||
for (const agent of ['default', 'buyer', 'admin']) {
|
||||
reporter.handle(finished(result({ status: 'passed', id: 't1', agent, file: 'tests/checkout.e2e.ts', title: ['checkout', 'pays'], attempts: [attempt({ durationMs: 80 })] })));
|
||||
}
|
||||
@@ -1035,6 +1054,7 @@ describe('ListReporter', () => {
|
||||
type: 'step',
|
||||
testId: 'm1',
|
||||
agent: 'default',
|
||||
repeat: 0,
|
||||
target: 'chromium',
|
||||
progress: { phase: 'end', kind: 'agent', api: 'agent.act', label: 'fill the form', status, durationMs: 4_200, modelCalls: 3 },
|
||||
});
|
||||
@@ -1062,10 +1082,10 @@ describe('ListReporter', () => {
|
||||
reporter.handle(runStarted());
|
||||
reporter.handle(plan([{ file: 'tests/case.e2e.ts', tests: 2 }]));
|
||||
reporter.handle(testStarted('m1', 'step 1', 'chromium', 'tests/case.e2e.ts', 'wizard'));
|
||||
reporter.handle({ type: 'step', testId: 'm1', agent: 'default', target: 'chromium', progress: { phase: 'start', kind: 'locator', api: 'app.open', label: '/wizard' } });
|
||||
reporter.handle({ type: 'step', testId: 'm1', agent: 'default', repeat: 0, target: 'chromium', progress: { phase: 'start', kind: 'locator', api: 'app.open', label: '/wizard' } });
|
||||
expect(chunks.at(-1)).toContain('step 1');
|
||||
reporter.handle(testStarted('m2', 'step 2', 'chromium', 'tests/case.e2e.ts', 'wizard'));
|
||||
reporter.handle({ type: 'step', testId: 'm2', agent: 'default', target: 'chromium', progress: { phase: 'start', kind: 'locator', api: 'locator.fill', label: 'Plan' } });
|
||||
reporter.handle({ type: 'step', testId: 'm2', agent: 'default', repeat: 0, target: 'chromium', progress: { phase: 'start', kind: 'locator', api: 'locator.fill', label: 'Plan' } });
|
||||
const window = chunks.at(-1)!;
|
||||
expect(window).toContain('step 2');
|
||||
expect(window).toContain('locator.fill "Plan"');
|
||||
@@ -1094,10 +1114,10 @@ describe('ListReporter', () => {
|
||||
const reporter = plainReporter(output);
|
||||
reporter.handle(plan([{ file: 'tests/flow.e2e.ts', tests: 1 }]));
|
||||
reporter.handle(testStarted('t1', 'checkout', 'chromium', 'tests/flow.e2e.ts'));
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'default', target: 'chromium', progress: agentStep('start', 'add to cart') });
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'default', target: 'chromium', progress: agentStep('end', 'add to cart') });
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'default', target: 'chromium', progress: agentStep('start', 'pay') });
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'default', target: 'chromium', progress: agentStep('end', 'pay', 'failed') });
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'default', repeat: 0, target: 'chromium', progress: agentStep('start', 'add to cart') });
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'default', repeat: 0, target: 'chromium', progress: agentStep('end', 'add to cart') });
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'default', repeat: 0, target: 'chromium', progress: agentStep('start', 'pay') });
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'default', repeat: 0, target: 'chromium', progress: agentStep('end', 'pay', 'failed') });
|
||||
reporter.handle(finished(result({
|
||||
status: 'failed',
|
||||
id: 't1',
|
||||
@@ -1120,10 +1140,10 @@ describe('ListReporter', () => {
|
||||
const reporter = plainReporter(output, true);
|
||||
reporter.handle(plan([{ file: 'tests/flow.e2e.ts', tests: 2 }]));
|
||||
reporter.handle(testStarted('t1', 'checkout', 'chromium', 'tests/flow.e2e.ts'));
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'default', target: 'chromium', progress: agentStep('start', 'add to cart') });
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'default', target: 'chromium', progress: agentStep('end', 'add to cart') });
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'default', target: 'chromium', progress: agentStep('start', 'pay') });
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'default', target: 'chromium', progress: agentStep('end', 'pay', 'failed') });
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'default', repeat: 0, target: 'chromium', progress: agentStep('start', 'add to cart') });
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'default', repeat: 0, target: 'chromium', progress: agentStep('end', 'add to cart') });
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'default', repeat: 0, target: 'chromium', progress: agentStep('start', 'pay') });
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'default', repeat: 0, target: 'chromium', progress: agentStep('end', 'pay', 'failed') });
|
||||
expect(lines).toEqual([]);
|
||||
reporter.handle(finished(result({
|
||||
status: 'failed',
|
||||
@@ -1134,8 +1154,8 @@ describe('ListReporter', () => {
|
||||
attempts: [failedAttempt('pay step failed')],
|
||||
})));
|
||||
reporter.handle(testStarted('t2', 'refund', 'chromium', 'tests/flow.e2e.ts'));
|
||||
reporter.handle({ type: 'step', testId: 't2', agent: 'default', target: 'chromium', progress: agentStep('start', 'refund order') });
|
||||
reporter.handle({ type: 'step', testId: 't2', agent: 'default', target: 'chromium', progress: agentStep('end', 'refund order') });
|
||||
reporter.handle({ type: 'step', testId: 't2', agent: 'default', repeat: 0, target: 'chromium', progress: agentStep('start', 'refund order') });
|
||||
reporter.handle({ type: 'step', testId: 't2', agent: 'default', repeat: 0, target: 'chromium', progress: agentStep('end', 'refund order') });
|
||||
reporter.handle(finished(result({ status: 'passed', id: 't2', file: 'tests/flow.e2e.ts', title: ['refund'], declarationIndex: 1 })));
|
||||
expect(lines).toEqual([
|
||||
' ❯ |chromium| tests/flow.e2e.ts (2 tests | 1 failed) 240ms',
|
||||
@@ -1154,8 +1174,8 @@ describe('ListReporter', () => {
|
||||
reporter.handle(plan([{ file: 'tests/flow.e2e.ts', tests: 2 }]));
|
||||
reporter.handle(testStarted('t1', 'checkout', 'chromium', 'tests/flow.e2e.ts'));
|
||||
reporter.handle(testStarted('t2', 'refund', 'chromium', 'tests/flow.e2e.ts'));
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'default', target: 'chromium', progress: agentStep('start', 'add to cart') });
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'default', target: 'chromium', progress: agentStep('end', 'add to cart') });
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'default', repeat: 0, target: 'chromium', progress: agentStep('start', 'add to cart') });
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'default', repeat: 0, target: 'chromium', progress: agentStep('end', 'add to cart') });
|
||||
expect(lines).toEqual([' ✓ checkout > agent.act "add to cart" 4.20s · 3 model calls']);
|
||||
});
|
||||
|
||||
@@ -1167,8 +1187,8 @@ describe('ListReporter', () => {
|
||||
reporter.handle(plan([{ file: 'tests/flow.e2e.ts', tests: 1 }]));
|
||||
reporter.handle(testStarted('t1', 'checkout', 'chromium', 'tests/flow.e2e.ts'));
|
||||
const label = 'add two todos named "Buy milk" and "Walk the dog", then mark the first';
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'default', target: 'chromium', progress: agentStep('start', label) });
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'default', target: 'chromium', progress: agentStep('end', label) });
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'default', repeat: 0, target: 'chromium', progress: agentStep('start', label) });
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'default', repeat: 0, target: 'chromium', progress: agentStep('end', label) });
|
||||
expect(lines.at(-1)).toBe(` ✓ checkout > agent.act "${label}" 4.20s · 3 model calls`);
|
||||
} finally {
|
||||
restore();
|
||||
@@ -1183,6 +1203,7 @@ describe('ListReporter', () => {
|
||||
type: 'step',
|
||||
testId: 't1',
|
||||
agent: 'default',
|
||||
repeat: 0,
|
||||
target: 'chromium',
|
||||
progress: { phase: 'start', kind: 'locator', api: 'locator.tap', label: 'button' },
|
||||
});
|
||||
@@ -1190,6 +1211,7 @@ describe('ListReporter', () => {
|
||||
type: 'step',
|
||||
testId: 't1',
|
||||
agent: 'default',
|
||||
repeat: 0,
|
||||
target: 'chromium',
|
||||
progress: { phase: 'end', kind: 'locator', api: 'locator.tap', label: 'button', status: 'passed', durationMs: 5, modelCalls: 0 },
|
||||
});
|
||||
@@ -1240,6 +1262,7 @@ describe('ListReporter', () => {
|
||||
type: 'step',
|
||||
testId: 't1',
|
||||
agent: 'default',
|
||||
repeat: 0,
|
||||
target: 'chromium',
|
||||
progress: { phase: 'start', kind: 'agent', api: 'agent.act', label: 'add a todo' },
|
||||
});
|
||||
@@ -1247,6 +1270,7 @@ describe('ListReporter', () => {
|
||||
type: 'step',
|
||||
testId: 't1',
|
||||
agent: 'default',
|
||||
repeat: 0,
|
||||
target: 'chromium',
|
||||
progress: {
|
||||
phase: 'event',
|
||||
@@ -1271,6 +1295,7 @@ describe('ListReporter', () => {
|
||||
type: 'step',
|
||||
testId: 't1',
|
||||
agent: 'default',
|
||||
repeat: 0,
|
||||
target: 'chromium',
|
||||
progress: step,
|
||||
});
|
||||
@@ -1297,6 +1322,7 @@ describe('ListReporter', () => {
|
||||
type: 'step',
|
||||
testId: 't1',
|
||||
agent: 'default',
|
||||
repeat: 0,
|
||||
target: 'chromium',
|
||||
progress: { phase: 'start', kind: 'agent', api: 'agent.act', label: 'pay' },
|
||||
});
|
||||
@@ -1304,6 +1330,7 @@ describe('ListReporter', () => {
|
||||
type: 'step',
|
||||
testId: 't1',
|
||||
agent: 'default',
|
||||
repeat: 0,
|
||||
target: 'chromium',
|
||||
progress: {
|
||||
phase: 'event',
|
||||
@@ -1333,7 +1360,7 @@ describe('ListReporter', () => {
|
||||
const reporter = plainReporter(output, true);
|
||||
reporter.handle(runStarted());
|
||||
reporter.handle(testStarted('t1', 'a', 'chromium'));
|
||||
const step = (progress: object) => reporter.handle({ type: 'step', testId: 't1', agent: 'default', target: 'chromium', progress } as never);
|
||||
const step = (progress: object) => reporter.handle({ type: 'step', testId: 't1', agent: 'default', repeat: 0, target: 'chromium', progress } as never);
|
||||
step({ phase: 'start', kind: 'agent', api: 'agent.act', label: 'pay' });
|
||||
step({
|
||||
phase: 'event',
|
||||
@@ -1363,7 +1390,7 @@ describe('ListReporter', () => {
|
||||
const reporter = plainReporter(output, true);
|
||||
reporter.handle(runStarted());
|
||||
reporter.handle(testStarted('t1', 'a', 'chromium'));
|
||||
const step = (progress: object) => reporter.handle({ type: 'step', testId: 't1', agent: 'default', target: 'chromium', progress } as never);
|
||||
const step = (progress: object) => reporter.handle({ type: 'step', testId: 't1', agent: 'default', repeat: 0, target: 'chromium', progress } as never);
|
||||
step({ phase: 'start', kind: 'agent', api: 'agent.act', label: 'pay' });
|
||||
step({
|
||||
phase: 'event',
|
||||
@@ -1396,6 +1423,7 @@ describe('ListReporter', () => {
|
||||
type: 'step',
|
||||
testId: 't1',
|
||||
agent: 'default',
|
||||
repeat: 0,
|
||||
target: 'chromium',
|
||||
progress: { phase: 'end', kind: 'agent', api: 'agent.act', label: 'pay', status: 'passed', durationMs: 4_200, modelCalls: 3 },
|
||||
});
|
||||
@@ -1419,7 +1447,7 @@ describe('ListReporter', () => {
|
||||
reporter.handle(plan([{ file: 'tests/flow.e2e.ts', tests: 1 }]));
|
||||
reporter.handle(testStarted('t1', 'checkout', 'chromium', 'tests/flow.e2e.ts'));
|
||||
const label = 'add two todos named "Buy milk" and "Walk the dog", then mark the first one as done';
|
||||
const step = (progress: object) => reporter.handle({ type: 'step', testId: 't1', agent: 'default', target: 'chromium', progress } as never);
|
||||
const step = (progress: object) => reporter.handle({ type: 'step', testId: 't1', agent: 'default', repeat: 0, target: 'chromium', progress } as never);
|
||||
step({ phase: 'start', kind: 'agent', api: 'agent.act', label });
|
||||
step({ phase: 'end', kind: 'agent', api: 'agent.act', label, status: 'passed', durationMs: 4_200, modelCalls: 3 });
|
||||
const row = chunks.at(-1)!.replace(ANSI_PATTERN, '').split('\n').find((line) => line.includes('agent.act'))!;
|
||||
@@ -1436,7 +1464,7 @@ describe('ListReporter', () => {
|
||||
reporter.handle(runStarted());
|
||||
reporter.handle(plan([{ file: 'tests/flow.e2e.ts', tests: 1 }]));
|
||||
reporter.handle(testStarted('t1', 'checkout', 'chromium', 'tests/flow.e2e.ts'));
|
||||
const step = (progress: object) => reporter.handle({ type: 'step', testId: 't1', agent: 'default', target: 'chromium', progress } as never);
|
||||
const step = (progress: object) => reporter.handle({ type: 'step', testId: 't1', agent: 'default', repeat: 0, target: 'chromium', progress } as never);
|
||||
step({ phase: 'start', kind: 'agent', api: 'agent.act', label: 'add to cart' });
|
||||
step({ phase: 'end', kind: 'agent', api: 'agent.act', label: 'add to cart', status: 'passed', durationMs: 4_200, modelCalls: 3 });
|
||||
step({ phase: 'start', kind: 'agent', api: 'agent.act', label: 'pay' });
|
||||
@@ -1457,7 +1485,7 @@ describe('ListReporter', () => {
|
||||
const reporter = plainReporter(output, true);
|
||||
reporter.handle(runStarted());
|
||||
reporter.handle(testStarted('t1', 'checkout', 'chromium'));
|
||||
const step = (progress: object) => reporter.handle({ type: 'step', testId: 't1', agent: 'default', target: 'chromium', progress } as never);
|
||||
const step = (progress: object) => reporter.handle({ type: 'step', testId: 't1', agent: 'default', repeat: 0, target: 'chromium', progress } as never);
|
||||
step({ phase: 'start', kind: 'agent', api: 'agent.act', label: 'pay' });
|
||||
step({ phase: 'replay', api: 'agent.act', active: true });
|
||||
step({ phase: 'event', api: 'agent.act', event: { kind: 'engine', name: 'tap', detail: 'tap button "Pay"', durationMs: 27, status: 'passed' } });
|
||||
@@ -1479,6 +1507,7 @@ describe('ListReporter', () => {
|
||||
type: 'step',
|
||||
testId: 't1',
|
||||
agent: 'default',
|
||||
repeat: 0,
|
||||
target: 'chromium',
|
||||
progress: { phase: 'start', kind: 'locator', api: 'locator.tap', label: 'Pay' },
|
||||
});
|
||||
@@ -1498,12 +1527,12 @@ describe('ListReporter', () => {
|
||||
chunk.replace(ANSI_PATTERN, '').split('\n').findIndex((line) => line.startsWith(' Test Files'));
|
||||
const before = summaryRow(chunks.at(-1)!);
|
||||
reporter.handle(testStarted('t1', 'checkout', 'chromium', 'tests/flow.e2e.ts'));
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'default', target: 'chromium', progress: { phase: 'start', kind: 'agent', api: 'agent.act', label: 'pay' } });
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'default', repeat: 0, target: 'chromium', progress: { phase: 'start', kind: 'agent', api: 'agent.act', label: 'pay' } });
|
||||
for (let i = 0; i < 4; i += 1) {
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'default', target: 'chromium', progress: { phase: 'event', api: 'agent.act', event: { kind: 'model', durationMs: 10, count: 100 } as never } });
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'default', repeat: 0, target: 'chromium', progress: { phase: 'event', api: 'agent.act', event: { kind: 'model', durationMs: 10, count: 100 } as never } });
|
||||
}
|
||||
const during = summaryRow(chunks.at(-1)!);
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'default', target: 'chromium', progress: { phase: 'end', kind: 'agent', api: 'agent.act', label: 'pay', status: 'passed', durationMs: 40, modelCalls: 4 } });
|
||||
reporter.handle({ type: 'step', testId: 't1', agent: 'default', repeat: 0, target: 'chromium', progress: { phase: 'end', kind: 'agent', api: 'agent.act', label: 'pay', status: 'passed', durationMs: 40, modelCalls: 4 } });
|
||||
const after = summaryRow(chunks.at(-1)!);
|
||||
expect(before).toBeGreaterThan(5);
|
||||
expect(during).toBe(before);
|
||||
@@ -1599,9 +1628,9 @@ describe('ListReporter', () => {
|
||||
const reporter = plainReporter(output, true);
|
||||
reporter.handle(runStarted());
|
||||
reporter.handle(testStarted('t1', 'signs in', 'chromium'));
|
||||
const write = (stream: 'stdout' | 'stderr', text: string, pair?: { testId: string; agent: string }) =>
|
||||
const write = (stream: 'stdout' | 'stderr', text: string, pair?: { testId: string; agent: string; repeat: number }) =>
|
||||
reporter.handle({ type: 'output', target: 'chromium', pair, stream, text });
|
||||
const t1 = { testId: 't1', agent: 'default' };
|
||||
const t1 = { testId: 't1', agent: 'default', repeat: 0 };
|
||||
write('stdout', 'hello\n', t1);
|
||||
write('stdout', 'two\nlines\n', t1);
|
||||
write('stderr', 'oops\n', t1);
|
||||
@@ -1628,7 +1657,7 @@ describe('ListReporter', () => {
|
||||
reporter.handle(plan([{ file: 'tests/case.e2e.ts', tests: 1 }]));
|
||||
reporter.handle(testStarted('t1', 'signs in', 'chromium'));
|
||||
const write = (text: string) =>
|
||||
reporter.handle({ type: 'output', target: 'chromium', pair: { testId: 't1', agent: 'default' }, stream: 'stdout', text });
|
||||
reporter.handle({ type: 'output', target: 'chromium', pair: { testId: 't1', agent: 'default', repeat: 0 }, stream: 'stdout', text });
|
||||
write('progress ');
|
||||
write('50%\nnext');
|
||||
expect(lines.filter((line) => line.startsWith('progress') || line.startsWith('next'))).toEqual(['progress 50%']);
|
||||
@@ -1644,9 +1673,9 @@ describe('ListReporter', () => {
|
||||
const reporter = plainReporter(output, true);
|
||||
reporter.handle(runStarted());
|
||||
reporter.handle(testStarted('t1', 'signs in', 'chromium'));
|
||||
reporter.handle({ type: 'output', target: 'chromium', pair: { testId: 't1', agent: 'default' }, stream: 'stdout', text: 'one\n' });
|
||||
reporter.handle({ type: 'output', target: 'chromium', pair: { testId: 't1', agent: 'default', repeat: 0 }, stream: 'stdout', text: 'one\n' });
|
||||
reporter.handle({ type: 'notice', target: 'chromium', message: 'between' });
|
||||
reporter.handle({ type: 'output', target: 'chromium', pair: { testId: 't1', agent: 'default' }, stream: 'stdout', text: 'two\n' });
|
||||
reporter.handle({ type: 'output', target: 'chromium', pair: { testId: 't1', agent: 'default', repeat: 0 }, stream: 'stdout', text: 'two\n' });
|
||||
expect(lines.filter((line) => line.startsWith('stdout |'))).toHaveLength(2);
|
||||
expect(lines.at(-1)).toBe('two');
|
||||
});
|
||||
@@ -1724,6 +1753,7 @@ describe('ListReporter', () => {
|
||||
type: 'step',
|
||||
testId: id,
|
||||
agent: 'default',
|
||||
repeat: 0,
|
||||
target: 'chromium',
|
||||
progress: { phase: 'start', kind: 'agent', api: 'agent.act', label: `step ${id}` },
|
||||
});
|
||||
@@ -1732,6 +1762,7 @@ describe('ListReporter', () => {
|
||||
type: 'step',
|
||||
testId: id,
|
||||
agent: 'default',
|
||||
repeat: 0,
|
||||
target: 'chromium',
|
||||
progress: { phase: 'event', api: 'agent.act', event: { kind: 'model', durationMs: 10, count: 100 } as never },
|
||||
});
|
||||
@@ -1842,7 +1873,7 @@ describe('explore runs', () => {
|
||||
}
|
||||
|
||||
function stepEvent(progress: RunEventOf<'step'>['progress']): RunEventFact {
|
||||
return { type: 'step', testId: 't1', agent: 'default', target: 'web', progress };
|
||||
return { type: 'step', testId: 't1', agent: 'default', repeat: 0, target: 'web', progress };
|
||||
}
|
||||
|
||||
function engineEvent(name: string, detail?: string): RunEventFact {
|
||||
|
||||
@@ -399,6 +399,13 @@ describe('renderMarkdownReport', () => {
|
||||
expect(body).toContain('and 5 more\n</details>');
|
||||
});
|
||||
|
||||
it('renders a result from a report written before results carried repeat without a suffix', () => {
|
||||
const legacy = { ...named({ title: 'checkout', status: 'failed' }), repeat: undefined as unknown as number };
|
||||
const body = renderMarkdownReport(page({ status: 'failed', results: [legacy] }));
|
||||
expect(body).toContain('checkout');
|
||||
expect(body).not.toContain('repeat #');
|
||||
});
|
||||
|
||||
it('reads a serial member from its group: error, steps, failure evidence, and the artifacts of the attempt that failed', () => {
|
||||
const member = named({ title: 'step two', status: 'failed', serialGroupId: 'g1' });
|
||||
const group: ReportSerialGroup = {
|
||||
@@ -411,6 +418,7 @@ describe('renderMarkdownReport', () => {
|
||||
targetId: 'web',
|
||||
platform: 'web',
|
||||
agent: 'default',
|
||||
repeat: 0,
|
||||
memberTestIds: [member.testId],
|
||||
status: 'failed',
|
||||
attempts: [
|
||||
|
||||
@@ -49,6 +49,7 @@ function failedResult(error: SerializedError): ResultRecord {
|
||||
},
|
||||
target,
|
||||
agent: 'default',
|
||||
repeat: 0,
|
||||
status: 'failed',
|
||||
selected: true,
|
||||
attempts: [failedAttempt(error)],
|
||||
|
||||
@@ -96,6 +96,7 @@ describe('toEventResult', () => {
|
||||
} as unknown as ResultRecord['test'],
|
||||
target,
|
||||
agent: 'default',
|
||||
repeat: 0,
|
||||
status: 'passed',
|
||||
selected: true,
|
||||
attempts: [],
|
||||
|
||||
@@ -85,7 +85,7 @@ function makePair(
|
||||
target: ResolvedTarget,
|
||||
overrides: Partial<TestTargetPair> = {},
|
||||
): TestTargetPair {
|
||||
return { test, target, agent: 'default', options: defaultOptions, disposition: 'run', skip: undefined, ...overrides };
|
||||
return { test, target, agent: 'default', repeat: 0, options: defaultOptions, disposition: 'run', skip: undefined, ...overrides };
|
||||
}
|
||||
|
||||
function makeCollection(files: readonly string[], pairs: readonly TestTargetPair[]): Collection {
|
||||
@@ -214,6 +214,7 @@ class FakeRunner implements UnitRunner {
|
||||
type: 'pair-start',
|
||||
testId: pair.test.id,
|
||||
agent: pair.agent,
|
||||
repeat: pair.repeat,
|
||||
title: pair.test.id,
|
||||
file: pair.test.file,
|
||||
serialId: pair.test.serialId,
|
||||
@@ -224,7 +225,7 @@ class FakeRunner implements UnitRunner {
|
||||
const status = this.behaviour.status?.[pair.test.id] ?? 'passed';
|
||||
this.events.onMessage({
|
||||
type: 'result',
|
||||
result: { test: pair.test, agent: pair.agent, status, selected: true, attempts: [] },
|
||||
result: { test: pair.test, agent: pair.agent, repeat: pair.repeat, status, selected: true, attempts: [] },
|
||||
});
|
||||
}
|
||||
this.events.onMessage({ type: 'unit-done', unitId: message.unitId, runErrors: [] });
|
||||
|
||||
@@ -3,7 +3,7 @@ import { fileURLToPath } from 'node:url';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { collectFromRegistration, type Collection } from '../../src/collect/collect.ts';
|
||||
import { collectModule, test } from '../../src/collect/registry.ts';
|
||||
import { resolveOptions, select } from '../../src/collect/select.ts';
|
||||
import { repeatEach, resolveOptions, select } from '../../src/collect/select.ts';
|
||||
import { resolveConfig } from '../../src/config/resolve.ts';
|
||||
import { defineEngine } from '../../src/engine/index.ts';
|
||||
import { resultId } from '../../src/internal/ids.ts';
|
||||
@@ -537,6 +537,29 @@ describe('select', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('repeatEach', () => {
|
||||
it('runs every runnable ordinary pair n times, adjacent and numbered, and setups or left-out pairs once', async () => {
|
||||
const col = await collection(() => {
|
||||
test.setup('login', { sessions: ['user'] }, noop);
|
||||
test('a', { session: 'user' }, noop);
|
||||
test('b', { tags: ['slow'] }, noop);
|
||||
test.skip('c', noop);
|
||||
});
|
||||
const once = select(col, config(), { excludeTags: ['slow'] });
|
||||
expect(repeatEach(once, 1)).toBe(once);
|
||||
const thrice = repeatEach(once, 3);
|
||||
expect(thrice.pairs.map((pair) => [pair.test.title, pair.disposition, pair.repeat])).toEqual([
|
||||
['login', 'run', 0],
|
||||
['a', 'run', 0],
|
||||
['a', 'run', 1],
|
||||
['a', 'run', 2],
|
||||
['b', 'filtered', 0],
|
||||
['c', 'skip', 0],
|
||||
]);
|
||||
expect(thrice.perTarget[0]!.pairs).toEqual(thrice.pairs);
|
||||
});
|
||||
});
|
||||
|
||||
describe('positional file selection', () => {
|
||||
/** A file collected as `file:line` named it: only the tests declared at `lines` are selected. */
|
||||
// The tests are declared in this very file, which is what a line names, so
|
||||
|
||||
@@ -69,7 +69,7 @@ const defaultOptions: ResolvedTestOptions = {
|
||||
};
|
||||
|
||||
function makePair(test: CollectedTest, overrides: Partial<TestTargetPair> = {}): TestTargetPair {
|
||||
return { test, target, agent: 'default', options: defaultOptions, disposition: 'run', skip: undefined, ...overrides };
|
||||
return { test, target, agent: 'default', repeat: 0, options: defaultOptions, disposition: 'run', skip: undefined, ...overrides };
|
||||
}
|
||||
|
||||
function makeFile(file: string, tests: CollectedTest[]): CollectedFile {
|
||||
@@ -180,6 +180,7 @@ describe('wire protocol', () => {
|
||||
test,
|
||||
target,
|
||||
agent: 'default',
|
||||
repeat: 0,
|
||||
status: 'passed',
|
||||
selected: true,
|
||||
attempts: [],
|
||||
@@ -197,6 +198,7 @@ describe('wire protocol', () => {
|
||||
test: makeTest('tests/a.e2e.ts', 'x', 0),
|
||||
target,
|
||||
agent: 'default',
|
||||
repeat: 0,
|
||||
options: defaultOptions,
|
||||
disposition: 'skip',
|
||||
skip: { cause: 'explicit', reason: 'skipped' },
|
||||
|
||||
@@ -29,6 +29,7 @@ npx e2e telemetry [disable|enable] # anonymous usage telemetry: status, or the s
|
||||
| `--agent <names>` | Run unpinned tests as other configured agents (`agents.<name>`), comma-separated or repeated; several names run each such test once per agent. Default is `agents.default`. |
|
||||
| `--workers <n>`, `--retries <n>` | Override the resolved values. |
|
||||
| `--max-failures <n>` | Stop once this many tests failed: the rest are skipped with cause `failure-limit`, running tests end as `interrupted`, exit 1. |
|
||||
| `--repeat-each <n>` | Run every selected test n times, each run its own result (`repeat` 0 through n-1). Add `--no-cache`, or the later runs replay the first's recording. |
|
||||
| `--reporter <ids>` | `list`, `json`, `junit`, `markdown`, comma-separated. `json` cannot combine with `list`. |
|
||||
| `--artifacts <dir>` | Artifact root, default `.e2e/artifacts`. |
|
||||
| `--no-cache` | Run with the trace cache off. |
|
||||
@@ -90,7 +91,7 @@ recorded flow is stale — `--no-cache` only skips the cache for one run.
|
||||
- `.e2e/report.json` is written on every run whatever the reporters:
|
||||
`run.status`, `run.exitCode`, `run.errors[]` (run-level failures such as
|
||||
`APP_UNREACHABLE`), and `run.results[]`, one per test and target, with
|
||||
`titlePath`, `file`, `source`, `tags` (`[]` when the test declares none), `status`, and `attempts[]` holding `steps[]`,
|
||||
`titlePath`, `file`, `source`, `tags` (`[]` when the test declares none), `repeat` (0 unless `--repeat-each`), `status`, and `attempts[]` holding `steps[]`,
|
||||
`artifacts[]`, and `error`.
|
||||
- `junit`: `.e2e/junit.xml` beside the report, for CI test summaries.
|
||||
Combine it with the terminal output: `--reporter list,junit`.
|
||||
|
||||
Reference in New Issue
Block a user