[Repo Assist] refactor(rust-guard): consolidate check_file_secrecy into is_sensitive predicate#7786
Conversation
…e predicate Closes #7773 Two improvements to check_file_secrecy in tool_rules.rs: 1. Consolidate four separate early-return paths (each calling policy_private_scope_label verbatim) into a single is_sensitive boolean predicate. The 'what is sensitive?' logic is now separated from 'what do we return?', making the decision point explicit and eliminating 3 duplicate policy_private_scope_label calls. Also hoists let filename to the top of the function alongside let path_lower so all local bindings are linear. Zero behavior change. 2. Add two tests for the segment-starts-with branch of check_file_secrecy which previously had no coverage: - configs/.env.local: segment starts with .env but does not end with .env, so only the segment check catches it - keys/id_rsa.pub: segment starts with id_rsa but does not end with id_rsa, so only the segment check catches it All 507 existing + new tests pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
✅ Ready to approve
The refactor appears behavior-preserving and the added tests improve coverage for a previously untested sensitivity-detection path.
Note: this review does not count toward required approvals for merging.
Pull request overview
This PR refactors the Rust guard’s check_file_secrecy logic to make the “is this path sensitive?” decision explicit and non-duplicative, while also adding targeted tests to cover an otherwise untested branch of the sensitivity detection logic.
Changes:
- Consolidates multiple early-return branches in
check_file_secrecyinto a singleis_sensitivepredicate with one call site forpolicy_private_scope_label(...). - Adds two unit tests to specifically exercise the
path.split('/').any(|seg| seg.starts_with(pattern))branch using realistic filenames (.env.local,id_rsa.pub).
File summaries
| File | Description |
|---|---|
guards/github-guard/rust-guard/src/labels/tool_rules.rs |
Refactors check_file_secrecy into a single boolean predicate and adds tests for the segment-starts-with sensitivity branch. |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 0
Note
Your feedback helps us improve the quality of this feature.
Please use 👍 or 👎 to tell us whether this assessment is correct.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot resolve the merge conflicts in this pull request |
…get_code_quality_finding tests)
Done. Merged main into the branch — the only conflict was in |
🤖 This PR is from Repo Assist, an automated AI assistant for this repository.
Closes #7773
What
Two improvements to
check_file_secrecyinguards/github-guard/rust-guard/src/labels/tool_rules.rs:1. Single
is_sensitivepredicate (zero behavior change)The function had four separate early-return paths, each calling
policy_private_scope_label(owner, repo, repo_id, ctx)verbatim. This buries the single decision point ("is this file sensitive?") inside a chain of guarded returns.Before: 4×
return policy_private_scope_label(...),let filenamedefined mid-functionAfter: one
is_sensitiveboolean combining all four conditions with||; single call topolicy_private_scope_labelat the end;let filenamehoisted alongsidelet path_lowerThe refactoring makes the invariant explicit and eliminates 3 duplicate calls.
2. Two new tests for the segment-starts-with branch
The second condition (
path.split('/').any(|seg| seg.starts_with(pattern))) had zero test coverage — a regression there would be silent. Added:configs/.env.local—.env.localstarts with.envbut does not end with.env, so only the segment check fireskeys/id_rsa.pub—id_rsa.pubstarts withid_rsabut does not end withid_rsa, so only the segment check firesTest Status
507 tests pass (up from 505; the 2 new tests are included):
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
proxy.golang.orgSee Network Configuration for more information.
Add this agentic workflows to your repo
To install this agentic workflow, run