Skip to content

fix(ag-rledger): restore the panic envelope, repeated flags and short-flag echo after agcli 0.19 - #2859

Merged
robcohen merged 2 commits into
mainfrom
fix/ag-rledger-agcli-019-followups
Nov 4, 2026
Merged

robcohen merged 2 commits into
mainfrom
fix/ag-rledger-agcli-019-followups

Conversation

@robcohen

@robcohen robcohen commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #2846, which auto-merged before its review finished. Fixes the three regressions the review found, plus a misplaced doc comment.

What changed

  1. Panic envelope. The fallback parsed argv with Invocation::parse after skipping the program name, so the command word became the program: a panic in check f.beancount gave exit 2 UNKNOWN_COMMAND "Valid commands: f.beancount.", and bare check gave "Valid commands: ag-rledger.". build_cli is now build_cli_with(wrap), and the fallback is the real command tree with every handler replaced, since a command's last handler wins. agcli resolves the command, redacts and picks next actions exactly as in the run that panicked, whatever precedes the command word. The envelope is HANDLER_PANIC, exit 1, handler panicked: <message>, with agcli 0.17's fix text and the command's own next actions.
  2. Repeated list flags. agcli 0.18 refuses any flag given twice (PARSE_ERROR, no opt-out), but rledger's list flags take repeats: --plugin, --native-plugin, --include-rules, --exclude-rules, --investments/-i, --income/-n, --wasm-importer, --wasm-importer-dir, --mapping/-m. main now merges a repeated one into one comma-joined --flag=a,b before dispatch. flag_values already split each of these values on commas, so the handler reads exactly what it read before; a value containing a comma was split before too. Short forms merge only for the command that owns them (format -i is --in-place). A flag given once and repeated switches (--json --json) are left as written, and merging stops at --.
  3. <redacted> echo. agcli masks the value of an undeclared flag in command, and reads --account/-a <ACCOUNT> as declaring --account only. Short forms are now their own usage tokens: in report_flag_usage and in the check, query, format, report, doctor, extract, price, add and lint usage strings. config -f is left as it was, since its handler reads -f as both --format and --force.
  4. usage_for's doc comment had been inserted under with_globals's; each now has its own.

Main vs this branch (separate builds and target dirs)

Command main this branch
check f --native-plugin auto_accounts --native-plugin noduplicates PARSE_ERROR, exit 2 exit 0, --native-plugin=auto_accounts,noduplicates
report f returns --investments A --investments B (and -i A -i B) PARSE_ERROR, exit 2 exit 0, --investments=A,B
price --mapping A:B --mapping C:D --list-sources PARSE_ERROR, exit 2 exit 0, --mapping=A:B,C:D
report f balances -a Assets, journal -l 5, check f -f json, query f "SELECT 1" -f json value echoed as <redacted> value echoed
check f --json --json, format f -i -i, plain check f, c f, --account=Assets unchanged unchanged

How to test

  • cargo test -p rustledger --all-features --bin ag-rledger --test ag_rledger_test. New unit tests:
    • the panic fallback for check f.beancount, --json check f.beancount, bare check, and an alias with a short flag;
    • the merge for every multi-value flag in every spelling, the short forms per command, and the argv it leaves alone.
  • New integration tests: short flag values echoed, not redacted; repeated list flags accepted.
  • Verified locally:
    • cargo test -p rustledger --all-features: 47 test results, 0 failed;
    • workspace clippy -D warnings --all-features --all-targets and rustdoc -Dwarnings are clean;
    • cargo fmt --check is clean.

Review round 1 (e2e8617391)

  • Command word. It is now the first argument that names a registered command (COMMAND_NAMES, which a test checks against the root command tree) or a config alias, as agcli finds it. Before, a value flag before the command hid it: --format json report l returns -i A -i B and -f json price -m A:B -m C:D merged nothing and failed as "given twice". expand_config_aliases and the merge share the rule.

  • -P x check l.beancount. agcli 0.19 never takes a command's name as a bare flag's value, so this ran the x alias (extract) on the file check. Declaring -P does not change that rule, so a global value flag (-P, --profile, the plugin budget) before the command word is now passed with its value attached (-P=x).

  • Every flag a handler reads is declared. Still undeclared were:

    • check --plugin, --include-rules, --exclude-rules, --cache-filename, --lint-min-confidence, --file, --show-summary;
    • extract --wasm-importer, --wasm-importer-dir, --delimiter, --importers-config and its column, format, --skip-rows, --balance-date, --use-merchant-dict, --force and --ledger flags;
    • price --source-meta;
    • add -q.

    A new unit test, usage_declares_every_flag_the_handler_reads, runs every builder and fails when one reads a flag its command's usage does not declare.

  • Tests. Unit tests cover a value flag before the command word and attach_global_values. Integration tests cover --format json report ... -i A -i B, -f json price -m ... -m ..., -P x check (runs check, exit 0) and the echo of --plugin=a.wasm,b.wasm, --cache-filename, --include-rules and --delimiter.

  • Verification.

    • cargo test -p rustledger --all-features: 47 test results, 0 failed. The ag-rledger suites had 23 unit and 48 integration tests passing.
    • Workspace clippy -D warnings and rustdoc -Dwarnings are clean, and so is cargo fmt --check.

🤖 Generated with Claude Code

…-flag echo after agcli 0.19

Three regressions from the agcli 0.19 port (#2846):

- A handler panic was answered for the wrong command: the fallback parsed
  argv with `Invocation::parse` after skipping the program name, so the
  command word became the program (`check f.beancount` gave exit 2
  UNKNOWN_COMMAND "Valid commands: f.beancount."). The fallback is now the
  real command tree (`build_cli_with`) with every handler replaced, so
  agcli resolves the command, redacts and picks its next actions as in
  the run that panicked, whatever precedes the command word. The envelope
  is HANDLER_PANIC, exit 1, with agcli 0.17's fix text.
- agcli 0.18 refuses any repeated flag (PARSE_ERROR), but rledger's list
  flags (--plugin, --native-plugin, --include-rules, --exclude-rules,
  --investments/-i, --income/-n, --wasm-importer, --wasm-importer-dir,
  --mapping/-m) take repeats. A repeated one is merged into one
  comma-joined flag before dispatch (`merge_repeated_value_flags`), which
  `flag_values` already splits on commas. Short forms merge only for the
  command that owns them; a flag given once and repeated switches are
  left as written.
- agcli masks the value of an undeclared flag in `command`, and reads
  `--account/-a <ACCOUNT>` as declaring --account only, so every short
  value flag echoed `<redacted>`. Short forms are now their own usage
  tokens, in the report flags and the command usage strings. config -f,
  read as both --format and --force, is left as it was.

Also moves usage_for's doc comment off with_globals.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen
robcohen requested a review from a team as a code owner November 4, 2026 06:48
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100% (raw 93%, 179 masked)
Full AST Match 100%
Total Files 826
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
    The headline is the EFFECTIVE rate, after pairs where beanquery
    itself is wrong are masked. raw is the same run with nothing
    masked. A widening gap means the registry grew, not that rledger
    changed.
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

@codecov

codecov Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.25788% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/rustledger/src/bin/ag-rledger.rs 99.25% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 50.3ms ± 1.5ms 822.2ms ± 13.7ms 16.3x 34.5 MB / 51.1 MB
investment 76.8ms ± 1.5ms 3015.0ms ± 30.4ms 39.3x 44.7 MB / 59.0 MB
fifo 72.1ms ± 0.9ms 15029.3ms ± 320.6ms 208.6x 40.4 MB / 59.0 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 49.5ms ± 0.9ms 50.3ms ± 1.5ms +1.5% ✅ within noise 34.8 MB → 34.5 MB (-0.6%)
investment 75.9ms ± 1.4ms 76.8ms ± 1.5ms +1.1% ✅ within noise 44.6 MB → 44.7 MB (+0.1%)
fifo 72.2ms ± 0.8ms 72.1ms ± 0.9ms -0.1% ✅ within noise 40.7 MB → 40.4 MB (-0.5%)

A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: simple 0.8ms, investment 0.9ms, fifo 0.5ms), and is at least 5%.
10,000 transactions per shape · 20 runs, 3 warmup · hyperfine

What do these numbers mean?
  • simple — Two-posting transfers, one currency. The historical workload — keep as the floor, not as the benchmark.
  • investment — Cost specs, per-unit prices and lot reductions. Exercises booking and inventory, which simple leaves at 0.3%.
  • fifo — Bare {} reductions against a FIFO account — how FIFO sells are normally written. The other four shapes reach the ordered-selection path twice in 2k transactions between them, so it was effectively unprofiled until it turned out to be quadratic (plan_ordered scans every lot per reduction: FIFO ledgers are quadratic (8.8s at 20k transactions) #2083).
  • vs base: the PR and the base-branch commit it is built on, built and measured in the same job
  • RSS: peak resident set size, a single sample — reported without a verdict because there is no spread to test it against
  • A shape with no beancount column is one bean-check reports errors on; it is timed for rledger only

…ry flag a handler reads

Review of #2859:

- The command word was the first non-flag argument after the global value
  flags, so a value flag before it hid it: `--format json report l
  returns -i A -i B` merged no short forms and failed as "given twice".
  It is now the first argument that names a registered command
  (COMMAND_NAMES, checked against the root tree) or a config alias, as
  agcli finds it; expand_config_aliases and the merge use that rule.
- agcli 0.19 never takes a command's name as a bare flag's value, so
  `-P x check l.beancount` ran the `x` alias (extract) on `check`.
  Declaring -P does not change that rule, so a global value flag before
  the command word is now passed with its value attached (`-P=x`).
- Value flags the handlers read but the usage did not declare still
  echoed `<redacted>`: check --plugin, --include-rules, --exclude-rules,
  --cache-filename, --lint-min-confidence, --file, --show-summary;
  extract --wasm-importer, --wasm-importer-dir, --delimiter,
  --importers-config and its column, format and ledger flags; price
  --source-meta; add -q. All are declared now, and a unit test fails when
  a handler reads a flag its command's usage does not declare.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen
robcohen merged commit 418dd54 into main Nov 4, 2026
48 of 49 checks passed
@robcohen
robcohen deleted the fix/ag-rledger-agcli-019-followups branch November 4, 2026 12:56
robcohen added a commit to MoTechnicalities/rustledger that referenced this pull request Nov 7, 2026
Since agcli 0.19 (rustledger#2859) a flag given twice is refused unless it is in
MULTI_VALUE_FLAGS, so lint linked-transit --account A --account B failed
with PARSE_ERROR. --account takes one value on report and extract, so it
cannot join the global list. MULTI_VALUE_COMMAND_FLAGS scopes a long
list flag to the commands that own it, as MULTI_VALUE_SHORTS does for
short flags, and lists account for lint only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen added a commit to MoTechnicalities/rustledger that referenced this pull request Nov 7, 2026
…ated

Since agcli 0.19 (rustledger#2859) a flag given twice is refused unless
merge_repeated_value_flags merges it, and nothing checked that the
tables kept up with rledger. The new guard walks every rledger command
definition ag-rledger runs (and fails if one is missing from the list)
and asserts that each clap Vec flag taking one value per occurrence is
in MULTI_VALUE_FLAGS or, for its command, MULTI_VALUE_COMMAND_FLAGS,
with its short form in MULTI_VALUE_SHORTS; that no single-value flag is
merged where it applies (report and extract --account); and that no
entry is stale.

It found one gap, fixed here: check --lint is repeatable in rledger but
ag-rledger read one value, so a repeat was a PARSE_ERROR. It is now
scoped in MULTI_VALUE_COMMAND_FLAGS and read as a list.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen added a commit that referenced this pull request Nov 7, 2026
* feat: add linked transit transfer lint

Inspect explicitly linked transit legs without rewriting source or changing default validation.

Co-authored-by: Copilot <[email protected]>

* fix(lint): read the booked ledger in linked-transit

The lint read Loader::load output, so an elided transit amount always
came out ambiguous and any plugin line refused the whole ledger. It now
follows lint closed-nonempty: refuse on load errors, then run
rustledger_loader::process with plugins and the plugin budget, and read
the booked directives with ledger.source_map for locations.

The inferred-amount branch and the plugin refusal are gone. A processing
error refuses the input rather than being reported as a finding: a
transaction booking rejects is left out of the booked stream, so its link
would otherwise read as missing. Fees, prices, costs and several scoped
links stay ambiguous. Transit amounts are rustledger_core::Amount.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(ag-rledger): accept a repeated --account in lint

Since agcli 0.19 (#2859) a flag given twice is refused unless it is in
MULTI_VALUE_FLAGS, so lint linked-transit --account A --account B failed
with PARSE_ERROR. --account takes one value on report and extract, so it
cannot join the global list. MULTI_VALUE_COMMAND_FLAGS scopes a long
list flag to the commands that own it, as MULTI_VALUE_SHORTS does for
short flags, and lists account for lint only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* feat(lint): diagnose a linked-transit configuration that matches nothing

A typo in --account or --link-prefix printed "No linked transit transfers
found." and exited 0. Now:

- each --account must pass rustledger_parser::is_valid_account_name, or
  the lint refuses with the name;
- a leading ^ on --link-prefix is dropped with a LINK_PREFIX_CARET note,
  since links are matched without it;
- a configured account the ledger never opens or posts to
  (ACCOUNT_NOT_IN_LEDGER) and a prefix no link starts with
  (NO_LINK_MATCHES_PREFIX) are warnings, as are processing warnings.

Warnings go through Messages: warning: lines on stderr in rledger, and
records in the ag-rledger envelope's warnings (lint now runs under
run_buffered_with_warnings).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs(changelog): add rledger lint linked-transit (#2818)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(lint): validate linked-transit legs, and refuse only what can mislead

With validation off, a leg rledger check rejects could still be matched
(an unbalanced leg, an unopened account, a closed transit account), while
a plugin finding such as check_commodity or leafonly refused the whole
file. The lint now runs validation, as check does, and sorts what
processing reports by what it can do to the answer:

- a booking failure or a plugin failure refuses the input: either drops
  or alters transactions;
- any other error located on a linked transaction makes that link
  ambiguous, with the error as the reason;
- everything else (errors elsewhere, errors with no transaction location
  such as check_commodity, warnings) is passed through as a warning.
  Advisory-only codes stay silent, as in check.

A plugin finding and a plugin that failed to run are both PLUGIN errors,
so rustledger-loader marks the latter: LedgerError::is_plugin_failure is
set for a plugin that could not be resolved, failed while running, or
whose output was discarded.

The test ledgers now open their accounts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(lint): mark plugin-inserted linked-transit legs ambiguous

A transaction a plugin inserted with no source location failed the whole
run ("linked transaction has no source location"). One inserted at a
location another transaction already has was merged into it by the
dedup key, which is meant for a file read twice: two forecast copies of
one leg merged into one and matched the receiving leg.

An unlocated transaction now gets its own key and makes its link
ambiguous. A location shared by several transactions in one ledger
(forecast copies, effective_date splits) makes the link ambiguous too,
so a dedup merge can never produce a match.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(ag-rledger): keep a passed-through ledger error's file and line

linked-transit passes a ledger error that is not on a linked leg through
as a warning. The terminal line said where it was; the envelope's
warnings entry kept only the code and message. Diagnostic gains file and
line fields, which the lint fills from the error's location and the
envelope carries as "file" and "line". The struct literals that named
every field now fill the rest from Diagnostic::message.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* refactor(lint): a Status enum for linked-transit findings

The four statuses were string literals compared in several places. A
Status enum, serialized lowercase, replaces them; the JSON and text
output are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* feat(lint): say what differs in a linked-transit mismatch

"transit account, currency, amount, or direction differs" left the user
to work out which. A mismatch now names it: "account: A vs B",
"currency: 100 USD vs -100 EUR", "zero transit amount: 0 USD vs 0 USD",
"direction: 100 USD vs 100 USD (same sign)" or "amount: 100.00 USD vs
-90.00 USD". Each location in the JSON carries its transit postings,
with the booked number as a string and the currency.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* feat(lint): list only unmatched links in linked-transit text output

On a ledger with hundreds of transfers, listing every matched pair hid
the few problems. The text output now lists the links that did not
match, then a count line ("312 matched, 2 mismatch, 1 missing,
0 ambiguous"). The JSON keeps every finding and gains the same counts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* refactor(lint): print linked-transit paths as the other lints do

linked-transit canonicalized each source path itself, for both the
printed location and the dedup key, while the other lints print the
source map's path (the file's identity, symlinks already resolved). It
now uses that path for both, which drops a second resolution that could
fail on its own, and a test pins its locations to closed-nonempty's on
a ledger reached through a symlink.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* feat(lint): --fail-on for linked-transit, in rledger and ag-rledger

#2818 asks for an explicit way to make findings fail a CI job or a
pre-commit hook. --fail-on mismatch,missing,ambiguous (comma-separated
or repeated, any of the four statuses) exits 1 when a link ends in a
listed status, as check exits 1 on an error; without it findings still
exit 0, like the other lints.

ag-rledger reads it with the same names, refuses an unknown status as
INVALID_VALUE, and merges a repeated --fail-on in lint
(MULTI_VALUE_COMMAND_FLAGS). Its envelope is the one check gives: ok
true, exit_code and result.exit_status 1.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(lint): name and split the linked-transit tests

The tests follow test_<function>_<scenario>. The table-driven pair test
and the grab-bag dedup test are split by what they check, every
assertion names its link, and the 79228162514264337593543950335 case,
which mostly tested rust_decimal, is gone. The mismatch kinds it covered
are in test_run_with_writer_mismatch_names_what_differs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs: move the linked-transit docs to docs/commands/lint.md

The section was in check.md, but linked-transit is a lint subcommand.
docs/commands/lint.md lists the four lints and documents linked-transit
in full: options, statuses and reasons, the JSON shape, how processing
errors are handled, configuration warnings and --fail-on. The commands
index links it, and check.md keeps a pointer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(ag-rledger): guard that every rledger list flag merges when repeated

Since agcli 0.19 (#2859) a flag given twice is refused unless
merge_repeated_value_flags merges it, and nothing checked that the
tables kept up with rledger. The new guard walks every rledger command
definition ag-rledger runs (and fails if one is missing from the list)
and asserts that each clap Vec flag taking one value per occurrence is
in MULTI_VALUE_FLAGS or, for its command, MULTI_VALUE_COMMAND_FLAGS,
with its short form in MULTI_VALUE_SHORTS; that no single-value flag is
merged where it applies (report and extract --account); and that no
entry is stale.

It found one gap, fixed here: check --lint is repeatable in rledger but
ag-rledger read one value, so a repeat was a PARSE_ERROR. It is now
scoped in MULTI_VALUE_COMMAND_FLAGS and read as a list.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs(changelog): update the linked-transit entry

Covers validation and how processing errors are handled, plugin-inserted
legs, mismatch reasons, the quieter text output, --fail-on, the docs
page, LedgerError::is_plugin_failure, and ag-rledger check accepting a
repeated --lint.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* style(lint): satisfy clippy in linked-transit

An if-let for the source lookup (single_match_else) and backticks on
the plugin names in the module docs (doc_markdown).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(plugin): report a native plugin that cannot use its config as failed

A native plugin that cannot use its config (rename_accounts with a bad
pattern, zerosum with none, effective_date, the check_* "skipping"
configs, ...) returns every directive unchanged and one unlocated PLUGIN
error. The loader read that as a finding, so linked-transit reported two
legs as matched where the rename the config meant makes them ambiguous,
and exited 0 even under --fail-on.

PluginError gains failed, set with mark_failed() at every site where a
native plugin gives up without doing its work: an unusable config in
capital_gains (long_short, gain_loss, through unchanged()),
check_average_cost, check_commodity, check_option_expiry,
commodity_attr, document_discovery, effective_date, onecommodity,
rename_accounts and zerosum; a pattern it cannot evaluate (capital_gains,
check_commodity, onecommodity); and a documents directory it could not
scan. Errors a plugin reports on one directive it leaves as written
(valuation, effective_date) stay findings: they are located, so the
lint attributes them to the leg. The loader maps failed to
LedgerError::with_plugin_failure.

failed is serde(skip): the MessagePack array a WASM guest sends is
unchanged, so the ABI stays 3, and a WASM or Python plugin's errors
remain findings.

Tests: the rename_accounts repro (refused, and ambiguous once the
pattern is fixed), every marked config site, a finding left unmarked,
the wire shape, and one each for the loader's run-error, op-coverage
and invalid-entry sites.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs(loader): say plainly why is_plugin_failure exists

"Not readable from the code" read as a remark about the source; it
meant the error code. Reworded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* feat(lint): exit 2 when linked-transit cannot answer

With --fail-on, a finding exits 1, and so did a run that could not
answer (a missing file, load errors, a processing failure, a refused
configuration), so a CI job could not tell "found something" from
"never looked". rledger lint linked-transit now exits 2 for the latter,
as rledger check exits 2 on a file it cannot read. The other lints keep
exiting 1.

ag-rledger is unchanged: a run that could not answer is already an error
envelope ("ok": false, FILE_NOT_FOUND exit 3 or COMMAND_FAILED exit 1),
and 2 means a usage error there. Both are documented in lint.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(lint): attribute a plugin error on a posting line to its transaction

A plugin error is matched to a linked transaction by file and line, and
only the header line counted, so an error a plugin located at one of the
leg's postings was passed through as a warning and the link could
still match. Any line from the header to the last posting now counts.

No native plugin locates an error at a posting today (a Python plugin
can), so the lookup is a function with its own test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs(changelog): linked-transit plugin failures and exit 2

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(plugin): exact error counts in the failed-marker tests

The plugin-test-quality policy refuses a bare non-empty check: each
unusable config gives exactly one error, marked failed, and the finding
test exactly one, unmarked.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(plugin): zerosum refuses a config it cannot read, as beancount does

zerosum found its settings by matching regexes against the config text,
so parse_config never failed: a malformed config such as
{'zerosum_accounts': {'Assets:Transit' ('Assets:Transit-Matched', 30)}}
matched nothing and the plugin did nothing without a word. check exited
0, and lint linked-transit reported legs the plugin should have moved as
matched. Beancount's literal_eval raises on it.

The config is now read with the shared py_literal parser, as
effective_date and check_commodity read theirs. Anything other than a
dict, a zerosum_accounts that is not a dict of (target, days), an
account_name_replace that is not (from, to), or a tolerance that is not
a number is an error, marked failed. Every key stays optional and the
last of a repeated key wins, as in Python.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs(changelog): PluginError's new field breaks struct literals

PluginError is not non_exhaustive, so code building one with a struct
literal must add failed. Said under Breaking, as for NoteData. The wire
test also pins the encoded shape: a four-element fixarray.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(lint): pin the posting-line lookup to a real transaction span

errors_within's doc and test spoke of a transaction's header and
postings, but a directive's span runs up to the next directive, blank
and comment lines included. The range now comes from span_lines, whose
doc says so, and a test builds it from a parsed ledger: header to the
comment line before the next transaction, with an error at a posting
attributed to its own transaction only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(plugin): cover every site that marks a plugin failure, and guard findings

The marked-site tests covered the config errors only. They now cover the
other sites too: rename_accounts and check_commodity, onecommodity,
long_short and gain_loss on a pattern they cannot match (a word boundary
on a character Python and rledger disagree on), gain_loss's second rule
after a rewrite, check_commodity's pattern it cannot compile (whose
finding stays unmarked), the documents directory document_discovery
cannot scan, and zerosum's non-dict config.

A drift guard the other way pins that per-directive findings stay
unmarked: leafonly, no_unused, unique_prices, and valuation's zero-unit
total price.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(lint): exit cleanly when the reader closes the pipe

rledger lint | head reported "error: Broken pipe" and exited non-zero
(2 for linked-transit since the last change). The Lint arm now treats a
closed pipe as the Check arm does: exit 0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* style(plugin): let rustfmt format onecommodity's refusal

The format! call was too long for rustfmt to fit in the match arm, so it
left the block indented by hand, and wrongly. The message is now built
first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(plugin): read zerosum configs as the Python zerosum plugin does

zerosum comes from beancount_reds_plugins (0.4.0), whose config is
literal_eval'd, each key popped with a default, and each entry
unpacked, with no type checks. The previous change refused more than it
does. Now, as there:

- days may be a float (rounded down, as timedelta(days=x) added to a date
  is), an int in any literal form (3_0, 0x1e), or a bool (True is 1);
- a None target is an empty one, derived with account_name_replace;
- a two-character string unpacks into account_name_replace's pair;
- flag_unmatched, match_metadata, match_metadata_name, link_transactions
  and link_prefix are accepted and, like any other key, ignored.

It still refuses what the Python plugin refuses: a config that is not a
literal or not a dict, a zerosum_accounts that is not a dict, and an
entry or account_name_replace that does not unpack into two. A days
value or tolerance that is not a number is refused up front, a deliberate
strictness (the Python plugin fails, or matches nothing, only once a
zerosum posting is reached), commented and tested.

Checked against the Python plugin with bean-check and bean-query: the
accepted forms move the same postings, and every refused config fails
there too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs: a zerosum example that works

The reference showed plugin "beancount.plugins.zerosum" "Assets:Reimbursable 30",
which never worked: before, the plugin silently did nothing (so the
comment that the postings match was false), and now the config is a
plugin error. The example is now the dict form the Python zerosum plugin
(beancount_reds_plugins) reads, with the accounts opened, and its options
are listed. Checked with rledger check and query, and with bean-check and
bean-query with beancount_reds_plugins 0.4.0: the same two postings move
to Assets:Reimbursable-Matched.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs(changelog): credit zerosum's behavior to the Python zerosum plugin

zerosum is beancount_reds_plugins', not beancount's, and literal_eval
is only the first of its failures: pop and the unpacking after it fail on
the others. Also notes the forms now read as it reads them, the
deliberate strictness on a non-number days or tolerance, and the fixed
reference example.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs(plugin): correct what zerosum says about the Python plugin

- py_days: a negative range matches nothing across two transactions, as
  in Python, but rledger's same-transaction branch skips the date check,
  so two postings in one transaction still match. Noted as a known
  difference; behavior unchanged.
- A None tolerance raises TypeError in the Python plugin; it does not
  match nothing.
- CHANGELOG: only a config the Python plugin cannot read is now a plugin
  error. Days too large for timedelta (an overflow there) and an empty
  target with no account_name_replace (a hang there) still run here.
- plugins.md: with no account_name_replace, an empty target is
  <account>-Matched.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Copilot <[email protected]>
Co-authored-by: Rob Cohen <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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