Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

feat(e2e): write per-test timings json and add a --slowest report

Luigi Agosti2ab9a73f59e1
diff --git a/TESTING.md b/TESTING.md
index 058a227f..96190f68 100644
--- a/TESTING.md
+++ b/TESTING.md
@@ -177,6 +177,20 @@ The Go e2e runner captures suite output, prints the final suite summary, and wri
- `summary-plugin-smoke.txt` / `report-plugin-smoke.md`
- `summary-docker-smoke.txt` / `report-docker-smoke.md`
+Each suite also writes `timings-<suite>.json` beside its markdown report: one record per test with its scenario, name, duration in ms and status, plus per-scenario and suite totals. The records come from the same `E2E_RESULT` stream the markdown report is built from, so the two always agree on test count and total.
+
+Every record carries the suite, the stack (`singleCompose` or `multiCompose`) and the browser, because a comparison that mixes those is measuring contention rather than the change under test.
+
+Read a run back without re-running it:
+
+```bash
+go run ./tests/tools/runner e2e --suite api-extended --slowest 10
+```
+
+That prints the ten slowest tests and the per-scenario totals from the JSON. It starts nothing and does not need Docker.
+
+Gate suite-speed claims on the per-scenario and per-suite totals, not on per-test durations: measured run-to-run swing is around 16%, so aggregates over 20+ tests are the only stable signal. Tests under 100ms should be left out of any ratio entirely — a 10ms to 20ms move reads as +100% and means nothing. The threshold travels with the data as `comparisonFloorMs`.
+
The runner clears the target suite files before each run so stale results do not survive into the next suite. It also saves the captured suite output as `output-*.log`, captures compose service logs on failure, and writes GitHub Actions outputs and step summaries when running in CI.
## Writing New E2E Tests
diff --git a/tests/tools/runner/internal/e2e/e2e.go b/tests/tools/runner/internal/e2e/e2e.go
index 3b4ed62a..5cbe9d06 100644
--- a/tests/tools/runner/internal/e2e/e2e.go
+++ b/tests/tools/runner/internal/e2e/e2e.go
@@ -6,6 +6,7 @@ import (
"io"
"os"
"path/filepath"
+ "strconv"
"strings"
)
@@ -17,6 +18,7 @@ type Args struct {
Logs string
Provider string
Providers []string // resolved list; len>1 means matrix mode
+ Slowest int
DryRun bool
}
@@ -43,6 +45,9 @@ Options:
comma-separated names to run a browser matrix. Cloak
builds pinchtab-cloakbrowser:test unless SKIP_BUILD=1.
ghost-chrome uses Chrome with static routing.
+ --slowest N Report only: print the N slowest tests and the
+ per-scenario totals from results/timings-<suite>.json.
+ Runs nothing and needs no Docker.
--dry-run Print the compose plan without running it
--help, -h Show this help
`
@@ -59,6 +64,14 @@ func Run(argv []string, stdout, stderr io.Writer) int {
return 1
}
+ if args.Slowest > 0 {
+ if err := runSlowest(args.Suite, args.Slowest, resolveRepoRoot(), stdout); err != nil {
+ _, _ = fmt.Fprintf(stderr, "e2e: %v\n", err)
+ return 1
+ }
+ return 0
+ }
+
if len(args.Providers) > 1 {
return runProviderMatrix(args, stdout, stderr)
}
@@ -169,6 +182,16 @@ func ParseArgs(argv []string) (Args, error) {
return args, err
}
args.Provider = v
+ case "--slowest":
+ v, err := next(&i, arg)
+ if err != nil {
+ return args, err
+ }
+ n, convErr := strconv.Atoi(strings.TrimSpace(v))
+ if convErr != nil || n <= 0 {
+ return args, fmt.Errorf("--slowest must be a positive whole number (got %q)", v)
+ }
+ args.Slowest = n
case "--dry-run":
args.DryRun = true
default:
diff --git a/tests/tools/runner/internal/e2e/runner.go b/tests/tools/runner/internal/e2e/runner.go
index f07200eb..402d0904 100644
--- a/tests/tools/runner/internal/e2e/runner.go
+++ b/tests/tools/runner/internal/e2e/runner.go
@@ -55,6 +55,7 @@ type suiteDef struct {
Smoke bool
Summary string
Report string
+ Timings string
LogPrefix string
Output string
LogServices []string
diff --git a/tests/tools/runner/internal/e2e/suite.go b/tests/tools/runner/internal/e2e/suite.go
index 794cceb6..5a909fab 100644
--- a/tests/tools/runner/internal/e2e/suite.go
+++ b/tests/tools/runner/internal/e2e/suite.go
@@ -81,6 +81,7 @@ func (d suiteDescriptor) build() suiteDef {
Smoke: d.Smoke,
Summary: resultsPath("summary", d.Name, "txt"),
Report: resultsPath("report", d.Name, "md"),
+ Timings: resultsPath("timings", d.Name, "json"),
Output: resultsPath("output", d.Name, "log"),
LogPrefix: "logs-" + d.Name,
LogServices: d.LogServices,
@@ -291,7 +292,7 @@ func (r *Runner) prepareSuiteResults(def suiteDef) {
_, _ = fmt.Fprintf(r.stdout, "# prepare results for %s\n", def.Name)
return
}
- for _, path := range []string{def.Summary, def.Report, def.Output} {
+ for _, path := range []string{def.Summary, def.Report, def.Timings, def.Output} {
_ = os.Remove(filepath.Join(r.repoRoot, path))
}
for _, path := range []string{
@@ -347,7 +348,7 @@ func execCommand(command []string, dir string) *exec.Cmd {
}
func (r *Runner) showFailureArtifacts(def suiteDef, duration time.Duration) {
- paths := []string{def.Summary, def.Report, def.Output}
+ paths := []string{def.Summary, def.Report, def.Timings, def.Output}
for _, path := range paths {
if fileExists(filepath.Join(r.repoRoot, path)) {
_, _ = fmt.Fprintf(r.stdout, " artifact: %s\n", path)
@@ -398,6 +399,8 @@ func (r *Runner) writeSuiteReports(def suiteDef, duration time.Duration, exitCod
if err := os.WriteFile(filepath.Join(r.repoRoot, def.Report), []byte(report), 0o644); err != nil {
_, _ = fmt.Fprintf(r.stderr, "e2e: failed to write %s: %v\n", def.Report, err)
}
+
+ r.writeSuiteTimings(def, data, timestamp)
return data
}
diff --git a/tests/tools/runner/internal/e2e/timings.go b/tests/tools/runner/internal/e2e/timings.go
new file mode 100644
index 00000000..b761dc82
--- /dev/null
+++ b/tests/tools/runner/internal/e2e/timings.go
@@ -0,0 +1,206 @@
+package e2e
+
+import (
+ "encoding/json"
+ "fmt"
+ "io"
+ "os"
+ "path/filepath"
+ "sort"
+ "strings"
+)
+
+// comparisonFloorMs is the duration below which a run-to-run ratio is noise:
+// measured median swing between runs is ~16%, so a 10ms→20ms move reads as
+// +100% and means nothing. Sub-floor tests stay in the records and in the
+// totals; only ratio comparisons must skip them.
+const comparisonFloorMs = 100
+
+type timingRecord struct {
+ Suite string `json:"suite"`
+ Stack string `json:"stack"`
+ Provider string `json:"provider"`
+ Scenario string `json:"scenario"`
+ Test string `json:"test"`
+ Ms int64 `json:"ms"`
+ Status string `json:"status"`
+}
+
+type scenarioTotal struct {
+ Scenario string `json:"scenario"`
+ Tests int `json:"tests"`
+ Ms int64 `json:"ms"`
+}
+
+type suiteTimings struct {
+ Suite string `json:"suite"`
+ Stack string `json:"stack"`
+ Provider string `json:"provider"`
+ Timestamp string `json:"timestamp"`
+ ComparisonFloorMs int64 `json:"comparisonFloorMs"`
+ Tests int `json:"tests"`
+ TotalMs int64 `json:"totalMs"`
+ Scenarios []scenarioTotal `json:"scenarios"`
+ Records []timingRecord `json:"records"`
+}
+
+// stackLabel names the compose file the suite ran under. Run-to-run comparisons
+// that mix stacks are measuring contention, not the change under test.
+func stackLabel(compose string) string {
+ switch compose {
+ case singleCompose:
+ return "singleCompose"
+ case multiCompose:
+ return "multiCompose"
+ case "":
+ return "none"
+ default:
+ return compose
+ }
+}
+
+// splitScenario reads the "[scenario] test name" shape the E2E_RESULT stream
+// already carries, so the scenario grouping needs no second source of truth.
+func splitScenario(name string) (scenario, test string) {
+ if !strings.HasPrefix(name, "[") {
+ return "", name
+ }
+ end := strings.Index(name, "]")
+ if end < 0 {
+ return "", name
+ }
+ return name[1:end], strings.TrimSpace(name[end+1:])
+}
+
+func buildSuiteTimings(suite, stack, provider, timestamp string, results []suiteTestResult) suiteTimings {
+ timings := suiteTimings{
+ Suite: suite,
+ Stack: stack,
+ Provider: provider,
+ Timestamp: timestamp,
+ ComparisonFloorMs: comparisonFloorMs,
+ Tests: len(results),
+ Records: make([]timingRecord, 0, len(results)),
+ }
+
+ totals := map[string]*scenarioTotal{}
+ var order []string
+ for _, result := range results {
+ scenario, test := splitScenario(result.Name)
+ timings.TotalMs += result.DurationMs
+ timings.Records = append(timings.Records, timingRecord{
+ Suite: suite,
+ Stack: stack,
+ Provider: provider,
+ Scenario: scenario,
+ Test: test,
+ Ms: result.DurationMs,
+ Status: result.Status,
+ })
+ total, seen := totals[scenario]
+ if !seen {
+ total = &scenarioTotal{Scenario: scenario}
+ totals[scenario] = total
+ order = append(order, scenario)
+ }
+ total.Tests++
+ total.Ms += result.DurationMs
+ }
+
+ for _, scenario := range order {
+ timings.Scenarios = append(timings.Scenarios, *totals[scenario])
+ }
+ sort.Slice(timings.Scenarios, func(i, j int) bool {
+ if timings.Scenarios[i].Ms != timings.Scenarios[j].Ms {
+ return timings.Scenarios[i].Ms > timings.Scenarios[j].Ms
+ }
+ return timings.Scenarios[i].Scenario < timings.Scenarios[j].Scenario
+ })
+ return timings
+}
+
+func (r *Runner) writeSuiteTimings(def suiteDef, data suiteReportData, timestamp string) {
+ provider := r.args.Provider
+ if provider == "" {
+ provider = "chrome"
+ }
+ timings := buildSuiteTimings(def.Name, stackLabel(def.Compose), provider, timestamp, data.Results)
+
+ encoded, err := json.MarshalIndent(timings, "", " ")
+ if err != nil {
+ _, _ = fmt.Fprintf(r.stderr, "e2e: failed to encode %s: %v\n", def.Timings, err)
+ return
+ }
+ encoded = append(encoded, '\n')
+ if err := os.WriteFile(filepath.Join(r.repoRoot, def.Timings), encoded, 0o644); err != nil {
+ _, _ = fmt.Fprintf(r.stderr, "e2e: failed to write %s: %v\n", def.Timings, err)
+ }
+}
+
+func loadSuiteTimings(repoRoot, suite string) (suiteTimings, error) {
+ path := filepath.Join(repoRoot, resultsPath("timings", suite, "json"))
+ data, err := os.ReadFile(path)
+ if err != nil {
+ return suiteTimings{}, fmt.Errorf("no timings for suite %q: %w (run the suite once to produce it)", suite, err)
+ }
+ var timings suiteTimings
+ if err := json.Unmarshal(data, &timings); err != nil {
+ return suiteTimings{}, fmt.Errorf("cannot parse %s: %w", path, err)
+ }
+ return timings, nil
+}
+
+func renderSlowest(timings suiteTimings, top int) string {
+ var out strings.Builder
+ fmt.Fprintf(&out, "suite: %s stack: %s browser: %s\n", timings.Suite, timings.Stack, timings.Provider)
+ if timings.Timestamp != "" {
+ fmt.Fprintf(&out, "run: %s\n", timings.Timestamp)
+ }
+ fmt.Fprintf(&out, "total: %d tests in %s\n", timings.Tests, formatMs(timings.TotalMs))
+
+ records := append([]timingRecord(nil), timings.Records...)
+ sort.SliceStable(records, func(i, j int) bool { return records[i].Ms > records[j].Ms })
+ if top > len(records) {
+ top = len(records)
+ }
+
+ fmt.Fprintf(&out, "\nslowest %d tests\n", top)
+ for _, record := range records[:top] {
+ fmt.Fprintf(&out, " %9s [%s] %s\n", formatMs(record.Ms), record.Scenario, record.Test)
+ }
+
+ fmt.Fprintf(&out, "\nper-scenario totals\n")
+ for _, scenario := range timings.Scenarios {
+ fmt.Fprintf(&out, " %9s %-32s %s\n", formatMs(scenario.Ms), scenario.Scenario, pluralTests(scenario.Tests))
+ }
+
+ fmt.Fprintf(&out, "\nGate on the totals above, not on per-test ratios: run-to-run swing is ~16%%.\n")
+ fmt.Fprintf(&out, "Exclude tests under %dms from any ratio — at that size the ratio is noise.\n", timings.ComparisonFloorMs)
+ return out.String()
+}
+
+func pluralTests(n int) string {
+ if n == 1 {
+ return "1 test"
+ }
+ return fmt.Sprintf("%d tests", n)
+}
+
+func formatMs(ms int64) string {
+ if ms < 1000 {
+ return fmt.Sprintf("%dms", ms)
+ }
+ return fmt.Sprintf("%.2fs", float64(ms)/1000)
+}
+
+func runSlowest(suite string, top int, repoRoot string, stdout io.Writer) error {
+ timings, err := loadSuiteTimings(repoRoot, suite)
+ if err != nil {
+ return err
+ }
+ if len(timings.Records) == 0 {
+ return fmt.Errorf("timings for suite %q hold no test records", suite)
+ }
+ _, _ = io.WriteString(stdout, renderSlowest(timings, top))
+ return nil
+}
diff --git a/tests/tools/runner/internal/e2e/timings_test.go b/tests/tools/runner/internal/e2e/timings_test.go
new file mode 100644
index 00000000..cf357209
--- /dev/null
+++ b/tests/tools/runner/internal/e2e/timings_test.go
@@ -0,0 +1,221 @@
+package e2e
+
+import (
+ "bytes"
+ "encoding/json"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+)
+
+func sampleResults() []suiteTestResult {
+ return []suiteTestResult{
+ {Name: "[actions-basic] pinchtab click <button>", Status: "passed", DurationMs: 790},
+ {Name: "[actions-basic] pinchtab press <key>", Status: "passed", DurationMs: 20},
+ {Name: "[audit-basic] sitemap mode discovers pages", Status: "failed", DurationMs: 6050},
+ {Name: "ungrouped result with no scenario", Status: "passed", DurationMs: 140},
+ }
+}
+
+func TestBuildSuiteTimingsGroupsByScenarioAndTotalsReconcile(t *testing.T) {
+ timings := buildSuiteTimings("api-extended", "multiCompose", "chrome", "2026-01-01T00:00:00Z", sampleResults())
+
+ if timings.Tests != 4 {
+ t.Errorf("Tests = %d, want 4", timings.Tests)
+ }
+
+ var recordSum int64
+ for _, record := range timings.Records {
+ recordSum += record.Ms
+ }
+ var scenarioSum int64
+ for _, scenario := range timings.Scenarios {
+ scenarioSum += scenario.Ms
+ }
+ if timings.TotalMs != recordSum || timings.TotalMs != scenarioSum {
+ t.Errorf("totals disagree: suite=%d records=%d scenarios=%d; a totals file whose parts do not add up cannot be diffed against a later run",
+ timings.TotalMs, recordSum, scenarioSum)
+ }
+ if timings.TotalMs != 7000 {
+ t.Errorf("TotalMs = %d, want 7000", timings.TotalMs)
+ }
+
+ if got := len(timings.Scenarios); got != 3 {
+ t.Fatalf("scenarios = %d, want 3", got)
+ }
+ if timings.Scenarios[0].Scenario != "audit-basic" || timings.Scenarios[0].Ms != 6050 {
+ t.Errorf("scenarios are not ordered slowest-first: got %+v", timings.Scenarios[0])
+ }
+ for _, scenario := range timings.Scenarios {
+ if scenario.Scenario == "actions-basic" && scenario.Tests != 2 {
+ t.Errorf("actions-basic tests = %d, want 2", scenario.Tests)
+ }
+ }
+}
+
+func TestBuildSuiteTimingsStampsEveryRecordWithItsRunConditions(t *testing.T) {
+ timings := buildSuiteTimings("api-extended", "multiCompose", "cloak", "2026-01-01T00:00:00Z", sampleResults())
+
+ for _, record := range timings.Records {
+ if record.Suite != "api-extended" || record.Stack != "multiCompose" || record.Provider != "cloak" {
+ t.Fatalf("record %q lost its run conditions (%+v); records extracted from the file would silently mix stacks and providers across runs", record.Test, record)
+ }
+ }
+ if timings.ComparisonFloorMs != comparisonFloorMs {
+ t.Errorf("ComparisonFloorMs = %d, want %d recorded in the file so consumers read the rule from the data", timings.ComparisonFloorMs, comparisonFloorMs)
+ }
+}
+
+func TestSplitScenarioReadsTheBracketPrefix(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ in string
+ wantScenario string
+ wantTest string
+ }{
+ {"bracketed", "[actions-basic] pinchtab click", "actions-basic", "pinchtab click"},
+ {"no bracket", "plain name", "", "plain name"},
+ {"unclosed bracket", "[broken name", "", "[broken name"},
+ {"bracket later in name", "click [not a scenario]", "", "click [not a scenario]"},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ scenario, test := splitScenario(tc.in)
+ if scenario != tc.wantScenario || test != tc.wantTest {
+ t.Errorf("splitScenario(%q) = (%q, %q), want (%q, %q)", tc.in, scenario, test, tc.wantScenario, tc.wantTest)
+ }
+ })
+ }
+}
+
+func TestStackLabelNamesTheComposeFile(t *testing.T) {
+ if got := stackLabel(singleCompose); got != "singleCompose" {
+ t.Errorf("stackLabel(single) = %q", got)
+ }
+ if got := stackLabel(multiCompose); got != "multiCompose" {
+ t.Errorf("stackLabel(multi) = %q", got)
+ }
+ if got := stackLabel(""); got != "none" {
+ t.Errorf("stackLabel(\"\") = %q, want none", got)
+ }
+}
+
+func TestRenderSlowestReportsTotalsAndTheComparisonFloor(t *testing.T) {
+ timings := buildSuiteTimings("api-extended", "multiCompose", "chrome", "2026-01-01T00:00:00Z", sampleResults())
+ out := renderSlowest(timings, 2)
+
+ if !strings.Contains(out, "slowest 2 tests") {
+ t.Errorf("missing the slowest header:\n%s", out)
+ }
+ if !strings.Contains(out, "sitemap mode discovers pages") {
+ t.Errorf("slowest test is not listed first:\n%s", out)
+ }
+ if !strings.Contains(out, "per-scenario totals") {
+ t.Errorf("per-scenario totals missing; gating is meant to happen on aggregates:\n%s", out)
+ }
+ if !strings.Contains(out, "under 100ms") {
+ t.Errorf("the report does not state the comparison floor, so a reader will compute ratios on noise:\n%s", out)
+ }
+ if !strings.Contains(out, "1 test\n") {
+ t.Errorf("scenario counts should read '1 test', not '1 tests':\n%s", out)
+ }
+}
+
+func TestRenderSlowestCapsTheListAtTheNumberOfTests(t *testing.T) {
+ timings := buildSuiteTimings("api", "singleCompose", "chrome", "", sampleResults())
+ out := renderSlowest(timings, 500)
+ if !strings.Contains(out, "slowest 4 tests") {
+ t.Errorf("asking for more tests than the run holds should report what exists:\n%s", out)
+ }
+}
+
+func TestRunSlowestReadsTheCheckedInJSONWithoutRunningAnything(t *testing.T) {
+ root := t.TempDir()
+ if err := os.MkdirAll(filepath.Join(root, "tests/e2e/results"), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ timings := buildSuiteTimings("api-extended", "multiCompose", "chrome", "2026-01-01T00:00:00Z", sampleResults())
+ encoded, err := json.MarshalIndent(timings, "", " ")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(filepath.Join(root, resultsPath("timings", "api-extended", "json")), encoded, 0o644); err != nil {
+ t.Fatal(err)
+ }
+
+ var out bytes.Buffer
+ if err := runSlowest("api-extended", 3, root, &out); err != nil {
+ t.Fatalf("runSlowest() error = %v", err)
+ }
+ if !strings.Contains(out.String(), "stack: multiCompose") {
+ t.Errorf("run conditions missing from the report:\n%s", out.String())
+ }
+}
+
+func TestRunSlowestSaysWhichSuiteHasNoTimingsYet(t *testing.T) {
+ err := runSlowest("api-extended", 3, t.TempDir(), &bytes.Buffer{})
+ if err == nil {
+ t.Fatal("runSlowest() on a suite that has never run reported success")
+ }
+ if !strings.Contains(err.Error(), "api-extended") {
+ t.Errorf("error does not name the suite: %v", err)
+ }
+}
+
+func TestSuiteTimingsPathSitsBesideTheMarkdownReport(t *testing.T) {
+ def := suiteDescriptor{Name: "api-extended", Compose: multiCompose}.build()
+ if def.Timings != "tests/e2e/results/timings-api-extended.json" {
+ t.Errorf("Timings = %q", def.Timings)
+ }
+}
+
+func TestParseArgsValidatesSlowest(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ argv []string
+ want int
+ wantErr bool
+ }{
+ {"positive", []string{"--slowest", "10"}, 10, false},
+ {"equals form", []string{"--slowest=5"}, 5, false},
+ {"zero", []string{"--slowest", "0"}, 0, true},
+ {"negative", []string{"--slowest", "-3"}, 0, true},
+ {"not a number", []string{"--slowest", "many"}, 0, true},
+ {"absent", []string{"--suite", "api"}, 0, false},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ args, err := ParseArgs(tc.argv)
+ if tc.wantErr {
+ if err == nil {
+ t.Fatalf("ParseArgs(%v) error = nil, want an error", tc.argv)
+ }
+ return
+ }
+ if err != nil {
+ t.Fatalf("ParseArgs(%v) error = %v", tc.argv, err)
+ }
+ if args.Slowest != tc.want {
+ t.Errorf("Slowest = %d, want %d", args.Slowest, tc.want)
+ }
+ })
+ }
+}
+
+func TestPrepareSuiteResultsClearsStaleTimings(t *testing.T) {
+ root := t.TempDir()
+ def := suiteDescriptor{Name: "api-extended", Compose: multiCompose}.build()
+ if err := os.MkdirAll(filepath.Join(root, "tests/e2e/results"), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ stale := filepath.Join(root, def.Timings)
+ if err := os.WriteFile(stale, []byte(`{"tests":1}`), 0o644); err != nil {
+ t.Fatal(err)
+ }
+
+ r := &Runner{repoRoot: root}
+ r.prepareSuiteResults(def)
+
+ if _, err := os.Stat(stale); !os.IsNotExist(err) {
+ t.Fatalf("stale timings survived the run preparation (stat err = %v); a run that dies before writing reports would leave the previous run's numbers looking current", err)
+ }
+}