Skip to content

test(precision): characterize and guard the Decimal->float JSON boundary (C2)#209

Merged
robcohen merged 3 commits into
mainfrom
test/number-precision-boundary
Jul 1, 2026
Merged

test(precision): characterize and guard the Decimal->float JSON boundary (C2)#209
robcohen merged 3 commits into
mainfrom
test/number-precision-boundary

Conversation

@robcohen

@robcohen robcohen commented Jul 1, 2026

Copy link
Copy Markdown
Member

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.NumberFormat at 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

robcohen and others added 2 commits July 1, 2026 13:30
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.
@robcohen robcohen enabled auto-merge (squash) July 1, 2026 14:05
@robcohen robcohen merged commit 2362a8c into main Jul 1, 2026
23 of 24 checks passed
@robcohen robcohen deleted the test/number-precision-boundary branch July 1, 2026 14:25
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