Skip to content

[test-improver] Improve tests for resolve_guard_policy_test.go - #13065

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
test-improver/resolve-guard-policy-table-driven-301a9be9cbfdd6b6
Draft

[test-improver] Improve tests for resolve_guard_policy_test.go#13065
github-actions[bot] wants to merge 1 commit into
mainfrom
test-improver/resolve-guard-policy-table-driven-301a9be9cbfdd6b6

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Summary

Refactors internal/server/resolve_guard_policy_test.go to reduce duplication and improve structure, per the Test Improver workflow.

File analyzed: internal/server/resolve_guard_policy_test.go (505 lines, 32 standalone Test* functions, no table-driven tests, 0 manual error-check anti-patterns — testify was already used throughout).

Improvements made

  • Converted the 10 TestNormalizeScopeKind_* functions into a single table-driven TestNormalizeScopeKind with t.Run subtests (kept TestNormalizeScopeKind_DoesNotMutateInput separate since it asserts on the input map, not just the result, which doesn't fit the table cleanly).
  • Converted the 18 TestResolveGuardPolicy_* functions into a single table-driven TestResolveGuardPolicy, using an optional wantPolicyCheck callback for cases needing to inspect the parsed policy contents (vs. simple identity comparison for pass-through cases).
  • Converted the 5 TestResolveWriteSinkPolicy_* functions into a single table-driven TestResolveWriteSinkPolicy.
  • Preserved every original test case, assertion, and comment/rationale (e.g. why empty GuardPolicySource defaults to "override", why an empty policy struct is invalid, legacy-fallback semantics, etc.) — no test coverage was dropped.
  • No production code changes; this is a test-only refactor.

Coverage before/after

Coverage of the exercised functions was already 100% and remains 100% after the refactor (verified via go tool cover -func):

github.com/github/gh-aw-mcpg/internal/server/guard_init.go:314  resolveGuardPolicyForAgent  100.0%
github.com/github/gh-aw-mcpg/internal/server/guard_init.go:328  resolveGuardPolicy          100.0%
github.com/github/gh-aw-mcpg/internal/server/guard_init.go:380  resolveWriteSinkPolicy      100.0%

Overall internal/server package coverage unchanged at 95.2%.

Test output

$ go test -v ./internal/server/ -run "TestNormalizeScopeKind|TestResolveGuardPolicy|TestResolveWriteSinkPolicy"
...
PASS
ok  	github.com/github/gh-aw-mcpg/internal/server	0.017s

Also verified:

  • go test -count=3 ./internal/server/... — passes (no flakiness)
  • go vet ./... — clean
  • gofmt -l internal/server/resolve_guard_policy_test.go — no output (already formatted)
  • make build and make lint — pass (golangci-lint binary unavailable in this sandbox; gofmt check passed)

Generated by Test Improver · copilot · auto · 283.1 AIC · ⊞ 8.4K ·

Convert 32 standalone Test functions into three table-driven test
functions (TestNormalizeScopeKind, TestResolveGuardPolicy,
TestResolveWriteSinkPolicy), reducing duplication while preserving
every existing test case and assertion. Coverage of resolveGuardPolicy,
resolveWriteSinkPolicy, and NormalizeScopeKind remains 100%.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

0 participants