@@ -3043,4 +3043,53 @@ def test_bundled_preset_missing_locally_cli_error(self, project_dir):
30433043 assert result .exit_code == 1
30443044 output = strip_ansi (result .output ).lower ()
30453045 assert "bundled" in output , result .output
3046- assert "reinstall" in output , result .output
3046+
3047+
3048+ class TestWrapStrategy :
3049+ """Tests for strategy: wrap preset command substitution."""
3050+
3051+ def test_substitute_core_template_replaces_placeholder (self , project_dir ):
3052+ """Core template body replaces {CORE_TEMPLATE} in preset command body."""
3053+ from specify_cli .presets import _substitute_core_template
3054+ from specify_cli .agents import CommandRegistrar
3055+
3056+ # Set up a core command template
3057+ core_dir = project_dir / ".specify" / "templates" / "commands"
3058+ core_dir .mkdir (parents = True , exist_ok = True )
3059+ (core_dir / "specify.md" ).write_text (
3060+ "---\n description: core\n ---\n \n # Core Specify\n \n Do the thing.\n "
3061+ )
3062+
3063+ registrar = CommandRegistrar ()
3064+ body = "## Pre-Logic\n \n Before stuff.\n \n {CORE_TEMPLATE}\n \n ## Post-Logic\n \n After stuff.\n "
3065+ result = _substitute_core_template (body , "specify" , project_dir , registrar )
3066+
3067+ assert "{CORE_TEMPLATE}" not in result
3068+ assert "# Core Specify" in result
3069+ assert "## Pre-Logic" in result
3070+ assert "## Post-Logic" in result
3071+
3072+ def test_substitute_core_template_no_op_when_placeholder_absent (self , project_dir ):
3073+ """Returns body unchanged when {CORE_TEMPLATE} is not present."""
3074+ from specify_cli .presets import _substitute_core_template
3075+ from specify_cli .agents import CommandRegistrar
3076+
3077+ core_dir = project_dir / ".specify" / "templates" / "commands"
3078+ core_dir .mkdir (parents = True , exist_ok = True )
3079+ (core_dir / "specify.md" ).write_text ("---\n description: core\n ---\n \n Core body.\n " )
3080+
3081+ registrar = CommandRegistrar ()
3082+ body = "## No placeholder here.\n "
3083+ result = _substitute_core_template (body , "specify" , project_dir , registrar )
3084+ assert result == body
3085+
3086+ def test_substitute_core_template_no_op_when_core_missing (self , project_dir ):
3087+ """Returns body unchanged when core template file does not exist."""
3088+ from specify_cli .presets import _substitute_core_template
3089+ from specify_cli .agents import CommandRegistrar
3090+
3091+ registrar = CommandRegistrar ()
3092+ body = "Pre.\n \n {CORE_TEMPLATE}\n \n Post.\n "
3093+ result = _substitute_core_template (body , "nonexistent" , project_dir , registrar )
3094+ assert result == body
3095+ assert "{CORE_TEMPLATE}" in result
0 commit comments