Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def result_content(
)
for event_file in event_files:
matches: list[tuple[bool | None, dict[str, Any]]] = []
matching_call_ids: set[str] = set()
with event_file.open(encoding="utf-8") as handle:
for line in handle:
if not line.strip():
Expand All @@ -58,14 +59,29 @@ def result_content(
event = json.loads(line)
except json.JSONDecodeError:
continue
if event.get("type") != "tool.execution_complete":
continue
data = event.get("data")
if not isinstance(data, dict):
continue
if event.get("type") == "tool.execution_start":
arguments = data.get("arguments")
call_id = data.get("toolCallId")
if (
data.get("toolName") == "session_store_sql"
and isinstance(arguments, dict)
and arguments.get("query") == sql
and isinstance(call_id, str)
):
matching_call_ids.add(call_id)
continue
if event.get("type") != "tool.execution_complete":
continue
result = data.get("result")
if not isinstance(result, dict):
continue
call_id = data.get("toolCallId")
if isinstance(call_id, str) and call_id in matching_call_ids:
matches.append((data.get("success"), result))
continue
detailed = result.get("detailedContent")
sql_match = (
DETAILED_SQL_RE.fullmatch(detailed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,44 @@ def test_matches_detailed_content_with_sql_and_rendered_result(self) -> None:

self.assertEqual(content, materializer.result_content(events_root, sql))

def test_matches_completion_by_exact_start_event_sql(self) -> None:
with tempfile.TemporaryDirectory() as temporary:
events_root = Path(temporary)
event_dir = events_root / "session-1"
event_dir.mkdir()
sql = "SELECT id AS session_id, updated_at FROM sessions"
content = "Query returned 0 rows."
events = [
{
"type": "tool.execution_start",
"data": {
"toolCallId": "call-1",
"toolName": "session_store_sql",
"arguments": {
"description": "Discover repository sessions",
"query": sql,
},
},
},
{
"type": "tool.execution_complete",
"data": {
"toolCallId": "call-1",
"success": True,
"result": {
"content": content,
"detailedContent": "SQL omitted from detailed output",
},
},
},
]
(event_dir / "events.jsonl").write_text(
"".join(json.dumps(event) + "\n" for event in events),
encoding="utf-8",
)

self.assertEqual(content, materializer.result_content(events_root, sql))

def test_skips_malformed_event_log_lines_before_a_match(self) -> None:
with tempfile.TemporaryDirectory() as temporary:
events_root = Path(temporary)
Expand Down