Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/specify_cli/integrations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,12 @@ def remove_catalog(self, index: int) -> str:

Returns the removed catalog's name.
"""
if os.environ.get("SPECKIT_INTEGRATION_CATALOG_URL", "").strip():
raise IntegrationValidationError(
"The active catalog comes from SPECKIT_INTEGRATION_CATALOG_URL. "
"Unset that variable to remove a project catalog source."
)

config_path = self.project_root / ".specify" / self.CONFIG_FILENAME
if not config_path.exists():
raise IntegrationValidationError("No catalog config file found.")
Expand Down
17 changes: 17 additions & 0 deletions tests/specify_cli/integrations/catalog/test_command_remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@
from tests.specify_cli.integrations._catalog_helpers import IntegrationCatalogCliTestBase

class TestIntegrationCatalogRemove(IntegrationCatalogCliTestBase):
def test_catalog_remove_refuses_environment_override(self, tmp_path, monkeypatch):
project = self._make_project(tmp_path)
config = project / ".specify" / "integration-catalogs.yml"
config.write_text(
"catalogs:\n - name: project\n url: https://project.example.com/catalog.json\n"
)
before = config.read_bytes()
monkeypatch.setenv(
"SPECKIT_INTEGRATION_CATALOG_URL", "https://env.example.com/catalog.json"
)

result = self._invoke(["integration", "catalog", "remove", "0"], project)

assert result.exit_code == 1
assert "SPECKIT_INTEGRATION_CATALOG_URL" in result.output
assert config.read_bytes() == before

def test_catalog_remove_out_of_range(self, tmp_path, monkeypatch):
project = self._make_project(tmp_path)
# Need a config file for remove to attempt an index lookup
Expand Down
19 changes: 19 additions & 0 deletions tests/specify_cli/integrations/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,25 @@ def test_remove_catalog_happy_path(self, tmp_path, monkeypatch):
)
assert [e["name"] for e in data["catalogs"]] == ["b"]

def test_remove_catalog_refuses_inactive_project_sources(self, tmp_path, monkeypatch):
self._isolate(tmp_path, monkeypatch)
cat = IntegrationCatalog(tmp_path)
cat.add_catalog("https://a.example.com/catalog.json", name="a")
cat.add_catalog("https://b.example.com/catalog.json", name="b")
config = tmp_path / ".specify" / "integration-catalogs.yml"
before = config.read_bytes()

monkeypatch.setenv(
"SPECKIT_INTEGRATION_CATALOG_URL", " https://env.example.com/catalog.json "
)
with pytest.raises(IntegrationValidationError, match="SPECKIT_INTEGRATION_CATALOG_URL"):
cat.remove_catalog(0)
assert config.read_bytes() == before

monkeypatch.setenv("SPECKIT_INTEGRATION_CATALOG_URL", " \t ")
assert cat.remove_catalog(0) == "a"
assert [e["name"] for e in yaml.safe_load(config.read_text())["catalogs"]] == ["b"]

def test_remove_catalog_index_out_of_range(self, tmp_path, monkeypatch):
self._isolate(tmp_path, monkeypatch)
cat = IntegrationCatalog(tmp_path)
Expand Down
Loading