Skip to content

chore: exclude 4 Unicode-account-start files from compat suite - #772

Merged
robcohen merged 2 commits into
mainfrom
chore/exclude-unicode-account-conformance-gaps
Apr 11, 2026
Merged

robcohen merged 2 commits into
mainfrom
chore/exclude-unicode-account-conformance-gaps

Conversation

@robcohen

Copy link
Copy Markdown
Member

Summary

The compatibility test suite currently reports ~98-99% match across 784 real-world beancount files. This PR investigates and documents the remaining gap, then marks the affected files as deliberate exclusions so the report will read 100% across all metrics.

Zero code changes. This is purely an exclusions-file update with detailed rationale in TOML comments.

The gap

Earlier in this session (while investigating PR #771's compat output) I asked why those 4 files fail. The answer is the same for all of them:

rustledger's Token::Account lexer regex enforces the beancount v3 spec rule that every account segment must start with an ASCII uppercase letter (or ASCII digit for sub-segments). Unicode letters ARE permitted in subsequent positions within a segment — e.g. Förra-årets-resultat parses fine because it starts with F. Python beancount is more permissive and accepts Unicode at segment starts too.

This is a deliberate and documented divergence settled in issues #572, #736, and #739. The pta-standards conformance suite depends on the stricter behavior. rustledger's lexer has dedicated unit tests pinning it (test_tokenize_account_unicode, test_tokenize_account_unicode_letters_after_ascii_start).

The 4 files, diagnosed

File Failing construct Category
double-entry-generator/example_hxsec_example-hxsec-output.beancount Assets:Hxsec:Positions:沪深300 CJK at sub-segment start
fava-portfolio-returns/src_fava_portfolio_returns_test_ledger_unicode.beancount Assets:CORP✨ Symbol (U+2728) in segment, not a letter
ledger2beancount/tests_accounts.beancount Expenses:École-républicaine, Expenses:École Accented Latin capital at sub-segment start
pinto-reports/example.beancount Årets-resultat, Öres-och-kronutjämning, and 4 more Swedish capitals at sub-segment start

What does not fail (verified against pinto-reports/example.beancount): lines like Förra-årets-resultat parse cleanly because F is ASCII at the segment start; the ö and å mid-segment are in \p{L} and are permitted. This confirms the rule is specifically about the first character of each colon-delimited segment.

Why not fix the parser?

  1. It's a deliberate design decision with dedicated lexer unit tests pinning the strict behavior.
  2. The spec is on rustledger's side. Python beancount's permissiveness is a historical accident predating the v3 spec clarification.
  3. Relaxing the rule would break pta-standards conformance. The conformance suite specifically asserts ASCII-at-start rejection.
  4. The affected files are <0.5% of the corpus. None are mainstream usage patterns — they're test fixtures that deliberately exercise edge cases, or charts of accounts using non-Latin scripts at segment starts.
  5. Workarounds exist for affected users: prefix segments with ASCII characters, or use name_* options to rename root segments.

Why exclude rather than ignore?

Previously the compat output was "98-99% with a mystery 1-2% gap." That invited speculation about hidden bugs. After this PR the output will be "100% with 8 documented deliberate exclusions." Readers who want to understand the gap can read exclusions.toml, where each entry lives alongside detailed TOML comments that:

This is the same pattern the existing exclusions use (decimal precision >28 digits, removed v2 plugins).

Verification

  1. TOML parses cleanly via tomllib — 8 exclusions total, 4 pre-existing + 4 new.
  2. All 4 source paths verified via gh api contents against the upstream repos.
  3. All 4 safename values computed per fetch-compat-test-files.sh's tr '/' '_' rule and matched against the expected tests/compatibility/files/<subdir>/<safename> paths.
  4. Substring matching confirmed — the CI uses if pattern in rel_path, and each pattern is specific enough that it won't cross-match any other file in the corpus.
  5. Root cause validated locally by running rledger check on all 4 files from the release-plz-2026-04-11T20-44-43Z branch (with the 0.12.0 version bump already applied). Error codes match the CI output exactly: P0012×4 (hxsec), P0012×1 (fava unicode), P0006×2 + P0012×3 (tests_accounts), P0012×6 (pinto-reports example).

Files changed

  • tests/compatibility/exclusions.toml — +95 lines, 4 new [[exclusions]] entries with detailed details = """...""" blocks.

Related

The compatibility test suite currently reports ~98-99% match rate
across 784 real-world beancount files. The remaining 1-2% gap is
4 specific files that fail for exactly one reason: they contain
account segments starting with non-ASCII characters.

rustledger's lexer enforces the beancount v3 spec rule that every
account segment must begin with an ASCII uppercase letter (or ASCII
digit for sub-segments). Unicode letters ARE permitted in subsequent
positions within a segment, e.g. `Förra-årets-resultat` parses fine
because it starts with `F`, and `Banque-Épargne` is similarly fine.
The strict rule applies only to the FIRST character of each
colon-delimited segment.

Python beancount is more permissive and accepts Unicode at segment
starts too. This is a deliberate and documented divergence — the
pta-standards conformance suite asserts the stricter rule, and
rustledger's lexer has dedicated tests pinning the behavior. See
issues #572, #736, and #739 for the full history and rationale.

The 4 files:

- `double-entry-generator/example_hxsec_example-hxsec-output.beancount`
  CJK at sub-segment start: `Assets:Hxsec:Positions:沪深300`.

- `fava-portfolio-returns/src_fava_portfolio_returns_test_ledger_unicode.beancount`
  Emoji in segment: `Assets:CORP✨` (U+2728 is Symbol, not Letter).

- `ledger2beancount/tests_accounts.beancount`
  Accented Latin capital at sub-segment start: `Expenses:École`
  and `Expenses:École-républicaine`.

- `pinto-reports/example.beancount`
  Swedish BAS chart of accounts with 6 segments starting with `Å`
  or `Ö` (e.g. `Liabilities:2069:Årets-resultat`).

None of these represent mainstream usage patterns. They're either
test fixtures that deliberately exercise edge cases (fava-portfolio-
returns/test/ledger/unicode.beancount, ledger2beancount's own
account-names test suite) or charts of accounts that use non-Latin
scripts at segment starts. Affected users can work around the
limitation via ASCII-prefixed segment names or the `name_*` options
for root-segment renaming.

After this PR the compat report will read 100% across all metrics,
with the understanding that "the gap" is exactly "4 files we
deliberately reject per spec." This is honest — previously the
mystery 1-2% invited speculation about hidden bugs; now the
exclusions document the specific cases and point at the design
decision that caused them.

All 4 exclusion patterns have been verified:
1. Verified against the fetch script's `$name/$safename` format
2. Substring-matched against the expected full paths
3. Specific enough that they won't cross-match unrelated files
4. Upstream source paths verified via `gh api contents`
5. TOML parses cleanly via tomllib

Does not change any code. Does not relax the parser rule. Just
documents the known limitations in the same place the existing
4 exclusions live (decimal precision, forecast plugin, unrealized
plugin).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@robcohen
robcohen requested a review from a team as a code owner April 11, 2026 21:41
Copilot AI review requested due to automatic review settings April 11, 2026 21:41
@robcohen
robcohen enabled auto-merge April 11, 2026 21:42
@codecov

codecov Bot commented Apr 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the compatibility suite’s exclusions list to document and intentionally exclude 4 real-world fixtures that diverge due to rustledger’s stricter beancount v3 account-segment rules (ASCII-uppercase/digit segment starts, Unicode letters allowed only after ASCII start, symbols/emoji rejected).

Changes:

  • Added 4 new [[exclusions]] entries for known Unicode/symbol account-name incompatibilities.
  • Added detailed TOML comments and per-file rationale/workarounds to make the remaining compat gap explicit.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/compatibility/exclusions.toml Resolved
Comment thread tests/compatibility/exclusions.toml Resolved
Comment thread tests/compatibility/exclusions.toml Resolved
@github-actions

github-actions Bot commented Apr 11, 2026 •

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100%
Full AST Match 98%
Total Files 780
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

Three inline comments, all about the accuracy of the explanatory
prose in the exclusions-file comment blocks. All legitimate — the
original wording conflated two unrelated things:

  1. The account-segment start-character rule (the actual rule
     being enforced and documented in these exclusions)
  2. Account root-type localization via `name_*` options (a
     different feature — issue #572)

Fixes:

1. **Section header was too narrow.** I called the new section
   "Unicode-at-account-segment-start exclusions" but the
   `Assets:CORP✨` (fava-portfolio-returns) exclusion fails for a
   different reason: the emoji `✨` is in Unicode category `So`
   (Symbol, Other), not `L` (Letter), so it's rejected *anywhere*
   in the segment body, not specifically at the start. Renamed
   the section to "Non-ASCII account name exclusions" and split
   the explanation into two enumerated rules:

     - Rule 1: segment start must be ASCII
     - Rule 2: segment body must be ASCII digits, hyphens, or
       Unicode letters — no symbols or emoji anywhere

   Then documented which of the 4 files exercises which rule.

2. **Intro paragraph mentioned `name_*` as a workaround.** It
   doesn't apply: `name_*` options rename the ROOT segment type
   (`Assets` → `Activos`), but all 4 exclusions fail on SUB-segments,
   not root segments. Replaced the `name_*` suggestion with an
   accurate workaround (rename the offending sub-segment to start
   with ASCII) and explicitly noted that `name_*` does not help
   with sub-segment localization.

3. **`pinto-reports/example.beancount` details suggested `name_*`.**
   Same issue as #2, but in the per-file details block. The Swedish
   chart of accounts has ASCII root segments (`Liabilities`, `Income`,
   `Expenses`) and accented sub-segments (`Årets-resultat` et al.),
   so `name_*` renaming does nothing. Replaced with the accurate
   workaround.

No code changes. TOML still parses cleanly (8 exclusions total, 4
pre-existing + 4 new). Functional behavior of the exclusions is
unchanged — the compat bot already shows Check Compatibility at
100% and Total Files dropped from 784 to 780, confirming the 4
new patterns match their intended files.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@robcohen
robcohen disabled auto-merge April 11, 2026 21:53
@robcohen
robcohen enabled auto-merge April 11, 2026 21:53
@robcohen
robcohen added this pull request to the merge queue Apr 11, 2026
Merged via the queue into main with commit 1067032 Apr 11, 2026
33 checks passed
@robcohen
robcohen deleted the chore/exclude-unicode-account-conformance-gaps branch April 11, 2026 22:04
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.

2 participants