from dataclasses import dataclass import json import pytest from agent_evaluation.datasets.models import EvaluationCase from agent_evaluation.evaluators import EvaluationContext from agent_evaluation.models import SkillBundle, TaskArtifact, TestPoint as Point, TestPointSet as PointSet, TraceRef from agent_evaluation.backend import NativeTraceStore from agent_evaluation.instrumentation import ( build_event_carrier_readers, build_instrumentation, ) from agent_evaluation.trace_evidence import ( matching_session_spans, project_spans, ) from agent_evaluation.evaluators.trace import ( testpoint_duration as evaluate_testpoint_duration, testpoint_total_tokens as evaluate_testpoint_total_tokens, ) class Spans: def __init__(self, rows): self.rows = rows self.logged = None self.dataframe_kwargs = None self.read_count = 0 def get_spans_dataframe(self, **kwargs): self.read_count += 1 self.dataframe_kwargs = kwargs return self.rows def get_spans(self, **kwargs): return self.rows def log_span_annotations_dataframe(self, *, dataframe, **kwargs): self.logged = dataframe class Projects: def get(self, **kwargs): return {"id": "project-id"} @dataclass class Client: rows: list def __post_init__(self): self.spans = Spans(self.rows) self.projects = Projects() def read_spans(self, project, session_id): return self.spans.get_spans_dataframe() def _rows(): attrs = {"session.id": "ses-1"} event = {"protocol": "eval-events/v1", "event_type": "state", "entity_type": "testpoint", "entity_id": "stage-1", "state": "completed", "sequence": 1} return [ {"name": "Turn", "parent_id": None, "context": {"trace_id": "trace-1", "span_id": "root-1"}, "start_time": "2026-01-01T00:00:00+00:00", "end_time": "2026-01-01T00:00:01+00:00", "attributes": attrs}, {"name": "LLM: test", "parent_id": "root-1", "context": {"trace_id": "trace-1", "span_id": "llm-1"}, "start_time": "2026-01-01T00:00:00.100000+00:00", "end_time": "2026-01-01T00:00:00.500000+00:00", "attributes": {**attrs, "llm.token_count.prompt": 10, "llm.token_count.completion": 5, "llm.token_count.total": 15, "llm.output": '{"protocol":"eval-events/v1","event_type":"state","entity_type":"testpoint","entity_id":"stage-1","state":"completed","sequence":1}', "eval.events": json.dumps([event])}}, {"name": "write", "parent_id": "llm-1", "context": {"trace_id": "trace-1", "span_id": "tool-1"}, "attributes": {**attrs, "tool.name": "read", "tool.input": "fixture.md"}}, ] def _point(testpoint_id: str, ordinal: int, name: str, previous: str | None = None) -> Point: return Point(testpoint_id, "runtime_state", ordinal, name, previous, f"complete {name}") def _project(rows): return project_spans( TraceRef("demo", "ses-1"), rows, build_instrumentation("eval-events/v1", ("llm_message", "tool_call")), ) def _event_ids(evidence): return tuple(event.entity_id for event in (evidence.events or ()) if event.entity_type == "testpoint") def _rule_context(evidence, point): skill = SkillBundle("demo", "working", "SKILL.md", "entry", "bundle") points = PointSet("demo", "working", "bundle", "test", [point]) return EvaluationContext( EvaluationCase("case-1", "build", {}), TaskArtifact("run-1", "case-1", "completed", {}), skill, points, evidence, point, ) def _duration(evidence, point): return evaluate_testpoint_duration(_rule_context(evidence, point), {}) def _tokens(evidence, point): return evaluate_testpoint_total_tokens(_rule_context(evidence, point), {}) def test_trace_reader_projects_persisted_span_evidence(): rows = _rows() evidence = _project(rows) spans = matching_session_spans(TraceRef("demo", "ses-1"), rows) assert len(spans) == 3 assert evidence is not None assert evidence.trace_ids == ("trace-1",) assert evidence.duration_seconds == 1.0 assert _event_ids(evidence) == ("stage-1",) assert evidence.root_start_time < evidence.root_end_time assert evidence.llm_spans[0].total_tokens == 15 assert [step.name for step in evidence.steps] == ["Turn", "LLM: test", "read"] assert [step.kind for step in evidence.steps] == ["turn", "llm", "tool"] assert evidence.steps[1].input_status == "omitted_by_policy" assert evidence.steps[1].output_status == "available" assert evidence.steps[2].input_text == "fixture.md" assert evidence.steps[2].input_status == "available" projected = json.dumps([step.to_dict() for step in evidence.steps]) assert "fixture.md" in projected assert "tool.input" not in projected assert "llm.output" not in projected def test_trace_reader_uses_redaction_safe_stage_summary(): rows = _rows() rows[1]["attributes"]["llm.output"] = "" evidence = _project(rows) assert evidence is not None assert _event_ids(evidence) == ("stage-1",) assert evidence.steps[1].output_text is None assert evidence.steps[1].output_status == "redacted" def test_native_trace_store_caches_one_session_projection(): client = Client(_rows()) from types import SimpleNamespace store = NativeTraceStore(SimpleNamespace(spans=client.read_spans), wait_seconds=0) first = store.read( TraceRef("demo", "ses-1"), instrumentation=build_instrumentation("eval-events/v1", ("llm_message", "tool_call")), ) second = store.read( TraceRef("demo", "ses-1"), instrumentation=build_instrumentation("eval-events/v1", ("llm_message", "tool_call")), ) assert first is second assert client.spans.read_count == 1 def test_trace_reader_uses_nested_tool_summary(): rows = _rows() rows[1]["attributes"].pop("eval.events") rows.append({"name": "write", "parent_id": "llm-1", "context": {"trace_id": "trace-1", "span_id": "tool-1"}, "end_time": "2026-01-01T00:00:00.800000+00:00", "attributes": {"session": {"id": "ses-1"}, "tool": {"name": "write", "input": { "protocol": "eval-events/v1", "event_type": "state", "entity_type": "testpoint", "entity_id": "stage-1", "state": "completed", "sequence": 1}}}}) evidence = _project(rows) assert evidence is not None assert _event_ids(evidence) == () def test_stage_measurements_use_completion_intervals_and_token_attributes(): rows = _rows() rows[1]["end_time"] = "2026-01-01T00:00:00.800000+00:00" evidence = _project(rows) point = _point("stage-1", 1, "First") assert _duration(evidence, point).score == pytest.approx(0.8) assert _tokens(evidence, point).score == 15 assert _tokens(evidence, point).value == { "prompt": 10, "completion": 5, "total": 15 } assert _tokens(evidence, point).metadata["attribution_status"] == "exact" def test_parent_llm_anchor_prevents_crossing_span_from_being_counted_twice(): attrs = {"session.id": "ses-1"} rows = [ {"name": "Turn", "parent_id": None, "context": {"trace_id": "trace-1", "span_id": "root-1"}, "start_time": "2026-01-01T00:00:00+00:00", "end_time": "2026-01-01T00:00:10+00:00", "attributes": attrs}, {"name": "LLM: first", "parent_id": "root-1", "context": {"trace_id": "trace-1", "span_id": "llm-1"}, "start_time": "2026-01-01T00:00:00+00:00", "end_time": "2026-01-01T00:00:05+00:00", "attributes": {**attrs, "llm.token_count.prompt": 10, "llm.token_count.completion": 5, "llm.token_count.total": 15}}, {"name": "message", "parent_id": "llm-1", "context": {"trace_id": "trace-1", "span_id": "message-1"}, "start_time": "2026-01-01T00:00:04+00:00", "end_time": "2026-01-01T00:00:04+00:00", "attributes": {**attrs, "message.content": '{"protocol":"eval-events/v1","event_type":"state","entity_type":"testpoint","entity_id":"stage-1","state":"completed","sequence":1}', "eval.events": json.dumps([{"protocol":"eval-events/v1","event_type":"state","entity_type":"testpoint","entity_id":"stage-1","state":"completed","sequence":1}])}}, {"name": "LLM: second", "parent_id": "root-1", "context": {"trace_id": "trace-1", "span_id": "llm-2"}, "start_time": "2026-01-01T00:00:04+00:00", "end_time": "2026-01-01T00:00:07+00:00", "attributes": {**attrs, "llm.token_count.prompt": 20, "llm.token_count.completion": 8, "llm.token_count.total": 28}}, {"name": "message", "parent_id": "llm-2", "context": {"trace_id": "trace-1", "span_id": "message-2"}, "start_time": "2026-01-01T00:00:06+00:00", "end_time": "2026-01-01T00:00:07+00:00", "attributes": {**attrs, "message.content": '{"protocol":"eval-events/v1","event_type":"state","entity_type":"testpoint","entity_id":"stage-2","state":"completed","sequence":2}', "eval.events": json.dumps([{"protocol":"eval-events/v1","event_type":"state","entity_type":"testpoint","entity_id":"stage-2","state":"completed","sequence":2}])}}, ] evidence = _project(rows) first = _tokens(evidence, _point("stage-1", 1, "First")) second = _tokens(evidence, _point("stage-2", 2, "Second", "stage-1")) assert evidence.testpoint_completion_llm_ids == {"stage-1": "llm-1", "stage-2": "llm-2"} assert first.value == {"prompt": 10, "completion": 5, "total": 15} assert second.value == {"prompt": 20, "completion": 8, "total": 28} assert first.metadata["attribution_status"] == "partial" assert second.metadata["attribution_status"] == "exact" def test_sequential_emitters_under_one_llm_keep_reach_exact_but_tokens_unavailable(): rows = _rows() rows[1]["attributes"].pop("llm.output") rows[1]["attributes"].pop("eval.events") for index, testpoint_id in enumerate(("stage-1", "stage-2"), start=1): rows.append({"name": "bash", "parent_id": "llm-1", "context": {"trace_id": "trace-1", "span_id": f"tool-{index}"}, "end_time": f"2026-01-01T00:00:00.{500 + index}00+00:00", "attributes": {"session.id": "ses-1", "tool.name": "bash", "tool.output": f'{{"protocol":"eval-events/v1","event_type":"state","entity_type":"testpoint","entity_id":"{testpoint_id}","state":"completed","sequence":{index}}}', "eval.events": json.dumps([{"protocol":"eval-events/v1","event_type":"state","entity_type":"testpoint","entity_id":testpoint_id,"state":"completed","sequence":index}])}}) evidence = _project(rows) assert evidence.testpoint_event_status == {"stage-1": "exact", "stage-2": "exact"} assert _duration(evidence, _point("stage-1", 1, "First")).metadata["attribution_status"] == "exact" assert _tokens(evidence, _point("stage-2", 2, "Second", "stage-1")).metadata["attribution_status"] == "ambiguous" def test_stage_token_measurement_marks_boundary_crossing_span_partial(): rows = _rows() rows[1]["start_time"] = "2025-12-31T23:59:59.900000+00:00" rows[1]["end_time"] = "2026-01-01T00:00:01.200000+00:00" rows[1]["attributes"].pop("llm.output") rows[1]["attributes"].pop("eval.events") rows.append({"name": "message", "parent_id": "llm-1", "context": {"trace_id": "trace-1", "span_id": "message-1"}, "start_time": "2026-01-01T00:00:00.700000+00:00", "end_time": "2026-01-01T00:00:00.800000+00:00", "attributes": {"session.id": "ses-1", "message.content": '{"protocol":"eval-events/v1","event_type":"state","entity_type":"testpoint","entity_id":"stage-1","state":"completed","sequence":1}', "eval.events": json.dumps([{"protocol":"eval-events/v1","event_type":"state","entity_type":"testpoint","entity_id":"stage-1","state":"completed","sequence":1}])}}) evidence = _project(rows) point = _point("stage-1", 1, "First") result = _tokens(evidence, point) assert result.score == 15 assert result.metadata["attribution_status"] == "partial" def test_stage_measurement_marks_missing_tokens_and_unreached_stage(): rows = _rows() rows[1]["attributes"] = {"session.id": "ses-1"} rows[1]["end_time"] = "2026-01-01T00:00:00.8+00:00" evidence = _project(rows) point = _point("stage-1", 1, "First") assert _tokens(evidence, point).metadata["attribution_status"] == "missing_explicit_event" missing = _point("stage-2", 2, "Second", "stage-1") assert _duration(evidence, missing).metadata["attribution_status"] == "missing_explicit_event" def test_observed_completion_with_ambiguous_previous_boundary_is_not_unreached(): from types import SimpleNamespace from agent_evaluation.evaluators.trace import testpoint_interval_status from agent_evaluation.trace_evidence import EvalEvent evidence = SimpleNamespace( testpoint_event_status={"stage-1": "exact", "preflight": "ambiguous"}, testpoint_completion_times={"stage-1": 2.0}, root_start_time=0.0, events=[], ) evidence.events = [EvalEvent("eval-events/v1", "state", "testpoint", "stage-1", "completed", 2, {}, "tool_call", "s", None, 2.0)] status = testpoint_interval_status(evidence, _point("stage-1", 2, "First", "preflight")) assert status == "previous_boundary_ambiguous" assert status != "testpoint_not_reached" def test_missing_completion_event_keeps_testpoint_not_reached(): evidence = _project(_rows()) result = _duration(evidence, _point("stage-2", 2, "Second", "stage-1")) assert result.metadata["attribution_status"] == "testpoint_not_reached" def test_batched_explicit_events_are_not_exact(): rows = _rows() rows[1]["attributes"]["eval.events"] = json.dumps([ {"protocol":"eval-events/v1","event_type":"state","entity_type":"testpoint","entity_id":"stage-1","state":"completed","sequence":1}, {"protocol":"eval-events/v1","event_type":"state","entity_type":"testpoint","entity_id":"stage-2","state":"completed","sequence":2}, ]) evidence = _project(rows) assert evidence is not None assert evidence.testpoint_event_status == {"stage-1": "batched", "stage-2": "batched"} def test_sequence_mismatch_is_ambiguous_instead_of_silent_drop(): rows = _rows() rows[1]["attributes"]["eval.events"] = json.dumps([{"protocol":"eval-events/v1","event_type":"state","entity_type":"testpoint","entity_id":"stage-1","state":"completed","sequence":2}]) evidence = _project(rows) assert evidence is not None assert _event_ids(evidence) == ("stage-1",) # The reader cannot know the compiled ordinal for an arbitrary TestPoint; # the evaluator performs that comparison below. assert evidence.testpoint_event_status == {"stage-1": "exact"} def test_evaluator_checks_event_sequence_against_compiled_testpoint_ordinal(): evidence = _project(_rows()) point = _point("stage-1", 2, "Stage 1", "preflight") result = _duration(evidence, point) assert result.score is None assert result.metadata["attribution_status"] == "ambiguous" def test_missing_earlier_event_does_not_poison_later_testpoint_reach(): rows = _rows() rows[1]["attributes"]["eval.events"] = json.dumps([{"protocol":"eval-events/v1","event_type":"state","entity_type":"testpoint","entity_id":"stage-1","state":"completed","sequence":2}]) rows.append({"name": "message", "parent_id": "llm-1", "context": {"trace_id": "trace-1", "span_id": "message-2"}, "end_time": "2026-01-01T00:00:00.900000+00:00", "attributes": {"session.id": "ses-1", "message.content": '{"protocol":"eval-events/v1","event_type":"state",' '"entity_type":"testpoint","entity_id":"stage-2",' '"state":"completed","sequence":3}', "eval.events": json.dumps([{"protocol":"eval-events/v1","event_type":"state","entity_type":"testpoint","entity_id":"stage-2","state":"completed","sequence":3}])}}) evidence = _project(rows) assert evidence is not None assert evidence.testpoint_event_status == {"stage-1": "exact", "stage-2": "exact"} from agent_evaluation.evaluators.trace import testpoint_reached point = _point("stage-1", 2, "Stage 1", "preflight") result = testpoint_reached(_rule_context(evidence, point), {}) assert result.label == "pass" def test_duplicate_stage_events_are_ambiguous(): rows = _rows() rows.append({"name": "message", "parent_id": "root-1", "context": {"trace_id": "trace-1", "span_id": "message-2"}, "end_time": "2026-01-01T00:00:00.900000+00:00", "attributes": {"session.id": "ses-1", "message.content": '{"protocol":"eval-events/v1","event_type":"state","entity_type":"testpoint","entity_id":"stage-1","state":"completed","sequence":1}', "eval.events": json.dumps([{"protocol":"eval-events/v1","event_type":"state","entity_type":"testpoint","entity_id":"stage-1","state":"completed","sequence":1}])}}) evidence = _project(rows) assert evidence is not None assert evidence.testpoint_event_status == {"stage-1": "ambiguous"} def test_tool_call_transport_decodes_native_event_mapping(): rows = _rows() rows[1]["attributes"].pop("llm.output") rows[1]["attributes"].pop("eval.events") rows.append({"name": "tool", "parent_id": "root-1", "context": {"trace_id": "trace-1", "span_id": "tool-2"}, "end_time": "2026-01-01T00:00:00.900000+00:00", "attributes": {"session.id": "ses-1", "tool.name": "emit", "eval.events": {"protocol": "eval-events/v1", "event_type": "state", "entity_type": "testpoint", "entity_id": "stage-1", "state": "completed", "sequence": 1}}}) evidence = _project(rows) assert evidence is not None assert _event_ids(evidence) == ("stage-1",) def test_read_tool_does_not_turn_skill_examples_into_events(): rows = _rows() rows[1]["attributes"].pop("llm.output") rows[1]["attributes"].pop("eval.events") rows.append({"name": "read", "parent_id": "llm-1", "context": {"trace_id": "trace-1", "span_id": "tool-read"}, "end_time": "2026-01-01T00:00:00.900000+00:00", "attributes": {"session.id": "ses-1", "tool.name": "read", "tool.output": '{"protocol":"eval-events/v1","event_type":"state","entity_type":"testpoint","entity_id":"stage-1","state":"completed","sequence":1}'}}) evidence = _project(rows) assert evidence is not None assert evidence.events == () def test_shell_tool_decodes_marked_event_text(): rows = _rows() rows[1]["attributes"].pop("llm.output") rows[1]["attributes"].pop("eval.events") rows.append({"name": "bash", "parent_id": "llm-1", "context": {"trace_id": "trace-1", "span_id": "tool-bash"}, "end_time": "2026-01-01T00:00:00.900000+00:00", "attributes": {"session.id": "ses-1", "tool.name": "bash", "tool.output": '{"protocol":"eval-events/v1","event_type":"state","entity_type":"testpoint","entity_id":"stage-1","state":"completed","sequence":1}', "eval.events": json.dumps([{"protocol":"eval-events/v1","event_type":"state","entity_type":"testpoint","entity_id":"stage-1","state":"completed","sequence":1}])}}) evidence = _project(rows) assert evidence is not None assert _event_ids(evidence) == ("stage-1",) def test_any_tool_input_can_carry_an_explicit_event(): rows = _rows() rows[1]["attributes"].pop("llm.output") rows[1]["attributes"].pop("eval.events") rows.append({"name": "python", "parent_id": "llm-1", "context": {"trace_id": "trace-1", "span_id": "tool-python"}, "end_time": "2026-01-01T00:00:00.900000+00:00", "attributes": {"session.id": "ses-1", "tool.name": "python", "tool.input": "print('') " "print('{\"protocol\":\"eval-events/v1\",\"event_type\":\"state\"," "\"entity_type\":\"testpoint\",\"entity_id\":\"handoff\"," "\"state\":\"completed\",\"sequence\":7}') " "print('')"}}) evidence = _project(rows) assert evidence is not None assert _event_ids(evidence) == () def test_tool_carrier_is_detected_from_standard_input_attribute_without_tool_name(): rows = _rows() rows[1]["attributes"].pop("llm.output") rows[1]["attributes"].pop("eval.events") rows.append({"name": "python", "parent_id": "llm-1", "context": {"trace_id": "trace-1", "span_id": "tool-python"}, "end_time": "2026-01-01T00:00:00.900000+00:00", "attributes": {"session.id": "ses-1", "input.value": '{"protocol":"eval-events/v1","event_type":"state",' '"entity_type":"testpoint","entity_id":"handoff",' '"state":"completed","sequence":7}'}}) evidence = _project(rows) assert evidence is not None assert _event_ids(evidence) == () def test_tool_call_transport_decodes_reconciler_eval_events_attribute(): rows = _rows() rows[1]["attributes"].pop("llm.output") rows[1]["attributes"].pop("eval.events") event = {"protocol": "eval-events/v1", "event_type": "state", "entity_type": "testpoint", "entity_id": "preflight", "state": "completed", "sequence": 1} rows.append({"name": "bash", "parent_id": "llm-1", "context": {"trace_id": "trace-1", "span_id": "tool-bash"}, "end_time": "2026-01-01T00:00:00.900000+00:00", "attributes": {"session.id": "ses-1", "tool.name": "bash", "input.value": "", "output.value": "", "eval.events": json.dumps([event])}}) evidence = _project(rows) assert evidence is not None assert _event_ids(evidence) == ("preflight",) assert evidence.testpoint_event_status == {"preflight": "exact"} def test_llm_transport_decodes_reconciler_eval_events_when_output_is_redacted(): rows = _rows() rows[1]["attributes"].pop("llm.output") event = {"protocol": "eval-events/v1", "event_type": "state", "entity_type": "testpoint", "entity_id": "preflight", "state": "completed", "sequence": 1} rows[1]["attributes"]["eval.events"] = json.dumps([event]) evidence = _project(rows) assert evidence is not None assert _event_ids(evidence) == ("preflight",) assert evidence.testpoint_event_status == {"preflight": "exact"} def test_reader_decodes_flattened_eval_projection_repr(): rows = _rows() rows[1]["attributes"].pop("llm.output") rows[1]["attributes"].pop("eval.events") rows.append({"name": "bash", "parent_id": "llm-1", "context": {"trace_id": "trace-1", "span_id": "tool-bash"}, "end_time": "2026-01-01T00:00:00.900000+00:00", # Tabular form flattens this to an # ``attributes.eval`` column whose value is a repr string. "attributes.session.id": "ses-1", "attributes.tool.name": "bash", "attributes.eval": repr({"events": json.dumps([{ "protocol": "eval-events/v1", "event_type": "state", "entity_type": "testpoint", "entity_id": "stage-1", "state": "completed", "sequence": 1}])})}) evidence = _project(rows) assert evidence is not None assert _event_ids(evidence) == ("stage-1",) assert evidence.testpoint_event_status == {"stage-1": "exact"} def test_reader_waits_for_a_stable_span_snapshot(): first = _rows()[:2] complete = _rows() class EventuallyStableSpans(Spans): calls = 0 def get_spans_dataframe(self, **kwargs): self.calls += 1 return first if self.calls == 1 else complete client = Client(first) client.spans = EventuallyStableSpans(first) from types import SimpleNamespace evidence = NativeTraceStore(SimpleNamespace(spans=client.read_spans), wait_seconds=0.3).read( TraceRef("demo", "ses-1"), instrumentation=build_instrumentation("eval-events/v1", ("llm_message", "tool_call")), ) assert evidence is not None assert _event_ids(evidence) == ("stage-1",) assert client.spans.calls >= 3 def test_trace_store_stability_tracks_flattened_eval_wrapper(): event = {"protocol": "eval-events/v1", "event_type": "state", "entity_type": "testpoint", "entity_id": "stage-1", "state": "completed", "sequence": 1} first = [{**row, "attributes": {**row.get("attributes", {}), "eval": "{}"}} for row in _rows()[:2]] complete = [{**row, "attributes": {**row.get("attributes", {}), "eval": repr({"events": json.dumps([event])})}} for row in _rows()[:2]] class EventuallyStableFlattenedSpans(Spans): calls = 0 def get_spans_dataframe(self, **kwargs): self.calls += 1 return first if self.calls == 1 else complete client = Client(first) client.spans = EventuallyStableFlattenedSpans(first) from types import SimpleNamespace evidence = NativeTraceStore(SimpleNamespace(spans=client.read_spans), wait_seconds=0.3).read( TraceRef("demo", "ses-1"), instrumentation=build_instrumentation("eval-events/v1", ("llm_message", "tool_call")), ) assert evidence is not None assert _event_ids(evidence) == ("stage-1",) assert client.spans.calls >= 3 def test_non_testpoint_events_are_preserved_without_affecting_testpoint_order(): rows = _rows() rows[1]["attributes"]["eval.events"] = json.dumps([ {"protocol":"eval-events/v1","event_type":"state","entity_type":"phase","entity_id":"preflight","state":"completed","sequence":0}, {"protocol":"eval-events/v1","event_type":"state","entity_type":"testpoint","entity_id":"stage-1","state":"completed","sequence":1}, ]) evidence = _project(rows) assert evidence is not None assert [(event.entity_type, event.entity_id) for event in evidence.events] == [ ("phase", "preflight"), ("testpoint", "stage-1") ] assert _event_ids(evidence) == ("stage-1",) assert evidence.testpoint_event_status == {"stage-1": "exact"} @pytest.mark.parametrize( "envelope", [ '{"protocol":"eval-events/v0","event_type":"state","entity_type":"testpoint","entity_id":"stage-1","state":"completed","sequence":1}', '{"protocol":"eval-events/v1","event_type":"state","entity_type":"testpoint","entity_id":"stage-1","state":"completed"}', '{not-json}', ], ) def test_invalid_explicit_event_is_rejected(envelope): rows = _rows() rows[1]["attributes"]["eval.events"] = envelope with pytest.raises(ValueError, match="eval event|JSON|missing"): _project(rows) def test_event_transport_ids_must_be_unique(): with pytest.raises(ValueError, match="unique"): build_event_carrier_readers(["llm_message", "llm_message"]) def test_missing_turn_is_incomplete_instead_of_using_child_span(): rows = [row for row in _rows() if row["name"] != "Turn"] evidence = _project(rows) spans = matching_session_spans(TraceRef("demo", "ses-1"), rows) assert spans assert evidence is None