openclaw-session-amplifier / tests /session_snapshot_smoke.py
Ordo
Initial public release
63c75d5
#!/usr/bin/env python3
"""Standalone smoke test for session snapshot generation.
This intentionally avoids pytest so the sidecar can be checked in constrained
gateway/runtime shells where pytest is not installed.
"""
import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
from reviewer import session_snapshot as snap
def main() -> int:
summary = {
"session_id": "s1",
"agent_id": "ops",
"last_event_at": "2026-05-12T12:00:00+00:00",
"event_count": 4,
"tool_result_count": 2,
"error_count": 1,
"noisy_tool_results": 0,
"last_entry_idx": 4,
"hints": ["1 error(s)"],
}
activity = [
{"session_id": "s1", "agent_id": "ops", "entry_idx": 1, "role": "user", "preview": "deploy to Cloud Run?", "clean_text": "deploy to Cloud Run?", "is_error": 0},
{"session_id": "s1", "agent_id": "ops", "entry_idx": 2, "role": "toolResult", "tool_name": "exec", "preview": "permission denied", "clean_text": "permission denied", "is_error": 1},
]
original_activity = snap.get_session_activity
original_recent = snap.get_recent_sessions
try:
snap.get_session_activity = lambda session_id, limit: activity
result = snap.build_session_snapshot(summary, activity_limit=20)
assert result["schema"] == "openclaw.session.v1"
assert result["id"] == "s1"
assert result["state"]["state"] == "warning"
assert "approval_or_permission" in result["risk"]["flags"]
assert "external_infra" in result["risk"]["flags"]
assert result["outputs"]["recent_events"][1]["event_type"] == "tool_error"
snap.get_recent_sessions = lambda limit: [summary]
collection = snap.build_recent_session_snapshots(limit=1, activity_limit=1)
assert collection["schema"] == "openclaw.session.v1.collection"
assert collection["count"] == 1
finally:
snap.get_session_activity = original_activity
snap.get_recent_sessions = original_recent
print("session_snapshot_smoke: ok")
return 0
if __name__ == "__main__":
raise SystemExit(main())