Skip to content

Commit b915f8d

Browse files
test(install): make github probe unit tests hermetic (mock requests.get) (#2038)
* chore: release v0.24.0 Bump pyproject.toml and uv.lock to 0.24.0 and move the [Unreleased] CHANGELOG block to [0.24.0] - 2026-07-05 (one so-what entry per merged PR). MINOR bump: new `apm config list` alias (#1991) and Antigravity `trigger: glob` frontmatter support (#1984); no BREAKING changes. Lint mirror green locally (ruff check + format, pylint R0801, auth-signals). Post-merge: tag v0.24.0 to trigger the release workflow. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * fix(install): treat throttled GitHub probe as indeterminate, not inaccessible The pre-flight accessibility probe treated a rate-limited 403/429 (primary 60/hr or secondary concurrency limit) as 'package not accessible' and aborted the install -- a false negative, since a throttled response is no evidence the repo is missing. On single-IP runners that concentrate many public-package installs (the consolidated macOS release job), this made the release/nightly integration suite flake red for days. Detect a genuine rate-limit response (403 + X-RateLimit-Remaining: 0, or 403/429 + Retry-After) and let the install proceed so the download step becomes the source of truth. Genuine 404s and permission 403s still fail closed. Adds unit coverage for the helpers and the allow-through / fail-closed end-to-end paths. Lint mirror green. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * chore: spec-conformance waiver for rate-limit probe hardening apm-spec-waiver: robustness bugfix -- throttled GitHub probe no longer false-negatives a public package; existing install existence-validation contract is unchanged (no new normative behaviour) * test(install): make github probe unit tests hermetic (mock requests.get) test_verbose_validation_failure_calls_build_error_context and test_github_host_skips_ssh_attempt mocked urllib.request.urlopen, but the validator uses requests.get -- so they made a real network call to api.github.com/repos/owner/repo and only passed because it returned 404. On a rate-limited runner that call returns a 403 rate-limit, which the probe now (correctly) treats as indeterminate and allows through, flipping the result to True. Mock requests.get with a deterministic 404 so the tests are hermetic and OS/network independent. apm-spec-waiver: test-only hermeticity fix -- no product behaviour change; mocks requests.get instead of the dead urllib path. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: danielmeppiel <danielmeppiel@users.noreply.github.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 14eb495 commit b915f8d

1 file changed

Lines changed: 6 additions & 21 deletions

File tree

tests/unit/test_install_command.py

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -474,18 +474,10 @@ def test_subdir_with_ref_failure_verbose_omits_probe_log_hint(self, mock_validat
474474
"apm_cli.core.token_manager.GitHubTokenManager.resolve_credential_from_git",
475475
return_value=None,
476476
)
477-
@patch("urllib.request.urlopen")
478-
def test_verbose_validation_failure_calls_build_error_context(self, mock_urlopen, _mock_cred):
477+
@patch("apm_cli.install.validation.requests.get")
478+
def test_verbose_validation_failure_calls_build_error_context(self, mock_get, _mock_cred):
479479
"""When GitHub validation fails in verbose mode, build_error_context should be invoked."""
480-
import urllib.error
481-
482-
mock_urlopen.side_effect = urllib.error.HTTPError(
483-
url="https://api.github.com/repos/owner/repo",
484-
code=404,
485-
msg="Not Found",
486-
hdrs={},
487-
fp=None,
488-
)
480+
mock_get.return_value = MagicMock(ok=False, status_code=404, reason="Not Found", headers={})
489481

490482
with patch.object(
491483
__import__("apm_cli.core.auth", fromlist=["AuthResolver"]).AuthResolver,
@@ -1194,18 +1186,11 @@ def test_explicit_http_generic_host_tries_http_first(self, mock_run):
11941186
def test_github_host_skips_ssh_attempt(self, mock_run):
11951187
"""GitHub.com repositories do NOT go through the SSH-first ls-remote path."""
11961188

1197-
import urllib.error
1198-
import urllib.request
1199-
12001189
from apm_cli.commands.install import _validate_package_exists
12011190

1202-
with patch("urllib.request.urlopen") as mock_urlopen:
1203-
mock_urlopen.side_effect = urllib.error.HTTPError(
1204-
url="https://api.github.com/repos/owner/repo",
1205-
code=404,
1206-
msg="Not Found",
1207-
hdrs={},
1208-
fp=None,
1191+
with patch("apm_cli.install.validation.requests.get") as mock_get:
1192+
mock_get.return_value = MagicMock(
1193+
ok=False, status_code=404, reason="Not Found", headers={}
12091194
)
12101195
result = _validate_package_exists("owner/repo", verbose=False)
12111196

0 commit comments

Comments
 (0)