Skip to main content

Forty Red Tests: Splitting the Work without Gaps or Overlaps

Why This Matters

Forty failures are rarely forty problems. Split the work badly and two agents investigate the same outage, while the one real product bug falls between the cracks. Testers recognise this as a coverage problem, and the fix is the same: make coverage checkable.

Group first, then investigate

Most grouping needs no model at all. In code, before any agent starts:

function signature(r: TestResult): string {
  const msg = (r.error?.message ?? "").replace(/\d+/g, "N").slice(0, 120);
  return `${msg}`;
}
const groups = groupBy(failedTests(run), signature);

Twelve failures with connect ECONNREFUSED 10.0.4.17:8443 become one group: probably one environment problem, worth one investigation, not twelve. Use the model only for groups that code cannot separate.

Spot the shared cause early

When one group is large and points at infrastructure (connection refused, 503, out of memory), check that first. If the payment sandbox is down, there is no point spending tokens on twelve separate root-cause investigations. The report can say: 12 failures, one cause: payment-sandbox unavailable (OOMKilled at 14:03).

Assign each group exactly once

The coordinator proposes an assignment; your code checks it:

const assigned = plan.flatMap((p) => p.failureIds);
const missing = allIds.filter((id) => !assigned.includes(id));
const duplicate = assigned.filter((id, i) => assigned.indexOf(id) !== i);
if (missing.length || duplicate.length) {
  throw new PlanError({ missing, duplicate });
}

Feed the error back to the coordinator once, like the flaky guard in lesson 10. A plan that still has gaps goes to a human.

The coverage check at the end

The final report must account for every failure exactly once: triaged, grouped under a shared cause, or listed as not triaged with a reason. Check it in code before the report is published:

expect(report.accountedFor()).toEqual(new Set(allIds));

Exercise

Use fixtures/runs/run-1099.json from the repository: 40 failures, made up of 12 payment-sandbox errors, 15 timeouts in search tests, 10 assertion failures after a pricing commit, and 3 unrelated failures. Do not peek at the composition while you build: your grouping code should find those four groups by itself. Implement grouping in code and the coverage check, and run the team on it.

Compare with solution/lesson-40-triage-team, which covers lessons 34–40 (see docs/exercises.md, module 5).