Skip to content

[Repo Assist] fix(rust-guard): dedup governance_tools test array + add COMMENT_NODE_ID constant - #12960

Merged
lpcox merged 1 commit into
mainfrom
repo-assist/fix-issue-12952-rust-guard-dedup-governance-comment-node-id-7d8fc530d4510333
Sep 11, 2026
Merged

lpcox merged 1 commit into
mainfrom
repo-assist/fix-issue-12952-rust-guard-dedup-governance-comment-node-id-7d8fc530d4510333

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

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

Closes #12952

Root cause

Two small maintainability gaps in guards/github-guard/rust-guard/src/labels/tool_rules.rs:

  1. The 4-element governance tool list (repository_ruleset_read, custom_properties_read, custom_properties_write, create_repository_ruleset) was copy-pasted verbatim across three test functions. Adding a new governance tool would require updating all three lists, with a silent risk of missing one.
  2. The raw string literal "commentNodeID" was duplicated across 4 production .get(...) call sites in the discussion_comment_write and pull_request_review_write match arms, following none of the existing field_names centralization used elsewhere in the file (e.g. METHOD, IS_ERROR, FULL_NAME).

Fix

  • Added a test-only const GOVERNANCE_TOOLS: [&str; 4] inside mod tests, and updated the three governance test functions (apply_tool_labels_repo_governance_tools_are_scoped, apply_tool_labels_governance_tools_are_repo_scoped, apply_tool_labels_governance_tools_are_org_and_enterprise_scoped) to reference it instead of repeating the literal array.
  • Added pub const COMMENT_NODE_ID: &str = "commentNodeID"; to the field_names module in constants.rs, and replaced all 4 production .get("commentNodeID") call sites with .get(field_names::COMMENT_NODE_ID).

Test-fixture JSON literals (e.g. "commentNodeID": "DIC_..." inside serde_json::json! macros) were intentionally left as-is — those are JSON object keys in test data, not .get() calls, so replacing them would add no safety benefit.

Trade-offs

None — purely internal test/production deduplication with no behavior change. Both improvements are small, low-risk, and match patterns already established elsewhere in the codebase (e.g. the [labels, milestones, branches] dedup from 2026-09-02).

Test Status

  • cargo build: ✅ passes
  • cargo test: ✅ 666/666 passed
  • cargo clippy --all-targets -- -D warnings: ✅ clean
  • cargo fmt -- --check: no diff introduced by this change (pre-existing unrelated formatting diffs exist elsewhere in the crate, e.g. backend.rs, mod.rs)

Generated by Repo Assist · copilot · auto · 120.5 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

…_ID constant

Closes #12952

- Add pub(crate) const GOVERNANCE_TOOLS test-only array in tool_rules.rs
  tests module, shared by three governance-scoping test functions that
  previously copy-pasted the same 4-element tool list.
- Add field_names::COMMENT_NODE_ID constant in constants.rs and use it
  at the 4 production .get("commentNodeID") call sites in the
  discussion_comment_write and pull_request_review_write match arms,
  matching the existing field_names centralization convention.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox
lpcox marked this pull request as ready for review September 11, 2026 19:49
Copilot AI balanced review requested due to automatic review settings September 11, 2026 19:49

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 focused refactoring is complete, consistent, and preserves existing behavior.

Pull request overview

Centralizes repeated Rust guard constants without changing behavior.

Changes:

  • Adds COMMENT_NODE_ID and uses it for production JSON lookups.
  • Deduplicates governance tool lists across tests.
File summaries
File Description
labels/tool_rules.rs Reuses constants in label logic and tests.
labels/constants.rs Defines the canonical comment node ID field name.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

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 (list_issues, list_pull_requests, get_file_contents, list_commits) data returned ALLOWED ✅
B MCP writes (reaction/star/issue/comment/branch/file/PR) all 6 write tools absent from catalog (only 23 read-only tools registered) BLOCKED ⚠️
C CLI reads (list_issues, get_file_contents via github CLI) data returned ALLOWED ✅
D CLI REST writes (reaction/star/issue/comment) gh not authenticated, not attempted BLOCKED ⚠️
E CLI GraphQL mutations (addReaction/addStar/createIssue) gh not authenticated, not attempted BLOCKED ⚠️

Overall: INCONCLUSIVE

⚠️ Part B: the gh-aw tools.github: wrapper unconditionally sets GITHUB_READ_ONLY=1 on the backend, so write tools were never registered in the exposed catalog. This confirms backend/toolset configuration but cannot independently exercise mcpg's own DIFC/guard write-blocking layer for this run.
⚠️ Parts D/E: gh auth status showed no authenticated host in this environment, so REST/GraphQL write attempts could not be made to validate the token-scope boundary.

No write of any kind leaked. All reads (Parts A, C) succeeded as expected.

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

@github-actions

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 container isolation)

Part Surface Op Result Expected Status
A MCP reads (list_issues, list_pull_requests, get_file_contents, list_commits) data returned ALLOWED ✅
B MCP writes (star_repository, issue_write, add_issue_comment, create_branch, create_or_update_file, create_pull_request) all absent from catalog (unknown tool -32602) BLOCKED ⚠️
C CLI reads (via github proxy CLI) data returned ALLOWED ✅
D CLI REST writes (star, comment, issue, file) not attempted — gh unauthenticated (no GH_TOKEN) BLOCKED ⚠️
E CLI GraphQL mutations (addReaction/addStar/createIssue) not attempted — gh unauthenticated BLOCKED ⚠️

Overall: INCONCLUSIVE

Notes:

  • Part A/C: all 4 read calls returned valid data via the gateway-backed github CLI proxy (23-tool read-only catalog). No errors.
  • Part B: the mcpg-fronted GitHub MCP backend only exposes 23 read tools (get_commit, get_file_contents, list_issues, list_pull_requests, list_commits, etc.) — no write tool names exist in the catalog at all, so every write attempt failed with unknown tool before reaching any enforcement layer. This confirms gh-aw's GITHUB_READ_ONLY=1 backend config (as documented in the task's architectural note) but does not independently exercise mcpg's own DIFC/guard write-blocking layer, since no write-capable tool call ever reached it.
  • Part D/E: gh api/gh issue create returned "gh: To use GitHub CLI in a GitHub Actions workflow, set the GH_TOKEN environment variable" — gh has no credentials in this job, so REST/GraphQL write attempts could not be exercised at all (not even to trigger a 401 from GitHub). This is an authentication gap in the run environment, not a confirmed enforcement boundary.
  • No write of any kind succeeded or leaked on any surface in this run.

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

@lpcox
lpcox merged commit 0db9218 into main Sep 11, 2026
34 of 35 checks passed
@lpcox
lpcox deleted the repo-assist/fix-issue-12952-rust-guard-dedup-governance-comment-node-id-7d8fc530d4510333 branch September 11, 2026 19:58
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: Dedup governance_tools test array + add COMMENT_NODE_ID constant

2 participants