Skip to content

[Repo Assist] refactor(rust-guard): add scope_names constants and replace bare string literals#4857

Merged
lpcox merged 2 commits intomainfrom
repo-assist/fix-issue-4846-scope-constants-2359441ca66ed7ad
Apr 30, 2026
Merged

[Repo Assist] refactor(rust-guard): add scope_names constants and replace bare string literals#4857
lpcox merged 2 commits intomainfrom
repo-assist/fix-issue-4846-scope-constants-2359441ca66ed7ad

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant.

Summary

Closes #4846

Adds a pub mod scope_names submodule to labels/constants.rs with three constants — GITHUB, USER, and GLOBAL — and replaces all 15 bare scope string literals across the codebase with these constants.

Root Cause

Scope tokens ("github", "user", "global") were used as bare string literals in 15 places across lib.rs, labels/tool_rules.rs, and labels/helpers.rs. A typo (e.g. "Github") in any of these would silently produce wrong DIFC labels with no compiler error.

Fix

// labels/constants.rs — new submodule following established pattern
pub mod scope_names {
    pub const GITHUB: &str = "github";
    pub const USER:   &str = "user";
    pub const GLOBAL: &str = "global";
}

All 15 call sites replaced:

  • labels/helpers.rsproject_github_label
  • labels/tool_rules.rs — 10 baseline_scope/integrity call sites
  • lib.rsinfer_scope_for_baseline, blocked override path, metadata path, 2 test assertions

Trade-offs

  • Follows the existing label_constants, policy_integrity, and field_names submodule pattern — no new convention introduced
  • Typo safety: misspelled scopes are now caught at compile time
  • Discoverability: grep scope_names:: finds every usage

Test Status

Rust tests: 345/345 passed (cargo test)

⚠️ Go build/tests: Infrastructure failure — Go toolchain download blocked by network firewall. Changes are Rust-only; no Go files modified.

Warning

⚠️ Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • proxy.golang.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "proxy.golang.org"

See Network Configuration for more information.

Generated by Repo Assist · ● 4.9M ·

To install this agentic workflow, run

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

…rals

Add `pub mod scope_names` to `labels/constants.rs` with GITHUB, USER,
and GLOBAL constants, following the existing pattern of `label_constants`,
`policy_integrity`, and `field_names` submodules.

Replace all 15 bare scope string literals across:
- `labels/constants.rs` — new submodule
- `labels/helpers.rs` — project_github_label
- `labels/tool_rules.rs` — 10 baseline_scope/integrity call sites
- `lib.rs` — infer_scope_for_baseline, blocked override, metadata path, tests

A typo (e.g. `"Github"`) in any of these locations would silently produce
wrong DIFC labels with no compiler error. Using constants makes that class
of bug impossible.

Closes #4846

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox lpcox marked this pull request as ready for review April 30, 2026 13:31
Copilot AI review requested due to automatic review settings April 30, 2026 13:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR centralizes the Rust guard’s reserved scope tokens ("github", "user", "global") into a scope_names constants module and updates several labeling call sites to use those constants, reducing the risk of silent typos that would change DIFC labeling behavior.

Changes:

  • Added labels::constants::scope_names::{GITHUB, USER, GLOBAL}.
  • Replaced several hard-coded scope token literals in lib.rs, labels/tool_rules.rs, and labels/helpers.rs with scope_names::*.
  • Updated a few tests/assertions to reference scope_names::GITHUB.
Show a summary per file
File Description
guards/github-guard/rust-guard/src/lib.rs Uses scope_names for inferred baseline scope and metadata/blocked-tool scope handling.
guards/github-guard/rust-guard/src/labels/tool_rules.rs Replaces hard-coded "user"/"github" baseline scope + integrity scoping with scope_names constants.
guards/github-guard/rust-guard/src/labels/helpers.rs Updates project_github_label to use scope_names::GITHUB.
guards/github-guard/rust-guard/src/labels/constants.rs Introduces the new scope_names module with the canonical reserved scope tokens.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 4/4 changed files
  • Comments generated: 3

Comment on lines +34 to +36
/// Canonical scope token strings used for baseline and integrity scoping.
///
/// These are the three scope tokens used throughout the labeling system.
Comment on lines +39 to +45
pub mod scope_names {
/// Owner-scoped policy (GitHub-org-level resources)
pub const GITHUB: &str = "github";
/// User-scoped policy (personal resources)
pub const USER: &str = "user";
/// Global-scoped policy (cross-repo / no specific owner)
pub const GLOBAL: &str = "global";
@@ -678,16 +678,16 @@ pub fn apply_tool_labels(
// Requires writer-level integrity to prevent low-trust agents from
// self-escalating by enabling additional tool groups.
// S = public (empty — no repository-scoped data); I = writer (global)
@lpcox
Copy link
Copy Markdown
Collaborator

lpcox commented Apr 30, 2026

@copilot address the review feedback

- Clarify doc comment: scope_names holds reserved tokens only, not all scopes
- Replace remaining bare "user" literals in response_items.rs, response_paths.rs, and mod.rs tests
- Fix misleading comment in tool_rules.rs:680 (global -> github)

Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/0b9658de-7428-496f-8105-7b56860e54c0

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 30, 2026

@copilot address the review feedback

Addressed all three review findings in 52bf1c5:

  1. Clarified scope_names doc comment — now explicitly states these are the canonical reserved scope tokens and that dynamic scopes (e.g. owner, owner/repo) also exist at runtime.
  2. Replaced remaining bare "user" literals — updated response_items.rs, response_paths.rs, and the mod.rs test assertions to use scope_names::USER.
  3. Fixed misleading comment in tool_rules.rs:680 — changed "writer (global)" to "writer (github)" to match the scope_names::GITHUB scope used in the code.

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] Rust Guard: Add scope name constants + test label_response_items

3 participants