Skip to content

Consolidate internal helpers and align public-repository policy overrides - #17010

Merged
lpcox merged 3 commits into
mainfrom
copilot/refactor-semantic-function-clustering
Nov 21, 2026
Merged

lpcox merged 3 commits into
mainfrom
copilot/refactor-semantic-function-clustering

Conversation

@lpcox

@lpcox lpcox commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Force-public policy mutation was duplicated across proxy and server layers; the proxy could add allow-only to a write-sink-only policy, creating an invalid combination. Several internal helpers also duplicated shared implementations or existed only for tests.

  • Policy overrides

    • Centralize mutation in config helpers for typed policies and raw maps.
    • Leave write-sink-only policies unchanged.
    • Preserve other fields and canonical/legacy key spelling; update every allow-only alias.
  • Helper consolidation

    • Remove redundant host-network, GraphQL alias-detection, and MCP text-response wrappers.
    • Call the shared atomic writer directly.
    • Delegate registry creation to MapGetOrCreate and mount parsing to mountspec.Parse.
  • Preserved semantics

    • Retain ASCII-only repository-scope folding; Unicode folding and whitespace trimming are not equivalent.

@lpcox lpcox changed the title [WIP] Refactor duplicate, dead, and misplaced helpers in internal Consolidate internal helpers and align public-repository policy overrides Nov 21, 2026
@lpcox
lpcox marked this pull request as ready for review November 21, 2026 16:50
Copilot AI adaptive review requested due to automatic review settings November 21, 2026 16:51
@github-actions

This comment has been minimized.

@lpcox

lpcox commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot merge main and resolve conflicts

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.

🟡 Changes recommended

Critical policy alias and casing flaws can leave private-repository access enabled or discard approved integrity and blocked-user restrictions in public workflows.

3 open issues
What changed in this PR

Addresses #16964 by consolidating internal helpers in the MCP gateway and sharing public-repository policy overrides between proxy and server paths.

Changes:

  • Add config helpers for typed and raw policy overrides, leaving write-sink-only policies unchanged.
  • Replace redundant wrappers, mount adapters, and locking logic with shared implementations.
  • Update regression tests and documentation while retaining ASCII-only repository-scope folding.
File Description
internal/​sys/​docker.go Remove the unused host-network helper.
internal/​sys/​docker_test.go Test the retained helper, including case-insensitive matching.
internal/​syncutil/​registry.go Delegate registry creation to MapGetOrCreate.
internal/​syncutil/​registry_test.go Add zero-value caching coverage.
internal/​syncutil/​registry_internal_test.go Adapt concurrent-miss tests to the public method.
internal/​server/​system_tools.go Use the shared MCP text-response constructor.
internal/​server/​guard_visibility.go Call config helpers for public-scope overrides.
internal/​server/​circuit_breaker_test.go Migrate text-response fixtures to the shared constructor.
internal/​proxy/​proxy.go Use the shared text-response constructor.
internal/​proxy/​graphql.go Remove the test-only alias-detection wrapper.
internal/​proxy/​graphql_aliased_pr_test.go Call the parsed alias-detection helper directly.
internal/​middleware/​jqschema_test.go Update the MCP response fixture constructor.
internal/​mcpresult/​mcpresult.go Correct the constructor name in a comment.
internal/​mcp/​tool_result.go Remove the redundant text-response wrapper.
internal/​mcp/​tool_result_test.go Migrate fixtures and remove wrapper-only tests.
internal/​logger/​write_json_to_file_test.go Update test names and atomic-write comments.
internal/​logger/​observed_url_domains_logger_test.go Update helper names in test comments.
internal/​logger/​fileutil.go Call util.AtomicWriteFile directly.
internal/​logger/​atomic_write_test.go Delete redundant wrapper tests.
internal/​launcher/​mount_policy.go Use mountspec.Parse and its shared type directly.
internal/​launcher/​mount_policy_test.go Exercise parser failures through ValidateMount.
internal/​difc/​path_labels_test.go Rename the text-response subtest.
internal/​config/​guard_policy_string_validation_test.go Add ASCII-only folding regression coverage.
internal/​config/​guard_policy_public.go Add typed and raw-map public-scope helpers.
internal/​config/​guard_policy_public_test.go Cover overrides, aliases, and write-sink preservation.
internal/​cmd/​proxy.go Replace duplicated policy mutation with the config helper.
internal/​cmd/​proxy_force_public_repos_test.go Add write-sink-only policy preservation coverage.
docs/​PROXY_MODE.md Clarify force-public behavior for policy types.

Review effort: Max (adaptive)

Comment thread internal/config/guard_policy_public.go Outdated
}
for _, key := range allowOnlyKeys {
if allowOnly, ok := raw[key].(map[string]interface{}); ok && allowOnly != nil {
allowOnly["repos"] = policy.AllowOnly.Repos
Comment thread internal/config/guard_policy_public.go Outdated
Comment on lines +50 to +53
raw[key] = map[string]interface{}{
"repos": policy.AllowOnly.Repos,
"min-integrity": IntegrityNone,
}
"min-integrity": config.IntegrityNone,
}
} else {
if !config.ForcePublicReposInMap(serverCfg.GuardPolicies) {
…ntic-function-clustering

# Conflicts:
#	internal/logger/observed_url_domains_logger_test.go
#	internal/logger/write_json_to_file_test.go
#	internal/mcp/tool_result_test.go
#	internal/proxy/graphql_aliased_pr_test.go
#	internal/server/circuit_breaker_test.go
#	internal/sys/docker_test.go

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

lpcox commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot merge main and resolve conflicts then address all review feedback

Copilot AI commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

@copilot merge main and resolve conflicts

Merged main, resolved the conflicts, and published two-parent merge commit 9d9637e. make agent-finished passed.

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

Copilot AI commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

@copilot merge main and resolve conflicts then address all review feedback

main was already merged and had no newer commits. I addressed all three policy review findings in dd44c4b; targeted tests and make agent-finished passed, and CodeQL found no alerts.

@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 AWF (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 (reaction/star/issue/comment/branch/file/PR) all 6 write tools absent from the 23-tool catalog — none callable BLOCKED ⚠️
C CLI reads (github list_issues, get_file_contents) via gateway data returned ALLOWED ✅
D CLI REST writes (reaction/star/issue/comment) gh CLI unauthenticated (no GH_TOKEN) — not exercised BLOCKED ⚠️
E CLI GraphQL mutations (addReaction/addStar/createIssue) gh CLI unauthenticated — not exercised BLOCKED ⚠️

Overall: INCONCLUSIVE

⚠️ Part B: the gateway-fronted github CLI only exposes 23 read-only tools (get_commit, get_file_contents, list_issues, list_pull_requests, list_commits, search_*, etc.); add_issue_comment, star_repository, issue_write, create_branch, create_or_update_file, and create_pull_request are entirely absent from the catalog, so they could not be invoked. This confirms backend/toolset read-only configuration but does not independently exercise mcpg's own DIFC/guard write-blocking layer (per the gh-aw GITHUB_READ_ONLY=1 architectural note).

⚠️ Parts D/E: gh is not authenticated in this job (gh auth status reports not logged in; no GH_TOKEN), so REST/GraphQL write probes could not be attempted — this is an authentication-coverage gap, not evidence of blocking.

No reaction, star, issue, comment, branch, file, or PR was created in any part of this test; no writes leaked.

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

@lpcox
lpcox merged commit ed6727d into main Nov 21, 2026
29 checks passed
@lpcox
lpcox deleted the copilot/refactor-semantic-function-clustering branch November 21, 2026 17:51
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.

[refactor] Semantic function clustering: duplicate, dead, and misplaced helpers in internal/

3 participants