Skip to content

fix(tests): mock search_servers fallback in registry-client UUID-not-found test#1264

Merged
danielmeppiel merged 1 commit into
mainfrom
fix/windows-registry-client-test
May 11, 2026
Merged

fix(tests): mock search_servers fallback in registry-client UUID-not-found test#1264
danielmeppiel merged 1 commit into
mainfrom
fix/windows-registry-client-test

Conversation

@danielmeppiel
Copy link
Copy Markdown
Collaborator

TL;DR

test_find_server_by_reference_uuid_not_found made a real HTTPS call to api.mcp.github.com because only get_server_info was mocked. The Windows runner in build-release.yml can't resolve that hostname and raised socket.gaierror [Errno 11001] getaddrinfo failed, failing the unit-test step. Linux/macOS runners happened to resolve the host so the PR gate (ci.yml, Linux-only) stayed green.

Failing run: https://github.com/microsoft/apm/actions/runs/25651666245

Root cause

find_server_by_reference(reference) in src/apm_cli/registry/client.py:349:

  1. If reference is UUID-shaped, calls self.get_server_info(reference).
  2. If that raises ValueError, it catches and falls through to self.search_servers(reference) (the name-search fallback).

The test mocked step (1) to raise ValueError but left step (2) unmocked. search_servers builds a requests call to the live registry — on a runner that can't resolve the host, you get a DNS error instead of a ValueError, propagating out of the test as a hard fail.

Fix

Mock search_servers to return [] so the not-found path completes hermetically. Test now exercises both branches of the UUID-not-found path and never touches the network — consistent with the existing .github/instructions/tests.instructions.md rule ("Tests must never hit a real HTTP endpoint").

Why this didn't surface earlier

The Linux PR gate (ci.yml) is Linux-only by design; Windows is covered post-merge by build-release.yml. So this latent network leak only manifested on the Windows post-merge runner.

Validation

uv run --extra dev ruff check src/ tests/        # silent
uv run --extra dev ruff format --check src/ tests/  # silent
uv run pytest tests/unit/test_registry_client.py -x -q
# 31 passed, 5 subtests passed in 2.80s

…found test

test_find_server_by_reference_uuid_not_found mocked
SimpleRegistryClient.get_server_info to raise ValueError, but
find_server_by_reference catches ValueError and falls through to
self.search_servers(reference) -- which was not mocked and made a
real HTTPS call to api.mcp.github.com.

On the Windows runner (build-release.yml -> Build & Test
(windows-latest)) that runner's DNS cannot resolve
api.mcp.github.com, raising socket.gaierror [Errno 11001] and
failing the unit test step. Linux/macOS runners happened to resolve
the host so the failure was not surfaced on the Linux-only ci.yml
PR gate.

Fix: also mock search_servers to return []. The test now exercises
both branches of the not-found path and never touches the network,
which is the existing 'no live network calls' rule documented in
.github/instructions/tests.instructions.md.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 11, 2026 05:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 fixes a unit test network leak in the MCP registry client test suite by ensuring the UUID-not-found path is fully mocked and cannot fall through to a real HTTPS request (which was breaking Windows CI due to DNS resolution failures).

Changes:

  • Mock SimpleRegistryClient.search_servers in test_find_server_by_reference_uuid_not_found so the UUID lookup fallback path is hermetic.
  • Add a CHANGELOG.md entry under ## [Unreleased] / ### Fixed documenting the test fix and the Windows CI impact.
Show a summary per file
File Description
tests/unit/test_registry_client.py Extends the UUID-not-found test to also mock the search_servers fallback and assert it is called, preventing real network I/O.
CHANGELOG.md Records the unit test fix under Unreleased/Fixed with the PR number.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 0

@danielmeppiel danielmeppiel merged commit 0693341 into main May 11, 2026
21 checks passed
@danielmeppiel danielmeppiel deleted the fix/windows-registry-client-test branch May 11, 2026 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants