Skip to content

fix(ci): the test health report has printed "undefined" on every run since it was written - #757

Merged
thinkclay merged 1 commit into
mainfrom
claude/753-flake
Sep 14, 2026
Merged

thinkclay merged 1 commit into
mainfrom
claude/753-flake

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

#753 filed two Unit tests flakes that passed on re-run and did not reproduce locally. Diagnosing them turned out to be impossible for two reasons that have nothing to do with the flake, and both are fixed here.

1. The analyzer parsed a shape nothing writes

scripts/test-health-analyzer.ts read the report as { totalTests, passed, failed, skipped, duration, tests[] }. Vitest's json reporter emits the Jest shape: { numTotalTests, numPassedTests, …, testResults[].assertionResults[] }.

So every field came back undefined, data.tests was undefined, and the analyzer returned early with "⚠️ No test results found" — while reporting success. This is what CI has printed on every run, including green ones:

Summary:
  Total Tests: undefined
  Passed: undefined ✅
  Failed: undefined
  Total Duration: NaNs

It now reads the real schema. Unknown-shaped files are skipped rather than throwing, so one malformed report can't hide the rest.

2. Five projects wrote one file, and the last writer won

Every package inherits the root vitest config, so nx affected -t test had all five projects writing tests/reports/coverage/test-results.json in turn — including when an earlier project was the one that failed.

Demonstrated rather than assumed. With a deliberately failing test in scf-schemas and scaffald-app running after it:

files written analyzer reports
old fixed path 1 85 tests, 0 failed
one file per project 2 143 tests, 1 failed

Under the old path the failure was simply gone. The reporter now keys the filename on NX_TASK_TARGET_PROJECT; a bare vitest run outside nx keeps the original name. Only the analyzer consumes this path, so the blast radius is one file.

3. Failures are now named

nx affected prints only Failed tasks: - <project> — no test name, no assertion, no stack. That is precisely why a red build could not be told from a flake without reproducing it locally. The report now leads with:

❌ Failed Tests (1):
  1. probe suite deliberately fails so the analyzer has something to name
     .../__probe__/flake-probe.test.ts
     AssertionError: expected { a: 1 } to deeply equal { a: 2 }

The step keeps if: always() and still exits 0 — it is diagnostic; Test (affected) remains what fails the build.

What this does not do

It does not identify the flake. It makes the next one legible, which the two that prompted #753 were not.

Worth recording for whoever picks that up: GitHub discards a superseded attempt's logs. gh run view --job=<attempt-1 job id> --log returns the re-run's output while the steps API reports attempt 1's conclusions — so after a re-run there is nothing left to read. Both flakes were re-run before the logs were captured, which is why the only surviving evidence is the failing project name I noted at the time.

So the honest state of #753: acceptance box 1 is done, boxes 2 and 3 are not. I'd suggest leaving it open until a third flake occurs — this time it will say what failed.

Verified

End to end with a deliberate failing test: named in the report, surviving alongside a later-running project, and absent under the old fixed path. pnpm prepush green.

Refs #753

…since it was written

#753 filed two Unit tests flakes that passed on re-run and did not reproduce
locally. Diagnosing them turned out to be impossible for two reasons that have
nothing to do with the flake itself, and both are fixed here.

**1. The analyzer parsed a shape nothing writes.**
scripts/test-health-analyzer.ts read the report as

    { totalTests, passed, failed, skipped, duration, tests[] }

Vitest's json reporter emits the Jest shape:

    { numTotalTests, numPassedTests, …, testResults[].assertionResults[] }

So every field came back undefined, `data.tests` was undefined, and the analyzer
returned early with "⚠️ No test results found. Run tests first." — while
reporting success. That is what CI has printed on every run, including green
ones:

    Total Tests: undefined
    Passed: undefined ✅
    Total Duration: NaNs

It now reads the real schema. Unknown-shaped files are skipped rather than
throwing, so one malformed report cannot hide the rest, and the original shape
is still accepted since reading it costs nothing.

**2. Five projects wrote one file, and the last writer won.**
Every package inherits the root vitest config, so `nx affected -t test` had all
five projects writing tests/reports/coverage/test-results.json in turn —
including when an earlier project was the one that failed. Demonstrated rather
than assumed: with a deliberately failing test in scf-schemas and scaffald-app
running after it, the old fixed path produced one file and the analyzer reported
"85 tests, 0 failed". The failure was simply gone.

The reporter now writes one file per project, keyed on NX_TASK_TARGET_PROJECT,
and the analyzer aggregates them. Same scenario: two files, 143 tests, 1 failed.
A bare `vitest run` outside nx keeps the original filename.

**3. Failures are now named.**
`nx affected` prints only "Failed tasks: - <project>" — no test name, no
assertion, no stack — which is why a red build could not be told from a flake
without reproducing it. The report now leads with the failing tests:

    ❌ Failed Tests (1):
      1. probe suite deliberately fails so the analyzer has something to name
         .../__probe__/flake-probe.test.ts
         AssertionError: expected { a: 1 } to deeply equal { a: 2 }

The step keeps `if: always()` and still exits 0. It is diagnostic; `Test
(affected)` remains the thing that fails the build.

This does not identify the flake. It makes the next one legible, which the two
that prompted #753 were not — GitHub also discards a superseded attempt's logs,
so after a re-run there is nothing left to read.

Verified end to end with a deliberate failing test: named in the report,
surviving alongside a later-running project, and absent under the old fixed
path.

Refs #753

Co-Authored-By: Claude Opus 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant