Skip to content

Commit e292a1c

Browse files
committed
fix(offline): address third round of review comments
- Add 120s timeout to subprocess.run in scaffold_from_core_pack to prevent indefinite hangs during offline scaffolding - Add test_pyproject_force_include_covers_all_templates to catch missing template files in wheel bundling - Tighten kiro alias test to assert specific scaffold path (download vs offline)
1 parent 50ebe97 commit e292a1c

File tree

3 files changed

+54
-12
lines changed

3 files changed

+54
-12
lines changed

src/specify_cli/__init__.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,10 +1158,19 @@ def scaffold_from_core_pack(
11581158
env["AGENTS"] = ai_assistant
11591159
env["SCRIPTS"] = script_type
11601160

1161-
result = subprocess.run(
1162-
cmd, cwd=str(tmp), env=env,
1163-
capture_output=True, text=True,
1164-
)
1161+
try:
1162+
result = subprocess.run(
1163+
cmd, cwd=str(tmp), env=env,
1164+
capture_output=True, text=True,
1165+
timeout=120,
1166+
)
1167+
except subprocess.TimeoutExpired:
1168+
msg = "release script timed out after 120 seconds"
1169+
if tracker:
1170+
tracker.error("scaffold", msg)
1171+
else:
1172+
console.print(f"[red]Error:[/red] {msg}")
1173+
return False
11651174

11661175
if result.returncode != 0:
11671176
msg = result.stderr.strip() or result.stdout.strip() or "unknown error"

tests/test_ai_skills.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -795,14 +795,14 @@ def test_kiro_alias_normalized_to_kiro_cli(self, tmp_path):
795795
)
796796

797797
assert result.exit_code == 0
798-
# Alias normalisation should have happened regardless of scaffold path used.
799-
# Either scaffold_from_core_pack or download_and_extract_template may be called
800-
# depending on whether bundled assets are present; check the one that was called.
801-
if mock_scaffold.called:
802-
assert mock_scaffold.call_args.args[1] == "kiro-cli"
803-
else:
804-
assert mock_download.called
805-
assert mock_download.call_args.args[1] == "kiro-cli"
798+
# Without --offline, the download path should be taken.
799+
assert mock_download.called, (
800+
"Expected download_and_extract_template to be called (default non-offline path)"
801+
)
802+
assert mock_download.call_args.args[1] == "kiro-cli"
803+
assert not mock_scaffold.called, (
804+
"scaffold_from_core_pack should not be called without --offline"
805+
)
806806

807807
def test_q_removed_from_agent_config(self):
808808
"""Amazon Q legacy key should not remain in AGENT_CONFIG."""

tests/test_core_pack_scaffold.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,3 +526,36 @@ def test_parity_bundled_vs_release_script(tmp_path, agent):
526526
f"Agent '{agent}': file '{name}' content differs between "
527527
f"bundled output and release script ZIP"
528528
)
529+
530+
531+
# ---------------------------------------------------------------------------
532+
# Section 10 – pyproject.toml force-include covers all template files
533+
# ---------------------------------------------------------------------------
534+
535+
def test_pyproject_force_include_covers_all_templates():
536+
"""Every file in templates/ (excluding commands/) must be listed in
537+
pyproject.toml's [tool.hatch.build.targets.wheel.force-include] section.
538+
539+
This prevents new template files from being silently omitted from the
540+
wheel, which would break ``specify init --offline``.
541+
"""
542+
templates_dir = _REPO_ROOT / "templates"
543+
# Collect all files directly in templates/ (not in subdirectories like commands/)
544+
repo_template_files = sorted(
545+
f.name for f in templates_dir.iterdir()
546+
if f.is_file()
547+
)
548+
assert repo_template_files, "Expected at least one template file in templates/"
549+
550+
pyproject_path = _REPO_ROOT / "pyproject.toml"
551+
pyproject_text = pyproject_path.read_text()
552+
553+
missing = [
554+
name for name in repo_template_files
555+
if f"templates/{name}" not in pyproject_text
556+
]
557+
assert not missing, (
558+
f"Template files not listed in pyproject.toml force-include "
559+
f"(offline scaffolding will miss them):\n "
560+
+ "\n ".join(missing)
561+
)

0 commit comments

Comments
 (0)