Skip to content

test: pin the display-precision fallback's cost/balance/price arms directly - #262

Merged
robcohen merged 1 commit into
mainfrom
fix/display-precision-fallback-coverage
Jul 18, 2026
Merged

test: pin the display-precision fallback's cost/balance/price arms directly#262
robcohen merged 1 commit into
mainfrom
fix/display-precision-fallback-coverage

Conversation

@robcohen

Copy link
Copy Markdown
Member

rustledger WIT 3.8+ engines ship options.display_precision (rustledger#1766, implemented in rustledger#1808) — the "planned FFI field" the fallback's guard comment anticipates. Against such a component, integration tests no longer reach _compute_display_precision's cost/balance/price tracking arms, and the 100% coverage gate trips in rustledger's downstream rustfava tests against PR component job.

This pins those arms with a direct unit test (cost per-unit and total shapes, number-less cost, balance and price-directive amounts, repeat-currency accumulation, and a non-tracked entry type), so the fallback stays covered and correct for engines that predate the field — regardless of which engine the suite runs against.

Verified locally: full suite at 100.00% coverage and 666 passed against the rustledger#1808 debug component.

Once rustfava requires a 3.8+ engine, the fallback (and this test) can be deleted outright — the engine-provided field supersedes it, and the local re-derivation has known drift from the canonical inference (per-unit-first cost sampling where rustledger core samples total-first).

🤖 Generated with Claude Code

https://claude.ai/code/session_013gJH7uBBF9Xw9et9QFRcsU

…rectly

rustledger WIT 3.8+ engines ship options.display_precision
(rustledger#1766, rustledger#1808), so integration tests running against
such a component no longer reach the fallback's cost/balance/price
tracking arms and the 100% coverage gate trips in rustledger's
downstream job. Pin those arms with a direct unit test so the fallback
stays covered and correct for engines that predate the field, regardless
of which engine the suite runs against.
robcohen added a commit to rustledger/rustledger that referenced this pull request Jul 18, 2026
…ield directly

The declarations-only export broke rustfava for real (2 test failures,
not just coverage): its loader treats a non-empty display_precision as
THE per-currency precision map and only falls back to local inference
when the field is empty — so a partial declarations map starved every
undeclared currency. The de-facto wire contract since the tracker era is
the full resolved map, and that is also what a rendering embedder
actually wants.

display_precision is again resolved_precisions(): fixed declarations
where present, canonical inference otherwise, every observed currency
listed. The rustfava-side coverage for its now-bypassed fallback lands
in rustledger/rustfava#262.
@robcohen
robcohen merged commit e089446 into main Jul 18, 2026
32 checks passed
@robcohen
robcohen deleted the fix/display-precision-fallback-coverage branch July 18, 2026 23:45
robcohen added a commit to rustledger/rustledger that referenced this pull request Jul 19, 2026
…on (WIT 3.8.0) (#1808)

* feat: session.format renders held entries with ledger display precision (WIT 3.8.0)

The #1766 format surface: `session.format` renders the HELD directives to
canonical beancount text honoring the ledger's per-currency display
precision, built from the held entries plus the held options.

- rustledger-core: `DisplayContext::from_directives` is now THE canonical
  builder (moved verbatim from the loader): amount-scan inference, then
  `option "display_precision"` overrides, then commodity `precision:`
  metadata. New `resolved_precisions()` exports the per-currency answer
  for the wire. The loader's `build_display_context` delegates.
- rustledger-ffi-wasi: `PrecisionTracker` deleted — it was a re-derivation
  of DisplayContext inference that OVERWROTE the option-derived
  `display_precision`, so the user's explicit option never crossed the
  boundary, and the two load paths disagreed (`load_source` shipped
  inference-only, `load_file` option-only). `build_ledger_options` now
  takes the ledger's DisplayContext and ships the canonical resolution.
- rustledger-ffi-component: WIT 3.8.0 + API_VERSION 3.8; `session.format`
  builds the context via `from_directives` and renders through the same
  `canonicalize_directives` path as the free format interface. Integer
  metadata now crosses the wire as `number`, not `text` — as text, a
  session round-trip turned `precision: 4` into `precision: "4"`.

Part of #1766.

* fix: ship declared precisions across the boundary, not inference

The rustfava CI job caught the first cut shipping RESOLVED precisions
(inference frozen as fixed entries for every observed currency), which
starved rustfava's documented undeclared-currency fallback (its tests
passed; only its 100% coverage gate tripped). Shipping inference as
declarations was also semantically wrong: it would pin a consumer's
precision against later entry-set changes, and inference is derivable
from the entries themselves wherever they travel.

`ledger-options.display-precision` now carries DECLARATIONS only —
`option "display_precision"` entries plus commodity `precision:`
metadata, precedence-resolved by the canonical DisplayContext
(`declared_precisions()` replaces `resolved_precisions()`).
`session.format` behavior is unchanged: its `from_directives` stage-1
scan re-infers from the held entries, so undeclared currencies land on
the same mode the loader would pick.

* fix: restore resolved precisions on the wire; rustfava consumes the field directly

The declarations-only export broke rustfava for real (2 test failures,
not just coverage): its loader treats a non-empty display_precision as
THE per-currency precision map and only falls back to local inference
when the field is empty — so a partial declarations map starved every
undeclared currency. The de-facto wire contract since the tracker era is
the full resolved map, and that is also what a rendering embedder
actually wants.

display_precision is again resolved_precisions(): fixed declarations
where present, canonical inference otherwise, every observed currency
listed. The rustfava-side coverage for its now-bypassed fallback lands
in rustledger/rustfava#262.
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