Skip to content

Commit 1634fe9

Browse files
doquanghuyclaude
andcommitted
test(shell): emit JSON via sys.executable for cross-platform output_format tests
Address review (#2963): replace non-portable echo '{...}' (Windows cmd.exe keeps the single quotes, breaking JSON) with the established '"{py}" "{script}"' pattern using sys.executable + a temp script, so the output_format tests pass on the Windows CI matrix. Also make the validate test's run inert (exit 0). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 00ecbf1 commit 1634fe9

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

tests/test_workflows.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -945,11 +945,18 @@ def test_output_format_json_exposes_data(self, tmp_path):
945945
from specify_cli.workflows.steps.shell import ShellStep
946946
from specify_cli.workflows.base import StepContext, StepStatus
947947

948+
import sys
949+
950+
py = sys.executable
951+
script = tmp_path / "emit.py"
952+
script.write_text(
953+
'import json; print(json.dumps({"items": [1, 2]}))\n', encoding="utf-8"
954+
)
948955
step = ShellStep()
949956
ctx = StepContext(project_root=str(tmp_path))
950957
config = {
951958
"id": "emit",
952-
"run": "echo '{\"items\": [1, 2]}'",
959+
"run": f'"{py}" "{script}"',
953960
"output_format": "json",
954961
}
955962
result = step.execute(config, ctx)
@@ -961,11 +968,16 @@ def test_output_format_json_invalid_stdout_fails(self, tmp_path):
961968
from specify_cli.workflows.steps.shell import ShellStep
962969
from specify_cli.workflows.base import StepContext, StepStatus
963970

971+
import sys
972+
973+
py = sys.executable
974+
script = tmp_path / "emit.py"
975+
script.write_text("print('not-json')\n", encoding="utf-8")
964976
step = ShellStep()
965977
ctx = StepContext(project_root=str(tmp_path))
966978
config = {
967979
"id": "emit",
968-
"run": "echo not-json",
980+
"run": f'"{py}" "{script}"',
969981
"output_format": "json",
970982
}
971983
result = step.execute(config, ctx)
@@ -976,9 +988,16 @@ def test_no_output_format_keeps_raw_output_only(self, tmp_path):
976988
from specify_cli.workflows.steps.shell import ShellStep
977989
from specify_cli.workflows.base import StepContext, StepStatus
978990

991+
import sys
992+
993+
py = sys.executable
994+
script = tmp_path / "emit.py"
995+
script.write_text(
996+
'import json; print(json.dumps({"items": []}))\n', encoding="utf-8"
997+
)
979998
step = ShellStep()
980999
ctx = StepContext(project_root=str(tmp_path))
981-
config = {"id": "emit", "run": "echo '{\"items\": []}'"}
1000+
config = {"id": "emit", "run": f'"{py}" "{script}"'}
9821001
result = step.execute(config, ctx)
9831002
assert result.status == StepStatus.COMPLETED
9841003
assert "data" not in result.output
@@ -987,7 +1006,7 @@ def test_validate_rejects_unknown_output_format(self):
9871006
from specify_cli.workflows.steps.shell import ShellStep
9881007

9891008
step = ShellStep()
990-
errors = step.validate({"id": "emit", "run": "true", "output_format": "yaml"})
1009+
errors = step.validate({"id": "emit", "run": "exit 0", "output_format": "yaml"})
9911010
assert any("'output_format' must be 'json'" in e for e in errors)
9921011

9931012
class _StubStdin:

0 commit comments

Comments
 (0)