Skip to content

Commit 9af802a

Browse files
test: load overlap blob from fixture and tighten minimal bash asserts
Read the task_message overlap toolUseResult from real_session_all_tool_types instead of duplicating an inline dict. Pin minimal fixture bash stdout, exit code, and message index. Document JSONDecodeError skip path in malformed_lines.
1 parent f9f0d7f commit 9af802a

3 files changed

Lines changed: 33 additions & 12 deletions

File tree

scripts/gen_real_session_fixtures.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ def write_malformed_lines() -> None:
243243
for obj in valid:
244244
f.write(_line(obj))
245245
f.write("\n")
246+
f.write(
247+
"# parse_session skips lines where json.loads raises JSONDecodeError "
248+
"(blank, garbage, truncated JSON below).\n"
249+
)
246250
f.write("{not valid json\n")
247251
f.write('{"type": "user", "timestamp": "2026-05-26T10:02:00Z", "message": {"content": ')
248252
f.write("\n")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{"type": "user", "timestamp": "2026-05-26T10:00:00Z", "cwd": "/sanitized/project/path", "message": {"content": [{"type": "text", "text": "Valid line before malformed section"}]}, "sessionId": "session-sanitized-malformed-lines"}
22
{"type": "assistant", "timestamp": "2026-05-26T10:01:00Z", "message": {"model": "claude-sanitized", "content": [{"type": "text", "text": "Recovered after bad lines."}], "usage": {"input_tokens": 10, "output_tokens": 5}}, "sessionId": "session-sanitized-malformed-lines"}
33

4+
# parse_session skips lines where json.loads raises JSONDecodeError (blank, garbage, truncated JSON below).
45
{not valid json
56
{"type": "user", "timestamp": "2026-05-26T10:02:00Z", "message": {"content":
67
{"type": "user", "timestamp": "2026-05-26T10:03:00Z", "cwd": "/sanitized/project/path", "message": {"content": [{"type": "text", "text": "Valid line after malformed section"}]}, "toolUseResult": {"stderr": "warn only", "exitCode": 1}, "sessionId": "session-sanitized-malformed-lines"}

tests/test_real_session_fixtures.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,27 @@ def _fixture_path(name: str) -> str:
2525
return os.path.join(FIXTURES_DIR, name)
2626

2727

28+
def _overlap_tool_result_from_all_tool_types_fixture() -> dict:
29+
"""Last toolUseResult in real_session_all_tool_types (task_message overlap blob)."""
30+
path = _fixture_path("real_session_all_tool_types.jsonl")
31+
overlap: dict | None = None
32+
with open(path, encoding="utf-8") as f:
33+
for line in f:
34+
line = line.strip()
35+
if not line or line.startswith("#"):
36+
continue
37+
entry = json.loads(line)
38+
tr = entry.get("toolUseResult")
39+
if isinstance(tr, dict) and tr.get("agentId") == "agent-sanitized-overlap":
40+
overlap = tr
41+
if overlap is None:
42+
pytest.fail(
43+
"overlap toolUseResult (agent-sanitized-overlap) missing from "
44+
"real_session_all_tool_types.jsonl"
45+
)
46+
return overlap
47+
48+
2849
def _assert_session_shape(session: dict) -> None:
2950
assert isinstance(session["session_id"], str) and session["session_id"]
3051
assert isinstance(session["title"], str) and session["title"] not in (
@@ -61,12 +82,12 @@ def test_real_fixture_parses_with_expected_message_count(
6182

6283
def test_real_session_minimal_has_bash_tool_result() -> None:
6384
session = parse_session(_fixture_path("real_session_minimal.jsonl"))
64-
parsed_types = [
65-
m["tool_result_parsed"]["result_type"]
66-
for m in session["messages"]
67-
if m.get("tool_result_parsed")
68-
]
69-
assert "bash" in parsed_types
85+
assert len(session["messages"]) == _FIXTURE_MESSAGE_COUNTS["real_session_minimal.jsonl"]
86+
parsed = session["messages"][2]["tool_result_parsed"]
87+
assert parsed is not None
88+
assert parsed["result_type"] == "bash"
89+
assert parsed["stdout"] == "sanitized output\n"
90+
assert parsed["exit_code"] == 0
7091

7192

7293
def test_real_session_all_tool_types_covers_dispatch_predicates() -> None:
@@ -152,12 +173,7 @@ def test_task_completed_with_message_key_matches_task_message_first() -> None:
152173

153174

154175
def test_overlap_blob_from_all_tool_types_fixture_locks_task_message_order() -> None:
155-
tr = {
156-
"agentId": "agent-sanitized-overlap",
157-
"totalDurationMs": 500,
158-
"status": "completed",
159-
"message": "status update sanitized",
160-
}
176+
tr = _overlap_tool_result_from_all_tool_types_fixture()
161177
result = _parse_tool_result(tr)
162178
assert result is not None
163179
assert result["result_type"] == "task"

0 commit comments

Comments
 (0)