@@ -955,3 +955,95 @@ def test_remove_last_catalog_deletes_file_and_restores_defaults(
955955 # Follow-up loads fall back to built-in defaults, not an error.
956956 active = cat .get_active_catalogs ()
957957 assert [e .name for e in active ] == ["default" , "community" ]
958+
959+ def test_remove_catalog_uses_display_order_with_explicit_priorities (
960+ self , tmp_path , monkeypatch
961+ ):
962+ """`remove_catalog(index)` must remove the entry shown at that index by
963+ `catalog list`, not the entry at that raw YAML position."""
964+ self ._isolate (tmp_path , monkeypatch )
965+ # YAML order: alpha (priority=20), beta (priority=10), gamma (priority=15).
966+ # Display (sorted by priority asc): beta (10), gamma (15), alpha (20).
967+ cfg_path = tmp_path / ".specify" / "integration-catalogs.yml"
968+ cfg_path .parent .mkdir (parents = True , exist_ok = True )
969+ cfg_path .write_text (
970+ yaml .dump (
971+ {
972+ "catalogs" : [
973+ {"url" : "https://alpha.example.com/c.json" , "name" : "alpha" , "priority" : 20 },
974+ {"url" : "https://beta.example.com/c.json" , "name" : "beta" , "priority" : 10 },
975+ {"url" : "https://gamma.example.com/c.json" , "name" : "gamma" , "priority" : 15 },
976+ ]
977+ }
978+ ),
979+ encoding = "utf-8" ,
980+ )
981+ cat = IntegrationCatalog (tmp_path )
982+
983+ # Display index 0 = beta (lowest priority), not alpha (raw YAML idx 0).
984+ removed = cat .remove_catalog (0 )
985+ assert removed == "beta"
986+
987+ data = yaml .safe_load (cfg_path .read_text (encoding = "utf-8" ))
988+ remaining_names = [c ["name" ] for c in data ["catalogs" ]]
989+ # YAML order is preserved for the survivors; only beta is gone.
990+ assert remaining_names == ["alpha" , "gamma" ]
991+
992+ def test_remove_catalog_display_order_with_missing_priorities (
993+ self , tmp_path , monkeypatch
994+ ):
995+ """Entries without `priority` default to `idx + 1` (matching
996+ `_load_catalog_config`), so display order tracks YAML order and the
997+ first display entry is the first YAML entry."""
998+ self ._isolate (tmp_path , monkeypatch )
999+ cfg_path = tmp_path / ".specify" / "integration-catalogs.yml"
1000+ cfg_path .parent .mkdir (parents = True , exist_ok = True )
1001+ cfg_path .write_text (
1002+ yaml .dump (
1003+ {
1004+ "catalogs" : [
1005+ {"url" : "https://one.example.com/c.json" , "name" : "one" },
1006+ {"url" : "https://two.example.com/c.json" , "name" : "two" },
1007+ {"url" : "https://three.example.com/c.json" , "name" : "three" },
1008+ ]
1009+ }
1010+ ),
1011+ encoding = "utf-8" ,
1012+ )
1013+ cat = IntegrationCatalog (tmp_path )
1014+
1015+ # Implicit priorities: one=1, two=2, three=3 → display order matches YAML.
1016+ removed = cat .remove_catalog (0 )
1017+ assert removed == "one"
1018+
1019+ data = yaml .safe_load (cfg_path .read_text (encoding = "utf-8" ))
1020+ assert [c ["name" ] for c in data ["catalogs" ]] == ["two" , "three" ]
1021+
1022+ def test_remove_catalog_display_order_mixes_explicit_and_default (
1023+ self , tmp_path , monkeypatch
1024+ ):
1025+ """An explicit low priority should sort ahead of default-priority
1026+ siblings, even if it appears later in the YAML."""
1027+ self ._isolate (tmp_path , monkeypatch )
1028+ cfg_path = tmp_path / ".specify" / "integration-catalogs.yml"
1029+ cfg_path .parent .mkdir (parents = True , exist_ok = True )
1030+ # Defaults: a=1, b=2 (implicit). Explicit c=0 → display: c, a, b.
1031+ cfg_path .write_text (
1032+ yaml .dump (
1033+ {
1034+ "catalogs" : [
1035+ {"url" : "https://a.example.com/c.json" , "name" : "a" },
1036+ {"url" : "https://b.example.com/c.json" , "name" : "b" },
1037+ {"url" : "https://c.example.com/c.json" , "name" : "c" , "priority" : 0 },
1038+ ]
1039+ }
1040+ ),
1041+ encoding = "utf-8" ,
1042+ )
1043+ cat = IntegrationCatalog (tmp_path )
1044+
1045+ removed = cat .remove_catalog (0 )
1046+ assert removed == "c"
1047+
1048+ data = yaml .safe_load (cfg_path .read_text (encoding = "utf-8" ))
1049+ assert [c ["name" ] for c in data ["catalogs" ]] == ["a" , "b" ]
0 commit comments