Repository navigation
fix(ci): the test health report has printed "undefined" on every run since it was written - #757
Merged
Merged
Conversation
…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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#753 filed two
Unit testsflakes 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.tsread 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⚠️ No test results found" — while reporting success. This is what CI has printed on every run, including green ones:
undefined,data.testswasundefined, and the analyzer returned early with "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 testhad all five projects writingtests/reports/coverage/test-results.jsonin turn — including when an earlier project was the one that failed.Demonstrated rather than assumed. With a deliberately failing test in
scf-schemasandscaffald-apprunning after it:Under the old path the failure was simply gone. The reporter now keys the filename on
NX_TASK_TARGET_PROJECT; a barevitest runoutside nx keeps the original name. Only the analyzer consumes this path, so the blast radius is one file.3. Failures are now named
nx affectedprints onlyFailed 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: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> --logreturns 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 prepushgreen.Refs #753