Import AITURK IDE 1.0.0-beta.1 from Hermes 63279301; preserve MIT license
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
"""Tests for terminal command exit code semantic interpretation."""
|
||||
|
||||
import pytest
|
||||
|
||||
from tools.terminal_tool import _interpret_exit_code
|
||||
|
||||
|
||||
class TestInterpretExitCode:
|
||||
"""Test _interpret_exit_code returns correct notes for known command semantics."""
|
||||
|
||||
# ---- exit code 0 always returns None ----
|
||||
|
||||
def test_success_returns_none(self):
|
||||
assert _interpret_exit_code("grep foo bar", 0) is None
|
||||
assert _interpret_exit_code("diff a b", 0) is None
|
||||
assert _interpret_exit_code("test -f /etc/passwd", 0) is None
|
||||
|
||||
# ---- grep / rg family: exit 1 = no matches ----
|
||||
|
||||
@pytest.mark.parametrize("cmd", [
|
||||
"grep 'pattern' file.txt",
|
||||
"egrep 'pattern' file.txt",
|
||||
"fgrep 'pattern' file.txt",
|
||||
"rg 'foo' .",
|
||||
"ag 'foo' .",
|
||||
"ack 'foo' .",
|
||||
])
|
||||
def test_grep_family_no_matches(self, cmd):
|
||||
result = _interpret_exit_code(cmd, 1)
|
||||
assert result is not None
|
||||
assert "no matches" in result.lower()
|
||||
|
||||
|
||||
# ---- diff: exit 1 = files differ ----
|
||||
|
||||
def test_diff_files_differ(self):
|
||||
result = _interpret_exit_code("diff file1 file2", 1)
|
||||
assert result is not None
|
||||
assert "differ" in result.lower()
|
||||
|
||||
def test_colordiff_files_differ(self):
|
||||
result = _interpret_exit_code("colordiff file1 file2", 1)
|
||||
assert result is not None
|
||||
assert "differ" in result.lower()
|
||||
|
||||
|
||||
# ---- test / [: exit 1 = condition false ----
|
||||
|
||||
def test_test_condition_false(self):
|
||||
result = _interpret_exit_code("test -f /nonexistent", 1)
|
||||
assert result is not None
|
||||
assert "false" in result.lower()
|
||||
|
||||
|
||||
# ---- find: exit 1 = partial success ----
|
||||
|
||||
|
||||
# ---- curl: various informational codes ----
|
||||
|
||||
|
||||
# ---- git: exit 1 is context-dependent ----
|
||||
|
||||
|
||||
# ---- pipeline / chain handling ----
|
||||
|
||||
|
||||
# ---- full paths ----
|
||||
|
||||
|
||||
# ---- env var prefix ----
|
||||
|
||||
|
||||
# ---- unknown commands return None ----
|
||||
|
||||
|
||||
# ---- edge cases ----
|
||||
|
||||
|
||||
def test_only_env_vars(self):
|
||||
"""Command with only env var assignments, no actual command."""
|
||||
assert _interpret_exit_code("FOO=bar", 1) is None
|
||||
Reference in New Issue
Block a user