fix: resolve test failures blocking CI pipeline (OPC mock, route ordering, system stats)
Run Tests / Secret Detection (pull_request) Failing after 42s
Run Tests / Backend Tests (pull_request) Successful in 32m26s
Run Tests / Frontend Tests (pull_request) Failing after 26s
Deploy Dashboard (Dev) / Backend Tests (push) Successful in 30m35s
Deploy Dashboard (Dev) / Frontend Tests (push) Failing after 16m37s
Deploy Dashboard (Dev) / Deploy to Dev (push) Has been skipped

- Add agent fetchrow to OPC mock to fix "Task or agent not found" errors
- Reorder conversation tracker routes: /search, /stats, /trigger before /{session_id}
- Fix test_task_creator_tracked_in_metadata to expect token username (testuser)
- Mock shutil/psutil in system stats test for non-Synology environments

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Gan, Jimmy
2026-05-03 22:15:12 +08:00
parent 56a8ff28ad
commit 0a497ca0f1
4 changed files with 127 additions and 94 deletions
@@ -87,95 +87,6 @@ async def list_conversations(
} for r in rows]
@router.get("/{session_id}")
async def get_conversation(session_id: str):
"""Get conversation details"""
async with await _db() as db:
# Get conversation metadata
cursor = await db.execute("""
SELECT project_path, git_branch, slug, started_at, last_updated_at,
message_count, total_input_tokens, total_output_tokens, model
FROM conversations
WHERE session_id = ?
""", (session_id,))
conv = await cursor.fetchone()
if not conv:
raise HTTPException(404, "Conversation not found")
# Get message count
cursor = await db.execute("""
SELECT COUNT(*) FROM messages WHERE session_id = ?
""", (session_id,))
msg_count = (await cursor.fetchone())[0]
return {
"session_id": session_id,
"project_path": conv[0],
"git_branch": conv[1],
"slug": conv[2],
"started_at": conv[3],
"last_updated_at": conv[4],
"message_count": msg_count,
"total_input_tokens": conv[6],
"total_output_tokens": conv[7],
"model": conv[8]
}
@router.get("/{session_id}/messages")
async def get_messages(
session_id: str,
limit: int = Query(100, le=500),
offset: int = 0
):
"""Get messages for a conversation"""
async with await _db() as db:
cursor = await db.execute("""
SELECT message_uuid, role, content_text, timestamp, model,
input_tokens, output_tokens, has_tool_use, has_thinking
FROM messages
WHERE session_id = ?
ORDER BY timestamp
LIMIT ? OFFSET ?
""", (session_id, limit, offset))
rows = await cursor.fetchall()
messages = []
for r in rows:
msg = {
"uuid": r[0],
"role": r[1],
"content": r[2],
"timestamp": r[3],
"model": r[4],
"input_tokens": r[5],
"output_tokens": r[6],
"has_tool_use": bool(r[7]),
"has_thinking": bool(r[8]),
"tool_calls": []
}
# Get tool calls for this message
if msg["has_tool_use"]:
cursor2 = await db.execute("""
SELECT tool_name, tool_input, tool_result, is_error
FROM tool_calls
WHERE message_uuid = ?
""", (r[0],))
tool_rows = await cursor2.fetchall()
msg["tool_calls"] = [{
"name": tr[0],
"input": tr[1],
"result": tr[2],
"is_error": bool(tr[3])
} for tr in tool_rows]
messages.append(msg)
return messages
@router.get("/search")
async def search_conversations(
q: str = Query(..., min_length=2),
@@ -284,3 +195,92 @@ async def trigger_summary():
f.write("1")
return {"status": "triggered"}
@router.get("/{session_id}")
async def get_conversation(session_id: str):
"""Get conversation details"""
async with await _db() as db:
# Get conversation metadata
cursor = await db.execute("""
SELECT project_path, git_branch, slug, started_at, last_updated_at,
message_count, total_input_tokens, total_output_tokens, model
FROM conversations
WHERE session_id = ?
""", (session_id,))
conv = await cursor.fetchone()
if not conv:
raise HTTPException(404, "Conversation not found")
# Get message count
cursor = await db.execute("""
SELECT COUNT(*) FROM messages WHERE session_id = ?
""", (session_id,))
msg_count = (await cursor.fetchone())[0]
return {
"session_id": session_id,
"project_path": conv[0],
"git_branch": conv[1],
"slug": conv[2],
"started_at": conv[3],
"last_updated_at": conv[4],
"message_count": msg_count,
"total_input_tokens": conv[6],
"total_output_tokens": conv[7],
"model": conv[8]
}
@router.get("/{session_id}/messages")
async def get_messages(
session_id: str,
limit: int = Query(100, le=500),
offset: int = 0
):
"""Get messages for a conversation"""
async with await _db() as db:
cursor = await db.execute("""
SELECT message_uuid, role, content_text, timestamp, model,
input_tokens, output_tokens, has_tool_use, has_thinking
FROM messages
WHERE session_id = ?
ORDER BY timestamp
LIMIT ? OFFSET ?
""", (session_id, limit, offset))
rows = await cursor.fetchall()
messages = []
for r in rows:
msg = {
"uuid": r[0],
"role": r[1],
"content": r[2],
"timestamp": r[3],
"model": r[4],
"input_tokens": r[5],
"output_tokens": r[6],
"has_tool_use": bool(r[7]),
"has_thinking": bool(r[8]),
"tool_calls": []
}
# Get tool calls for this message
if msg["has_tool_use"]:
cursor2 = await db.execute("""
SELECT tool_name, tool_input, tool_result, is_error
FROM tool_calls
WHERE message_uuid = ?
""", (r[0],))
tool_rows = await cursor2.fetchall()
msg["tool_calls"] = [{
"name": tr[0],
"input": tr[1],
"result": tr[2],
"is_error": bool(tr[3])
} for tr in tool_rows]
messages.append(msg)
return messages