Skip to content

[test-improver] Improve tests for registerPromptsFromBackend#8307

Merged
lpcox merged 4 commits into
mainfrom
test-improver/register-prompts-coverage-9e2d79a510ab9a3a
Jun 30, 2026
Merged

[test-improver] Improve tests for registerPromptsFromBackend#8307
lpcox merged 4 commits into
mainfrom
test-improver/register-prompts-coverage-9e2d79a510ab9a3a

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

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.goregisterPromptsFromBackend (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:

  • newStreamableBackendWithPromptsCapabilityhttptest.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

Firewall blocked 1 domain

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:

network:
  allowed:
    - defaults
    - "index.crates.io"

See Network Configuration for more information.

Generated by Test Improver · 787.4 AIC · ⊞ 5.6K ·

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>

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.

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.go suite 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.prompts and serves prompts/list.
  • Increased coverage of registerPromptsFromBackend beyond 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

Comment thread internal/server/register_prompts_test.go Outdated
Comment thread internal/server/register_prompts_test.go
Comment thread internal/server/register_prompts_test.go
lpcox and others added 3 commits June 30, 2026 06:30
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>
GitHub Advanced Security started work on behalf of lpcox June 30, 2026 13:30 View session
GitHub Advanced Security started work on behalf of lpcox June 30, 2026 13:31 View session
GitHub Advanced Security started work on behalf of lpcox June 30, 2026 13:31 View session
GitHub Advanced Security finished work on behalf of lpcox June 30, 2026 13:31
GitHub Advanced Security finished work on behalf of lpcox June 30, 2026 13:31
GitHub Advanced Security finished work on behalf of lpcox June 30, 2026 13:31
@lpcox lpcox merged commit dc07359 into main Jun 30, 2026
24 checks passed
@lpcox lpcox deleted the test-improver/register-prompts-coverage-9e2d79a510ab9a3a branch June 30, 2026 13:38
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.

2 participants