Skip to content

fix(prefilter): use token-boundary matching for test and migration framework detection - #68

Open
Adityakk9031 wants to merge 2 commits into
Corgea:mainfrom
Adityakk9031:fix/prefilter-token-boundary-test-migration
Open

Adityakk9031 wants to merge 2 commits into
Corgea:mainfrom
Adityakk9031:fix/prefilter-token-boundary-test-migration

Conversation

@Adityakk9031

Copy link
Copy Markdown
Contributor

Summary

  • Replaces unbounded substring matching in has_test_patterns and has_migration_patterns with token-boundary aware matching matches_token_or_module.
  • Prevents false-positive test file exclusions on legitimate production files that import modules containing substrings of test words (such as \�ttestation, \contest, \latest, \ astest, \user_migration).
  • Adds regression unit test cases in \ ests/unit/prefilter_should_scan_tests.rs.

@juangaitanv
juangaitanv self-requested a review August 17, 2026 08:32
Comment thread src/scanner/prefilter.rs
];

test_patterns.iter().any(|pattern| imports_text.contains(pattern))
test_patterns.iter().any(|pattern| Self::matches_token_or_module(imports_text, pattern))

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.

vitest, Go testing, and testify no longer match the test patterns, so their imports are scanned. could we retain explicit patterns for these framework roots while preserving the boundary fix?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@juangaitanv Thanks for the review! Added explicit patterns for "testing", "testify", "vitest", and "github.com/stretchr/testify" to test_patterns while retaining token boundary checking. Added unit test file_with_testing_or_vitest_import_is_skipped.

Comment thread src/scanner/prefilter.rs
Comment on lines -249 to -251
"migration",
"migrations",
"migrate",

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.

from django.db import migrations no longer matches a migration pattern, so those files are scanned in general mode. could we retain generic migration indicators while treating _ and digits as identifier characters?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@juangaitanv Restored "migration" and "migrations" to migration_patterns, and updated is_identifier_character to treat [A-Za-z0-9_] as non-boundary identifier characters. Now from django.db import migrations matches and is skipped, while identifiers like attestation or user_migration are not falsely matched. Added unit tests for both cases.

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