Skip to content

ci(rust): boar_fast_filter — testable pure-Rust core, 19 unit tests, clippy 1.95-safe CI gate - #263

Closed
FabioLeitao wants to merge 2 commits into
mainfrom
cursor/anchieta-rust-ci-c9ab
Closed

FabioLeitao wants to merge 2 commits into
mainfrom
cursor/anchieta-rust-ci-c9ab

Conversation

@FabioLeitao

Copy link
Copy Markdown
Collaborator

Summary

Lands the missing CI/CD coverage and unit tests for the repository's only Rust component — rust/boar_fast_filter/ (PyO3 high-speed PII pre-filter for Data Boar Pro+). Supersedes the failing PRs in the #255–#260 series by combining the cleanest scope from each, fixing the clippy 1.95 manual_is_multiple_of self-block, and proving the gate green on both the homelab toolchain (Rust 1.83) and the CI runner toolchain (stable Rust 1.95).

Scoping note. The original task brief named a "data-board-report" Rust component. There is no such crate in this repo — the only Rust code is rust/boar_fast_filter/. I treated that as the intended target. If a separate data-board-report crate lands later, this workflow will pick it up automatically once it is added under rust/**, since the paths: trigger is rust/** rather than crate-specific.

What changes

1. Pure-Rust testable core in rust/boar_fast_filter/src/lib.rs

The previous module returned PyResult<Self> from new and consumed Vec<String> by value, both awkward to drive from cargo test. Refactor with zero behaviour change for the Python binding:

  • pub fn try_new() -> Result<Self, regex::Error> — pure-Rust constructor.
  • pub fn filter_batch_pure(&self, batch: &[String]) -> Vec<usize> — borrowed-slice testable core. The PyO3-exposed filter_batch delegates here so the Python and Rust paths share one implementation.
  • pub fn check_luhn(...) — exposed for direct unit testing.

2. 19 #[cfg(test)] unit tests

Group Cases
Luhn (8) valid Visa / MasterCard / Amex test PANs, invalid check digit, too short, too long, separator tolerance (- and space), empty / non-numeric
Constructor (1) try_new compiles all baseline regexes
Detection (4) CPF with punctuation, CPF without punctuation, email, valid-Luhn credit card
Negative paths (3) clean content, card-shaped digits failing Luhn, empty batch
Behaviour (3) each line reported at most once, output preserves input order, mixed-signal batch returns indexes in order

3. .github/workflows/rust-ci.yml

  • Triggers on push and PR to main / master, scoped via paths: to rust/** and the workflow file itself.
  • working-directory: rust/boar_fast_filter.
  • Reuses the actions/checkout and actions/setup-python SHAs already vetted in ci.yml (PyO3 needs a Python interpreter at link time).
  • Toolchain installed via rustup directly to avoid adding a new third-party Action SHA to track.
  • Steps: cargo fmt --all -- --check → cargo check --all-targets --locked → cargo test --all-targets --locked → cargo clippy --all-targets --locked -- -D warnings. Any clippy lint promotes to a CI failure.
  • permissions: contents: read only.

4. Slack failure notify

slack-ci-failure-notify.yml now subscribes to CI, Rust CI, Semgrep, SBOM (was CI, Semgrep, SBOM). When the Rust gate fails, the operator gets a Slack ping on the same SLACK_WEBHOOK_URL secret as every other CI failure. Skipped cleanly when the secret is unset (per tests/test_github_workflows.py::test_slack_post_workflows_guard_webhook_secret).

5. Workflow guard test

New test_rust_ci_workflow_present_and_valid in tests/test_github_workflows.py asserts name, contents: read, path-scoped triggers, working directory, and that all four cargo steps (with the exact -D warnings predicate) are present. Regression guard so removing or downgrading the Rust gate is caught at PR time.

The clippy 1.95 fix (why we keep % 10)

clippy 1.95 added manual_is_multiple_of, which suggests rewriting sum % 10 == 0 as sum.is_multiple_of(10). With -D warnings, that's a hard error. But u32::is_multiple_of only stabilised in Rust 1.87, and the homelab toolchain is pinned at 1.83. Following clippy's auto-suggestion would break the homelab build with error[E0658]: use of unstable library feature 'unsigned_is_multiple_of'.

The chosen fix keeps the canonical Luhn arithmetic readable and tells clippy this is intentional:

#[allow(unknown_lints, clippy::manual_is_multiple_of)]
pub fn check_luhn(card_number: &str) -> bool { ... sum % 10 == 0 }

unknown_lints is paired with the lint name so older clippys (which haven't seen manual_is_multiple_of yet) still accept the attribute.

Local verification (both toolchains)

From rust/boar_fast_filter/:

# Rust 1.83 (homelab pin)
cargo fmt --all -- --check                                # clean
cargo check --all-targets --locked                        # clean
cargo test --all-targets --locked                         # 19 passed
cargo clippy --all-targets --locked -- -D warnings        # clean

# Rust 1.95 (CI runner)
rustup run stable cargo fmt --all -- --check              # clean
rustup run stable cargo check --all-targets --locked      # clean
rustup run stable cargo test --all-targets --locked       # 19 passed
rustup run stable cargo clippy --all-targets --locked -- -D warnings   # clean

Repository hygiene:

uv run pytest tests/test_github_workflows.py -q           # 12 of 12 passed (incl. new Rust CI guard)
uv run pre-commit run --files .github/workflows/rust-ci.yml \
    .github/workflows/slack-ci-failure-notify.yml \
    tests/test_github_workflows.py \
    rust/boar_fast_filter/src/lib.rs                      # all hooks green

Defensive architecture review

  • DB locks / customer impact: none. boar_fast_filter is a pure-CPU regex+Luhn prefilter; it does not open connections, hold locks, or change any DB-bound code path.
  • Behaviour delta vs main: zero on the hot path. filter_batch still takes Vec<String> and returns PyResult<Vec<usize>>; it just delegates to filter_batch_pure. Every existing caller in Python keeps working.
  • Forward-compat: when the homelab eventually moves to Rust 1.87+, the #[allow] becomes a one-line removal — the is_multiple_of migration is a clean follow-up.
  • No supply-chain change: no new dependencies, no MSRV bump, no new third-party Action.

Commits (split per commit-grouping policy)

  • test(rust): expose pure-Rust API and add 19 unit tests for boar_fast_filter
  • ci(rust): add Rust CI workflow with fmt, check, test, clippy -D warnings

Relationship to the open PR series

The maintainer can pick this branch and close the others as superseded, or cherry-pick the % 10 #[allow] block into whichever branch they prefer to land.

Slack Thread

Open in Web Open in Cursor 

cursoragent and others added 2 commits April 27, 2026 19:58
…filter

Refactor (no behaviour change for the Python binding):

- pub fn try_new() -> Result<Self, regex::Error> — pure-Rust constructor
  that returns the underlying regex error directly, so cargo test can drive
  it without a Python interpreter.
- pub fn filter_batch_pure(&self, batch: &[String]) -> Vec<usize> —
  borrowed-slice testable core. The PyO3-exposed filter_batch now delegates
  here so the Python and Rust paths share one implementation.
- pub fn check_luhn(...) — exposed for direct unit testing.

19 #[cfg(test)] unit tests:

- Luhn (8): valid Visa / MasterCard / Amex test PANs, invalid check digit,
  too-short, too-long, separator tolerance (- and space),
  empty / non-numeric.
- Constructor (1): try_new compiles all baseline regexes.
- Detection (4): CPF with punctuation, CPF without punctuation, email,
  valid-Luhn credit card.
- Negative paths (3): clean content, card-shaped digits failing Luhn,
  empty batch.
- Behaviour (3): each line reported at most once, output preserves input
  order, mixed-signal batch returns indexes in order.

Clippy 1.95 portability: keep the canonical % 2 / % 10 Luhn arithmetic and
suppress clippy::manual_is_multiple_of behind #[allow(unknown_lints, ...)].
The std method u32::is_multiple_of only stabilised in Rust 1.87, so following
clippy's suggestion would break the homelab toolchain pinned at 1.83.
unknown_lints is paired so older clippys (which haven't seen the new lint
yet) still accept the attribute.

Local verification on both stable 1.95 (CI runner) and 1.83 (homelab):
- cargo fmt --all -- --check       clean
- cargo check --all-targets --locked   clean
- cargo test --all-targets --locked    19 passed
- cargo clippy --all-targets --locked -- -D warnings   clean

Co-authored-by: Fabio Tavares Leitão <[email protected]>
New workflow .github/workflows/rust-ci.yml:

- Triggers on push and PR to main / master, scoped via paths to rust/**
  and the workflow file itself, so unrelated Python or docs PRs do not
  spin Rust builds.
- working-directory pinned to rust/boar_fast_filter so steps stay terse.
- actions/checkout and actions/setup-python reuse the SHAs already vetted
  in ci.yml. Toolchain installed via rustup (no new third-party Action
  SHA to track).
- Steps in order: cargo fmt --all -- --check, cargo check --all-targets
  --locked, cargo test --all-targets --locked, cargo clippy --all-targets
  --locked -- -D warnings — promotes any clippy lint to a CI failure.
- permissions: contents: read only.

Wire the new workflow into Slack failure notify:

- slack-ci-failure-notify.yml now subscribes to CI, Rust CI, Semgrep,
  SBOM (was: CI, Semgrep, SBOM). When the Rust gate fails, the operator
  gets a Slack ping on the same SLACK_WEBHOOK_URL secret as every other
  CI failure (skipped cleanly when the secret is unset).

Tests:

- test_github_workflows.py: new test_rust_ci_workflow_present_and_valid
  asserts name, contents: read permission, path-scoped triggers, working
  directory, and that all four cargo steps with the exact -D warnings
  predicate are present. Regression guard so removing or downgrading
  the Rust gate is caught at PR time.
- Updated test_slack_ci_failure_notify_workflow_present_and_valid to
  expect the new workflow list.
- 12 of 12 workflow guard tests pass.

Co-authored-by: Fabio Tavares Leitão <[email protected]>
@FabioLeitao
FabioLeitao force-pushed the main branch 2 times, most recently from ae0da8d to b5c995c Compare May 3, 2026 17:52
@FabioLeitao
FabioLeitao force-pushed the cursor/anchieta-rust-ci-c9ab branch from f896e49 to 20dc1a8 Compare May 3, 2026 17:52
FabioLeitao added a commit that referenced this pull request May 3, 2026
… merges

Maintainer Slack message in thread 1777319823.055829 (channel C0AN7HY3NP9)
asks to halt new Rust PRs based on origin/main and rebase/wait for the
auditoria-ia branch (claimed 27 commits ahead; origin currently shows 2,
implying ~25 unpushed local commits).

This commit is doc-only, additive, zero blast radius:

- New file docs/ops/sre_audits/STOP_DIRECTIVE_AUDITORIA_IA_REBASE_2026-04-27.md
  records the directive verbatim, the reproducible gh/git trace that
  established ground truth, the open-PR surface this STOP applies to
  (#255, #256, #258, #260, #263), and the maintainer-side resolution
  recommendation. Pattern matches neighbouring dated SRE audit ledgers.
- Index docs/ops/sre_audits/README.md gets one new row pointing at the
  STOP ledger so the next Slack-triggered SRE agent reads it before
  trying to base another Rust PR on the old main.

No Rust crate, workflow, connector, DB, or customer payload was touched.
Defensive Scanning Manifesto and The Art of the Fallback respected:
audit-only, diagnostic-on-fall, paper trail before silence.

Co-authored-by: Fabio Tavares Leitão <[email protected]>
@FabioLeitao FabioLeitao closed this May 3, 2026
@FabioLeitao
FabioLeitao deleted the cursor/anchieta-rust-ci-c9ab branch May 3, 2026 18:27
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