d26bf998 - fix(ledger): drop unreachable fallbacks on the mark-to-market counts - #4487
Merged
Merged
Conversation
legCount and valuedCount come from COUNT(*) aggregates without GROUP BY, so getRawOne always returns a row and neither column can be null. The `?? 0` guards could therefore never fire, and no test could reach them. Narrow the raw row type to match what the query actually returns and drop both guards; the SUM-based native and chf fallbacks stay, since those really can be null on an empty leg set. With the two unreachable branches gone the file reaches full coverage, so pin it in the ratchet.
…vice 422 files pinned, totals refreshed against the commit they were measured on. The paragraph on unreachable branches no longer points at ledger-mark-to-market as an open case - both of its examples have since been closed by deleting the fallback.
The gate run behind them was made on the branch, not on plain develop.
Collaborator
Author
|
Closed out after two review passes across both dimensions — conformance and project rules on one side, logic and correctness against the coverage data on the other.
The wording deliberately names the develop base rather than the branch commit, since the latter disappears on squash-merge.
|
TaprootFreak
marked this pull request as ready for review
July 30, 2026 09:30
This was referenced Jul 30, 2026
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.
Summary
ledger-mark-to-market.service.tssat at 92.3% branch coverage with two branches that no test could ever reach. They were?? 0guards over SQLCOUNT(*)columns, which cannot be null. Removing them is the correct fix — and the one the project's rule against silent fallbacks asks for. With them gone the file reaches full coverage and is pinned.Why the branches were unreachable
accountBalanceselects both counts as aggregates without aGROUP BY:Such a query always returns exactly one row, and
COUNTreturns0on an empty set — neverNULL. So+(raw.legCount ?? 0)could only ever evaluate its left side. Covering the right side would have required mocking a row the database cannot produce, which proves nothing.Change
legCount: stringandvaluedCount: stringinstead ofstring | null.+(raw.legCount ?? 0) === +(raw.valuedCount ?? 0)becomes+raw.legCount === +raw.valuedCount.+(raw?.native ?? 0)and+(raw?.chf ?? 0)sit overSUM(...), which really does returnNULLon an empty leg set. Their types keep| null.PINNED_LOGIC(421 → 422).docs/coverage-gate.mdrecords the new state. Its paragraph on unreachable branches no longer cites this file as an open case, since both examples it names have now been closed by deletion rather than by a test.No behaviour changes: for every row the query can produce, the old and new expressions evaluate identically.
Precedent in the same subdomain
This is not a new convention.
ledger-reconciliation.service.tsalready types the same two columns as non-nullablestringand compares them directly, without a guard — see itsgetRawOnegeneric and the two comparisons+row.legCount === +row.valuedCount(lines 334 and 549). This PR bringsledger-mark-to-market.service.tsin line with a pattern that is already established next to it.PR completeness
Migration: none. Environment/infrastructure: none. Service/DTO/interface: no contract changes — the narrowed type describes an internal query result, not an exposed shape. Frontend synchronization: none.
Test plan
npm run test:gate:covon this branch: exit 0 with all 422 thresholds, 336 suites / 6,207 tests.ledger-mark-to-market.service.tsreports 100/100/100/100 with branches at 22/22 — the two unreachable ones are gone and every remaining branch is covered.tsc --noEmitandprettier --checkboth clean. No test needed changing: no existing stub setsbaseUnitswithout the two counts, so none relied on the removed guards.