[test-improver] Improve tests for registerPromptsFromBackend#8307
Merged
lpcox merged 4 commits intoJun 30, 2026
Conversation
Add internal/server/register_prompts_test.go with four new tests: - TestRegisterPromptsFromBackend_NoCapability: verifies early return when backend does not declare prompts capability (plain JSON-RPC connection) - TestRegisterPromptsFromBackend_RequestError: verifies graceful skip when backend returns HTTP 500 for prompts/list (handleRequestError path) - TestRegisterPromptsFromBackend_EmptyPromptsList: verifies nil return for an empty prompts/list response - TestRegisterPromptsFromBackend_RegistersPrompts: verifies prompts returned by a streamable HTTP backend are registered without error Coverage of registerPromptsFromBackend improved from 9.4% to 68.8%. Overall server package coverage improved from 91.8% to 93.1%. Helper functions added: - newStreamableBackendWithPromptsCapability: httptest.Server that speaks streamable HTTP MCP protocol with capabilities.prompts declared - connectStreamableBackend: establishes a launcher connection that has BackendHasPromptsCapability() == true - minimalPromptsTestServer: minimal UnifiedServer with only the sdk.Server field wired up (sufficient for the registration phase) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds focused unit tests in internal/server to exercise additional branches in UnifiedServer.registerPromptsFromBackend, which registers MCP prompt definitions from capable backends into the unified SDK server.
Changes:
- Added a new
register_prompts_test.gosuite covering: no prompts capability, request failure, empty list, and non-empty prompt list. - Introduced streamable-HTTP MCP test helpers to simulate a backend that declares
capabilities.promptsand servesprompts/list. - Increased coverage of
registerPromptsFromBackendbeyond the early-return branch.
Show a summary per file
| File | Description |
|---|---|
| internal/server/register_prompts_test.go | Adds new unit tests + helpers for registerPromptsFromBackend and streamable HTTP prompt-list scenarios. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 3
- Review effort level: Low
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
internal/server/register_prompts_test.gowith four new tests targetingregisterPromptsFromBackendininternal/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.goTestRegisterPromptsFromBackend_NoCapabilityTestRegisterPromptsFromBackend_RequestErrorhandleRequestErrorcallback → graceful nil returnTestRegisterPromptsFromBackend_EmptyPromptsList{"prompts": []}→ empty-list path → nil returnTestRegisterPromptsFromBackend_RegistersPromptsThree reusable helpers were introduced:
newStreamableBackendWithPromptsCapability—httptest.Serverthat speaks streamable HTTP MCP protocol (Mcp-Session-Idheader in initialize,capabilities: {"prompts": {}}, 202 for notifications/initialized, delegate forprompts/list)connectStreamableBackend— establishes alauncher.Connectionbacked by the test server and assertsBackendHasPromptsCapability() == trueminimalPromptsTestServer— minimalUnifiedServerwith only the SDK server field populated (sufficient for the registration phase;launcheris not needed until a prompt is actually invoked)Coverage
registerPromptsFromBackendinternal/serverpackage totalTest output
All existing tests continue to pass (
make agent-finishedgreen for all Go packages and integration tests).Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
index.crates.ioSee Network Configuration for more information.