Skip to content

Commit 5fd76c9

Browse files
marcelsafinCopilot
andcommitted
fix(cli): preserve shell fallback without preference
Co-authored-by: Copilot <[email protected]>
1 parent 158a773 commit 5fd76c9

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

‎src/specify_cli/integrations/base.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,13 @@ def select_script_variant(
644644
platform_variant = (
645645
"ps" if platform.system().lower().startswith("win") else "sh"
646646
)
647-
for candidate in (platform_variant, "py"):
647+
secondary_variant = "sh" if platform_variant == "ps" else "ps"
648+
fallbacks = (
649+
(platform_variant, "py")
650+
if requested == "py"
651+
else (platform_variant, secondary_variant, "py")
652+
)
653+
for candidate in fallbacks:
648654
if candidate in script_commands:
649655
return candidate
650656

‎tests/test_command_template_py_scripts.py‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,35 @@ def test_template_renders_python_invocation(name: str):
8484

8585

8686
def test_py_missing_variant_rejects_opposite_shell_only():
87+
opposite_variant = "sh" if os.name == "nt" else "ps"
88+
opposite_command = (
89+
"scripts/bash/setup-plan.sh --json"
90+
if opposite_variant == "sh"
91+
else "scripts/powershell/setup-plan.ps1 -Json"
92+
)
8793
content = """---
8894
scripts:
89-
ps: scripts/powershell/setup-plan.ps1 -Json
95+
{variant}: {command}
9096
---
91-
Run {SCRIPT} now.
92-
"""
97+
Run {{SCRIPT}} now.
98+
""".format(variant=opposite_variant, command=opposite_command)
9399

94100
with pytest.raises(ValueError, match="No runnable script variant"):
95101
IntegrationBase.process_template(content, "agent", "py")
96102

97103

104+
def test_missing_script_preference_keeps_available_shell(monkeypatch):
105+
monkeypatch.setattr(
106+
"specify_cli.integrations.base.platform.system", lambda: "Windows"
107+
)
108+
109+
selected = IntegrationBase.select_script_variant(
110+
None, {"sh": "scripts/bash/setup-plan.sh --json"}
111+
)
112+
113+
assert selected == "sh"
114+
115+
98116
def test_spaced_python_interpreter_uses_powershell_call_operator(monkeypatch):
99117
interpreter = r"C:\Program Files\Py$thon's\python.exe"
100118
quoted_interpreter = interpreter.replace("'", "''")

0 commit comments

Comments
 (0)