Commit dc07359
authored
[test-improver] Improve tests for registerPromptsFromBackend (#8307)
## Summary
Adds `internal/server/register_prompts_test.go` with four new tests
targeting `registerPromptsFromBackend` in
`internal/server/tool_registry.go`.
### File analyzed
**`internal/server/tool_registry.go`** — `registerPromptsFromBackend`
(lines 382–460)
Before this PR, the function had **9.4% coverage** because the only
covered path was the early-return guard
(`!conn.BackendHasPromptsCapability()`). All other paths required a
streamable HTTP backend that declares prompts capability, which existing
tests did not set up.
### Improvements made
New file: `internal/server/register_prompts_test.go`
| Test | Path covered |
|------|-------------|
| `TestRegisterPromptsFromBackend_NoCapability` | Early-return when
backend has no prompts capability (plain JSON-RPC connection) |
| `TestRegisterPromptsFromBackend_RequestError` | HTTP 500 from backend
→ `handleRequestError` callback → graceful nil return |
| `TestRegisterPromptsFromBackend_EmptyPromptsList` | Streamable backend
returns `{"prompts": []}` → empty-list path → nil return |
| `TestRegisterPromptsFromBackend_RegistersPrompts` | Streamable backend
returns 2 prompts → prompts are registered → nil return |
Three reusable helpers were introduced:
- **`newStreamableBackendWithPromptsCapability`** — `httptest.Server`
that speaks streamable HTTP MCP protocol (`Mcp-Session-Id` header in
initialize, `capabilities: {"prompts": {}}`, 202 for
notifications/initialized, delegate for `prompts/list`)
- **`connectStreamableBackend`** — establishes a `launcher.Connection`
backed by the test server and asserts `BackendHasPromptsCapability() ==
true`
- **`minimalPromptsTestServer`** — minimal `UnifiedServer` with only the
SDK server field populated (sufficient for the registration phase;
`launcher` is not needed until a prompt is actually invoked)
### Coverage
| Metric | Before | After |
|--------|--------|-------|
| `registerPromptsFromBackend` | 9.4% | **68.8%** |
| `internal/server` package total | 91.8% | **93.1%** |
### Test output
```
=== RUN TestRegisterPromptsFromBackend_NoCapability
--- PASS: TestRegisterPromptsFromBackend_NoCapability (0.00s)
=== RUN TestRegisterPromptsFromBackend_RequestError
--- PASS: TestRegisterPromptsFromBackend_RequestError (0.00s)
=== RUN TestRegisterPromptsFromBackend_EmptyPromptsList
--- PASS: TestRegisterPromptsFromBackend_EmptyPromptsList (0.00s)
=== RUN TestRegisterPromptsFromBackend_RegistersPrompts
--- PASS: TestRegisterPromptsFromBackend_RegistersPrompts (0.00s)
PASS
ok github.com/github/gh-aw-mcpg/internal/server 0.017s
```
All existing tests continue to pass (`make agent-finished` green for all
Go packages and integration tests).
> [!WARNING]
> <details>
> <summary>Firewall blocked 1 domain</summary>
>
> The following domain was blocked by the firewall during workflow
execution:
>
> - `index.crates.io`
>> To allow these domains, add them to the `network.allowed` list in
your workflow frontmatter:
>
> ```yaml
> network:
> allowed:
> - defaults
> - "index.crates.io"
> ```
>
> See [Network
Configuration](https://github.github.com/gh-aw/reference/network/) for
more information.
>
> </details>
> Generated by [Test
Improver](https://github.com/github/gh-aw-mcpg/actions/runs/28410847582)
· 787.4 AIC · ⊞ 5.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, version:
1.0.65, model: claude-sonnet-4.6, id: 28410847582, workflow_id:
test-improver, run:
https://github.com/github/gh-aw-mcpg/actions/runs/28410847582 -->
<!-- gh-aw-workflow-id: test-improver -->
<!-- gh-aw-workflow-call-id: github/gh-aw-mcpg/test-improver -->1 file changed
Lines changed: 224 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 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 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
0 commit comments