Repository navigation
fix: ops::clamp threads account config instead of hardcoding Equity roots - #1810
Merged
Merged
Conversation
…oots
clamp had two independent hardcodings, both broken on a ledger that
renames its roots or sets account_previous_*:
1. Synthesized summary account names — the opening-balance contra
(Equity:Opening-Balances) and the earnings rollup target
(Equity:Earnings:Previous), which should come from
account_previous_balances / account_previous_earnings.
2. Account classification — is_balance_sheet / is_income_statement
matched root prefixes by literal string ("Assets" | "Liabilities" |
...). On a renamed-root ledger the classifier matched nothing, so NO
opening balances were synthesized at all — a silently empty clamp,
the more dangerous of the two. This is the AccountTypes anti-pattern
the canonical-function discipline forbids.
Both fold into one ClampAccounts config (AccountTypes classifier +
previous_balances/previous_earnings names), threaded through
clamp/clamp_indexed. Default reproduces the prior hardcoded behavior
exactly. session.clamp builds it from the held options (the #1766
payoff — from-entries-with-options now drives clamp too), sharing a new
account_types() helper with query; the builder free clamp over a bare
directive list passes the default.
Drift guards: an ops-level test clamps a fully renamed ledger and
asserts the renamed asset root IS carried forward (catches the
silent-empty classifier failure a names-only test would miss) and the
summary legs use the configured accounts; a component test proves
session.clamp consumes the held options where from_entries defaults.
Closes #1806.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Pull request overview
Updates rustledger_ops::clamp to honor ledger-configured account roots and configured “previous balances/earnings” summary accounts, eliminating hardcoded Equity-root behavior that breaks renamed-root ledgers. This also threads the config through the WASI component so session.clamp uses held ledger options while the options-less free function falls back to defaults.
Changes:
- Introduce
ClampAccounts(withAccountTypes+ configurable summary accounts) and thread it throughclamp/clamp_indexed. - Switch clamp’s classification from hardcoded root-prefix matching to the canonical
AccountTypesclassifier. - Update the component’s
clampsurfaces to pass either defaults (free function) or options-derivedClampAccounts(session), and add regression tests.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| crates/rustledger-ops/src/clamp.rs | Adds ClampAccounts, uses AccountTypes for classification, threads configurable contra/earnings accounts, and expands tests. |
| crates/rustledger-ffi-component/src/convert.rs | Updates WIT/component clamp paths to pass default vs held-options clamp config; deduplicates AccountTypes construction via a helper; adds component-level test. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
📊 Benchmark Results
vs main branch (2026-07-19)
What do these numbers mean?
|
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
Copilot review: the parenthetical listed both ClampAccounts fields together, reading as if `contra` were previous_earnings. Spell out each parameter's source field explicitly.
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.
What
rustledger_ops::clamphad two independent hardcodings — the issue named one, and the second is the more dangerous — both broken on a ledger that renames its roots or setsaccount_previous_*. This folds both into oneClampAccountsconfig.1. Synthesized summary account names (the issue's original scope): the opening-balance contra (
Equity:Opening-Balances) and the earnings rollup target (Equity:Earnings:Previous) were literals. They now come fromaccount_previous_balances/account_previous_earnings.2. Account classification (surfaced during review):
is_balance_sheet/is_income_statementmatched root prefixes by literal string ("Assets" | "Liabilities" | ...) — exactly theAccountTypesanti-pattern the canonical-function discipline forbids. On aoption "name_assets" "Activa"ledger the classifier matched nothing, so no opening balances were synthesized at all — a silently empty clamp. Now uses the canonicalAccountTypes.Design
Defaultreproduces the prior hardcoded behavior exactly, so existing callers are unaffected.clamp/clamp_indexedtake&ClampAccounts. The two component callers:session.clampbuilds it from the held options — a newaccount_types()helper (shared withquery, deleting a duplicate inlineAccountTypesconstruction) plus the twoaccount_previous_*names. This is the WIT contract: entries-accepting surfaces classify/render with default ledger options #1766 payoff:from-entries-with-optionsnow drives clamp too.clampover a bare directive list has no options → passesClampAccounts::default().Scope note
There is no
rledger clampCLI subcommand — the only two callers are both in the component (the issue's "CLI" mention was inaccurate). And only the twoprevious_*options are relevant: clamp does no conversion / current-earnings summarization, soaccount_previous_conversions/account_current_*are deliberately not threaded.Tests
clamp_honors_renamed_roots_and_summary_accounts): clamps a fully renamed ledger (Activa/Vermogen/Inkomsten roots + renamed summary accounts) and asserts the renamed asset root IS carried forward — catching the silent-empty classifier failure a names-only test would miss — plus that summary legs use the configured accounts and noEquity:*default leaks.clamp_accounts_default_matches_legacy_hardcoding): pins the pre-ops::clamp synthesizes hardcoded Equity:Opening-Balances for every caller #1806 behavior.clamp_honors_held_options_for_classification_and_summaries): provessession.clampconsumes held options (renamed income rolls into the configured earnings account) where options-lessfrom_entriesdefaults.Workspace green (3946 tests), clippy/doc/fmt clean.
Closes #1806.
🤖 Generated with Claude Code
https://claude.ai/code/session_013gJH7uBBF9Xw9et9QFRcsU