Commit ef7c3df
authored
[test-improver] Improve tests for validateSingleAgentPolicy error paths (#12193)
## Summary
Improved `internal/config/agent_policy_test.go` by adding coverage for
previously-untested error branches in `validateSingleAgentPolicy`
(`internal/config/agent_policy.go`).
## File analyzed
`internal/config/agent_policy_test.go` (tests
`internal/config/agent_policy.go`)
## Improvements made
Added two new test functions:
- `TestValidateSingleAgentPolicy_ErrorPaths` — table-driven test
covering:
- empty server entry (`Servers: []string{""}`)
- unknown server reference
- duplicate server entry
- tools map referencing a server not in the policy's `Servers` list
- empty tool entry
- duplicate tool entry
- invalid `AllowOnly` sub-policy (propagated validation error)
- `TestValidateSingleAgentPolicy_ValidPolicySucceeds` — a happy-path
sanity check that a fully valid policy returns no error.
All new tests use testify
(`require.Error`/`assert.ErrorContains`/`assert.NotContains`/`assert.NoError`),
consistent with the existing file's conventions, and assert that the raw
agent ID is never leaked into error messages (matching the existing
whitespace test's behavior).
## Coverage before/after
- `validateSingleAgentPolicy`: 87.5% → **100%**
- `internal/config` package total: 96.9% → 97.1%
## Test output
```
go test -run "TestValidateSingleAgentPolicy" -v ./internal/config/
--- PASS: TestValidateSingleAgentPolicy_RejectsSurroundingWhitespace (0.00s)
--- PASS: TestValidateSingleAgentPolicy_ErrorPaths (0.00s)
--- PASS: TestValidateSingleAgentPolicy_ValidPolicySucceeds (0.00s)
PASS
ok github.com/github/gh-aw-mcpg/internal/config 0.008s
```
Also verified:
- `go test -count=3 ./internal/config/...` — all pass (stability check)
- `go vet ./internal/config/` — clean
- `gofmt -l internal/config/agent_policy_test.go` — no output (already
formatted)
No existing tests were modified or removed; all changes are additive.
> Generated by [Test
Improver](https://github.com/github/gh-aw-mcpg/actions/runs/33342548419)
· copilot · auto · 133.9 AIC · ⊞ 8.6K ·
[◷](https://github.com/search?q=repo%3Agithub%2Fgh-aw-mcpg+%22gh-aw-workflow-id%3A+test-improver%22&type=pullrequests)
<!-- gh-aw-agentic-workflow: Test Improver, engine: copilot, model:
auto, id: 33342548419, workflow_id: test-improver, run:
https://github.com/github/gh-aw-mcpg/actions/runs/33342548419 -->
<!-- gh-aw-workflow-id: test-improver -->
<!-- gh-aw-workflow-call-id: github/gh-aw-mcpg/test-improver -->1 file changed
Lines changed: 84 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
89 | 173 | | |
90 | 174 | | |
91 | 175 | | |
| |||
0 commit comments