test_cmd_hub_release_list.py
python
sha256:c4f1efcedc75c6d1eda18b7f73bbe06081120c20afd3aa3eb688a63cc22389c7
fix: muse hub release list crashed on every call (_hub_api …
Sonnet 5
patch
1 day ago
| 1 | """Regression test for `muse hub release list` (musehub staging #185 wrap-up). |
| 2 | |
| 3 | Found while confirming build versions before tagging a new release: |
| 4 | `run_release_list` called `_hub_api(..., params=params)`, but `_hub_api` |
| 5 | has no `params` keyword at all — every invocation of this command crashed |
| 6 | with a TypeError before making any request. Completely untested until now. |
| 7 | """ |
| 8 | import argparse |
| 9 | import json |
| 10 | |
| 11 | import pytest |
| 12 | |
| 13 | from muse.cli.commands.hub import releases as releases_mod |
| 14 | |
| 15 | |
| 16 | class _FakeIdentity: |
| 17 | pass |
| 18 | |
| 19 | |
| 20 | class TestRunReleaseList: |
| 21 | def test_limit_and_cursor_reach_the_request_url_as_query_params( |
| 22 | self, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture, |
| 23 | ) -> None: |
| 24 | captured_urls: list[str] = [] |
| 25 | |
| 26 | def _fake_hub_api(hub_url, identity, method, path, body=None, timeout=10.0): |
| 27 | captured_urls.append(path) |
| 28 | return {"releases": [], "nextCursor": None, "total": 0} |
| 29 | |
| 30 | monkeypatch.setattr(releases_mod, "_hub_api", _fake_hub_api) |
| 31 | monkeypatch.setattr( |
| 32 | releases_mod, "_get_hub_and_identity", |
| 33 | lambda hub_url_override=None: ("https://staging.musehub.ai/gabriel/muse", _FakeIdentity()), |
| 34 | ) |
| 35 | monkeypatch.setattr(releases_mod, "_resolve_repo_id", lambda hub_url, identity: "sha256:abc") |
| 36 | |
| 37 | args = argparse.Namespace(json_output=True, limit=10, cursor="tok123", hub=None) |
| 38 | releases_mod.run_release_list(args) |
| 39 | |
| 40 | assert len(captured_urls) == 1 |
| 41 | assert "limit=10" in captured_urls[0] |
| 42 | assert "cursor=tok123" in captured_urls[0] |
| 43 | |
| 44 | def test_no_cursor_omits_cursor_param( |
| 45 | self, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture, |
| 46 | ) -> None: |
| 47 | captured_urls: list[str] = [] |
| 48 | |
| 49 | def _fake_hub_api(hub_url, identity, method, path, body=None, timeout=10.0): |
| 50 | captured_urls.append(path) |
| 51 | return {"releases": [], "nextCursor": None, "total": 0} |
| 52 | |
| 53 | monkeypatch.setattr(releases_mod, "_hub_api", _fake_hub_api) |
| 54 | monkeypatch.setattr( |
| 55 | releases_mod, "_get_hub_and_identity", |
| 56 | lambda hub_url_override=None: ("https://staging.musehub.ai/gabriel/muse", _FakeIdentity()), |
| 57 | ) |
| 58 | monkeypatch.setattr(releases_mod, "_resolve_repo_id", lambda hub_url, identity: "sha256:abc") |
| 59 | |
| 60 | args = argparse.Namespace(json_output=True, limit=50, cursor=None, hub=None) |
| 61 | releases_mod.run_release_list(args) |
| 62 | |
| 63 | assert "cursor=" not in captured_urls[0] |
| 64 | |
| 65 | def test_json_output_includes_releases_from_response( |
| 66 | self, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture, |
| 67 | ) -> None: |
| 68 | def _fake_hub_api(hub_url, identity, method, path, body=None, timeout=10.0): |
| 69 | return {"releases": [{"tag": "v1.0.0"}], "nextCursor": None, "total": 1} |
| 70 | |
| 71 | monkeypatch.setattr(releases_mod, "_hub_api", _fake_hub_api) |
| 72 | monkeypatch.setattr( |
| 73 | releases_mod, "_get_hub_and_identity", |
| 74 | lambda hub_url_override=None: ("https://staging.musehub.ai/gabriel/muse", _FakeIdentity()), |
| 75 | ) |
| 76 | monkeypatch.setattr(releases_mod, "_resolve_repo_id", lambda hub_url, identity: "sha256:abc") |
| 77 | |
| 78 | args = argparse.Namespace(json_output=True, limit=50, cursor=None, hub=None) |
| 79 | releases_mod.run_release_list(args) |
| 80 | |
| 81 | out = json.loads(capsys.readouterr().out) |
| 82 | assert out["releases"] == [{"tag": "v1.0.0"}] |
File History
1 commit
sha256:c4f1efcedc75c6d1eda18b7f73bbe06081120c20afd3aa3eb688a63cc22389c7
fix: muse hub release list crashed on every call (_hub_api …
Sonnet 5
patch
1 day ago