@@ -2737,12 +2737,18 @@ def test_remove_base_does_not_compose_other_agents_layer_into_historical_dir(
27372737 assert "Low body" not in content and "Base preset body" not in content
27382738 assert "Core custom body" in content and "Middle body" in content
27392739
2740- @pytest .mark .parametrize ("extension_agent" , ["codex" , "claude" ])
2740+ @pytest .mark .parametrize (
2741+ "extension_agent,unrelated_claude_command" ,
2742+ [("codex" , False ), ("codex" , True ), ("claude" , False )],
2743+ ids = ["codex" , "codex-unrelated-claude-command" , "claude" ],
2744+ )
27412745 def test_historical_skill_uses_only_registered_extension (
2742- self , project_dir , temp_dir , extension_agent
2746+ self , project_dir , temp_dir , extension_agent , unrelated_claude_command
27432747 ):
27442748 """Removing a base must not introduce another agent's extension
2745- into a historical skill or alias; a registered base must survive."""
2749+ into a historical skill or alias; a registered base must survive.
2750+ Another command of the extension recorded for Claude (a partial
2751+ registration) does not register this one there."""
27462752 self ._write_init_options (project_dir , ai = extension_agent , ai_skills = True )
27472753 for folder in (".agents" , ".claude" ):
27482754 (project_dir / folder / "skills" ).mkdir (parents = True )
@@ -2771,6 +2777,16 @@ def test_historical_skill_uses_only_registered_extension(
27712777 extension_agent : ["speckit.foreign.run" ]
27722778 }
27732779 assert extensions .registry .get ("foreign" )["registered_skills" ] == []
2780+ if unrelated_claude_command :
2781+ extensions .registry .update (
2782+ "foreign" ,
2783+ {
2784+ "registered_commands" : {
2785+ extension_agent : ["speckit.foreign.run" ],
2786+ "claude" : ["speckit.foreign.other" ],
2787+ }
2788+ },
2789+ )
27742790
27752791 self ._write_init_options (project_dir , ai = "claude" , ai_skills = True )
27762792 self ._create_skill (project_dir / ".claude" / "skills" , "speckit-foreign-run" )
@@ -3016,6 +3032,139 @@ def test_rescaffold_keeps_other_presets_alias_named_like_baseless_command(
30163032
30173033 assert target .read_text (encoding = "utf-8" ) == installed
30183034
3035+ @pytest .mark .parametrize (
3036+ "active,expected,unexpected" ,
3037+ [
3038+ ("codex" , "$speckit-plan" , "/speckit-plan" ),
3039+ ("agy" , "/speckit-plan" , "$speckit-plan" ),
3040+ ("claude" , "/speckit-plan" , "$speckit-plan" ),
3041+ ],
3042+ ids = ["codex-active" , "agy-active" , "shared-dir-historical" ],
3043+ )
3044+ @pytest .mark .parametrize ("middle" , [False , True ], ids = ["winner" , "owner-refresh" ])
3045+ def test_shared_dir_survivor_skill_rendered_once_per_directory (
3046+ self , project_dir , temp_dir , active , expected , unexpected , middle
3047+ ):
3048+ """Codex and agy share ``.agents/skills``, and the surviving composer
3049+ records both. Its primary skill is one file, so it is refreshed once:
3050+ with the active agent's renderer when that agent uses the directory,
3051+ otherwise with the first recorded agent in sorted order (agy), the
3052+ same choice the alias pass and preset removal make. ``middle`` adds a
3053+ higher preset registered only for another directory, which sends the
3054+ refresh through the owner route instead of the winner route."""
3055+ self ._write_init_options (project_dir , ai = "codex" , ai_skills = True )
3056+ shared = project_dir / ".agents" / "skills"
3057+ self ._create_skill (shared , "speckit-custom" )
3058+ self ._write_core_custom (project_dir )
3059+ manager = PresetManager (project_dir )
3060+ install = functools .partial (self ._install_alias_layer , manager , temp_dir )
3061+ install ("base-preset" , "Base preset body" , "replace" , 10 , alias = False )
3062+ install ("append-preset" , "Run `__SPECKIT_COMMAND_PLAN__`." , "append" , 5 )
3063+ self ._write_init_options (project_dir , ai = "agy" , ai_skills = True )
3064+ manager .register_enabled_presets_for_agent ("agy" )
3065+ self ._write_init_options (project_dir , ai = "codex" , ai_skills = True )
3066+ manager .register_enabled_presets_for_agent ("codex" )
3067+ recorded = manager .registry .get ("append-preset" ).get ("registered_skills" , {})
3068+ assert {"codex" , "agy" } <= set (recorded )
3069+ if middle or active == "claude" :
3070+ self ._write_init_options (project_dir , ai = "claude" , ai_skills = True )
3071+ self ._create_skill (project_dir / ".claude" / "skills" , "speckit-custom" )
3072+ if middle :
3073+ install ("top-preset" , "Top body" , "append" , 3 , alias = False )
3074+ self ._write_init_options (project_dir , ai = active , ai_skills = True )
3075+
3076+ assert manager .remove ("base-preset" ) is True
3077+
3078+ for name in ("speckit-custom" , "speckit-custom-short" ):
3079+ text = (shared / name / "SKILL.md" ).read_text (encoding = "utf-8" )
3080+ assert "Core custom body" in text and "Base preset body" not in text
3081+ assert "Top body" not in text
3082+ assert expected in text and unexpected not in text
3083+
3084+ @pytest .mark .parametrize ("core" , [False , True ], ids = ["no-fallback" , "core-fallback" ])
3085+ def test_remove_base_requires_this_commands_registration_in_historical_dir (
3086+ self , project_dir , temp_dir , core
3087+ ):
3088+ """``low`` provides ``speckit.custom`` and ``speckit.other`` and is
3089+ installed while Codex is active. A partial registration then records
3090+ only its unrelated ``speckit.other`` skill for Claude. That record
3091+ must not admit its ``speckit.custom`` layer into Claude's skill and
3092+ alias when the base under Claude's composer is removed."""
3093+ self ._write_init_options (project_dir , ai = "claude" , ai_skills = True )
3094+ self ._create_skill (project_dir / ".claude" / "skills" , "speckit-custom" )
3095+ if core :
3096+ self ._write_core_custom (project_dir )
3097+ manager = PresetManager (project_dir )
3098+ install = functools .partial (self ._install_alias_layer , manager , temp_dir )
3099+ install ("base-preset" , "Base preset body" , "replace" , 10 , alias = False )
3100+ install ("middle-preset" , "Middle body" , "append" , 7 )
3101+ claude_skill = project_dir / ".claude" / "skills" / "speckit-custom" / "SKILL.md"
3102+ claude_alias = self ._alias_skill (project_dir )
3103+ self ._write_init_options (project_dir , ai = "codex" , ai_skills = True )
3104+ manager .register_enabled_presets_for_agent ("codex" )
3105+ low = self ._create_multi_command_preset (
3106+ temp_dir , "low-preset" , ["speckit.custom" , "speckit.other" ]
3107+ )
3108+ (low / "commands" / "speckit.custom.md" ).write_text (
3109+ "---\n description: low\n ---\n \n Low body\n " , encoding = "utf-8"
3110+ )
3111+ manager .install_from_directory (low , "0.1.5" , priority = 12 )
3112+ meta = manager .registry .get ("low-preset" )
3113+ assert "claude" not in meta ["registered_skills" ]
3114+ assert "claude" not in meta ["registered_commands" ]
3115+ manager .registry .update (
3116+ "low-preset" ,
3117+ {
3118+ "registered_skills" : {
3119+ ** meta ["registered_skills" ], "claude" : ["speckit-other" ],
3120+ },
3121+ "registered_commands" : {
3122+ ** meta ["registered_commands" ], "claude" : ["speckit.other" ],
3123+ },
3124+ },
3125+ )
3126+
3127+ assert manager .remove ("base-preset" ) is True
3128+
3129+ for output in (claude_skill , claude_alias ):
3130+ if not core :
3131+ assert not output .exists ()
3132+ continue
3133+ content = output .read_text (encoding = "utf-8" )
3134+ assert "Low body" not in content and "Base preset body" not in content
3135+ assert "Core custom body" in content and "Middle body" in content
3136+
3137+ def test_shared_dir_outputs_use_active_renderer_when_only_another_agent_recorded (
3138+ self , project_dir , temp_dir
3139+ ):
3140+ """The presets were registered while agy was active. Codex uses the
3141+ same ``.agents/skills`` and is active now, without having been
3142+ recorded. The primary skill and its alias are refreshed in Codex's
3143+ directory, so both use Codex's command-reference syntax."""
3144+ self ._write_init_options (project_dir , ai = "agy" , ai_skills = True )
3145+ shared = project_dir / ".agents" / "skills"
3146+ self ._create_skill (shared , "speckit-custom" )
3147+ self ._write_core_custom (project_dir )
3148+ manager = PresetManager (project_dir )
3149+ install = functools .partial (self ._install_alias_layer , manager , temp_dir )
3150+ install ("base-preset" , "Base preset body" , "replace" , 10 , alias = False )
3151+ install ("append-preset" , "Run `__SPECKIT_COMMAND_PLAN__`." , "append" , 5 )
3152+ meta = manager .registry .get ("append-preset" )
3153+ assert set (meta ["registered_skills" ]) == {"agy" }
3154+ assert set (meta ["registered_commands" ]) == {"agy" }
3155+ for name in ("speckit-custom" , "speckit-custom-short" ):
3156+ assert "/speckit-plan" in (shared / name / "SKILL.md" ).read_text (
3157+ encoding = "utf-8"
3158+ )
3159+ self ._write_init_options (project_dir , ai = "codex" , ai_skills = True )
3160+
3161+ assert manager .remove ("base-preset" ) is True
3162+
3163+ for name in ("speckit-custom" , "speckit-custom-short" ):
3164+ text = (shared / name / "SKILL.md" ).read_text (encoding = "utf-8" )
3165+ assert "Core custom body" in text and "Base preset body" not in text
3166+ assert "$speckit-plan" in text and "/speckit-plan" not in text
3167+
30193168 def test_alias_refresh_rewrites_the_same_file (self , project_dir , temp_dir ):
30203169 """The alias is refreshed in place, as command registration always
30213170 wrote it: the same inode keeps its owner, ACL and mode."""
0 commit comments