Repository navigation
feat(plugin)!: effective_date moves a marked posting correctly or reports it - #2536
Conversation
…onfig The native effective_date plugin had two kinds of hash-order output: - The holding-account `open`s it synthesizes were emitted in `HashSet` order, all on one date. PRINT and #entries therefore listed them differently from run to run over the same ledger. A sweep of the compatibility corpus, three runs each, found this file and no other. The upstream plugin emits `sorted(new_accounts)`; so does this one now (BTreeSet). - The holding-accounts config was a `HashMap`. When two configured prefixes matched one account (`Expenses`, `Expenses:Car`), the winner was random, and `find_holding_account` and `find_account_prefix` iterated separately, so the prefix replaced could differ from the one the holding account was chosen for. The config is now a list in config order (a repeated key keeps its first position, as a Python dict literal does), the last matching prefix wins as upstream, and one lookup returns both. Both tests fail on the previous code (the second repeats 32 times so a lucky hash order cannot pass it). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
📊 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?
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
…en-order # Conflicts: # CHANGELOG.md
…en-order # Conflicts: # CHANGELOG.md
A review against the upstream plugin (beancount_reds_plugins 3.2.3 oracle, multi-prefix config) found two silent behaviors where upstream raises: - A config that does not parse fell back to the default config, which moved postings to holding accounts nobody had configured. It is now an error and the plugin changes nothing, as with upstream's `literal_eval` failure. The parser now accepts what the Python dict literal accepts: either quote style, and `later` before `earlier` (before, such a valid config silently became the default). An empty dict is still the default config. - An `effective_date` equal to the transaction's own date was routed through a holding account and back on the same day. Upstream reports "Effective and actual dates are identical" and leaves the entry as written; so does this now. A posting that no configured prefix matches is still kept as written, without an error, as the existing `test_effective_date_unconfigured_prefix_unchanged` pins. Upstream raises KeyError there and applies nothing at all. The multi-prefix oracle comparison agrees on every posting and on the synthesized opens' names, date (the ledger's first entry) and sorted order. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
Review passCompared against the upstream plugin: Agrees with upstream:
Found and fixed (6ebce3e), each with a test that fails on the previous head:
Divergences kept on purpose:
CHANGELOG category: Fixed, not Breaking. A config without overlapping prefixes produces the same entries as before. Only the new errors change results, and both are inputs upstream rejects. Review pass 2Config parser, found and fixed (524d6eb). Round 4's two regexes disagreed with
A new
Same-date error: checked, nothing to fix. It is reported at the transaction's own file and line, as upstream reports it at Interaction with #2525, tested on main 899ee96 and on this branch merged with it:
The no-matching-prefix behavior is unchanged and waits on robcohen's decision. Review pass 3 (robcohen's decision implemented, 0da2913 + 8d3f713)
Oracle runs on the multi-prefix ledger plus a new one per case match upstream wherever the rules agree, and show exactly the documented divergences wherever they don't. Each new test fails on the previous head; the replaced unconfigured-prefix test included. My own review pass on the result found two things, both fixed:
The divergences are documented in compatibility.md under "Plugin Differences", in its own section so it won't collide with #2530's §16. The CHANGELOG entry is now under Breaking. Review pass 4 (round 5's new code, reviewed as fresh; da06234)Found and fixed:
Checked, nothing to fix:
Known gap, still rejected: Follow-up for the coordinator, not filed: the native registry matches a plugin by the last dotted segment of its name, so a user module called Review pass 5 (fuzzing, differential vs Python, surfacing; ab5e29b)Found and fixed:
Checked, nothing more found:
Review pass 6 (convergence check; fa57578)Found and fixed: line continuations. I ran the differential with 10 new seeds × 20,000 configs (200,000 total) against Python 3.13. Two disagreed, both a backslash continuation near the end of the text.
Checked, nothing found:
Convergence loop (rounds 9–11; final head d90a2c7)Each round: a fresh review of the previous round's changes plus one area of the PR not re-read since round 5; the differential against Python 3.13's
Round 11 found nothing in review, had 0 disagreements, and passed both suites (plugin 364, rustledger 947), so the loop stops there. The generator now also emits CR and CRLF line breaks, and |
…en-order # Conflicts: # CHANGELOG.md
Round 4's config reader was two regexes. Against Python 3.13
`ast.literal_eval` it accepted and rejected the wrong things. It took
`'Ex\x70enses'` as the prefix `Ex\x70enses`, where Python reads
`Expenses`. It rejected valid literals: adjacent strings, `r`/`u`
prefixes, triple quotes, a parenthesized dict. And it made falsy values
like `None`, `[]` and `0` errors, where upstream's `if not holding_accts`
treats them as the default config.
New `native/plugins/py_literal.rs` reads the Python literal grammar a
config uses:
- strings, with prefixes, escapes, triple quotes and implicit
concatenation;
- numbers, `None`, `True` and `False`;
- dicts, lists, tuples and sets;
- comments, trailing commas, and Python's line rules (a line break ends
a top-level expression; a backslash continuation needs a token after
it).
parse_config applies upstream's semantics on top:
- an empty config string, or a falsy literal, is the default config;
- a dict maps prefix -> {earlier, later}, extra keys ignored, a repeated
key keeps its first position and its last value;
- anything else is an error. Upstream fails only when a posting reaches
a malformed entry (KeyError/TypeError); this reports it up front.
The new test holds 61 configs, each classified by running literal_eval.
It fails on the round-4 parser.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
…en-order # Conflicts: # CHANGELOG.md
…orts it robcohen's rule for #2536: a posting marked `effective_date` is either moved correctly or reported, never silently dropped or half-applied. - Prefixes match on account-component boundaries (`account == prefix`, or `prefix:` starts it; a prefix written with a trailing `:` counts), and the most specific matching prefix wins whatever the config order. Upstream's raw `startswith` let `Expenses:Car` take `Expenses:Cards:Fee`, and its last-match rule let a general prefix listed after a specific one shadow it. - Only the leading prefix is replaced in the holding-account name. Upstream's `str.replace` turned `Income:Interest:Income` into `Assets:Hold:Income:Interest:Assets:Hold:Income`. - A marked posting the plugin cannot move is an Error naming the account at the entry's location, and the whole transaction is left as written. This covers no matching prefix, a non-date value, an elided amount, and an identical date. A posting with no matching prefix used to stay in place silently while its siblings moved. `test_effective_date_unconfigured_prefix_unchanged` becomes `..._is_reported_and_entry_kept`, with a covered sibling that must not move. - Links number the entries moved in this run (`edate-<yymmdd>-<n>`), not a process-global counter mod 4096. The same ledger gives byte-identical output when processed twice in one process, and 5,000 entries get 5,000 links. - The new entry keeps the transaction's payee, tags, links and metadata, plus `original_date`. The moved posting keeps its metadata, `effective_date` included. Both were checked against the beancount 3.2.3 oracle, which does exactly that. Every new test fails on the previous head. The deliberate divergences from upstream are documented in compatibility.md ("Plugin Differences"). The CHANGELOG entry moves to Breaking, with the fixed parts noted. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
… arms Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
… edits
Round-6 review of round 5's new code, with fixes:
- Nesting depth. A config of 100,000 `[` overflowed the stack and
aborted the process; the parser recursed without limit. It now stops at
200 levels, as Python's parser does ("too many nested parentheses"),
and reports an error. Main never had this: it used the regex parser.
- Tokenizer parity. A second oracle table of 72 literals, each
classified by Python 3.13's `ast.literal_eval`, found and pinned these
disagreements, now fixed:
- `--1` was accepted (one unary sign, directly on a number, as Python);
- `1__0`, `0__0` and `1_` were accepted (an underscore must sit between
digits or right after a base prefix);
- `1j` was rejected;
- in bytes literals, `\u` was treated as an escape and a raw non-ASCII
character was accepted.
`\N{...}` stays a documented gap. A bytes literal as a prefix is
rejected; upstream would raise TypeError on first use.
- Links now number moved entries per date. Adding an unrelated
transaction, or a moved one on another date, leaves every link as it
was; only a moved entry added earlier on the same date renumbers the
later ones of that date. Documented in compatibility.md.
- New pinning test: a kept entry leaves no holding-account opens behind
while a sibling entry in the same run is moved, and `'Expenses:'` does
not match the root `Expenses`, as upstream's `startswith` does not.
This test also passes on the previous head.
Every other new test fails on the previous head; the depth test aborts
the process there.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
…erated cases Round 7 on #2536: fuzzing, a differential test against Python, and how errors surface. - Differential test. A generator draws configs from a small grammar: every quote style and prefix, escapes, implicit concatenation, comments, line continuations, trailing commas, repeated and extra keys, non-string values, plus random mutations. Each config is classified by Python 3.13's `ast.literal_eval`. On 20,000 drawn configs it found one real disagreement, now fixed: a repeated prefix key was validated per occurrence, so a malformed value that a later duplicate replaces made the whole config an error. Python builds the dict first (first position, last value), so the replaced value is never read. 500 of the cases are frozen in tests/fixtures/effective_date/configs.json, with the generator beside them, and checked by `the_config_reads_as_literal_eval_reads_it_on_generated_configs`. That test fails on the previous head. - Numbers. Based integers are unbounded in Python, but `0x` + a million digits overflowed u128 and was rejected; validity and zero-ness are now read from the digits. A decimal integer over 4300 digits is rejected, as Python's int-conversion limit rejects it, unless it is all zeros. - No panic and linear time. Proptests draw 4,096 grammar-alphabet strings and arbitrary Unicode, asserting no panic. A table of megabyte-scale inputs (continuations, long strings and comments, 500,000 items, 199 mixed nesting levels, long numbers) must each parse in seconds; it fails on the previous head for the number cases. - Surfacing. Config errors and the depth error read the same in check, query and report. The LSP runs the native plugin: a new protocol test opens a hostile config and an unclosed one, and requires the error as a diagnostic with the server still answering. On the round-5 parser that test aborts with a stack overflow, which would have taken down an editor's language server. The fixture's strings are split and mutated at random (keys split mid-word), so .typos.toml excludes it, and the pre-commit typos hook gains --force-exclude so that exclusion also applies to the files prek passes. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
… Python Round 8 on #2536, a convergence check. The differential generator ran 10 new seeds x 20,000 configs (200,000 total) against Python 3.13's `ast.literal_eval`. Two disagreed, both a backslash continuation near the end of the text (`...}\<newline><newline>`). py_literal accepted a continuation only if a token followed it. Python accepts one followed by anything at all, even a lone line break, a space or a comment, and rejects one only at the very end of the text. The cases `{}\<nl><nl>`, `{}\<nl># c`, `{}\<nl> ` (now accepted) and `{}\<nl>\<nl>`, `[1,\<nl>` (still rejected) join the hand table; the accepted three fail on the previous head. After the fix, all 200,000 agree. Also pinned: number edges, each checked against Python. The 4300-digit limit counts digits only, not a leading `+`/`-` or underscores, and applies to decimal integers only. Also `0_0`, `0x__f`, `0b_`, `0o_7`, `-0x0`, and a leading zero on a long non-zero integer. All passed already; the test is a pin. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
Round 9 on #2536. Python reads `\r\n` and a lone `\r` as `\n` everywhere in the source, inside strings too. py_literal did not, so a continuation written `\<CR><LF>` was rejected, and a CR inside brackets was taken for something other than whitespace. Configs from CRLF ledgers or Windows editors can carry these when they reach the plugin directly; through `rledger check` the loader already hands over LF, and an end-to-end CRLF ledger agrees with beancount 3.2.3. The source is now normalized before tokenizing. Eight cases from the Python oracle join the hand table; three of them fail on the previous head. The generator now emits CR and CRLF line breaks too, and configs.json is regenerated from it (seed 2536, N 500, classified by Python 3.13). 10 new seeds x 20,000: 0 disagreements. Re-read this round: the effective_date move logic (atomic plan-then-apply, opens only for entries that moved, the new entry's metadata and links, locations) found nothing. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
… mode does Round 10 on #2536. - Differential, 10 new seeds x 20,000: one disagreement. ` # c\n {...}` is an IndentationError in Python. `literal_eval` strips spaces and tabs from the start of the text only; every later line holding a token must not be indented. A form feed resets the count, a continuation keeps counting, and blank or comment lines may be indented. An indented last line with no line break is also an error (`{}\n `). py_literal ignored indentation entirely. It now reads each top-level line's indentation the same way. 43 oracle cases join the hand table; 20 of them fail on the previous head. After the fix, the 200,000 agree. - Docs, re-read this round: - The CHANGELOG said nesting input is "an error rather than a stack overflow". Main never overflowed (it fell back to the default config), so it now says the reader follows Python's 200-level limit. - compatibility.md now lists every config error rledger reports up front (missing `earlier`/`later`, a non-string account, a truthy non-dict) and the one grammar gap (`\N{NAME}`). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
…g generator literal_eval only yields builtin literals, whose truth test never raises, so the except branch CodeQL flagged could not run. Output is unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
The native
effective_dateplugin now follows robcohen's rule: a posting markedeffective_dateis either moved correctly or reported, never silently dropped or half-applied. The output is also the same on every run.Breaking
Prefixes match whole account components. A prefix matches when the account equals it or continues with
:; a prefix written with its own trailing:also counts.Expenses:Carno longer takesExpenses:Cards:Fee.Only the leading prefix is renamed. Prefix
Incomeused to turnIncome:Interest:IncomeintoAssets:Hold:Income:Interest:Assets:Hold:Income(upstream'sstr.replace).A marked posting the plugin cannot move is an error, and the whole transaction stays as written. The error names the account and points at the entry. It fires when:
effective_dateis not a date (e.g. a quoted string);A posting no prefix matched used to stay in place silently while its sibling postings moved.
test_effective_date_unconfigured_prefix_unchangedis replaced bytest_effective_date_unconfigured_prefix_is_reported_and_entry_kept, which adds a covered sibling that must not move either.Fixed
opens were emitted inHashSetorder, and the config was aHashMap. They are now sorted, as upstream (sorted(new_accounts)), and the config keeps its order.edate-<yymmdd>-<n>, no wraparound). They used to come from a process-wide counter mod 4096: they changed on every LSP or FFI reload and collided after 4,096 entries.process()twice in one process and compares the outputs byte for byte; 5,000 moved entries get 5,000 distinct links.ast.literal_evalreads it. The reader is the newpy_literal.rs, pinned by 61 configs each classified by running Python.literal_evalrejects is an error and changes nothing. It used to fall back silently to the default config.{},None) means the default config, as upstream.original_date, and the moved posting keeps its metadata,effective_dateincluded. Both were checked against the beancount 3.2.3 oracle, which does exactly this. rledger used to drop the transaction's metadata and links.Oracle comparison (beancount 3.2.3 +
beancount_reds_plugins)Expenses:Cards:Fee,Expenses:Car:Gaswith the general prefix listed after the specific one,Income:Interest:Income, unmatched / non-date / elided postings), and the link format. Each is listed indocs/reference/compatibility.mdunder "Plugin Differences".Routing (checked on main after #2525)
beancount_reds_plugins.effective_date.effective_date,effective_date,foo.bar.effective_date.python:with a module name gives E8004, and the plugin is not applied..pypath to the upstream file reaches the Python sandbox and fails on the missingbeancount_reds_pluginspackage.Every new test fails on the code before it. The CHANGELOG entry is under Breaking, with the fixed parts noted.
🤖 Generated with Claude Code
https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr