[Repo Assist] refactor(rust-guard): add tool_names::SEARCH_CODE constant - #12805
[Repo Assist] refactor(rust-guard): add tool_names::SEARCH_CODE constant#12805github-actions[bot] wants to merge 1 commit into
Conversation
Replaces the raw string literal "search_code" at 7 production/test call sites across lib.rs, labels/mod.rs, and labels/tool_rules.rs with the new tool_names::SEARCH_CODE constant, consistent with the existing pattern used for tool_names::GET_COMMIT and tool_names::SEARCH_REPOSITORIES. Closes #12793 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
The change is a low-risk constant centralization with consistent replacements and no remaining production "search_code" literals at the reported call sites.
Pull request overview
This PR refactors the Rust GitHub Guard (guards/github-guard/rust-guard) to centralize the "search_code" tool name into a shared constant, aligning it with the existing tool_names::* pattern and reducing the risk of silent typos across match/dispatch logic and tests.
Changes:
- Added
tool_names::SEARCH_CODE("search_code") tolabels/constants.rswith a canonical-value assertion. - Replaced 7
"search_code"literal usages in production logic and tests withtool_names::SEARCH_CODE. - Updated
lib.rsto importtool_namesfor the new constant-based match arm and test call sites.
File summaries
| File | Description |
|---|---|
| guards/github-guard/rust-guard/src/lib.rs | Imports tool_names and uses tool_names::SEARCH_CODE in infer_scope_for_baseline and relevant tests. |
| guards/github-guard/rust-guard/src/labels/tool_rules.rs | Uses tool_names::SEARCH_CODE in the “Code / Commit Search” match arm and matching test assertion. |
| guards/github-guard/rust-guard/src/labels/mod.rs | Updates test call site to use tool_names::SEARCH_CODE. |
| guards/github-guard/rust-guard/src/labels/constants.rs | Introduces pub const SEARCH_CODE: &str = "search_code"; and asserts canonical value in tests. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
🔒 mcpg Read-Only Stress — defaultSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: INCONCLUSIVE Notes:
|
🔒 mcpg Read-Only Stress — gVisorSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: INCONCLUSIVE No write leaked in this run. Part B is
|
🤖 This PR was created automatically by Repo Assist, an AI assistant.
Root Cause
Issue #12793 (auto-generated by the Rust Guard Improver report) identified that the raw string literal
"search_code"was repeated at 7 production/test call sites acrosslib.rs,labels/mod.rs, andlabels/tool_rules.rsin therust-guardcrate, following the same anti-pattern already fixed fortool_names::GET_COMMITandtool_names::SEARCH_REPOSITORIESin prior runs (see issue #12726). Repeated raw literals are prone to silent typos causing mismatched dispatch/test comparisons.Fix
pub const SEARCH_CODE: &str = "search_code";to thetool_namesmodule inlabels/constants.rs, plus a matchingdispatch_constants_match_canonical_valuesassertion.lib.rs::infer_scope_for_baselinematch armlib.rslabels/tool_rules.rs::apply_tool_labelsmatch arm ("Code / Commit Search" section)labels/tool_rules.rsapply_tool_labelstest call inlabels/mod.rsTrade-offs
None — purely additive constant plus mechanical literal replacement. No behavior change; only compile-time string interning changes.
Test Status
cargo build— ✅ succeedscargo test --lib— ✅ 666/666 tests passcargo clippy --all-targets— ✅ clean, no warningsCloses #12793
Add this agentic workflow to your repo
To install this agentic workflow, run