Skip to content

The agent that grows with you

fix(agent): skip interpreter flags only for Python when matching verify commands

Tekniumfb83d824c1cc
diff --git a/agent/verification_evidence.py b/agent/verification_evidence.py
index 695d59f8f2e..c67a627f1e4 100644
--- a/agent/verification_evidence.py
+++ b/agent/verification_evidence.py
@@ -313,14 +313,16 @@ def _is_harmless_interpreter_flag(token: str) -> bool:
def _normalize_tokens(tokens: list[str]) -> list[str]:
- """Comparison form: no leading ``./``, interpreters collapsed, harmless flags dropped."""
+ """Comparison form: no leading ``./``, interpreters collapsed, Python's harmless flags
+ dropped. Only Python's: the same letters mean other things elsewhere (``bash -s``
+ reads commands from stdin and never runs the script named after it)."""
normalized: list[str] = []
i = 0
while i < len(tokens):
family = _interpreter_family(tokens[i])
normalized.append(family or re.sub(r"^(?:\./)+", "", tokens[i]))
i += 1
- if family:
+ if family == "python":
while i < len(tokens) and _is_harmless_interpreter_flag(tokens[i]):
i += 2 if tokens[i] in {"-W", "-X"} else 1
return normalized
diff --git a/tests/agent/test_verification_evidence.py b/tests/agent/test_verification_evidence.py
index bf1d08b1fc4..ba3e8b1ca01 100644
--- a/tests/agent/test_verification_evidence.py
+++ b/tests/agent/test_verification_evidence.py
@@ -188,6 +188,17 @@ def test_dot_slash_script_invocation_matches_detected_script(tmp_path, monkeypat
assert evidence.canonical_command == "scripts/run_tests.sh"
[email protected]("command", ["bash -s scripts/run_tests.sh", "sh -s scripts/run_tests.sh"])
+def test_shell_flag_that_skips_the_script_is_not_evidence(tmp_path, monkeypatch, command):
+ """``bash -s`` reads commands from stdin: the script named after it never runs."""
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path / ".hermes"))
+ _node_project(tmp_path)
+
+ assert classify_verification_command(
+ command, cwd=tmp_path, session_id="s1", exit_code=0,
+ ) is None
+
+
@pytest.mark.parametrize(
"command",
["timeout 300 pytest -q", "nice -n 5 pytest -q", "timeout 5m pytest -q", "timeout -s KILL 300 pytest -q"],