diff --git a/src/apm_cli/commands/marketplace.py b/src/apm_cli/commands/marketplace.py index a3d34fd1b..a7c39d038 100644 --- a/src/apm_cli/commands/marketplace.py +++ b/src/apm_cli/commands/marketplace.py @@ -39,6 +39,7 @@ def add(repo, name, branch, verbose): from ..marketplace.client import _auto_detect_path, fetch_marketplace from ..marketplace.models import MarketplaceSource from ..marketplace.registry import add_marketplace + from ..utils.github_host import default_host # Parse OWNER/REPO if "/" not in repo: @@ -72,11 +73,13 @@ def add(repo, name, branch, verbose): logger.verbose_detail(f" Branch: {branch}") # Auto-detect marketplace.json location + host = default_host() probe_source = MarketplaceSource( name=display_name, owner=owner, repo=repo_name, branch=branch, + host=host, ) detected_path = _auto_detect_path(probe_source) @@ -96,6 +99,7 @@ def add(repo, name, branch, verbose): owner=owner, repo=repo_name, branch=branch, + host=host, path=detected_path, ) diff --git a/tests/unit/marketplace/test_marketplace_commands.py b/tests/unit/marketplace/test_marketplace_commands.py index 7e77377d5..0bf1b7645 100644 --- a/tests/unit/marketplace/test_marketplace_commands.py +++ b/tests/unit/marketplace/test_marketplace_commands.py @@ -53,6 +53,29 @@ def test_successful_add(self, mock_detect, mock_fetch, runner): assert result.exit_code == 0 assert "registered" in result.output.lower() or "1 plugin" in result.output + @patch("apm_cli.marketplace.client.fetch_marketplace") + @patch("apm_cli.marketplace.client._auto_detect_path") + def test_add_respects_github_host(self, mock_detect, mock_fetch, runner, monkeypatch): + from apm_cli.commands.marketplace import marketplace + + monkeypatch.setenv("GITHUB_HOST", "ghe.corp.example.com") + mock_detect.return_value = "marketplace.json" + mock_fetch.return_value = MarketplaceManifest( + name="Test", + plugins=(MarketplacePlugin(name="p1"),), + ) + + result = runner.invoke(marketplace, ["add", "acme-org/plugins"]) + assert result.exit_code == 0 + + # The probe source passed to _auto_detect_path should carry the GHE host + probe_source = mock_detect.call_args[0][0] + assert probe_source.host == "ghe.corp.example.com" + + # The final source passed to fetch_marketplace should also carry it + final_source = mock_fetch.call_args[0][0] + assert final_source.host == "ghe.corp.example.com" + @patch("apm_cli.marketplace.client._auto_detect_path") def test_no_marketplace_json_found(self, mock_detect, runner): from apm_cli.commands.marketplace import marketplace