Repository navigation
fix(parser): tags and links are not valid custom or pushmeta values - #1959
Merged
Merged
Conversation
Two rules, not one, and that is the whole difficulty: position #tag ^link metadata value valid rejected (fixed in #1954) pushmeta k: ... valid rejected custom "t" ... rejected rejected `pushmeta` follows the METADATA rule - it pushes a metadata key/value, so a tag is fine and only a link is not. `custom` is stricter than both and takes neither. Verified per position against beancount, each with a control on the same directive (custom with string/number/bool, date, account; pushmeta with a number). WHY IT IS NOT ONE CHECK `value_tokens_to_meta` serves BOTH callers - `extract_custom_values` and `pushmeta_value`. A single check inside that shared helper would either let a tag through in `custom` or wrongly reject one in `pushmeta`. The scan therefore keys on the DIRECTIVE node kind and carries a per-kind flag. Third time in this sequence the correct answer has split a pair that lexes and reads as one: #1953 (note/document DO take both), #1954 (a tag is valid where a link is not), and now this. The test makes the collapse fail: sabotaging the pushmeta flag to `true` fails on `pushmeta: tag`. Lives in `parse_via_cst_inner` alongside the #1954 scan, so green and red share it and there is no dual-path mirror to keep in sync. A TEST WAS PINNING THE DIVERGENCE `test_custom_directive_preserves_sign_and_tag_link` asserted that a custom directive CARRIES Tag/Link values. beancount rejects that exact fixture with `syntax error, unexpected TAG` and produces no directive at all - checked before the expectation was touched. The test had two separable claims. The MINUS-sign regression it was written for (`-50.00` once emitted `+50.00`) is real and kept, with a tag-free fixture that beancount accepts. Only the tag/link half is removed, and the reasoning is recorded in place. CORPUS One baseline drifted: `parser-lima/examples_data_custom.beancount`, whose first line packs every value kind including `#tag1 ^link1`. Both tools rejected that file before AND after - beancount stops at an earlier `unexpected CURRENCY`, which we already objected to as well - so only our error set grew, by the two new objections. Updated surgically. Caches: loader 23 -> 24, wasm 9 -> 10. Closes #1958.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
📊 Benchmark Results
vs main branch (2026-08-04)
What do these numbers mean?
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens rustledger-parser’s Beancount compatibility by enforcing distinct acceptance rules for #tag / ^link when they appear as values in custom and pushmeta directives, and updates caches/baselines to account for newly erroring inputs.
Changes:
- Added a CST-based scan that rejects tag/link tokens in
customand (asymmetrically) rejects only links inpushmetavalues. - Updated parser integration tests to remove an incorrect expectation (custom carrying tag/link values) and add a new regression test that pins the two-rule behavior plus green/red parity.
- Bumped loader and wasm cache versions and updated the parser corpus manifest baseline for a changed corpus file output.
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 |
|---|---|
| tests/baselines/parser-corpus.manifest | Updates the stored baseline hash for examples_data_custom.beancount reflecting the new parser diagnostics. |
| crates/rustledger-wasm/src/cache.rs | Bumps wasm cache version to invalidate caches after the parser behavior change. |
| crates/rustledger-parser/tests/parser_integration_test.rs | Adjusts the custom directive regression test and adds a dedicated test covering the custom vs pushmeta tag/link rules + green/red parity. |
| crates/rustledger-parser/src/cst/convert.rs | Implements the new directive-kind-aware scan that emits syntax errors for invalid tag/link value positions. |
| crates/rustledger-loader/src/cache.rs | Bumps loader cache version (and fixture version constants) to prevent stale “previously clean” parses from being served. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
robcohen
enabled auto-merge (squash)
August 4, 2026 18:57
Contributor
|
| Metric | Result |
|---|---|
| Check Compatibility | 100% |
| BQL Compatibility | 95% (raw 89%, 162 masked) |
| Full AST Match | 100% |
| Total Files | 812 |
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
robcohen
added a commit
that referenced
this pull request
Aug 4, 2026
Rebasing onto main after #1959 landed, the new tripwire fired on an actual version move rather than a sabotage: the rustledger-loader cache version moved and this one did not... Answering its own question: #1959 made tags and links parse errors in custom and pushmeta values, so PARSER OUTPUT changed - and it correctly bumped BOTH caches, loader 23 to 24 and wasm 9 to 10. Only the pin was behind. So this is the update-the-pin-alone branch of the message, and the guard did exactly what it exists for: it made the question get asked at the moment the versions diverged, rather than leaving it to be noticed in review, or not at all.
robcohen
added a commit
that referenced
this pull request
Aug 4, 2026
…ions together (#1960) * test(loader): cache round-trip properties, and pin the two cache versions together stale cache resurrects fixed bugs unless CACHE_VERSION is bumped, which is a property, not a review". This session proved that literally, twice. WHAT THE SESSION SHOWED The loader cache moved 17 -> 23 and the wasm cache 3 -> 9, six bumps each, every one done by hand and every one requiring a fresh judgment about whether the archived LAYOUT moved or only the VALUE. Two things went wrong: - On #1942 the parser was provably fixed - a probe showed the corrected cost - while `rledger check` still reported the old imbalance, because a stale cache was answering. - On the same PR I bumped the loader and MISSED the wasm cache entirely. It archives the same `Vec<Directive>`, so a stale blob would have kept serving a truncated cost basis on a fixed build. Review caught it. No test did. THREE PROPERTIES 1. `cache_roundtrip_preserves_parsed_directives` round-trips REAL PARSED ledgers, one per shape whose parser output changed in this series: cost arithmetic, negative cost, compound cost, metadata arithmetic, balance tolerance, a unicode account, tags and links, and lots with prices. The existing tests hand-build a CacheEntry from a literal directive, which proves the format works on the shape the author thought of - not the shape that keeps breaking. 2. `a_stale_version_is_refused_rather_than_reinterpreted` writes a real cache, rewrites the header version word to the previous version, and asserts the loader refuses it. This is the property that actually protects an upgrade: the layout usually does NOT change when parser output does, so nothing else stops an old blob deserializing cleanly into the new types and serving a pre-fix answer. 3. `loader_cache_version_is_pinned` pins the wasm cache against the loader's, so moving one without the other fails with a message that asks the right question: did PARSER OUTPUT change (bump both), or was it loader-internal (update the pin alone)? This is the guard for the bug that got past me. ALL THREE VERIFIED TO FAIL version check disabled -> "a cache blob one version behind must be refused" loader moved, pin did not -> the tripwire message above a fixture stops parsing -> "expected a multi-directive parse, got 0" The third is the non-vacuity guard on property 1: without it the comparison is satisfied by two empty vectors, and a shape that stopped parsing would pass as a clean round-trip. `CACHE_VERSION` is now `pub` so the wasm crate can pin against it; that pulled in a stricter doc lint on the public item, hence the paragraph break in its history comment. Refs #1902. * test(wasm): pin catches up to loader v24 - the tripwire firing for real Rebasing onto main after #1959 landed, the new tripwire fired on an actual version move rather than a sabotage: the rustledger-loader cache version moved and this one did not... Answering its own question: #1959 made tags and links parse errors in custom and pushmeta values, so PARSER OUTPUT changed - and it correctly bumped BOTH caches, loader 23 to 24 and wasm 9 to 10. Only the pin was behind. So this is the update-the-pin-alone branch of the message, and the guard did exactly what it exists for: it made the question get asked at the moment the versions diverged, rather than leaving it to be noticed in review, or not at all. * test(loader): unique fixture dirs and an env guard for the cache properties Two review findings, both real hazards rather than style. CONCURRENT RUNS COLLIDED. `temp_dir()` built a fixed name under the global temp dir, so two `cargo test` processes landed on the same path - and the cleanup at the START of the helper would delete the other run's fixture out from under it. Now a `tempfile::TempDir` with a unique suffix, which also removes itself on drop, so a failing assertion leaves no litter. Verified by running two copies of the suite concurrently: both pass. THE ENV VARS WERE INHERITED. `save_cache_entry` / `load_cache_entry` read process env, so an inherited BEANCOUNT_LOAD_CACHE_FILENAME would redirect these writes out of the fixture - silently making the round-trip assert nothing - and BEANCOUNT_DISABLE_LOAD_CACHE would stop a cache being written at all. Either could also clobber a developer's real cache file. The unit tests in cache.rs already guard themselves this way (`assert_clean_cache_env`). I did not follow the pattern the crate had already established. Verified the guard fires: $ BEANCOUNT_DISABLE_LOAD_CACHE=1 cargo test --test cache_roundtrip_properties unset BEANCOUNT_DISABLE_LOAD_CACHE before running this test ... Noted in place that CLAUDE.md warns against asserting environment as a precondition (#1729). The exception earns itself here: the alternative is not a hermetic test but one that writes somewhere unexpected, and failing loudly beats that. * docs(loader): backtick the generics in the now-public cache-version history CI's Documentation job failed with "unclosed HTML tag `Decimal`". The v8 entry in the version history contains `Option<Decimal> + Option<Decimal>` unescaped, and rustdoc parses a bare `<Decimal>` as an HTML tag. It has been there since v8 and was harmless because the constant was PRIVATE - rustdoc does not document private items by default. Making `CACHE_VERSION` public so the wasm crate could pin against it is what exposed the comment. Worth noting the shape: `cargo test` and clippy both pass on this. Only `cargo doc` catches it, which is why the repo has a separate Documentation job - and why I should have run it after making an item public rather than after CI told me. Checked the rest of the block for the same problem (none) and ran `RUSTDOCFLAGS=-D warnings cargo doc --workspace`, which is clean.
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.
Two rules, not one, and that's the whole difficulty:
#tag^linkpushmeta k: …custom "t" …pushmetafollows the metadata rule — it pushes a metadata key/value, so a tag is fine and only a link is not.customis stricter than both and takes neither. Verified per position against beancount, each with a control on the same directive (customwith string/number/bool, date, account;pushmetawith a number).Why it isn't one check
value_tokens_to_metaserves both callers —extract_custom_valuesandpushmeta_value. A single check inside that shared helper would either let a tag through incustomor wrongly reject one inpushmeta. The scan therefore keys on the directive node kind and carries a per-kind flag.Third time in this sequence the correct answer has split a pair that lexes and reads as one: #1953 (
note/documentdo take both), #1954 (a tag is valid where a link is not), and now this. The test makes the collapse fail — sabotaging the pushmeta flag totruefails onpushmeta: tag:It lives in
parse_via_cst_inneralongside the #1954 scan, so green and red share it and there's no dual-path mirror to keep in sync.A test was pinning the divergence
test_custom_directive_preserves_sign_and_tag_linkasserted a custom directive carries Tag/Link values. beancount rejects that exact fixture withsyntax error, unexpected TAGand produces no directive at all — checked before the expectation was touched.The test had two separable claims. The MINUS-sign regression it was written for (
-50.00once emitted+50.00) is real and kept, with a tag-free fixture beancount accepts. Only the tag/link half is removed, reasoning recorded in place.Corpus
One baseline drifted:
parser-lima/examples_data_custom.beancount, whose first line packs every value kind including#tag1 ^link1. Both tools rejected that file before and after — beancount stops at an earlierunexpected CURRENCY, which we already objected to as well — so only our error set grew, by the two new objections. Updated surgically.Caches: loader 23 → 24, wasm 9 → 10.
Verification
customcargo fmt --checkcleanCloses #1958.