@@ -770,49 +770,20 @@ def fake_download(project_path, *args, **kwargs):
770770 assert result .exit_code == 0
771771 mock_skills .assert_called_once ()
772772 assert mock_skills .call_args .kwargs .get ("overwrite_existing" ) is True
773- assert not (target / ".codex" ).exists ()
774773
775- def test_codex_ai_skills_removes_legacy_codex_dir_after_fallback (self , tmp_path ):
776- """Codex skills init should not leave legacy .codex prompt directory behind ."""
774+ def test_codex_ai_skills_here_mode_preserves_existing_codex_dir (self , tmp_path , monkeypatch ):
775+ """Codex --here skills init should not delete a pre-existing .codex directory."""
777776 from typer .testing import CliRunner
778777
779778 runner = CliRunner ()
780- target = tmp_path / "codex-cleanup-new"
781-
782- def fake_download (project_path , * args , ** kwargs ):
783- prompts_dir = project_path / ".codex" / "prompts"
784- prompts_dir .mkdir (parents = True , exist_ok = True )
785- (prompts_dir / "speckit.specify.md" ).write_text ("---\n description: Legacy prompt\n ---\n \n Body.\n " )
786-
787- with patch ("specify_cli.download_and_extract_template" , side_effect = fake_download ), \
788- patch ("specify_cli.ensure_executable_scripts" ), \
789- patch ("specify_cli.ensure_constitution_from_template" ), \
790- patch ("specify_cli.install_ai_skills" , return_value = True ), \
791- patch ("specify_cli.is_git_repo" , return_value = False ), \
792- patch ("specify_cli.shutil.which" , return_value = "/usr/bin/codex" ):
793- result = runner .invoke (
794- app ,
795- ["init" , str (target ), "--ai" , "codex" , "--ai-skills" , "--script" , "sh" , "--no-git" ],
796- )
797-
798- assert result .exit_code == 0
799- assert not (target / ".codex" ).exists ()
800-
801- def test_codex_ai_skills_here_mode_removes_legacy_codex_dir (self , tmp_path , monkeypatch ):
802- """Codex --here skills init should not leave legacy .codex prompt directory behind."""
803- from typer .testing import CliRunner
804-
805- runner = CliRunner ()
806- target = tmp_path / "codex-cleanup-here"
779+ target = tmp_path / "codex-preserve-here"
807780 target .mkdir ()
781+ existing_prompts = target / ".codex" / "prompts"
782+ existing_prompts .mkdir (parents = True )
783+ (existing_prompts / "custom.md" ).write_text ("custom" )
808784 monkeypatch .chdir (target )
809785
810- def fake_download (project_path , * args , ** kwargs ):
811- prompts_dir = project_path / ".codex" / "prompts"
812- prompts_dir .mkdir (parents = True , exist_ok = True )
813- (prompts_dir / "speckit.specify.md" ).write_text ("---\n description: Legacy prompt\n ---\n \n Body.\n " )
814-
815- with patch ("specify_cli.download_and_extract_template" , side_effect = fake_download ), \
786+ with patch ("specify_cli.download_and_extract_template" , return_value = target ), \
816787 patch ("specify_cli.ensure_executable_scripts" ), \
817788 patch ("specify_cli.ensure_constitution_from_template" ), \
818789 patch ("specify_cli.install_ai_skills" , return_value = True ), \
@@ -825,7 +796,8 @@ def fake_download(project_path, *args, **kwargs):
825796 )
826797
827798 assert result .exit_code == 0
828- assert not (target / ".codex" ).exists ()
799+ assert (target / ".codex" ).exists ()
800+ assert (existing_prompts / "custom.md" ).exists ()
829801
830802 def test_commands_preserved_when_skills_fail (self , tmp_path ):
831803 """If skills fail, commands should NOT be removed (safety net)."""
0 commit comments