Skip to content

Commit da57bb2

Browse files
committed
fix: address catalog env and priority review
1 parent 087f93b commit da57bb2

4 files changed

Lines changed: 63 additions & 5 deletions

File tree

src/specify_cli/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2593,7 +2593,7 @@ def integration_search(
25932593
raise typer.Exit(1)
25942594
except IntegrationCatalogError as exc:
25952595
console.print(f"[red]Error:[/red] {exc}")
2596-
if os.environ.get("SPECKIT_INTEGRATION_CATALOG_URL"):
2596+
if os.environ.get("SPECKIT_INTEGRATION_CATALOG_URL", "").strip():
25972597
console.print(
25982598
"\nTip: Check the SPECKIT_INTEGRATION_CATALOG_URL environment variable for an invalid "
25992599
"catalog URL, or unset it to use the configured catalog files "
@@ -2731,7 +2731,7 @@ def integration_info(
27312731
"(.specify/integration-catalogs.yml or ~/.specify/integration-catalogs.yml), "
27322732
"or use a built-in integration ID directly."
27332733
)
2734-
elif os.environ.get("SPECKIT_INTEGRATION_CATALOG_URL"):
2734+
elif os.environ.get("SPECKIT_INTEGRATION_CATALOG_URL", "").strip():
27352735
console.print(
27362736
"\nCheck whether SPECKIT_INTEGRATION_CATALOG_URL is set correctly and reachable, "
27372737
"or unset it to use the configured catalog files, or use a built-in integration ID directly."

src/specify_cli/integrations/catalog.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -650,10 +650,14 @@ def _is_removable_catalog_entry(item: Any) -> bool:
650650
if not _is_removable_catalog_entry(item):
651651
continue
652652

653-
try:
654-
priority = int(item.get("priority", yaml_idx + 1))
655-
except (TypeError, ValueError):
653+
raw_priority = item.get("priority", yaml_idx + 1)
654+
if isinstance(raw_priority, bool):
656655
priority = yaml_idx + 1
656+
else:
657+
try:
658+
priority = int(raw_priority)
659+
except (TypeError, ValueError):
660+
priority = yaml_idx + 1
657661
priority_pairs.append((priority, yaml_idx))
658662
if not priority_pairs:
659663
raise IntegrationValidationError(

tests/integrations/test_cli.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,31 @@ def test_search_invalid_env_catalog_url_shows_env_tip(
850850
assert "~/.specify/integration-catalogs.yml" in normalized_output
851851
assert "temporarily unavailable" not in normalized_output
852852

853+
def test_search_whitespace_env_catalog_url_uses_generic_catalog_tip(
854+
self, tmp_path, monkeypatch
855+
):
856+
project = self._make_project(tmp_path)
857+
monkeypatch.setenv("SPECKIT_INTEGRATION_CATALOG_URL", " ")
858+
859+
from specify_cli.integrations.catalog import (
860+
IntegrationCatalog,
861+
IntegrationCatalogError,
862+
)
863+
864+
def fail_search(self, **kwargs):
865+
raise IntegrationCatalogError("catalog offline")
866+
867+
monkeypatch.setattr(IntegrationCatalog, "search", fail_search)
868+
869+
result = self._invoke(["integration", "search"], project)
870+
normalized_output = _normalize_cli_output(result.output)
871+
assert result.exit_code == 1, result.output
872+
assert "temporarily unavailable" in normalized_output
873+
assert (
874+
"SPECKIT_INTEGRATION_CATALOG_URL environment variable"
875+
not in normalized_output
876+
)
877+
853878
def test_info_unknown_with_local_config_error_shows_local_config_tip(
854879
self, tmp_path, monkeypatch
855880
):

tests/integrations/test_integration_catalog.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,35 @@ def test_remove_catalog_display_order_with_missing_priorities(
13251325
data = yaml.safe_load(cfg_path.read_text(encoding="utf-8"))
13261326
assert [c["name"] for c in data["catalogs"]] == ["two", "three"]
13271327

1328+
def test_remove_catalog_bool_priority_falls_back_to_yaml_index(
1329+
self, tmp_path, monkeypatch
1330+
):
1331+
self._isolate(tmp_path, monkeypatch)
1332+
cfg_path = tmp_path / ".specify" / "integration-catalogs.yml"
1333+
cfg_path.parent.mkdir(parents=True, exist_ok=True)
1334+
cfg_path.write_text(
1335+
yaml.dump(
1336+
{
1337+
"catalogs": [
1338+
{"url": "https://one.example.com/c.json", "name": "one"},
1339+
{
1340+
"url": "https://bool.example.com/c.json",
1341+
"name": "bool",
1342+
"priority": False,
1343+
},
1344+
]
1345+
}
1346+
),
1347+
encoding="utf-8",
1348+
)
1349+
cat = IntegrationCatalog(tmp_path)
1350+
1351+
removed = cat.remove_catalog(0)
1352+
1353+
assert removed == "one"
1354+
data = yaml.safe_load(cfg_path.read_text(encoding="utf-8"))
1355+
assert [c["name"] for c in data["catalogs"]] == ["bool"]
1356+
13281357
def test_remove_catalog_display_order_skips_blank_url_entries(
13291358
self, tmp_path, monkeypatch
13301359
):

0 commit comments

Comments
 (0)