mirror of
https://github.com/HKUDS/CLI-Anything.git
synced 2026-10-02 02:44:51 +08:00
test(godot): add regression tests for stderr parse-error detection
Per review on #335: mock the Godot backend with returncode == 0 and a parse-error marker in stderr, assert validate_script reports valid=False and surfaces stderr in errors. Also cover the positive zero-stderr case, benign stderr noise (warnings), and the nonzero-returncode path. Verified the parse-error test fails against the pre-fix validate_script (returncode-only check) and passes with the stderr scan. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
a0ab4c7710
commit
34f762448d
@@ -273,6 +273,66 @@ class TestBackend:
|
||||
assert result is not None
|
||||
|
||||
|
||||
# ── Script validation tests ────────────────────────────────────────────
|
||||
|
||||
class TestValidateScript:
|
||||
"""Regression tests for #335: Godot 4.6.x exits 0 on parse errors,
|
||||
so validate_script must also scan stderr for error markers."""
|
||||
|
||||
@staticmethod
|
||||
def _godot_result(returncode=0, stdout="", stderr=""):
|
||||
return {"returncode": returncode, "stdout": stdout, "stderr": stderr}
|
||||
|
||||
def test_parse_error_with_zero_returncode_is_invalid(self, tmp_project):
|
||||
from cli_anything.godot.core.script import validate_script
|
||||
stderr = (
|
||||
"SCRIPT ERROR: Parse Error: Expected end of statement after "
|
||||
'expression, found ":" instead.\n'
|
||||
" at: GDScript::reload (res://scripts/player.gd:3)"
|
||||
)
|
||||
with mock.patch(
|
||||
"cli_anything.godot.core.script.run_godot",
|
||||
return_value=self._godot_result(returncode=0, stderr=stderr),
|
||||
):
|
||||
result = validate_script(str(tmp_project), "scripts/player.gd")
|
||||
assert result["status"] == "ok"
|
||||
assert result["valid"] is False
|
||||
assert "Parse Error" in result["errors"]
|
||||
|
||||
def test_clean_script_with_zero_stderr_is_valid(self, tmp_project):
|
||||
from cli_anything.godot.core.script import validate_script
|
||||
with mock.patch(
|
||||
"cli_anything.godot.core.script.run_godot",
|
||||
return_value=self._godot_result(returncode=0, stderr=""),
|
||||
):
|
||||
result = validate_script(str(tmp_project), "scripts/player.gd")
|
||||
assert result["status"] == "ok"
|
||||
assert result["valid"] is True
|
||||
assert result["errors"] == ""
|
||||
|
||||
def test_benign_stderr_noise_is_still_valid(self, tmp_project):
|
||||
from cli_anything.godot.core.script import validate_script
|
||||
stderr = "WARNING: Blend file import is enabled in the project settings.\n"
|
||||
with mock.patch(
|
||||
"cli_anything.godot.core.script.run_godot",
|
||||
return_value=self._godot_result(returncode=0, stderr=stderr),
|
||||
):
|
||||
result = validate_script(str(tmp_project), "scripts/player.gd")
|
||||
assert result["valid"] is True
|
||||
assert result["errors"] == ""
|
||||
|
||||
def test_nonzero_returncode_is_invalid(self, tmp_project):
|
||||
from cli_anything.godot.core.script import validate_script
|
||||
stderr = "Failed to load script res://scripts/player.gd\n"
|
||||
with mock.patch(
|
||||
"cli_anything.godot.core.script.run_godot",
|
||||
return_value=self._godot_result(returncode=1, stderr=stderr),
|
||||
):
|
||||
result = validate_script(str(tmp_project), "scripts/player.gd")
|
||||
assert result["valid"] is False
|
||||
assert "Failed to load script" in result["errors"]
|
||||
|
||||
|
||||
# ── CLI root tests ─────────────────────────────────────────────────────
|
||||
|
||||
class TestCLIRoot:
|
||||
|
||||
Reference in New Issue
Block a user