Repository navigation
fix: one canonical account-name rule; validate FFI ingress; warn on bad name_* roots - #1739
Conversation
…ad name_* roots Three surfaces hand-implemented "is this a valid account name" with three different accepted character sets (sweep finding L4): - the lexer: [Lu Lo Lt] roots, [Lu Lo Lt 0-9] sub-component starts, letters/digits/hyphens, >=2 components — the rule that decides what can actually round-trip through the language; - the validator's Open check: accepted digit-start ROOTS and ANY non-ASCII character mid-component (its reject condition required c.is_ascii(), so numero signs and emoji passed); - the loader's option guard (account_rounding etc.): a third first-char rule with no per-character check at all. Parsed ledgers were safe (the lexer gates them), but synthesized surfaces were not: the FFI builder path (entry.create/createBatch) bypasses the loader pipeline and accepted raw strings as accounts with NO validation — weaker than any of the three rules — so directives whose accounts can never be parsed back could enter programmatically. And name_* account-type renames were the one unguarded option family: option "name_assets" "1Assets" was accepted silently even though every account under it is unparsable (in both rledger and Python beancount). Fix, in one motion: - rustledger_parser::is_valid_account_name — the canonical predicate, implemented by RUNNING THE LEXER (exactly one Account token spanning the whole input), so it cannot drift from what the parser accepts. - validator delegates its character/structure rule to the predicate, keeping the root-type membership check (ledger semantics) and its error messages. Tightens: digit-start roots, non-ASCII garbage mid-component, and single-component names are now rejected — matching the parser and Python. - loader's is_valid_account delegates; name_* options now get an E7008 warning when the root is un-lexable (checked by running the predicate on "root:X"), mirroring the E7002 guard the account_* options always had. - FFI builder validates every account field (posting, open, close, balance, pad + source, note, document) through the predicate, returning a typed error naming the field. New tests pin the predicate's rule (unicode roots, digit-start sub-components, all rejection classes), the validator tightening, the E7008 warning, and the FFI rejection/acceptance paths. Co-Authored-By: Claude Fable 5 <[email protected]>
📊 Benchmark Results
vs main branch (2026-07-10)
What do these numbers mean?
|
There was a problem hiding this comment.
Pull request overview
Unifies account-name validation across the codebase by introducing a single canonical predicate (rustledger_parser::is_valid_account_name) implemented by running the lexer, then updating validator, loader option guards, and FFI directive-builder ingress to rely on that predicate. This closes gaps where synthesized/programmatic surfaces could previously admit account names that the parser could never round-trip.
Changes:
- Added
rustledger_parser::is_valid_account_name(lexer-based) and re-exported it fromrustledger-parser. - Tightened validator and loader option validation to delegate account-name structure/character checks to the canonical predicate; added loader warning E7008 for invalid
name_*roots. - Added FFI-WASI builder ingress validation for all account-bearing directive inputs with targeted error messages and tests.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/rustledger-validate/src/validators/helpers.rs | Delegates account-name lexing/structure validation to the canonical parser predicate; adds tests for tightened behavior and renamed roots. |
| crates/rustledger-parser/src/logos_lexer.rs | Introduces canonical is_valid_account_name implemented via the lexer; adds predicate unit tests. |
| crates/rustledger-parser/src/lib.rs | Re-exports is_valid_account_name as part of the parser crate’s public API. |
| crates/rustledger-loader/src/options.rs | Makes account_* option validation canonical; adds name_* root validation with new E7008 warning plus tests. |
| crates/rustledger-ffi-wasi/src/types/input.rs | Validates all FFI directive-builder account ingress points using the canonical predicate; adds regression tests for reject/accept cases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
The account-name ingress gate made input_entry_to_directive fallible on account validation, so the pass-through surfaces' "conversion is not expected to fail" comment was stale: a held directive with an un-lexable account (plugin-synthesized or embedder-constructed) is silently dropped. Documented at both sites with the trade-off and the escape hatch (a warnings channel on the WIT signature) if it stops being acceptable. Co-Authored-By: Claude Fable 5 <[email protected]>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…1753) * feat(fuzz): fuzz the FFI ingress boundary (input_entry_to_directive) The builder behind the component's entry.create/createBatch takes wire JSON from untrusted embedders and hand-validates it — dates, the account-name gate, cost-number arity, the BookedCost per-unit x units == total invariant — and none of that validation was fuzzed. New cargo-fuzz crate for rustledger-ffi-wasi with one target: arbitrary bytes driven through the REAL wire path (serde_json -> InputEntry -> input_entry_to_directive), asserting beyond no-panic that (1) any successfully converted directive carries only accounts the canonical lexer predicate accepts — a bypass would readmit the class #1739's gate blocks — and (2) conversion disposition is deterministic. Committed seeds (fuzz/seeds/, one JSON per InputEntry variant plus booked-pair and bad-account edges) document the wire format by example and are copied into the corpus before CI runs, so cold caches start with structural coverage. fuzz.yml gains a fuzz-ffi-ingress job cloned from fuzz-booking (max_len 4096 for JSON) and the dispatch target list gains fuzz_input_entry. Locally shaken: 9.65M executions over 120s, cov 6073, zero crashes, both invariants held. Co-Authored-By: Claude Fable 5 <[email protected]> * fix(fuzz): length guard, ffi paths trigger, full variant seeds (review) - explicit 64 KiB input guard in the harness so resource usage is bounded regardless of runner flags; - fuzz.yml pull_request paths gain crates/rustledger-ffi-wasi/** (the new job now runs where the boundary changes) and the workflow file itself; - seeds for the six missing InputEntry variants (commodity, price, event, document, query, custom) so the "one per variant" comment is true — 16 seeds total, re-shaken 60s locally with zero findings. Co-Authored-By: Claude Fable 5 <[email protected]> --------- Co-authored-by: Claude Fable 5 <[email protected]>
What
Establishes ONE canonical account-name rule — the lexer itself — and makes every surface that admits account names use it: the validator's Open check, the loader's option guards, and (new) the FFI directive-builder ingress. Also adds an
E7008warning forname_*account-type renames that can never head a parsable account.Why
Phase-1 correctness sweep, finding L4: three hand-written validators accepted three different character sets:
Accounttoken regex)[\p{Lu}\p{Lo}\p{Lt}]roots, sub-components may start with a digit, letters/digits/hyphens, ≥2 componentsvalidate_account_name)c.is_ascii()—№, emoji passed)is_valid_account)Parsed ledgers were safe (the lexer gates them). The live holes were the synthesized surfaces:
entry.create/createBatch) bypasses the loader pipeline and took rawaccount: Stringwith no validation whatsoever — directives whose accounts can never round-trip through text could enter programmatically.name_*renames were the one unguarded option family:option "name_assets" "1Assets"was accepted silently even though every account under a digit-start root is unparsable (in both rledger and Python beancount — verified during the probe), whileaccount_roundingetc. always had the E7002 guard.How
rustledger_parser::is_valid_account_name— the canonical predicate, implemented by running the lexer and requiring exactly oneAccounttoken spanning the whole input. Drift from the parser is impossible by construction; there is no second encoding of the rule to keep in sync.№/emoji mid-component, and single-component names are now rejected, matching the parser and Python.is_valid_accountdelegates.name_*roots are checked by running the predicate on"{root}:X"(a root is valid exactly when it can head a real account) →E7008warning, value still accepted for option-handling parity.input_entry_to_directive(review B-3.1 precedent).All three consumers already depended on
rustledger-parser; no new edges in the crate graph.Testing
é,№/emoji/underscore/space, structural::/trailing colon/whitespace).資産:現金).--all-features --all-targets -D warnings, fmt, rustdoc clean.🤖 Generated with Claude Code