fix: spawn_test never raises — coerce env/command to str, wrap unexpected errors (#34)
Closes #34 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -326,6 +326,42 @@ def test_spawn_test_large_stderr_does_not_deadlock():
|
||||
assert len(r["stderr"]) <= c._STDERR_CAP
|
||||
|
||||
|
||||
def test_spawn_test_non_string_env_value():
|
||||
# Pasted JSON can carry numeric env values ("env": {"PORT": 8080}) that never
|
||||
# round-trip through the editor. Popen rejects non-str env; spawn_test must
|
||||
# coerce instead of letting TypeError escape (which would leave the GUI's
|
||||
# Test launch / Test all buttons stuck disabled).
|
||||
r = c.spawn_test(
|
||||
{
|
||||
"command": sys.executable,
|
||||
"args": ["-c", "import os; raise SystemExit(0 if os.environ['PORT'] == '8080' else 1)"],
|
||||
"env": {"PORT": 8080},
|
||||
},
|
||||
timeout=2.0,
|
||||
)
|
||||
assert r["outcome"] == "exited"
|
||||
assert r["returncode"] == 0
|
||||
|
||||
|
||||
def test_spawn_test_non_string_command():
|
||||
# A non-string command must classify, not raise (str(123) resolves to nothing).
|
||||
r = c.spawn_test({"command": 123}, timeout=0.3)
|
||||
assert r["outcome"] == "not_found"
|
||||
|
||||
|
||||
def test_spawn_test_internal_error_yields_result(monkeypatch):
|
||||
# Any unexpected exception inside the spawn path must come back as a result
|
||||
# dict (outcome "error"), never escape — the UI only re-enables its buttons
|
||||
# when a result arrives.
|
||||
def boom(*a, **k):
|
||||
raise RuntimeError("simulated internal failure")
|
||||
|
||||
monkeypatch.setattr(c.shutil, "which", boom)
|
||||
r = c.spawn_test({"command": "python3"}, timeout=0.3)
|
||||
assert r["outcome"] == "error"
|
||||
assert "simulated internal failure" in r["detail"]
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# 8. Backup restore
|
||||
# --------------------------------------------------------------------------- #
|
||||
|
||||
Reference in New Issue
Block a user