Skip to content

test(core): drive BidLabCore to 100% coverage of reachable code#9

Merged
scumunna merged 4 commits into
mainfrom
test/native-core-coverage
Jun 23, 2026
Merged

test(core): drive BidLabCore to 100% coverage of reachable code#9
scumunna merged 4 commits into
mainfrom
test/native-core-coverage

Conversation

@scumunna

Copy link
Copy Markdown
Owner

Native app first: instruments the Swift engine and adds tests until BidLabCore is at 100% line/function/region coverage of all reachable code.

How coverage is measured

SwiftPM is broken on this machine, so swift test --enable-code-coverage can't run. New Scripts/coverage.sh instruments the existing swiftc test build (-profile-generate -profile-coverage-mapping), force-loads the archive (so every object's map is included), runs the suite, and emits an llvm-cov report scoped to Sources/BidLabCore.

./Scripts/coverage.sh

Result

Metric Before After Reachable
Regions 79.4% 99.5% 100%
Functions 86.7% 99.3% 100%
Lines 95.7% 99.9% 100%
  • Suite grew from 5,127 → 5,271 known-answer checks, all passing (instrumented and canonical).
  • 25 of 27 source files are at a clean 100%.
  • The 4 remaining regions are unreachable defensive guards (se>0 under baselineRate∈(0,1); a columnIndex alias guard; two Credential ?? fallbacks that are non-nil for valid input). They are kept and documented in docs/COVERAGE.md rather than removed, force-unwrapped, or covered with a contrived test.

What's in here

  • refactor(core) — collapse Cohort.byPath's five lookup dictionaries into one ordered accumulator (removes four dead fallbacks); drop a dead winRate guard in PacedFlight (intervalOpportunities is max(1, ...)). Behavior unchanged.
  • test(core) — getter/divide-by-zero tests across the domain suites, a boundary suite (EdgeCoverageTests), and a parser suite (ParserCoverageTests) covering Cohort transcripts, Exam parsing/grading, and the full LessonParser directive grammar.
  • choreScripts/coverage.sh, docs/COVERAGE.md, gitignore the .build-cov artifacts.

Scope notes

  • The SwiftUI app layer (Sources/BidLab) is not unit-coverable with this toolchain (no XCTest UI runner); the pure engine is where the logic and the coverage bar live.
  • This raises the native check count to 5,271; the figure cited in the README/ACCEPTANCE docs (updated in docs: sync all documentation with the current implementation #8 to 5,127) should be reconciled to 5,271 when these land.

🤖 Generated with Claude Code

Stephen Umunna and others added 3 commits June 21, 2026 23:21
byPath looked values back up in per-key dictionaries after building them, leaving
four nil-coalescing fallbacks that can never fire (an id is in `order` only
because its track was seen, which sets every dict). Collapse the five
dictionaries into one ordered accumulator so the lookups are total. PacedFlight
computed winRate with `intervalOpportunities > 0 ? ... : 0`, but
intervalOpportunities is `max(1, ...)`, so that guard is dead; divide directly.

Behavior is unchanged; both simplify the code and remove unreachable branches.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add boundary and parser coverage to the known-answer suite, taking BidLabCore
from 79% to 99.5% region / 99.3% function / 99.9% line coverage (100% of all
reachable code). New checks cover computed getters and their divide-by-zero
branches; a boundary suite (EdgeCoverageTests) for every guard return and
ternary fallback across Pricing, Scoring, Auction, ReachFrequency, Systems,
Analytics, Attribution, BudgetAllocation, Probability (p==0/1, sd==0, quantile
tails), Statistics, and Credential; and a parser suite (ParserCoverageTests)
exercising Cohort transcripts, Exam parsing/grading, and the full LessonParser
directive grammar.

The suite is now 5,271 checks, all passing. The 4 remaining uncovered regions
are unreachable defensive guards, documented in docs/COVERAGE.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Scripts/coverage.sh instruments the swiftc test build with llvm coverage and
emits a per-file BidLabCore report (SwiftPM, and so swift test --enable-code-
coverage, is broken on this machine). docs/COVERAGE.md records the result and the
rationale for the unreachable defensive branches. Ignore the .build-cov dir.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Adds a `check` mode to Scripts/coverage.sh that parses the llvm-cov TOTAL row and
fails if missed regions/functions/lines exceed the documented unreachable baseline
(4/2/2 — the defensive guards in docs/COVERAGE.md). Any newly uncovered code raises
a missed count and fails the build. Wired into ci.yml as a step after the known-
answer suite, and documented in COVERAGE.md.

A literal 100% gate is impossible without deleting safe defensive code (llvm-cov
has no per-line ignore), so this guards against regression instead. Verified
locally: passes at the current baseline, fails on a simulated 9/5/7 regression.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@scumunna
scumunna merged commit afbc92c into main Jun 23, 2026
1 check passed
@scumunna
scumunna deleted the test/native-core-coverage branch June 23, 2026 18:04
scumunna pushed a commit that referenced this pull request Jun 23, 2026
…0 web)

#9 raised the native suite to 5,271 checks and #10 the web suite to 180; update
the README and ACCEPTANCE.md to match, and add the CI coverage-gate story (web
100%, native 100% of reachable code). ACCEPTANCE.md's web engine-suite row now
includes the added boundary tests (47 -> 80).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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