Skip to content

Open-source skills for designing and reviewing software with AI agents

test: reject blank native read result text

n3wthe99517e1f659
diff --git a/TESTING.md b/TESTING.md
index b0c6edb..8635956 100644
--- a/TESTING.md
+++ b/TESTING.md
@@ -115,7 +115,8 @@ Track open cloud verification gaps in [#105 (Cowork)](https://github.com/google/
Run `pytest tests/unit/test_claude_traces.py` to exercise the Claude probe's
native child validator with synthetic records. A persona read request alone is
not a successful read: require a matching, non-error, nonempty native tool
-result. Missing or unrelated results fail even when the child says `UNKNOWN`.
+result containing non-whitespace text, either as a string or in native text
+blocks. Missing or unrelated results fail even when the child says `UNKNOWN`.
These tests do not invoke models or establish cloud support. A successful tool
result also does not by itself prove that the entire resource was read.
diff --git a/tests/integration/test_claude.py b/tests/integration/test_claude.py
index 8e94c21..3315488 100644
--- a/tests/integration/test_claude.py
+++ b/tests/integration/test_claude.py
@@ -44,8 +44,15 @@ def assert_child_probe(raw: str, persona: Path, markers: list[str]) -> None:
if block["type"] == "text":
answers.append(block["text"])
if (event.get("type") == "user" and block["type"] == "tool_result"
- and not block.get("is_error") and block.get("content")):
- successful.add(block["tool_use_id"])
+ and not block.get("is_error")):
+ result = block.get("content", "")
+ if isinstance(result, list):
+ result = "".join(
+ part["text"] for part in result
+ if part.get("type") == "text" and isinstance(part.get("text"), str)
+ )
+ if isinstance(result, str) and result.strip():
+ successful.add(block["tool_use_id"])
assert answers and answers[-1].strip() == "UNKNOWN"
assert [path for _, path in child_reads] == [str(persona)]
assert all(call_id in successful for call_id, _ in child_reads), (
diff --git a/tests/unit/test_claude_traces.py b/tests/unit/test_claude_traces.py
index 02b0eb1..274e006 100644
--- a/tests/unit/test_claude_traces.py
+++ b/tests/unit/test_claude_traces.py
@@ -3,8 +3,8 @@
"""Offline regression coverage for Claude's native transcript directory."""
-from pathlib import Path, PurePosixPath, PureWindowsPath
import json
+from pathlib import Path, PurePosixPath, PureWindowsPath
import runpy
from unittest.mock import Mock
@@ -44,7 +44,10 @@ def test_trace_directory(
)
[email protected]("result", ["success", "error", "missing", "unrelated", "empty"])
[email protected]("result", [
+ "success", "error", "missing", "unrelated", "empty", "whitespace",
+ "empty_text_block", "whitespace_text_block", "valid_text_blocks",
+])
def test_child_probe_requires_successful_read(result: str) -> None:
check = runpy.run_path(str(ROOT / "tests/integration/test_claude.py"))[
"assert_child_probe"
@@ -55,17 +58,27 @@ def test_child_probe_requires_successful_read(result: str) -> None:
"input": {"file_path": str(persona)},
}]}}]
if result != "missing":
+ content = {
+ "empty": "",
+ "whitespace": " \t\n",
+ "empty_text_block": [{"type": "text", "text": ""}],
+ "whitespace_text_block": [{"type": "text", "text": " \t\n"}],
+ "valid_text_blocks": [
+ {"type": "text", "text": ""},
+ {"type": "text", "text": "Persona text"},
+ ],
+ }.get(result, "Persona text")
events.append({"type": "user", "message": {"content": [{
"type": "tool_result",
"tool_use_id": "other-read" if result == "unrelated" else "read-persona",
"is_error": result == "error",
- "content": "" if result == "empty" else "Persona text",
+ "content": content,
}]}})
events.append({"type": "assistant", "message": {"content": [{
"type": "text", "text": "UNKNOWN",
}]}})
raw = "\n".join(json.dumps(event) for event in events)
- if result == "success":
+ if result in {"success", "valid_text_blocks"}:
check(raw, persona, ["parent-only-marker"])
else:
with pytest.raises(AssertionError, match="successful native tool result"):