Skip to content

[test] Add tests for server.overrideToPublicScope - #16181

Merged
lpcox merged 2 commits into
mainfrom
test/override-public-scope-coverage-35f0aad88b659a5d
Nov 8, 2026
Merged

lpcox merged 2 commits into
mainfrom
test/override-public-scope-coverage-35f0aad88b659a5d

Conversation

@github-actions

@github-actions github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Test Coverage Improvement: overrideToPublicScope

  • Package: internal/server (guard_visibility.go)
  • Function: UnifiedServer.overrideToPublicScope
  • Previous coverage: ~66% (unreached: empty global policy, unknown/nil server config, unparsable policy, unrecognized policy format)
  • New coverage: 88.4%
  • Complexity: High (many nested policy branches; security-relevant forced-public override)

Why this function?

It has the most branching among the lowest-covered non-trivial functions and enforces a security-critical policy override.

Tests added (TestOverrideToPublicScope_Branches)

  • ✅ Global policy with neither allow-only nor write-sink → allow-only public injected
  • ✅ Unknown server ID skipped
  • ✅ Nil server config entry skipped without panic
  • ✅ Unparsable per-server policy left unchanged
  • ✅ Unrecognized policy format → allow-only injected, existing keys preserved

Test execution

go test ./internal/server passes; go vet and gofmt clean.

Generated by Test Coverage Improver

Warning

Firewall blocked 4 domains

The following domains were blocked by the firewall during workflow execution:

  • example.com
  • nonexistent.local
  • slow.example.com
  • thishostdoesnotexist12345.com

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

network:
  allowed:
    - defaults
    - "example.com"
    - "nonexistent.local"
    - "slow.example.com"
    - "thishostdoesnotexist12345.com"

See Network Configuration for more information.

Generated by Test Coverage Improver · copilot · auto (Claude Sonnet 5.5) · ~40 AIC · ⊞ 11.5K · ◷

@lpcox
lpcox marked this pull request as ready for review November 8, 2026 17:00
Copilot AI adaptive review requested due to automatic review settings November 8, 2026 17:00

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

The change still has an unresolved redundant test group and an incomplete assertion that does not verify the full no-mutation contract for unparsable policies.

2 open issues
What changed in this PR

Adds branch-focused unit tests for UnifiedServer.overrideToPublicScope, covering empty policies, missing or nil server configurations, malformed policies, and unrecognized policy formats.

Changes:

  • Adds tests for public allow-only policy injection.
  • Verifies no-op behavior for unknown and nil server configurations.
  • Tests preservation of existing policy data for malformed and unrecognized policies.
  • Review comments note duplicated coverage and an incomplete assertion for malformed-policy handling.
File Summary Review comments
internal/​server/​force_public_repos_test.go Adds five branch-oriented tests for forced public repository scope overrides. Nit (4 votes): The aggregate subtest group duplicates existing coverage and should be removed or replaced. Moderate (2 votes): The malformed-policy test should compare the complete policy map rather than only the repos field.

Review effort: Lite (auto)


us.overrideToPublicScope("github")

assert.Equal(t, 123, cfg.Servers["github"].GuardPolicies["allow-only"].(map[string]interface{})["repos"])

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.

Updated in fa31d44: removed the redundant aggregate group. The dedicated invalid-policy tests compare the complete policy map before and after the call, covering the no-mutation contract.

Comment on lines +700 to +704
// TestOverrideToPublicScope_Branches covers the remaining override branches:
// empty global policy, missing/nil server config, unparsable and unrecognized
// per-server policies.
func TestOverrideToPublicScope_Branches(t *testing.T) {
t.Run("global policy without allow-only or write-sink gets allow-only public", func(t *testing.T) {

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.

Updated in fa31d44: removed the aggregate group because its cases duplicate the dedicated tests already in this file.

@github-actions

github-actions Bot commented Nov 8, 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 container isolation)

Part Surface Op Result Expected Status
A MCP reads data returned (list_issues, list_pull_requests, get_file_contents, list_commits) ALLOWED ✅
B MCP writes (reaction/star/issue/comment/branch/file/PR) all 6 write targets absent from the 23-tool github CLI catalog (read-only tools only) BLOCKED ⚠️
C CLI reads data returned via github CLI ALLOWED ✅
D CLI REST writes (reaction/star/issue/comment) gh CLI unauthenticated (not logged into any GitHub hosts) — could not test token-scope boundary BLOCKED ⚠️
E CLI GraphQL mutations (addReaction/addStar/createIssue) same gh auth gap as Part D — not attempted BLOCKED ⚠️

Overall: INCONCLUSIVE

⚠️ Part B: all 6 targeted write tools (add_issue_comment, star_repository, issue_write, create_branch, create_or_update_file, create_pull_request) are absent from the backend tool catalog entirely (gh-aw's GITHUB_READ_ONLY=1 wrapper), so refusal only proves backend/toolset configuration, not mcpg's own gateway-level DIFC/guard enforcement.

⚠️ Parts D/E: gh auth status reported not authenticated in this job, so gh api calls failed with a missing-token error rather than a GitHub API 403 from a read-scoped token — the token-scope write boundary could not be independently exercised this run.

No write leaked on any surface (zero reaction/star/issue/comment/branch/file/PR created). Full log: /tmp/gh-aw/agent/readonly-stress-42500236166.txt

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

@lpcox

lpcox commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator

@copilot address review feedback

Copilot AI requested a review from lpcox November 8, 2026 17:15
@lpcox
lpcox merged commit 5ca4974 into main Nov 8, 2026
29 checks passed
@lpcox
lpcox deleted the test/override-public-scope-coverage-35f0aad88b659a5d branch November 8, 2026 17:27
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.

3 participants