rust-guard: simplify default_secrecy conditions; remove lifetime noise from integrity helpers#7762
Conversation
…in Rust guard - response_paths.rs: Replace positive-list default_secrecy checks in the PR arm and Issue arm with negative checks (!= "search_pull_requests" / != "search_issues"). This directly expresses the invariant and stays correct when new tools are added to the outer match arm. - helpers.rs: Remove unnecessary 'a lifetime from effective_disapproval_integrity and effective_endorser_min_integrity. Both now return &'static str and validate unrecognized config values via MinIntegrity::from_policy_str, logging a warning and canonicalizing to the correct default (none / approved) at the boundary. Closes #7722
There was a problem hiding this comment.
Pull request overview
This PR makes small maintainability improvements to the Rust GitHub guard labeling logic by (1) expressing default secrecy rules for PR/Issue response labeling more robustly, and (2) simplifying integrity helper lifetimes while hardening handling of invalid integrity configuration values.
Changes:
- Update PR/Issue response-path labeling to compute
default_secrecyvia a negative check (everything in the arm except the correspondingsearch_*tool). - Update integrity helper functions to return
&'static strand to validate/canonicalize configured integrity levels viaMinIntegrity::from_policy_str, emitting targeted warnings on invalid values.
Show a summary per file
| File | Description |
|---|---|
| guards/github-guard/rust-guard/src/labels/response_paths.rs | Simplifies default_secrecy branching for PR/Issue tool match arms by excluding only the search_* variants. |
| guards/github-guard/rust-guard/src/labels/helpers.rs | Removes unnecessary lifetimes from integrity helpers and validates misconfigured integrity strings with a warning + safe default. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 1
| MinIntegrity::from_policy_str(v) | ||
| .unwrap_or_else(|| { | ||
| crate::log_warn(&format!( | ||
| "effective_disapproval_integrity: unrecognised level {:?}, defaulting to 'none'", | ||
| v | ||
| )); | ||
| MinIntegrity::None | ||
| }) | ||
| .as_str() |
|
@copilot address review feedback |
…egrity fallback behavior
Done — added |
Two small cleanups in the Rust guard identified by the Rust Guard Improver workflow.
response_paths.rs— negative check fordefault_secrecyThe PR and Issue match arms computed
default_secrecyvia a positive list of tool names, but the actual invariant is "everything in this arm gets repo-scoped secrecy except the search tool." The positive list silently breaks whenever a new tool is added to the outer arm.Same change applied to the Issue arm (
!= "search_issues").helpers.rs—&'static str+ validated fallback for integrity helperseffective_disapproval_integrityandeffective_endorser_min_integritycarried an'alifetime tying the return to thectxborrow, even though all callers only pass the result to functions returning owned values. Beyond the lifetime noise, invalid config values (e.g."strict") were silently forwarded throughintegrity_level_rank's generic fallback with no indication of which field was misconfigured.Both functions now:
&'static str(no lifetime)MinIntegrity::from_policy_str, log a named warning on unrecognised values, and canonicalize to the correct default (none/approved) at the boundary