@@ -702,6 +702,40 @@ def test_add_catalog_creates_config_file(self, tmp_path, monkeypatch):
702702 active = cat .get_active_catalogs ()
703703 assert [e .name for e in active ] == ["mine" ]
704704
705+ def test_add_catalog_recovers_from_empty_config_file (self , tmp_path , monkeypatch ):
706+ self ._isolate (tmp_path , monkeypatch )
707+ cfg_path = tmp_path / ".specify" / "integration-catalogs.yml"
708+ cfg_path .write_text ("" , encoding = "utf-8" )
709+
710+ cat = IntegrationCatalog (tmp_path )
711+ cat .add_catalog ("https://example.com/catalog.json" )
712+
713+ data = yaml .safe_load (cfg_path .read_text (encoding = "utf-8" ))
714+ assert data ["catalogs" ] == [
715+ {
716+ "name" : "catalog-1" ,
717+ "url" : "https://example.com/catalog.json" ,
718+ "priority" : 1 ,
719+ "install_allowed" : True ,
720+ "description" : "" ,
721+ }
722+ ]
723+
724+ @pytest .mark .parametrize ("config_content" , ["[]\n " , "false\n " , "0\n " , "''\n " ])
725+ def test_add_catalog_rejects_falsy_non_mapping_config_roots (
726+ self , tmp_path , monkeypatch , config_content
727+ ):
728+ self ._isolate (tmp_path , monkeypatch )
729+ cfg_path = tmp_path / ".specify" / "integration-catalogs.yml"
730+ cfg_path .write_text (config_content , encoding = "utf-8" )
731+
732+ cat = IntegrationCatalog (tmp_path )
733+ with pytest .raises (
734+ IntegrationValidationError ,
735+ match = "corrupted.*expected a mapping" ,
736+ ):
737+ cat .add_catalog ("https://example.com/catalog.json" )
738+
705739 def test_add_catalog_auto_derives_name_and_priority (self , tmp_path , monkeypatch ):
706740 self ._isolate (tmp_path , monkeypatch )
707741 cat = IntegrationCatalog (tmp_path )
0 commit comments