test: add coverage for pr_safety path-matching helpers - #1175
Draft
madara88645 wants to merge 1 commit into
Draft
Conversation
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds two new unit test files that give the pure, security-adjacent path-matching helpers behind the PR Safety verdict feature their first direct unit test coverage:
tests/test_pr_safety_path_rules_helpers.py— coversapp/pr_safety/path_rules.py:normalize_paths(backslash normalization, whitespace/empty-entry dropping, dedup-after-normalization, order preservation)_matches_any_pattern(match/no-match, empty pattern set, case sensitivity, short-circuit behavior)list_test_files(filtering, normalization, dedup, one representative case perTEST_FILE_PATTERNSfamily)list_source_files_needing_tests(filtering, exclusion of test/doc/config/unknown-extension files, normalization, order preservation)tests/test_pr_safety_repo_signals_pattern_matching.py— coversapp/pr_safety/repo_signals.py:_matches_repo_pattern(anchored vs. unanchored patterns,*/**/?glob semantics, trailing-slash directory wildcards, empty/whitespace patterns, backslash normalization, case sensitivity, regex-metacharacter escaping)_matches_any_repo_pattern(match/no-match/empty list)_matches_ordered_patterns(gitignore-style ordered include/exclude evaluation, negation, last-match-wins semantics)_is_safe_relative_path(path-traversal guarding: absolute paths, leading/embedded/trailing..components,.-segment tolerance, filenames that merely contain..as a substring)Why
These functions decide whether a changed file is "safe"/expected for the PR-safety verdict — including CODEOWNERS pattern matching, GitHub Actions
paths/paths-ignoreevaluation, and the relative-path traversal guard used before any filesystem read inrepo_signals.py. Before this PR they only had indirect coverage through higher-level functions (group_changed_files,detect_risky_areas,collect_repo_signals) in the existingtests/test_pr_safety_path_rules.pyandtests/test_pr_safety_repo_signals.pyfiles — none of the tests exercised these helpers, or their edge cases (path-traversal variants, pattern anchoring/negation ordering, empty inputs), directly. Given their security-adjacent role, direct coverage of the edge cases makes regressions easier to catch and easier to diagnose when they fail.Scope
tests/test_pr_safety_path_rules.pyandtests/test_pr_safety_repo_signals.pywere left untouched — new files use distinct names to avoid overlap.Test plan
python -m pytest tests/test_pr_safety_path_rules_helpers.py tests/test_pr_safety_repo_signals_pattern_matching.py -q→ 52 passedpython -m pytest tests/ -k pr_safety -q→ 159 passed (full existing pr_safety suite unaffected)Generated by Claude Code