/biloba-go:flake-huntfrom biloba-go
Runs a Biloba Ginkgo browser suite many times (60 by default) to measure per-spec failure rates from JSON reports. Use before declaring a flake fixed, after changing shared test helpers, or to measure suite performance.
Ships in biloba-go. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
A flake hunt measures how often each spec fails. It runs the whole suite many times, lets every run finish, and keeps one JSON report per run. You read the reports afterwards to get a failure rate per spec, and you diagnose each failure from the evidence in its report rather than by trying to reproduce it.
Fixing what a hunt finds → flaky-specs. Reading a single failure's artifacts → debug-failures. Sibling skills are named here without a prefix; invoke one with the same plugin prefix you loaded this skill under.
The gate for an ordinary change is still one ginkgo -r -p run. A hunt measures a rate; it doesn't replace the gate.
#!/usr/bin/env bash
# Run the browser suite RUNS times, every run to completion, one JSON report per run.
set -uo pipefail
PKG=${PKG:-./e2e}
RUNS=${RUNS:-60}
PROCS=${PROCS:-6} # your measured knee (see "Choosing --procs")
DIR=${DIR:-.ginkgo-report/flake}
GINKGO="go run github.com/onsi/ginkgo/v2/ginkgo"
rm -rf "$DIR" && mkdir -p "$DIR"
DIR=$(cd "$DIR" && pwd) # absolute: the test binary runs in its package directory
$GINKGO build "$PKG" >/dev/null || exit 1
BIN="$PKG/$(basename "$PKG").test" # compiled once; every run replays it
failed=0
for i in $(seq 1 "$RUNS"); do
n=$(printf '%03d' "$i")
if BILOBA_SCREENSHOTS_DIR="$DIR/run-$n" $GINKGO --procs="$PROCS" --randomize-all --no-color \
--poll-progress-after=10s \
${LABELS:+--label-filter="$LABELS"} ${FOCUS_FILE:+--focus-file="$FOCUS_FILE"} \
--json-report="run-$n.json" --output-dir="$DIR" \
"$BIN" >"$DIR/run-$n.log" 2>&1; then
echo "run $n/$RUNS ok"
else
failed=$((failed + 1)); echo "run $n/$RUNS FAIL ($DIR/run-$n.log)"
fi
done
echo "$failed of $RUNS runs failed"
[ "$failed" -eq 0 ]
Wrap it in a make flake-hunt target if the project has a Makefile, and gitignore the report directory. What each choice is for:
ginkgo --repeat and --until-it-fails stop at the first failure. That tells you something flaked but not how often, and the first frequent flake hides every rarer one behind it. The loop keeps going and exits non-zero at the end if any run failed.RandomSeed, each failure's message and file:line, the spec's GinkgoWriter output (where Biloba streams console.log), and Biloba's failure artifacts as report entries: the poll trajectory, the DOM outline, the screenshot path, and the detached-node, occluded-click, and shadowed-handler diagnoses when they apply.BILOBA_SCREENSHOTS_DIR per run. Failure screenshots are named after the spec and the tab, so in a shared directory a later run overwrites an earlier run's screenshot of the same spec. An explicit BilobaConfigScreenshotsToDir in the bootstrap takes precedence over the variable, so remove it or have it read the variable.--poll-progress-after=10s. A spec still running after 10s gets a progress report with a goroutine dump and a screenshot of every open tab's viewport. That's the evidence you need for a hang, and taking it doesn't change the page, so the flag doesn't change what you're hunting.LABELS and FOCUS_FILE narrow a hunt without editing the script (LABELS='!visual', FOCUS_FILE=checkout). Focus by file. A substring --focus into an Ordered container runs the matched spec without the earlier specs whose state it depends on.--procsA hunt runs in parallel because concurrency widens race windows. Beyond a point, more processes only add contention. A Biloba spec spends most of its time waiting for the one shared Chrome to render and lay out: in one measured suite Chrome used about 4.7 cores while the Go processes stayed near 2% CPU. Once Chrome saturates the machine's performance cores, each extra process slows every round trip and produces timeouts that come from the machine, not from the code.
Find the knee once per machine: run the suite at 2, 4, 6, and 8 processes and record the wall clock. It falls roughly linearly and then flattens. Hunt and gate at the point where it flattens. In the suite above, one Chrome per process and a RAM disk for temp files both made no difference, because the limit was Chrome's render CPU.
git stash from another process. Two signs a run was contaminated rather than flaky: many unrelated specs fail in one run and pass in the next, or the log has no SUCCESS!/FAIL! verdict line. Discard those runs.FOCUS_FILE puts every process behind a handful of specs. That gives heavy contention on one axis and none of the cross-file interleaving that --randomize-all produces across the whole suite. In one case, a shared-helper refactor passed 20 out of 20 focused runs and then flaked repeatedly in full-suite runs. For changes to shared helpers, fixtures, or a family of specs, only a full-suite hunt counts.HaveScreenshot uses its entire timeout before it fails, because every poll captures and compares again. One visual flake in 60 runs costs little. A stale baseline fails every visual spec on every run and turns a hunt of minutes into hours. Whether to include visual specs is a question of their summed spec time, not wall clock; if they carry a label, LABELS='!visual' excludes them.#!/usr/bin/env bash
# Per-spec failure rate across a hunt's reports, with the runs and seeds to look at.
DIR=${DIR:-.ginkgo-report/flake}
for log in "$DIR"/run-*.log; do
[ -f "${log%.log}.json" ] || echo "!! $(basename "$log" .log) left no report (killed?) — not a clean run"
done
jq -rn '
[inputs | .[0] as $s | {
run: (input_filename | sub(".*/"; "") | sub("\\.json$"; "")),
seed: $s.SuiteConfig.RandomSeed,
reasons: ($s.SpecialSuiteFailureReasons // []),
failures: [$s.SpecReports[] | select(.State | IN("failed", "panicked", "timedout", "aborted")) | {
spec: (.LeafNodeType as $type | (.ContainerHierarchyTexts + [.LeafNodeText])
| map(select(. != "")) | join(" > ") | if . == "" then "(\($type))" else . end),
at: "\(.Failure.Location.FileName | sub(".*/"; "")):\(.Failure.Location.LineNumber)"}]}]
| (map(select(.reasons | length > 0))) as $unfinished
| "\(length) runs: \(map(select(.failures | length > 0)) | length) with a failure, \($unfinished | length) unfinished",
($unfinished[] | "!! \(.run) did not finish (\(.reasons | join("; "))) — not a clean run"),
"",
([.[] | .run as $run | .seed as $seed | .failures[] | . + {run: $run, seed: $seed}]
| group_by(.spec) | sort_by(-length)[]
| "\(length)x \(.[0].spec)\n at \(.[0].at) runs: \(map(.run) | join(", ")) seeds: \(map(.seed) | join(", "))")
' "$DIR"/run-*.json
60 runs: 3 with a failure, 0 unfinished
2x checkout > applies the coupon
at checkout_test.go:88 runs: run-014, run-051 seeds: 1789182212, 1789182260
1x (SynchronizedBeforeSuite)
at e2e_suite_test.go:31 runs: run-033 seeds: 1789182244
A run that was interrupted, timed out, or failed to compile carries SpecialSuiteFailureReasons, and a run that was killed leaves no report. Neither is a clean run. A truncated run had less chance to flake, so counting it toward a clean streak skews the result toward "fixed".
jq -r --arg spec "applies the coupon" '
.[0].SpecReports[]
| select((.State | IN("failed", "panicked", "timedout", "aborted")) and (.LeafNodeText | contains($spec)))
| "== \(input_filename)\n\(.Failure.Message)\n"
+ (.ReportEntries // [] | map("-- \(.Name)\n\(.Value.Representation)") | join("\n"))
+ "\n-- GinkgoWriter\n\(.CapturedGinkgoWriterOutput // "")"
' .ginkgo-report/flake/run-*.json
That prints the failure message, Biloba's report entries (Poll trajectory, DOM Outline for: …, Screenshot for: …, and the others), and the spec's output. The screenshots are in run-NNN/, and a hang's progress report is in run-NNN.log. How to read each artifact → debug-failures.
Work from the evidence; don't try to reproduce the failure. Re-running a failed seed rarely reproduces a race: the seed fixes spec order, but not which process runs each spec or how the browser schedules its work. A rerun usually comes back green, which proves nothing. Form a hypothesis about the mechanism from the message, trajectory, outline, screenshot, and output, fix it for a reason you can state, and hunt again. When a failure does look order-dependent, the seed is worth a try: ginkgo --seed=<seed> --randomize-all --procs=<N> ./e2e.
Don't paper over a flake by widening a timeout, adding FlakeAttempts, or re-running until green. The fixes for each smell → flaky-specs.
Timed out after 8.3s on a 2s Eventually means a single call into the browser took seconds to return. The trajectory shows few samples, and the failure screenshot can show the right state because the page caught up after the assertion gave up. To show whether the tab's event loop was running during the gap, find something the tab itself produced, such as a request it made with a server-side timestamp; a goroutine dump only shows that Go was waiting. Biloba bounds each call into Chrome, so a wedge longer than 30s fails with deadline_exceeded instead → debug-failures. When stalls hit several processes at the same moment, in unrelated specs, in a handful of runs, the machine stalled: check what else was running (builds, other agents, Spotlight indexing) and rerun on an idle machine before root-causing any spec.A flake that fails in a fraction p of runs still passes n runs in a row with probability (1 − p)^n:
| Rate | 30 clean runs happen by chance | 60 clean runs happen by chance |
|---|---|---|
| 5% | 21% | 4.6% |
| 3% | 40% | 16% |
So 30 green runs tell you little about a flake that fires a few percent of the time. To call a flake at rate p dead with about 95% confidence you need roughly 3 / p clean runs: 60 for 5%, 100 for 3%. You also need a written root cause. If you can't say why it flaked, the clean runs may just be luck.
Every report records every spec's duration, so a hunt also gives you 60 timing samples per spec instead of one.
#!/usr/bin/env bash
# Where a hunt's time went: wall clock, parallel efficiency, slowest specs, the long tail.
DIR=${DIR:-.ginkgo-report/flake}
jq -rn '
def median: sort | if length == 0 then 0 elif length % 2 == 1 then .[length / 2 | floor]
else (.[length / 2 - 1] + .[length / 2]) / 2 end;
def r: . * 100 | round / 100;
[inputs | (input_filename | sub(".*/"; "") | sub("\\.json$"; "")) as $run | .[0]
| select((.SpecialSuiteFailureReasons // []) | length == 0) # unfinished runs flatter every number
| {run: $run, wall: (.RunTime / 1e9), procs: .SuiteConfig.ParallelTotal,
specs: [.SpecReports[] | select(.LeafNodeType == "It" and .State != "skipped" and .State != "pending") | {
run: $run, state: .State, t: (.RunTime / 1e9),
name: ((.ContainerHierarchyTexts + [.LeafNodeText]) | join(" > ")),
setup: ([.SpecEvents[]? | select(.SpecEventType == "Node (End)" and .NodeType == "BeforeAll")
| .Duration] | add // 0 | . / 1e9)}]}]
| (map(.wall) | median) as $wall | length as $n
| (map(.specs | map(.t) | add) | add / $n) as $summed
| ([.[].specs[] | select(.state == "passed")] | group_by(.name) | map({
name: .[0].name, med: (map(.t) | median), setup: (map(.setup) | median),
max: (max_by(.t) | .t), maxrun: (max_by(.t) | .run)})) as $specs
| ($specs | map(select(.med > 0.01 and .max >= 1 and .max / .med >= 3))) as $tail
| "\($n) finished runs at \(.[0].procs) procs, \($specs | length) specs",
"wall clock median \($wall | r)s min \(map(.wall) | min | r)s max \(map(.wall) | max | r)s",
"summed spec time \($summed | r)s per run; parallel efficiency \($summed / .[0].procs / $wall | r)",
"per-spec cost \(($specs | map(.med) | add) / ($specs | length) * 1000 | round)ms (sum of medians / spec count)",
"", "slowest by median (setup = BeforeAll, charged to the first spec of its Ordered container):",
($specs | sort_by(-.med)[:15][] | " \(.med | r)s setup \(.setup | r)s \(.name)"),
"", "long tail (worst run >= 3x the spec'"'"'s own median, and >= 1s):",
(if ($tail | length) == 0 then " none" else empty end),
($tail | sort_by(-(.max / .med))[] | " \(.max / .med | r)x median \(.med | r)s max \(.max | r)s [\(.maxrun)] \(.name)"),
"", "tail maxima by run (\($tail | length / $n | r) expected per run if independent):",
($tail | group_by(.maxrun) | sort_by(-length)[] | " \(length) \(.[0].maxrun)")
' "$DIR"/run-*.json
How to read it:
setup separates a spec from its container. A BeforeAll is charged to whichever spec runs first in its Ordered container, so the slowest spec may just be paying for the container's setup.flaky-specs §9). A By with a callback records its own duration in SpecEvents; for a plain By, take the gap between consecutive events' TimelineLocation.Time.--poll-progress-after=1s so short stalls also dump stacks, can separate them.End each hunt with a snapshot, committed with the work the hunt gated:
#!/usr/bin/env bash
# One row per hunt in perf/history.tsv, plus the per-spec medians it came from. Commit both.
DIR=${DIR:-.ginkgo-report/flake}
detail="perf/snapshots/$(date +%F)-$(git rev-parse --short HEAD).tsv"
mkdir -p perf/snapshots
[ -f perf/history.tsv ] ||
printf 'date\tsha\tbiloba\tprocs\truns\tspecs\twall_median_s\tsummed_s\tper_spec_ms\tefficiency\n' > perf/history.tsv
PRELUDE='
def median: sort | if length % 2 == 1 then .[length / 2 | floor] else (.[length / 2 - 1] + .[length / 2]) / 2 end;
def r: . * 1000 | round / 1000;
[inputs | .[0] | select((.SpecialSuiteFailureReasons // []) | length == 0)] as $runs
| ([$runs[].SpecReports[] | select(.LeafNodeType == "It" and .State == "passed")
| {name: ((.ContainerHierarchyTexts + [.LeafNodeText]) | join(" > ")), t: (.RunTime / 1e9)}]
| group_by(.name) | map({name: .[0].name, med: (map(.t) | median)})) as $specs
| $runs'
jq -rn "$PRELUDE"' | $specs[] | select(.med >= 0.5) | [(.med * 1000 | round), .name] | @tsv' \
"$DIR"/run-*.json > "$detail"
jq -rn --arg date "$(date +%F)" --arg sha "$(git rev-parse --short HEAD)" \
--arg biloba "$(go list -m -f '{{.Version}}' github.com/onsi/biloba)" "$PRELUDE"'
| length as $n | .[0].SuiteConfig.ParallelTotal as $procs | (map(.RunTime / 1e9) | median) as $wall
| (map([.SpecReports[] | select(.LeafNodeType == "It") | .RunTime] | add / 1e9) | add / $n) as $summed
| [$date, $sha, $biloba, $procs, $n, ($specs | length), ($wall | r), ($summed | r),
(($specs | map(.med) | add) / ($specs | length) * 1000 | r), ($summed / $procs / $wall | r)] | @tsv
' "$DIR"/run-*.json >> perf/history.tsv
column -t -s $'\t' perf/history.tsv | tail -n 2
A growing suite's wall clock can't tell "we added specs" from "every spec got slower". Per-spec cost can. To compare the newest row with an earlier one:
runs column. A snapshot from one run is much weaker evidence than one from sixty.Measure your own noise floor by taking two snapshots with no code change between them.
Divide before you attribute a slowdown. Take the size of the effect, divide it by the per-operation cost of the mechanism you suspect, and check that the number of operations is plausible. For scale: a bare round trip to Chrome costs about 0.2ms, a spec in Biloba's own suite sends about 12 commands to Chrome, and b.NewTab() costs about 41ms. If an attribution needs thousands of operations per spec, it's wrong, and you should measure instead. "Unexplained" is an acceptable finding.
What SKILL.md sets; muted values are Claude Code's defaults
12 skills in this plugin
/apiOne-line reference for every Biloba Go method and matcher, grouped by area — selectors/locators, lifecycle, poll-config (WithTimeout/WithPolling/WithContext/Immediate), capturing a matcher's observed value (.Capture), navigation (GetLocation/GetTitle), cookies/storage, tabs, cross-origin iframes (b.Frame frame handles), DOM existence/visibility/contents/properties/forms, clicking and interactions (incl. drag/scroll/tap/modifiers/text-selection), realistic mode, keyboard, uploads, element JS, dialogs, downloads, arbitrary JS (incl. the GetJSValue app-state barrier), network stubbing/aborting/modifying/observing/holding (HoldResponse + Limit/ReleaseNext), screenshots/screencasts/outline/window, the page clock (InstallClock/Clock + PauseAt/Resume/RunFor/FastForward/SetFixedTime/SetSystemTime), and visual regression (HaveScreenshot + Mask/Tolerance/ChannelTolerance/Animated/InColorSchemes). Use to look up the exact Go method or matcher name and shape. Methods marked (dual) poll until they succeed when fully applied and return a pollable matcher when under-applied./debug-failuresSee why a Go/Ginkgo Biloba spec failed or flaked — the on-failure artifacts (DOM outline + screenshots + poll trajectory of the timed-out read + the visual-regression diagnosis with its .actual.png/.diff.png, the "never settled" warning an update run prints + the detached-node "matched then stopped matching" signal + the occluded-click diagnosis naming what covered the target), how Biloba auto-adapts to humans vs CI vs AI agents, the env vars and config knobs that surface them (BILOBA_SCREENSHOTS_DIR, BILOBA_SCREENSHOT_BASELINES_DIR, BILOBA_UPDATE_SCREENSHOTS, BILOBA_INLINE_SCREENSHOTS, BILOBA_OUTLINE_MAX, BILOBA_INTERACTIVE, BilobaConfig*), attaching app/store state to a failure, headless quirks (stale innerText, unscheduled requestAnimationFrame), and using b.Outline()/b.A11yOutline() to understand why a selector did not match. Use when a browser spec is failing or flaky and you need visibility, or to configure failure output for CI/agents. For *preventing* flakes (single-shot reads, avoiding b.Immediate(), optimistic-UI) see this plugin's flaky-specs skill.npx claudepluginhub onsi/biloba --plugin biloba-goOther plugins' skills for the same job