Skip to content

fix(parser): harden Rust cfg(test) exclusion and remove file size cap#29

Open
tuannx wants to merge 1 commit into
codex/rust-parserfrom
fix/rust-parser-red-team-findings
Open

fix(parser): harden Rust cfg(test) exclusion and remove file size cap#29
tuannx wants to merge 1 commit into
codex/rust-parserfrom
fix/rust-parser-red-team-findings

Conversation

@tuannx

@tuannx tuannx commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

Red-team review findings against the Rust parser in #18. Three fixes:

1. Comment between #[cfg(test)] and item broke test exclusion

Tree-sitter emits line_comment/block_comment as named children. A comment between the attribute and its item cleared pending_attributes before the mod_item was reached, so #[cfg(test)] mod tests was NOT skipped.

#[cfg(test)]
// unit tests for this module
mod tests { struct Fixture; }  // ← was leaking into graph

Fix: Skip comment nodes without clearing pending_attributes.

2. #[cfg(test)] on non-mod items was silently ignored

is_cfg_test was computed for ALL node types but only checked in the mod_item branch. Functions, structs, and impls annotated with #[cfg(test)] were extracted as production entities.

#[cfg(test)]
fn test_only_helper() {}  // ← was leaking into graph

#[cfg(test)]
struct TestFixture { x: u64 }  // ← was leaking into graph

Fix: Skip ALL items when is_cfg_test is true (early continue before the type dispatch).

3. Removed _MAX_FILE_BYTES (1MB) cap

  • No other parser has a file size cap
  • Silently drops real code (generated protobuf, diesel schemas often exceed 1MB)
  • Never mitigated the recursion crashes it appeared to guard against
  • The per-file except Exception boundary is the actual backstop

Regression tests

  • test_rust_parser_skips_cfg_test_with_comment_between_attribute_and_item
  • test_rust_parser_skips_cfg_test_on_non_mod_items
  • test_rust_parser_handles_large_files_without_cap

Validation

  • 21 Rust parser tests pass
  • Ruff clean
  • No behavioral change for production code (only test-annotated items are now correctly excluded)

Copilot AI review requested due to automatic review settings July 23, 2026 14:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Red-team review findings against the Rust parser:

1. Comment/doc-comment between #[cfg(test)] and its item broke test
   exclusion — tree-sitter emits comments as named children which
   cleared pending_attributes before the mod_item was reached.
   Fix: skip line_comment/block_comment nodes without clearing.

2. #[cfg(test)] on non-mod items (functions, structs, impls) was
   silently ignored — is_cfg_test was computed but only checked for
   mod_item. Fix: skip ALL items annotated with #[cfg(test)].

3. Removed _MAX_FILE_BYTES (1MB) cap — no other parser has it, it
   silently drops real code (generated protobuf/diesel schemas), and
   the per-file except boundary is the actual backstop.

Regression tests cover all three fixes: comment-between-attribute,
cfg(test) on fn/struct/impl, and >1MB file survival.
@tuannx
tuannx force-pushed the fix/rust-parser-red-team-findings branch from 8b7e248 to 9dd08b3 Compare July 23, 2026 14:48
@github-actions

Copy link
Copy Markdown
Contributor

Architecture Drift Report

Algorithm: PKG | Entities: 722 | Components: 7

Drift from Baseline

Metric Baseline Current Delta
Components 7 7 +0
Similarity 0.98
BalancedArchitectureScore 0.68
PrincipleAlignmentScore 0.84
RCI 0.99
TurboMQ 0.24
BasicMQ 0.24
IntraConnectivity 0.00
InterConnectivity 0.01
TwoWayPairRatio 0.00
DependencyHealth 0.99
ComponentBalance 0.22
HubBalance 0.67
BoundaryClarity 1.00
DependencyDistribution 0.57
SmellDiscipline 0.91

Changes

  • 52 entity movement(s) between components

Smells (1)

  • Concern Overload: Tests

Generated by arcade-agent

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