Skip to content

Commit d98e275

Browse files
committed
test(codex): cover fresh-dir suppression of legacy .codex layout
1 parent 28b4801 commit d98e275

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

src/specify_cli/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,13 @@ def download_and_extract_template(
10851085
elif verbose:
10861086
console.print("[cyan]Flattened nested directory structure[/cyan]")
10871087

1088+
# For fresh-directory Codex skills init, suppress legacy
1089+
# prompt-based layout extracted from older archives.
1090+
if skip_legacy_codex_prompts and ai_assistant == "codex":
1091+
legacy_codex_dir = project_path / ".codex"
1092+
if legacy_codex_dir.is_dir():
1093+
shutil.rmtree(legacy_codex_dir, ignore_errors=True)
1094+
10881095
except Exception as e:
10891096
if tracker:
10901097
tracker.error("extract", str(e))

tests/test_ai_skills.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"""
1212

1313
import re
14+
import zipfile
1415
import pytest
1516
import tempfile
1617
import shutil
@@ -799,6 +800,36 @@ def test_codex_ai_skills_here_mode_preserves_existing_codex_dir(self, tmp_path,
799800
assert (target / ".codex").exists()
800801
assert (existing_prompts / "custom.md").exists()
801802

803+
def test_codex_ai_skills_fresh_dir_does_not_create_codex_dir(self, tmp_path):
804+
"""Fresh-directory Codex skills init should not leave legacy .codex from archive."""
805+
target = tmp_path / "fresh-codex-proj"
806+
archive = tmp_path / "codex-template.zip"
807+
808+
with zipfile.ZipFile(archive, "w") as zf:
809+
zf.writestr("template-root/.codex/prompts/speckit.specify.md", "legacy")
810+
zf.writestr("template-root/.specify/templates/constitution-template.md", "constitution")
811+
812+
fake_meta = {
813+
"filename": archive.name,
814+
"size": archive.stat().st_size,
815+
"release": "vtest",
816+
"asset_url": "https://example.invalid/template.zip",
817+
}
818+
819+
with patch("specify_cli.download_template_from_github", return_value=(archive, fake_meta)):
820+
specify_cli.download_and_extract_template(
821+
target,
822+
"codex",
823+
"sh",
824+
is_current_dir=False,
825+
skip_legacy_codex_prompts=True,
826+
verbose=False,
827+
)
828+
829+
assert target.exists()
830+
assert (target / ".specify").exists()
831+
assert not (target / ".codex").exists()
832+
802833
def test_commands_preserved_when_skills_fail(self, tmp_path):
803834
"""If skills fail, commands should NOT be removed (safety net)."""
804835
from typer.testing import CliRunner

0 commit comments

Comments
 (0)