test(precision): characterize and guard the Decimal->float JSON boundary (C2)#209
Merged
Conversation
The JSON API serializes Decimals via float() (core/charts.py), so exact ledger values cross the wire as float64. The frontend renders at display precision, so typical currency values are unaffected in the UI — but exports, raw API consumers, and high-precision values see the rounding. Layer 2 of the correctness plan: pin the boundary so it can't regress and a fix is measurable. - test_typical_values_are_lossless: currency + 8dp crypto + bounded magnitudes round-trip exactly (guards the common case). - test_high_precision_is_lost: xfail(strict) documenting that values beyond ~16 significant digits are rounded on the wire; flips green when numbers are emitted exactly (needs an exact JSON encoder + frontend decimal support, which also regenerates all snapshots — that epic, not an isolated wire change). - test_api_numbers_are_json_numbers_not_strings: pins the current wire contract so any format switch is deliberate.
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.
Layer 2 of the correctness plan — pins the Decimal→float64 JSON boundary (C2).
Investigation showed C2 is a data-fidelity issue (exports / raw API consumers / high-precision), not a wrong-number-in-the-UI issue: the frontend renders through
Intl.NumberFormatat display precision, so typical values aren't visibly wrong. A clean exact-wire fix needs a new dep (simplejson) + regenerating all snapshots + frontend decimal support (an epic).tests/test_number_precision_boundary.py:test_typical_values_are_lossless(guards the common case — currency/8dp crypto round-trip exactly),test_high_precision_is_lost(xfail(strict)documenting the frontier; flips green when numbers are emitted exactly — the acceptance test for the epic), and a wire-contract pin. 9 passed, 3 xfailed.(Was #205, stacked on #202 which is now merged; recreated to
main.)🤖 Generated with Claude Code