Skip to content

Deduplicate normalized allow-only policy fields - #16926

Merged
lpcox merged 4 commits into
mainfrom
copilot/duplicate-code-allow-only-policy
Nov 20, 2026
Merged

lpcox merged 4 commits into
mainfrom
copilot/duplicate-code-allow-only-policy

Conversation

@lpcox

@lpcox lpcox commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Repeated policy fields risked drift between configuration and normalized representations. This change makes AllowOnlyPolicy the single field-schema source.

  • Field sharing: Embed a method-free derived type in NormalizedGuardPolicy, avoiding inheritance of configuration-specific unmarshalling.
  • JSON compatibility: Preserve flat output, field order, and optional-field omission; continue emitting normalized scope fields instead of raw repos.
  • Regression coverage: Pin byte-identical serialization, normalized round-trips, input immutability, and raw-repository omission.

@lpcox lpcox changed the title [WIP] Refactor duplicate AllowOnlyPolicy field lists Deduplicate normalized allow-only policy fields Nov 20, 2026
@lpcox
lpcox marked this pull request as ready for review November 20, 2026 17:47
Copilot AI adaptive review requested due to automatic review settings November 20, 2026 17:47
@github-actions

This comment has been minimized.

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

No active review issues are reported for the policy-schema deduplication change.

No open issues 🎉

What changed in this PR

This PR reduces policy-schema duplication by sharing AllowOnlyPolicy fields with the normalized representation used for caching and observability, addressing part of #16837.

Changes:

  • Embed a method-free derived policy type to share fields without inheriting configuration-specific unmarshalling.
  • Preserve flat normalized JSON, field ordering, optional-field omission, and exclusion of raw repos.
  • Add regression tests for byte-identical serialization, normalized round-trips, and input immutability.
File Description
internal/​config/​guard_policy.go Shares policy fields and adds normalized JSON serialization that omits raw repositories.
internal/​config/​guard_policy_validation.go Updates normalization initialization for the embedded policy fields.
internal/​config/​guard_policy_marshal_test.go Adds serialization compatibility, round-trip, immutability, and repository-omission tests.

Review effort: Balanced (adaptive)

@lpcox

lpcox commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator Author

Co-authored-by: copilot-swe-agent[bot] <[email protected]>

Copilot AI commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

@copilot fix failing lint ci check https://github.com/github/gh-aw-mcpg/actions/runs/44772522556/job/136463391915?pr=16926

Fixed the flagged testifylint issue with a JSON-aware assertion. make agent-finished passes, including golangci-lint; commit: b2e832c.

@github-actions

Copy link
Copy Markdown
Contributor

🔒 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 data returned (issues, PRs, README.md, commits) ALLOWED ✅
B MCP writes (star/issue_write/comment/branch/file/PR) all 7 targets absent from 23-tool catalog ("unknown tool") BLOCKED ⚠️
C CLI reads data returned via github CLI proxy ALLOWED ✅
D CLI REST writes gh unauthenticated — not attempted BLOCKED ⚠️
E CLI GraphQL mutations gh unauthenticated — not attempted BLOCKED ⚠️

Overall: INCONCLUSIVE

No write leaked in any part. Part B is ⚠️ because the gateway's backend tool catalog (23 read-only tools) never exposed any write tool (star_repository, issue_write, add_issue_comment, create_branch, create_or_update_file, create_pull_request all returned Error [-32602]: unknown tool). This proves gh-aw's GITHUB_READ_ONLY=1 backend config, not mcpg's own independent DIFC/guard write-blocking layer. Parts D/E are ⚠️ because gh auth status reported no authenticated host in this environment, so the token-scope boundary could not be exercised.

No readonly-stress-pass-default label applied (result is INCONCLUSIVE, not PASS).

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

@lpcox
lpcox merged commit f376cad into main Nov 20, 2026
30 checks passed
@lpcox
lpcox deleted the copilot/duplicate-code-allow-only-policy branch November 20, 2026 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[duplicate-code] Duplicate Code Pattern: AllowOnlyPolicy Field List Repeated Across Three Types

3 participants