@@ -881,6 +881,42 @@ def test_add_catalog_defaults_missing_priority_to_index_plus_one(
881881 # max(implicit [1, 2]) + 1 == 3
882882 assert new_entry ["priority" ] == 3
883883
884+ def test_add_catalog_strips_whitespace_in_url (self , tmp_path , monkeypatch ):
885+ """Whitespace around the incoming URL should be normalized before write."""
886+ self ._isolate (tmp_path , monkeypatch )
887+ cat = IntegrationCatalog (tmp_path )
888+ cat .add_catalog (" https://a.example.com/catalog.json\n " , name = "a" )
889+
890+ cfg_path = tmp_path / ".specify" / "integration-catalogs.yml"
891+ data = yaml .safe_load (cfg_path .read_text (encoding = "utf-8" ))
892+ assert data ["catalogs" ][0 ]["url" ] == "https://a.example.com/catalog.json"
893+
894+ def test_add_catalog_rejects_whitespace_only_duplicate (self , tmp_path , monkeypatch ):
895+ """A second add with only whitespace differences must be rejected as a duplicate."""
896+ self ._isolate (tmp_path , monkeypatch )
897+ cat = IntegrationCatalog (tmp_path )
898+ cat .add_catalog ("https://a.example.com/catalog.json" , name = "a" )
899+ with pytest .raises (IntegrationValidationError , match = "already configured" ):
900+ cat .add_catalog (" https://a.example.com/catalog.json " )
901+
902+ def test_remove_catalog_wraps_unlink_oserror (self , tmp_path , monkeypatch ):
903+ """An OSError from `Path.unlink` surfaces as IntegrationValidationError."""
904+ self ._isolate (tmp_path , monkeypatch )
905+ cat = IntegrationCatalog (tmp_path )
906+ cat .add_catalog ("https://only.example.com/catalog.json" , name = "only" )
907+
908+ from pathlib import Path as _Path
909+
910+ def boom (self , * args , ** kwargs ):
911+ raise OSError ("simulated unlink failure" )
912+
913+ monkeypatch .setattr (_Path , "unlink" , boom )
914+
915+ with pytest .raises (
916+ IntegrationValidationError , match = "Failed to delete catalog config"
917+ ):
918+ cat .remove_catalog (0 )
919+
884920 def test_remove_catalog_empty_list_gives_clear_error (self , tmp_path , monkeypatch ):
885921 """Hand-edited empty `catalogs:` produces a clear error, not '0--1'."""
886922 self ._isolate (tmp_path , monkeypatch )
0 commit comments