@@ -3093,3 +3093,53 @@ def test_substitute_core_template_no_op_when_core_missing(self, project_dir):
30933093 result = _substitute_core_template (body , "nonexistent" , project_dir , registrar )
30943094 assert result == body
30953095 assert "{CORE_TEMPLATE}" in result
3096+
3097+ def test_register_commands_substitutes_core_template_for_wrap_strategy (self , project_dir ):
3098+ """register_commands substitutes {CORE_TEMPLATE} when strategy: wrap."""
3099+ from specify_cli .agents import CommandRegistrar
3100+
3101+ # Set up core command template
3102+ core_dir = project_dir / ".specify" / "templates" / "commands"
3103+ core_dir .mkdir (parents = True , exist_ok = True )
3104+ (core_dir / "specify.md" ).write_text (
3105+ "---\n description: core\n ---\n \n # Core Specify\n \n Core body here.\n "
3106+ )
3107+
3108+ # Create a preset command dir with a wrap-strategy command
3109+ cmd_dir = project_dir / "preset" / "commands"
3110+ cmd_dir .mkdir (parents = True , exist_ok = True )
3111+ (cmd_dir / "speckit.specify.md" ).write_text (
3112+ "---\n description: wrap test\n strategy: wrap\n ---\n \n "
3113+ "## Pre\n \n {CORE_TEMPLATE}\n \n ## Post\n "
3114+ )
3115+
3116+ commands = [{"name" : "speckit.specify" , "file" : "commands/speckit.specify.md" }]
3117+ registrar = CommandRegistrar ()
3118+
3119+ # Use a generic agent that writes markdown to commands/
3120+ agent_dir = project_dir / ".claude" / "commands"
3121+ agent_dir .mkdir (parents = True , exist_ok = True )
3122+
3123+ # Patch AGENT_CONFIGS to use a simple markdown agent pointing at our dir
3124+ import copy
3125+ original = copy .deepcopy (registrar .AGENT_CONFIGS )
3126+ registrar .AGENT_CONFIGS ["test-agent" ] = {
3127+ "dir" : str (agent_dir .relative_to (project_dir )),
3128+ "format" : "markdown" ,
3129+ "args" : "$ARGUMENTS" ,
3130+ "extension" : ".md" ,
3131+ "strip_frontmatter_keys" : [],
3132+ }
3133+ try :
3134+ registrar .register_commands (
3135+ "test-agent" , commands , "test-preset" ,
3136+ project_dir / "preset" , project_dir
3137+ )
3138+ finally :
3139+ registrar .AGENT_CONFIGS = original
3140+
3141+ written = (agent_dir / "speckit.specify.md" ).read_text ()
3142+ assert "{CORE_TEMPLATE}" not in written
3143+ assert "# Core Specify" in written
3144+ assert "## Pre" in written
3145+ assert "## Post" in written
0 commit comments