Repository navigation
fix(loader)!: read option values as beancount does, and make option "plugin" read-only - #2930
Merged
Merged
Conversation
…plugin" read-only Part 1 of #2925, checked against bean-check 3.2.3. - Booleans use beancount's two vocabularies: the converter options (render_commas, use_precise_interpolation, allow_pipe_separator, insert_pythonpath) read 1/true/yes as true; infer_tolerance_from_cost, read by grammar.option, reads true/on/1. Any other word reads as false and is the new E7011 warning, so check passes as bean-check does. parse_bool_word keeps serving metadata unchanged. - inferred_tolerance_default and display_precision share one parser that splits at the last colon followed by a number (A:B:0.01 is currency A:B) and rejects a sign (USD:-0.01). Text after the number stays E7002, a deliberate deviation. - tolerance_multiplier is read as D(): empty is 0, commas are stripped, exponents are accepted. NaN and Infinity stay E7002 (not representable). - experiment_explicit_tolerances and use_legacy_fixed_tolerances are unknown (E7001); their Options and CachedOptions fields are removed. - option "plugin" is E7005 (may not be set) instead of E7004, from an included file too. - E7007 is dropped: a valid account_rounding gives no diagnostic. - long_string_maxlines accepts any value, as beancount has no converter. Loader cache v69, WASM cache v92 (v91 is left to #2920). BREAKING CHANGE: render_commas "yes", infer_tolerance_from_cost "on" and tolerance maps like "A:B:0.01" now read as beancount reads them; the two dead options are errors; Options loses two public fields. Refs #2925 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
Contributor
📊 Benchmark Results
vs base, measured in this run
A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: What do these numbers mean?
|
- tolerance_multiplier drops every `_` as CPython's Decimal does (1__0, _1, 1._5, 1e_1), rejecting only an all-underscore value, and reads a zero significand as 0 at any exponent (0e100). - Tolerance maps need the colon on the first line, as beancount's `.*` does not cross a newline. - Deviation 3 is documented in full: values outside rust_decimal's range, and non-ASCII digits in a tolerance map, are E7002. - The converter test pins that `on` and `off` are not its words. - rledger doctor list-options prints the loader's known_options with option_value_kind, instead of a hand-written copy; a test keeps the descriptions in step. - CHANGELOG Breaking lists the included `filename`, exponent tolerance maps and the moved diagnostic codes. Refs #2925 Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Numbers are read exactly or rejected: a value rust_decimal cannot hold exactly (out of range, or too many digits, e.g. 1E-31) is E7002 instead of silently rounded, in tolerance_multiplier and the tolerance maps. The range is checked on the value, so 10e-29 and 0.1e29 are accepted. - Tolerance maps accept trailing whitespace, as beancount does; other trailing text stays E7002 (deviation 2). - option_value_kind gives long_string_maxlines "any", and a drift guard sets a value of each declared kind and asserts `set` accepts it. - docs/reference/options.md lists use_precise_interpolation and insert_pythonpath, and a test checks the table against known_options. - CHANGELOG: Breaking says what changed per option; Added lists the new loader API and the doctor list-options change; deviation 3 covers non-ASCII digits in any numeric option and inexact values. Refs #2925 Co-Authored-By: Claude Opus 5.5 <[email protected]>
- exact_decimal is linear in its input: leading zeros are skipped once and the trailing zeros to drop are counted, not popped one rescan at a time. A 160k-digit display_precision value was quadratic (30 s). - It also drops trailing zeros while the coefficient is past 96 bits, so 79228162514264337593543950335.0 and 10000000000000000000000000000.0 are held again, as on main and in beancount. - A zero's exponent is bounded by Python's MIN_ETINY / MAX_EMAX, so 0e99999999999999999999 is an error as in bean-check. - Whitespace is Python's str.isspace, in tolerance_multiplier and after a tolerance map's number. - insert_pythonpath is described as accepted with no effect. - CHANGELOG: tolerance_multiplier and USD:0_5 Breaking bullets, corrected Fixed wording, display_precision's 28-place limit under deviation 3. Refs #2925 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keeps both sides' CHANGELOG entries; caches stay at loader 69 / WASM 92. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- tolerance_multiplier strips in beancount's order: D() drops commas and spaces, then Decimal strips whitespace, then drops `_`. So "_\t1", "1\t_" and "1<U+3000>_" are E7002, as in bean-check; "_ 1" stays 1. - Tests pin the 96-bit pop loop with 29-digit coefficients and the MIN_ETINY edge for a zero's exponent. - Deviation 3 says display_precision keeps at most 28 places where beancount keeps any number, that dropping a trailing zero to fit 96 bits lowers it, and lists sNaN. Refs #2925 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Refs #2925 Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 10, 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.
What
Part 1 of #2925: rledger reads option values as beancount 3.2.3 does.
options_validate_booleanconverter (render_commas,use_precise_interpolation,allow_pipe_separator,insert_pythonpath) read1/true/yes(any case) as true.infer_tolerance_from_costhas no converter, sogrammar.option's bool branch reads it:true/on(any case) or1. Any other word reads as false, as in beancount. rledger reports it as the new E7011 warning, socheckpasses as bean-check does. These are separate fromparse_bool_word, which still servesrender_commas:metadata, unchanged.inferred_tolerance_defaultanddisplay_precisionshare one parser,parse_tolerance_map. Like beancount's(.*):([\d\.]+), it splits at the last colon followed by a number, soA:B:0.01is currencyA:B, and it rejects a sign (USD:-0.01is E7002).tolerance_multiplieris read as beancount'sD()reads it: empty is 0, commas and spaces are stripped, and a sign, an exponent and_between digits are accepted. Downstream, 0 was already accepted ("0") and is a zero tolerance; booking and validate are untouched.experiment_explicit_tolerancesanduse_legacy_fixed_tolerancesare removed fromKNOWN_OPTIONS, so they are E7001, as beancount says "Invalid option". TheirOptionsandCachedOptionsfields are removed too.option "plugin"is read-only (E7005, "may not be set") instead of deprecated (E7004). A read-only option in an included file now also gets E7005, not the E7009 warning, sopluginkeeps failing the build from anywhere, as it does in beancount.account_roundinggives no diagnostic. The option is inert in beancount 3.2.3 too, sincefill_residual_postingis never called.long_string_maxlinesaccepts any value with no diagnostic. beancount has no converter for it and never reads it.Why
Each row was a difference from bean-check 3.2.3 (see #2925 and the verified plan in its last comment). Three of them changed a value, not just a diagnostic:
render_commas "yes",infer_tolerance_from_cost "on"andA:B:0.01.Deliberate deviations
Unrecognized boolean word: false like beancount, plus a non-fatal E7011 warning (maintainer decision). bean-check reports nothing.
Trailing text in a tolerance map (
USD:0.01abc, which beancount reads as 0.01): still E7002 and not applied (maintainer decision). AStricter than Pythoncomment is onparse_tolerance_map, andtest_parse_tolerance_map_trailing_text_is_rejectedpins it.Not fixable locally: a value
rust_decimalcannot hold exactly is E7002 here, though beancount accepts it. It is rejected, never rounded. This is commented onparse_beancount_decimal,parse_tolerance_mapandexact_decimal, and pinned bytest_set_tolerance_multiplier_non_finite_is_rejected,test_parse_beancount_decimal_unrepresentable_is_rejectedandtest_parse_tolerance_map_unrepresentable_number_is_rejected. It covers:NaN,sNaNandInfinityintolerance_multiplier;rust_decimal's range (1e100,1e-29), intolerance_multiplierand in a tolerance map;rust_decimalholds, such as0.0000000000000000000000000000001, which beancount holds as 1E-31;"١"and"1"are 1 in beancount'stolerance_multiplier, andUSD:١is 1 in a tolerance map.display_precisionholds at most 28 decimal places, where beancount keeps any number of places;display_precision:USD:10000000000000000000000000000.0reads as 0 places, while beancount reads 1.A zero significand is 0 at any exponent (
0e100,0E-50), as in beancount. The range is checked on the value, so10e-29and0.1e29are accepted.Before / after
Each case is
option "<key>" "<value>"followed by2024-01-01 open Assets:A, run withbean-check3.2.3 (nix develop .#bench) and withrledger check --no-cachefrommain(6afd960) and from this branch. The beancount value comes fromloader.load_file(...)[2][key].render_commasbogusrender_commasyesrender_commasYESrender_commasoninfer_tolerance_from_costbogusinfer_tolerance_from_costoninfer_tolerance_from_costyesinfer_tolerance_from_cost1use_precise_interpolationyesallow_pipe_separatoryesinsert_pythonpathyesallow_deprecated_none_for_tags_and_linksTRUElong_string_maxlinesabctolerance_multiplier(empty)tolerance_multiplier1,000tolerance_multiplier1e-3tolerance_multiplier-0.5tolerance_multiplierabctolerance_multiplierNaNinferred_tolerance_defaultUSD:-0.01inferred_tolerance_defaultA:B:0.01inferred_tolerance_defaultUSD:0.01abcinferred_tolerance_defaultUSD:.5inferred_tolerance_defaultUSDdisplay_precisionUSD:-0.01display_precisionA:B:0.01display_precisionUSD:0.01abcexperiment_explicit_tolerancesTRUEuse_legacy_fixed_tolerancesTRUEaccount_roundingRoundingaccount_roundingbad-leafpluginbeancount.plugins.auto_accountsValues on this branch: each is pinned by a unit test below. End to end,
render_commas "yes"with a 1000.00 USD posting renders1,000.00 USDinrledger queryon this branch, and1000.00 USDplus an E7002 on main.Included-file rows (part 2, out of scope, unchanged except
plugin):name_equity "capital",booking_method "fifo",render_commas "bogus"name_equity "capital",booking_method "fifo",inferred_tolerance_default "USD:-0.01"name_equity "Capital"+open Capital:Zoption "plugin" "..."Canonical-function check
All option values still go through
Options::set/set_scoped_at:diagnostics.rsopts.set);options_from_rawandhelpers.rs;convert.rs,booking_methodonly).Nothing outside
options.rsparses option booleans or tolerance maps. A grep forparse_bool_word,split_once(':')andDecimal::from_strin wasm, ffi-wasi, ffi-component and lsp found no re-parsing.parse_bool_wordnow has one caller,meta_value_as_bool(metadata), and its doc says so. No BQL or other compat script registers any of these behaviors, so noKNOWN_list changes.Caches
CachedOptionsloses two fields and the cached option values move, so:CACHE_VERSIONgoes 68 to 69 (bothFIXTURE_VERSIONs);CACHE_VERSIONgoes 90 to 92, with the pin at 69. The WASM payload archives the option diagnostics. v91 is left to fix(validate)!: pad parents, sub-accounts, tolerances and cost lots as beancount does #2920.How to test
New tests in
crates/rustledger-loader/src/options.rs:test_set_converter_boolean_options_read_like_beancount,test_set_infer_tolerance_from_cost_reads_like_grammar_option,test_set_unrecognized_boolean_word_is_false_with_a_warning(deviation 1),test_set_insert_pythonpath_unrecognized_word_warns,test_set_boolean_options_leave_metadata_vocabulary_alone,test_parse_tolerance_map_splits_on_last_colon_before_number,test_parse_tolerance_map_rejects_sign,test_parse_tolerance_map_trailing_text_is_rejected(deviation 2),test_parse_beancount_decimal_matches_d,test_set_tolerance_multiplier_empty_is_zero,test_set_tolerance_multiplier_non_finite_is_rejected(deviation 3),test_set_dead_tolerance_options_are_unknown,test_set_scoped_plugin_option_is_read_only_everywhere,test_set_account_rounding_valid_value_no_diagnostic,test_set_long_string_maxlines_accepts_any_value, plus the round-1 tests listed below. Updated:only_e7003_and_e7009_are_warnings(E7010, E7011 warnings; E7007 gone), the WASMboth_paths_agree_for_every_option_code(E7011 case added), and coretest_parse_bool_word_metadata_spellings(renamed; metadata vocabulary unchanged).Review round 1
Commit 86413cd.
tolerance_multiplierunderscores (this was a regression against main): every_is now dropped, as CPython'sDecimaldrops it. Only a value that is nothing but underscores is an error._1(1),._5(0.5),1e_1(10),1__0(10),1_(1),1._5(1.5)._gives exit 1 in both._1,._5,1e_1,1_e1and__are added.option "filename"(E7009, exit 0, becomes E7005, exit 1);USD:1e-2, clean on main, now E7002, deviation 2);errors.mdand in the CHANGELOG.0e100,0E-50and-0e5are 0 (bean-check: exit 0).1e100and1e-29are E7002 (bean-check: exit 0, so they are part of deviation 3).test_set_converter_boolean_options_read_like_beancountnow has("on", false)and("off", false), with E7011 expected for those words. Addingonto the converter's true list now fails the test.parse_tolerance_mapedge cases:(.*)does not cross a newline."A\nB:0.5"is E7002, matching bean-check (exit 1, "Invalid value"). Pinned bytest_parse_tolerance_map_colon_after_newline_is_rejected.\ddigits are not implemented; they are documented as part of deviation 3.test_parse_tolerance_map_exponent_is_rejectedpinsUSD:1e-2.rledger doctor list-optionsnow prints the loader'sknown_options(), withoption_value_kind()for the type and(read-only)fromis_read_only_option(). All three are new public functions inrustledger-loader.test_option_description_covers_exactly_the_loader_optionsasserts that the listed names equal the loader's list, in order, and thatinsert_pythonpathis<bool>.test_option_value_kind_covers_every_known_optionasserts that every known option has a kind.Gates were re-run, all exit 0:
fmt --check--all-features --all-targets -D warningsRUSTDOCFLAGS=-Dwarnings cargo doccargo test --all-features --no-fail-fastfor core, loader, rustledger, wasm, lsp, ffi-wasi, ffi-component and validateMain has not moved, so the caches stay at loader 69 / WASM 92.
Review round 2
Commit 18fc58c.
use_precise_interpolationandallow_pipe_separatorread"1"and"yes"as silently false on main. Both are now true.insert_pythonpathis still recorded as a string.render_commasandinfer_tolerance_from_cost."A\nB:0.5", exit 0 on main, now E7002 as in beancount) is listed under Breaking.rustledger_loader::{known_options, option_value_kind, is_read_only_option};rledger doctor list-optionschange: six more options, corrected types, and read-only markers.errors.md, CHANGELOG, this body, the code docs): non-ASCII digits in any numeric option value, and any valuerust_decimalcannot hold exactly. Tested with"١"and"1".exact_decimalbuilds the value from its coefficient and scale withDecimal::try_from_i128_with_scale, and returnsNonewhen it cannot hold the value exactly. It replaces both thepower > 28cap andDecimal::from_str, which rounded silently.10e-29,0.1e29and the 29-digit10000000000000000000000000000are accepted. bean-check gives exit 0 for all three.0.0000000000000000000000000000001, as a multiplier or in a tolerance map, is E7002. bean-check gives exit 0, so this is deviation 3.display_precisionreads it:USD:0.010is still precision 3."USD:0.5 "and"USD:0.5\n"give rledger exit 0 and bean-check exit 0."USD:0.5 x"stays E7002 (deviation 2). Pinned bytest_parse_tolerance_map_trailing_whitespace_is_accepted.option_value_kinddrift:long_string_maxlinesis now theanykind.test_option_value_kind_matches_what_set_acceptssets a value of each option's declared kind and asserts no diagnostic other than a deprecation, or E7005 for a read-only option.docs/reference/options.md"All Options" addsuse_precise_interpolationandinsert_pythonpath, andlong_string_maxlinesis now typedany. A newcrates/rustledger-loader/tests/options_docs_test.rschecks that the table lists exactlyknown_options().Gates were re-run, all exit 0:
fmt --check--all-features --all-targets -D warningsRUSTDOCFLAGS=-Dwarnings cargo doccargo test --all-features --no-fail-fastfor core, loader, rustledger, wasm, lsp, ffi-wasi, ffi-component and validateMain is unchanged, so the caches stay at loader 69 / WASM 92.
Review round 3
Commit 302c6fa.
Quadratic
exact_decimal, fixed. The function is now linear:position;must_pop), not popped one rescan at a time.test_exact_decimal_is_linear_on_long_inputruns a 160k-zeros-each-side value through both parsers and asserts it takes under 2 s. The old version took about 30 s.rledger checkon the 320 KBdisplay_precisionrepro now takes 0.03 s.Coefficients past 96 bits. A trailing zero is also dropped while the coefficient is past 2^96 - 1, and the written scale is kept otherwise.
1000000000000000000000000000.00,10000000000000000000000000000.0,79228162514264337593543950335.0. bean-check gives exit 0 for each.79228162514264337593543950336is still E7002.test_exact_decimal_drops_trailing_zeros_past_96_bits.CHANGELOG
tolerance_multiplier.Nits:
"USD:0_5": clean on main, E7002 now (deviation 2), bean-check exit 0.USD:0.01abcwas already an error and the exponent and underscore forms were clean before.tolerance_multiplierentry mentions" 0.5"and"1 000". Both were E7002 on main and are now accepted; bean-check gives exit 0.MIN_ETINY..MAX_EMAX.0e99999999999999999999and0e1000000000000000000are E7002, matching bean-check (exit 1).0e999999999999999999and0e-1000000000000000000are 0, matching bean-check (exit 0).test_parse_beancount_decimal_zero_exponent_bounds.display_precisionholds at most 28 places. This is now in deviation 3 inerrors.md, the CHANGELOG, this body and theexact_decimaldoc.str.isspace(UnicodeWhite_Spaceplus U+001C to U+001F), through a newis_python_space. It applies totolerance_multiplier's surrounding whitespace and after a tolerance map's number. Tested with\x0c,\xa0,\x1cand U+3000.insert_pythonpathis now described as "Accepted for compatibility; no effect in rledger", inoptions.mdand the doctor. The plugin runtime sets only a fixedPYTHONPATH=/liband never reads the option.Gates were re-run, all exit 0:
fmt --check--all-features --all-targets -D warningsRUSTDOCFLAGS=-Dwarnings cargo doccargo test --all-features --no-fail-fastfor core, loader, rustledger, wasm, lsp, ffi-wasi, ffi-component and validateOne test,
python_plugin_wasi::ag_rledger_carries_the_runtime_download_and_compile_notices, failed once on an HTTP 500 while downloading the Python runtime, then passed on rerun.Caches stay at loader 69 / WASM 92. main moved by #2927, but its caches are unchanged.
Review round 4
Commit bec84d3.
Strip order.
tolerance_multiplieris now read in beancount's order:D()drops,and ASCII space;is_python_space;_is dropped.Checked against bean-check 3.2.3:
"_\t1","1\t_"and"1 _"(U+3000) give exit 1 in bean-check and are now E7002 here."_ 1"gives exit 0 in bean-check, not exit 1.D()removes the ASCII space first, leaving"_1", which is 1 (D("_ 1")returns 1 in Python). rledger reads it as 1 too.All four are in
test_parse_beancount_decimal_strips_python_whitespace.The 96-bit pop loop is now tested.
test_exact_decimal_drops_trailing_zeros_past_96_bitsadds the 29-digit values that only the loop handles, each checked both as a multiplier and asUSD:<value>:8000000000000000000000000000.09999999999999999999999999999.07922816251426433759354395034.080000000000000000000000000000e-1is checked as a multiplier only, because a tolerance map rejects exponents.With a bare option line, bean-check gives exit 0 for all four pop-loop rows (
8000...0.0,9999...9.0,7922...4.0,80000...0e-1) and forUSD:8000000000000000000000000000.0, and this PR accepts all of them. (Corrected after round 5: an earlier version of this sentence misread the exit codes.) Disabling the loop (while false && ...) fails this test.Nits:
test_parse_beancount_decimal_zero_exponent_boundsnow has0e-1999999999999999997(ok) and0e-1999999999999999998(err), matching bean-check (exit 0 and exit 1). MovingPYTHON_MIN_ETINYby +1 or by -1 fails the test.errors.md, CHANGELOG, this body, theexact_decimaldoc).display_precision(USD:10000000000000000000000000000.0reads as 0 places, while beancount reads 1).sNaNis now listed inerrors.mdand the CHANGELOG.Gates were re-run, all exit 0:
fmt --check--all-features --all-targets -D warningsRUSTDOCFLAGS=-Dwarnings cargo doccargo test --all-features --no-fail-fastfor core, loader, rustledger, wasm, lsp, ffi-wasi, ffi-component and validateMain has not moved, and the caches stay at loader 69 / WASM 92.
Refs #2925 (part 2, options in included files and option locations, follows).
🤖 Generated with Claude Code