Skip to content

fix(test): record scope provenance so a partial run cannot read as a full pass (#3763) - #3778

Merged
zackees merged 1 commit into
masterfrom
fix/3763-test-scope-provenance
Jul 31, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/3763-test-scope-provenance

Conversation

@zackees

@zackees zackees commented Jul 31, 2026 •

Copy link
Copy Markdown
Member

Refs #3763. Implements the mitigation the issue asks for, plus the structural half of it.

The problem

Cached test counts are replayed verbatim:

✓ Fingerprint cache valid - skipping C++ unit tests [357/357 passed in 55.20s]

Nothing said whether that number came from a full-suite run or a narrowed one. A partial result read as an authoritative green until something invalidated the fingerprint — and the reporter acted on a 1/1 passed line once, believing it was evidence of suite health.

What changed

FingerprintResult gains a scope field recorded alongside the counts, and get_cache_summary() renders it:

run rendered
full 274/274 passed in 30.47s
filtered 1/1 passed in 16.98s, filtered run - NOT the full suite
written before this field existed 357/357 passed in 55.20s, scope unrecorded

The third row is deliberate: an unknown provenance is not evidence of a full pass, so legacy entries are never silently promoted to "full".

save_all() carries scope forward together with the counts it labels — carrying counts without their scope would relabel a filtered result as a full one on the very next cache hit, which would have been a fresh instance of this same bug.

Verified end to end

$ bash test --cpp
✅ All tests passed (274/274 in 30.49s)
after FULL run -> {'num_tests_run': 274, 'num_tests_passed': 274, 'scope': 'full'}

9 new tests in ci/tests/test_fingerprint_scope.py cover rendering for all three scopes, JSON round-trip, legacy load, and the carry-forward-with-counts invariant. bash lint clean; 85 related Python tests pass.

What I found while doing this — worth reading

I root-caused the 274 in the issue, and it is not a truncated suite. Full write-up in the issue, short version:

measure count
test sources discovered by discover_test_files() (authoritative) 274
test .dll binaries built 274
test_list_cache.txt entries 274
reporter's clean-run baseline 357

357 - 274 = 83, which is exactly the "83 test binaries" the reporter computed. Those are the example targets. --cpp runs unit tests and examples, and both feed the same ✅ All tests passed (N/N) line — so the headline silently means unit + examples on one run and unit only on the next, with no wording change. Reproducible on demand by deleting .cache/fingerprint/cpp_test_quick.json and re-running.

Also worth recording: the replayed number does not come from .full_run_cache.json (which the reporter checked and correctly found keyed separately). It comes from the fingerprint metadata for the cpp_test key. That is the slot a wrong N lands in.

Scope of this PR, honestly

This makes the labelling trustworthy. It does not fix the unit-vs-examples denominator ambiguity above — that is the larger and riskier half, and I would rather land honest labelling first than bundle them. Filing that separately.

One thing I want to be straight about: I could not reproduce the 1/1 case, and filtered runs currently do not persist a cpp_test fingerprint at all, so the filtered-write path does not fire today. The two write sites still had no guard, so the safety was incidental rather than structural — this makes it structural, and the scope unrecorded behaviour is what actually changes day-to-day output.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Test cache summaries now indicate whether results represent the full test suite or a partial selection.
    • Cached test metadata preserves scope information across saves and reloads.
    • Legacy cache entries without scope metadata are clearly identified as unrecorded.
  • Bug Fixes

    • Prevented partial test-run counts from being misrepresented as full-suite results.

…full pass

A cached test result is replayed verbatim on later runs:

    ✓ Fingerprint cache valid - skipping C++ unit tests [357/357 passed in 55.20s]

Nothing in that line said whether the number came from a full-suite run or a
narrowed one, so a partial result was indistinguishable from a full pass and
was reported as authoritative until something invalidated the fingerprint.
That is a silent-wrong-answer failure mode in the gate the project relies on
to decide whether to merge.

Record the run's scope alongside the counts and render it:

  full      -> 274/274 passed in 30.47s
  filtered  -> 1/1 passed in 16.98s, filtered run - NOT the full suite
  legacy    -> 357/357 passed in 55.20s, scope unrecorded

A fingerprint written before this field existed reports "scope unrecorded"
rather than being silently promoted to "full" -- an unknown provenance is not
evidence of a full pass.

save_all() carries scope forward together with the counts it labels. Carrying
the counts without their scope would relabel a filtered result as a full one
on the very next cache hit, which would have been a fresh instance of this
same bug.

Note on the two write sites in test_runner.py: neither previously checked
whether a filter was active before recording counts, so a filtered run's
number could land in the slot that is later replayed as authoritative. In
practice filtered runs currently do not persist a cpp_test fingerprint at all,
so that path does not fire today -- but the safety was incidental rather than
structural, which is consistent with the reporter having hit a bogus `1/1`
once under state neither of us could reconstruct. This makes it structural.

Refs #3763

Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 33d48bb8-9a68-4d6e-a8d1-8cdd4ea8cff3

📥 Commits

Reviewing files that changed from the base of the PR and between e7051d4 and c13168a.

📒 Files selected for processing (4)
  • ci/tests/test_fingerprint_scope.py
  • ci/util/fingerprint.py
  • ci/util/test_runner.py
  • ci/util/test_types.py

📝 Walkthrough

Walkthrough

The change adds optional scope metadata to fingerprint results. Test runners record full or partial coverage, persistence preserves the metadata, cache summaries report its provenance, and tests cover legacy and round-trip behavior.

Changes

Fingerprint scope provenance

Layer / File(s) Summary
Scope metadata and cache summaries
ci/util/test_types.py
FingerprintResult records optional scope metadata. Cache summaries distinguish full, partial, and unrecorded scope.
Scope persistence and carry-forward
ci/util/fingerprint.py
Fingerprint reads and writes include scope. Cached counts retain their previous scope when carried forward.
Test-runner scope recording
ci/util/test_runner.py
C++ test updates record scope="partial" for filtered runs and scope="full" for unfiltered runs.
Scope behavior validation
ci/tests/test_fingerprint_scope.py
Tests cover summaries, JSON persistence, legacy fingerprints, metadata updates, and partial-scope preservation.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CppTestRunner
  participant FingerprintManager
  participant FingerprintResult
  participant FingerprintFile
  CppTestRunner->>FingerprintManager: Update test metadata with scope
  FingerprintManager->>FingerprintResult: Store counts and scope
  FingerprintManager->>FingerprintFile: Persist scope
  FingerprintFile-->>FingerprintManager: Load scope
Loading

Possibly related PRs

  • FastLED/FastLED#3739: Both changes preserve fingerprint cache metadata through FingerprintManager.save_all and FingerprintResult.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the scope provenance fix that prevents partial test runs from appearing as full-suite passes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/3763-test-scope-provenance

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant