Skip to content

ci(lint): add ML_PAT_A multi-line variant for weak >= N count assertions - #1013

Merged
robcohen merged 1 commit into
mainfrom
fix/lint-ml-pat-a
May 6, 2026
Merged

robcohen merged 1 commit into
mainfrom
fix/lint-ml-pat-a

Conversation

@robcohen

@robcohen robcohen commented May 6, 2026

Copy link
Copy Markdown
Member

ci(lint): add ML_PAT_A multi-line variant for weak >= N count assertions

Closes #1011.

What

scripts/check-plugin-test-quality.sh had multi-line variants for
shapes B (assert_ne!), C (!is_empty()), and D (!= 0) added in
#1005. Shape A — assert!(x.len() >= N) / precomputed-count — only
had its single-line PAT_A. So a multi-line write of the original
#992 bug shape:

assert!(
    txn_count >= 3,
    "forecast should expand to at least 3 transactions"
);

slipped past the lint. PR #1008 caught one such instance by hand;
PR #1012 caught two more.

Fix

Added ML_PAT_A mirroring single-line PAT_A with the same
count-shaped LHS restriction (COUNT_LHS) and the negative
lookbehind for prop_assert!/debug_assert! that the other
multi-line patterns already use:

ML_PAT_A='(?<!\w)assert!\(\s*'"$COUNT_LHS"'\s*(?:>|>=)\s*\d+'

Wired into the existing find_multiline_in_rs call.

Knock-on: tightened one existing test

The new pattern caught a real instance in
test_check_drained_adds_balance_assertions_on_close:

assert!(
    balance_count > 0,
    "should insert balance assertions after close"
);

The plugin emits exactly one balance assertion per (closed account,
currency); test setup has one Close on Assets:Bank with USD only,
so we expect 1. Tightened to assert_eq!(.count(), 1, ...).

Self-test

Extended scripts/test-plugin-test-quality.sh with 4 new cases
(28 → 32 total):

  • multi-line assert!(\n x.len() >= 1,\n "msg"\n)
  • multi-line assert!(\n price_count >= 1\n) (the actual [Compat]: implicit price is wrong #992 shape)
  • multi-line assert!(\n x.count() > 0\n)
  • false-positive guard: multi-line prop_assert!(\n x.len() >= 1\n)
    must NOT fire

Verified

  • 143/143 plugin tests pass (one pre-existing test tightened, no new
    test functions)
  • scripts/check-plugin-test-quality.sh: OK (clean on current main)
  • scripts/test-plugin-test-quality.sh: 32/32
  • cargo clippy -p rustledger-plugin --all-features --all-targets:
    clean

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

…tions

Closes #1011.

## What

`scripts/check-plugin-test-quality.sh` had multi-line variants for
shapes B (`assert_ne!`), C (`!is_empty()`), and D (`!= 0`) added in
#1005. Shape A — `assert!(x.len() >= N)` / precomputed-count — only
had its single-line PAT_A. So a multi-line write of the original
#992 bug shape:

    assert!(
        txn_count >= 3,
        "forecast should expand to at least 3 transactions"
    );

slipped past the lint. PR #1008 caught one such instance by hand;
PR #1012 caught two more.

## Fix

Added `ML_PAT_A` mirroring single-line `PAT_A` with the same
count-shaped LHS restriction (`COUNT_LHS`) and the negative
lookbehind for `prop_assert!`/`debug_assert!` that the other
multi-line patterns already use:

    ML_PAT_A='(?<!\w)assert!\(\s*'"$COUNT_LHS"'\s*(?:>|>=)\s*\d+'

Wired into the existing `find_multiline_in_rs` call.

## Knock-on: tightened one existing test

The new pattern caught a real instance in
`test_check_drained_adds_balance_assertions_on_close`:

    assert!(
        balance_count > 0,
        "should insert balance assertions after close"
    );

The plugin emits exactly one balance assertion per (closed account,
currency); test setup has one Close on Assets:Bank with USD only,
so we expect 1. Tightened to `assert_eq!(.count(), 1, ...)`.

## Self-test

Extended `scripts/test-plugin-test-quality.sh` with 4 new cases
(28 → 32 total):
- multi-line `assert!(\n    x.len() >= 1,\n    "msg"\n)`
- multi-line `assert!(\n    price_count >= 1\n)` (the actual #992 shape)
- multi-line `assert!(\n    x.count() > 0\n)`
- false-positive guard: multi-line `prop_assert!(\n    x.len() >= 1\n)`
  must NOT fire

## Verified

- 143/143 plugin tests pass (one pre-existing test tightened, no new
  test functions)
- `scripts/check-plugin-test-quality.sh`: OK (clean on current main)
- `scripts/test-plugin-test-quality.sh`: 32/32
- `cargo clippy -p rustledger-plugin --all-features --all-targets`:
  clean

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@robcohen
robcohen requested a review from a team as a code owner May 6, 2026 15:31
Copilot AI review requested due to automatic review settings May 6, 2026 15:31

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

This PR closes a lint gap in the plugin test-quality checker by adding a multi-line detection pattern for “shape A” weak count assertions (assert!(x.len() >= N) / precomputed *_count >= N), bringing it in line with the existing multi-line handling for shapes B/C/D. It also tightens one existing plugin integration test that was using a weak > 0 count assertion.

Changes:

  • Add ML_PAT_A (multi-line “shape A”) to scripts/check-plugin-test-quality.sh and wire it into the existing multi-line scan.
  • Extend the lint self-test script with new cases covering multi-line shape A matches and a prop_assert! false-positive guard.
  • Replace a weak balance_count > 0 assertion with a strict assert_eq!(..., 1, ...) in a plugin test.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
scripts/test-plugin-test-quality.sh Adds self-test cases for the new multi-line shape A lint match plus a prop_assert! guard.
scripts/check-plugin-test-quality.sh Introduces ML_PAT_A and includes it in the multi-line Rust test scan.
crates/rustledger-plugin/tests/native_plugins_test.rs Tightens a weak balance-assertion count check to a strict expected count.

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

@codecov

codecov Bot commented May 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 31.3ms ± 0.7ms 21.7 MB
beancount 930.1ms ± 6.4ms 50.2 MB
Comparison 29.7x faster 2.3x less

vs main branch (2026-05-06)

Metric main this PR Change
Time 30.9ms 31.3ms +1.3% ✅
10K transactions · 5 runs, 2 warmup · hyperfine
What do these numbers mean?
  • Time: Wall-clock time to parse and validate the ledger (± std dev)
  • Memory: Peak resident set size (RSS)
  • vs main: Compared to latest nightly benchmark on main branch

@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

⚠️ Compatibility Test Results

Metric Result
Check Compatibility 99%
BQL Compatibility 88%
Full AST Match 99%
Total Files 786
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

@robcohen
robcohen merged commit d30334f into main May 6, 2026
35 checks passed
@robcohen
robcohen deleted the fix/lint-ml-pat-a branch May 6, 2026 15:50
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.

ci(lint): add ML_PAT_A — multi-line variant of weak-count assert!(x.len() >= N) shape

2 participants