| from server import events as bus |
| from server.agent import run_agent_stream |
|
|
|
|
| def test_emit_and_recent(): |
| before = len(bus.recent(999)) |
| bus.emit("model", "unit test", latency_ms=12) |
| after = bus.recent(999) |
| assert len(after) >= before + 1 |
| assert after[0]["stage"] == "model" and after[0]["latency_ms"] == 12 |
|
|
|
|
| def test_run_scope_groups_events(): |
| with bus.run_scope("unit") as rid: |
| bus.emit("model", "a") |
| bus.emit("decision", "b") |
| runs = dict(bus.recent_runs(50)) |
| assert rid in runs |
| assert len(runs[rid]) == 2 |
|
|
|
|
| def test_streamed_run_produces_trace(): |
| for _ in run_agent_stream("lunch 1pm tomorrow", images=["data:image/png;base64,xx"]): |
| pass |
| |
| _, evs = bus.recent_runs(1)[0] |
| stages = {e["stage"] for e in evs} |
| assert {"vision", "model", "decision"} <= stages |
|
|
|
|
| def test_metrics_and_stage_counts_shapes(): |
| m = bus.metrics() |
| assert {"messages", "events_created", "conflicts", "model_calls"} <= set(m) |
| counts = bus.stage_counts() |
| assert {d["stage"] for d in counts} == set(bus.STAGES) |
|
|