@@ -820,6 +820,67 @@ def test_add_catalog_rejects_existing_entry_with_bad_url(self, tmp_path, monkeyp
820820 with pytest .raises (IntegrationCatalogError , match = "HTTPS" ):
821821 cat .add_catalog ("https://good.example.com/catalog.json" )
822822
823+ def test_add_catalog_wraps_yaml_parse_errors (self , tmp_path , monkeypatch ):
824+ """Invalid YAML on disk surfaces as IntegrationValidationError, not a raw YAMLError."""
825+ self ._isolate (tmp_path , monkeypatch )
826+ cfg_path = tmp_path / ".specify" / "integration-catalogs.yml"
827+ cfg_path .write_text (
828+ "catalogs:\n - url: 'https://a.example.com/cat.json'\n - [bad\n " ,
829+ encoding = "utf-8" ,
830+ )
831+ cat = IntegrationCatalog (tmp_path )
832+ with pytest .raises (
833+ IntegrationValidationError , match = "Failed to read catalog config"
834+ ):
835+ cat .add_catalog ("https://b.example.com/catalog.json" )
836+
837+ def test_remove_catalog_wraps_yaml_parse_errors (self , tmp_path , monkeypatch ):
838+ """Invalid YAML on disk surfaces as IntegrationValidationError from remove_catalog too."""
839+ self ._isolate (tmp_path , monkeypatch )
840+ cfg_path = tmp_path / ".specify" / "integration-catalogs.yml"
841+ cfg_path .write_text (
842+ "catalogs:\n - url: 'https://a.example.com/cat.json'\n - [bad\n " ,
843+ encoding = "utf-8" ,
844+ )
845+ cat = IntegrationCatalog (tmp_path )
846+ with pytest .raises (
847+ IntegrationValidationError , match = "Failed to read catalog config"
848+ ):
849+ cat .remove_catalog (0 )
850+
851+ def test_add_catalog_defaults_missing_priority_to_index_plus_one (
852+ self , tmp_path , monkeypatch
853+ ):
854+ """Existing entries without `priority` should be treated as idx + 1.
855+
856+ Matches the rule in `_load_catalog_config()`: a valid catalog entry
857+ without an explicit `priority` sorts at `idx + 1`, so the new entry
858+ should get `max(...) + 1` from those derived values.
859+ """
860+ self ._isolate (tmp_path , monkeypatch )
861+ cfg_path = tmp_path / ".specify" / "integration-catalogs.yml"
862+ cfg_path .write_text (
863+ yaml .dump (
864+ {
865+ "catalogs" : [
866+ # No explicit priority → should be treated as 1
867+ {"url" : "https://a.example.com/cat.json" , "name" : "a" },
868+ # No explicit priority → should be treated as 2
869+ {"url" : "https://b.example.com/cat.json" , "name" : "b" },
870+ ]
871+ }
872+ ),
873+ encoding = "utf-8" ,
874+ )
875+ cat = IntegrationCatalog (tmp_path )
876+ cat .add_catalog ("https://c.example.com/cat.json" , name = "c" )
877+
878+ data = yaml .safe_load (cfg_path .read_text (encoding = "utf-8" ))
879+ new_entry = data ["catalogs" ][- 1 ]
880+ assert new_entry ["name" ] == "c"
881+ # max(implicit [1, 2]) + 1 == 3
882+ assert new_entry ["priority" ] == 3
883+
823884 def test_remove_catalog_empty_list_gives_clear_error (self , tmp_path , monkeypatch ):
824885 """Hand-edited empty `catalogs:` produces a clear error, not '0--1'."""
825886 self ._isolate (tmp_path , monkeypatch )
0 commit comments