Skip to content

[Repo Assist] refactor(rust-guard): add tool_names::SEARCH_CODE constant - #12805

Open
github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/fix-issue-12793-search-code-constant-e23c9a3852ba274e
Open

[Repo Assist] refactor(rust-guard): add tool_names::SEARCH_CODE constant#12805
github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/fix-issue-12793-search-code-constant-e23c9a3852ba274e

Conversation

@github-actions

@github-actions github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

🤖 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 across lib.rs, labels/mod.rs, and labels/tool_rules.rs in the rust-guard crate, following the same anti-pattern already fixed for tool_names::GET_COMMIT and tool_names::SEARCH_REPOSITORIES in prior runs (see issue #12726). Repeated raw literals are prone to silent typos causing mismatched dispatch/test comparisons.

Fix

  • Added pub const SEARCH_CODE: &str = "search_code"; to the tool_names module in labels/constants.rs, plus a matching dispatch_constants_match_canonical_values assertion.
  • Replaced the literal at all 7 call sites:
    • lib.rs::infer_scope_for_baseline match arm
    • two test call sites in lib.rs
    • labels/tool_rules.rs::apply_tool_labels match arm ("Code / Commit Search" section)
    • its parallel test assertion in labels/tool_rules.rs
    • the apply_tool_labels test call in labels/mod.rs

Trade-offs

None — purely additive constant plus mechanical literal replacement. No behavior change; only compile-time string interning changes.

Test Status

  • cargo build — ✅ succeeds
  • cargo test --lib — ✅ 666/666 tests pass
  • cargo clippy --all-targets — ✅ clean, no warnings

Closes #12793

Generated by Repo Assist · copilot · auto · 230.1 AIC · ⊞ 16.4K ·
Comment /repo-assist to run again

Add this agentic workflow to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@851905c06e905bf362a9f6cc54f912e3df747d55

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>
@lpcox
lpcox marked this pull request as ready for review September 9, 2026 13:42
Copilot AI balanced review requested due to automatic review settings September 9, 2026 13:42

Copilot AI left a comment

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.

🟢 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") to labels/constants.rs with a canonical-value assertion.
  • Replaced 7 "search_code" literal usages in production logic and tests with tool_names::SEARCH_CODE.
  • Updated lib.rs to import tool_names for 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.

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

🔒 mcpg Read-Only Stress — default

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: default (normal AWF container, no extra isolation)

Part Surface Op Result Expected Status
A MCP reads data returned (issues, PRs, README.md, commits) ALLOWED
B MCP writes (reaction/star/issue/comment/branch/file/PR) all 6 write tools absent from proxy catalog (23 tools, read-only set) BLOCKED ⚠️
C CLI reads data returned via github CLI proxy ALLOWED
D CLI REST writes (reaction/star/issue/comment) gh unauthenticated in this env (no GH_TOKEN) BLOCKED ⚠️
E CLI GraphQL mutations (addReaction/addStar/createIssue) gh unauthenticated in this env BLOCKED ⚠️

Overall: INCONCLUSIVE

Notes:

  • Part A/C reads fully verified — gateway serves reads correctly on both MCP and CLI-proxy surfaces.
  • Part B: no write tools (add_issue_comment, star_repository, issue_write, create_branch, create_or_update_file, create_pull_request) appear in the exposed 23-tool catalog at all, consistent with gh-aw's GITHUB_READ_ONLY=1 backend config. This only confirms backend/toolset configuration, not the gateway's independent DIFC/guard write-blocking layer (per methodology note in the task).
  • Part D/E: gh auth status shows no authenticated host and GH_TOKEN is unset in this run, so REST/GraphQL write attempts fail on auth before reaching the API or gateway — not evidence of gateway/token-scope enforcement.
  • No writes leaked: zero reactions, stars, issues, comments, branches, files, or PRs were created during this run.

🔒 mcpg read-only stress (default AWF runtime) by Read-Only Stress: default runtime

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

🔒 mcpg Read-Only Stress — gVisor

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: gVisor (runsc)

Part Surface Op Result Expected Status
A MCP reads data returned (status=200) ALLOWED
B MCP writes (star/issue_write/comment/branch/file/PR) tools absent from catalog (unknown tool -32602) BLOCKED ⚠️
C CLI reads data returned ALLOWED
D CLI REST writes gh not authenticated BLOCKED ⚠️
E CLI GraphQL mutations gh not authenticated BLOCKED ⚠️

Overall: INCONCLUSIVE

No write leaked in this run. Part B is ⚠️ because none of the targeted write tools (star_repository, issue_write, add_issue_comment, create_branch, create_or_update_file, create_pull_request) appear in the 23-tool github MCP catalog exposed by the gateway — this reflects gh-aw's GITHUB_READ_ONLY=1 backend config, not an independent mcpg gateway-level refusal, so gateway DIFC/guard enforcement of writes could not be exercised on this surface. Parts D/E are ⚠️ because gh is not authenticated in this environment ("not logged into any GitHub hosts"), so the REST/GraphQL token-scope boundary could not be tested. Parts A and C (reads) fully passed on both the MCP and proxied-CLI surfaces.

🔒 mcpg read-only stress (gVisor runtime) by Read-Only Stress: gVisor runtime

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[rust-guard] Add tool_names::SEARCH_CODE constant to replace raw "search_code" literal

1 participant