2828 _preset_display_name ,
2929)
3030from specify_cli .extensions import ExtensionRegistry
31- from specify_cli .presets import PresetResolver
31+ from specify_cli .presets import PresetRegistry , PresetResolver
32+ from tests .conftest import install_preset
3233
3334
3435ERROR_REGEX = re .compile (
@@ -61,67 +62,6 @@ def non_project(tmp_path: Path) -> Path:
6162 return root
6263
6364
64- def _install_preset (project_root : Path , pack_id : str , provides : dict , priority : int = 10 ) -> Path :
65- """Drop a minimal preset onto disk and register it in the ``.registry`` file."""
66- pack_dir = project_root / ".specify" / "presets" / pack_id
67- pack_dir .mkdir (parents = True )
68- templates : list [dict [str , str ]] = []
69-
70- def _default_file (kind : str , name : str ) -> str :
71- if kind == "command" :
72- return f"commands/{ name } .md"
73- if kind == "script" :
74- return f"scripts/{ name } .sh"
75- return f"templates/{ name } .md"
76-
77- for entry in provides .get ("templates" , []):
78- if not isinstance (entry , dict ):
79- continue
80- entry_type = entry .get ("type" , "template" )
81- if not isinstance (entry_type , str ) or entry_type not in ("command" , "template" , "script" ):
82- continue
83- name = entry .get ("name" )
84- if not isinstance (name , str ):
85- continue
86- normalized = dict (entry )
87- normalized ["type" ] = entry_type
88- normalized .setdefault ("file" , _default_file (entry_type , name ))
89- templates .append (normalized )
90-
91- for kind_key , entry_type in (("commands" , "command" ), ("scripts" , "script" )):
92- for entry in provides .get (kind_key , []):
93- if not isinstance (entry , dict ):
94- continue
95- name = entry .get ("name" )
96- if not isinstance (name , str ):
97- continue
98- normalized = dict (entry )
99- normalized ["type" ] = entry_type
100- normalized .setdefault ("file" , _default_file (entry_type , name ))
101- templates .append (normalized )
102-
103- manifest = {
104- "schema_version" : "1.0" ,
105- "preset" : {
106- "id" : pack_id ,
107- "name" : f"Test preset { pack_id } " ,
108- "version" : "1.0.0" ,
109- "description" : f"Test preset { pack_id } " ,
110- },
111- "requires" : {"speckit_version" : ">=1.0.0" },
112- "provides" : {"templates" : templates },
113- }
114- (pack_dir / "preset.yml" ).write_text (yaml .safe_dump (manifest ), encoding = "utf-8" )
115- registry_path = project_root / ".specify" / "presets" / ".registry"
116- if registry_path .is_file ():
117- registry = json .loads (registry_path .read_text (encoding = "utf-8" ))
118- else :
119- registry = {"schema_version" : "1.0.0" , "presets" : {}}
120- registry ["presets" ][pack_id ] = {"priority" : priority , "version" : "1.0.0" }
121- registry_path .write_text (json .dumps (registry ), encoding = "utf-8" )
122- return pack_dir
123-
124-
12565# ---------------------------------------------------------------------------
12666# Contract tests — matching artifact-list.schema.json
12767# ---------------------------------------------------------------------------
@@ -307,7 +247,7 @@ def test_active_preset_description_overrides_hidden_core_description(
307247 "---\n description: Core description\n ---\n " , encoding = "utf-8"
308248 )
309249
310- pack = _install_preset (
250+ pack = install_preset (
311251 spec_kit_project ,
312252 "override-preset" ,
313253 {
@@ -335,7 +275,7 @@ def test_higher_precedence_preset_description_wins(self, spec_kit_project: Path)
335275 not leak through just because it happens to be enumerated first
336276 alphabetically.
337277 """
338- pack_low = _install_preset (
278+ pack_low = install_preset (
339279 spec_kit_project ,
340280 "aaa-low-priority-preset" ,
341281 {"templates" : [{"name" : "shared-artifact" , "description" : "Loser description" }]},
@@ -346,7 +286,7 @@ def test_higher_precedence_preset_description_wins(self, spec_kit_project: Path)
346286 "# Loser\n " , encoding = "utf-8"
347287 )
348288
349- pack_high = _install_preset (
289+ pack_high = install_preset (
350290 spec_kit_project ,
351291 "zzz-high-priority-preset" ,
352292 {"templates" : [{"name" : "shared-artifact" , "description" : "Winner description" }]},
@@ -477,7 +417,7 @@ def test_ambiguous_artifact_message(self, spec_kit_project: Path):
477417 # Register a preset that contributes 'shared-name' as both a
478418 # template and a script — the info lookup with no kind hint should
479419 # then be ambiguous.
480- pack = _install_preset (
420+ pack = install_preset (
481421 spec_kit_project ,
482422 "test-ambig" ,
483423 {
@@ -509,7 +449,7 @@ def test_info_rejects_corrupt_extension_registry(self, spec_kit_project: Path):
509449
510450class TestKindHint :
511451 def test_kind_flag_disambiguates (self , spec_kit_project : Path ):
512- _install_preset (
452+ install_preset (
513453 spec_kit_project ,
514454 "test-kind" ,
515455 {"templates" : [{"name" : "dup" , "description" : "t" }],
@@ -694,7 +634,7 @@ def test_output_is_utf8_without_bom(self, spec_kit_project: Path, monkeypatch: p
694634
695635class TestStackComposition :
696636 def test_preset_command_uses_entry_type (self , spec_kit_project : Path ):
697- pack = _install_preset (
637+ pack = install_preset (
698638 spec_kit_project ,
699639 "test-command" ,
700640 {
@@ -719,7 +659,7 @@ def test_preset_command_uses_entry_type(self, spec_kit_project: Path):
719659 def test_preset_single_segment_command_id_from_list_is_resolvable (
720660 self , spec_kit_project : Path
721661 ):
722- pack = _install_preset (
662+ pack = install_preset (
723663 spec_kit_project ,
724664 "test-single-command" ,
725665 {"commands" : [{"name" : "specify" , "description" : "single segment" }]},
@@ -739,7 +679,7 @@ def test_preset_single_segment_command_id_from_list_is_resolvable(
739679
740680 def test_preset_replace_hides_core (self , spec_kit_project : Path ):
741681 # Install a preset that replaces the constitution command.
742- pack = _install_preset (
682+ pack = install_preset (
743683 spec_kit_project ,
744684 "test-replace" ,
745685 {"commands" : [{"name" : "speckit.constitution" , "description" : "override" }]},
@@ -853,7 +793,11 @@ def test_malformed_dotted_override_is_not_forced_to_command(
853793 assert "command:speckit..local" not in ids
854794
855795 def test_unregistered_preset_template_without_manifest (self , spec_kit_project : Path ):
856- pack_dir = _install_preset (spec_kit_project , "legacy-preset" , provides = {"templates" : []})
796+ pack_dir = spec_kit_project / ".specify" / "presets" / "legacy-preset"
797+ pack_dir .mkdir ()
798+ PresetRegistry (pack_dir .parent ).add (
799+ "legacy-preset" , {"priority" : 10 , "version" : "1.0.0" }
800+ )
857801 preset_templates_dir = pack_dir / "templates"
858802 preset_templates_dir .mkdir ()
859803 (preset_templates_dir / "legacy-preset-template.md" ).write_text (
0 commit comments