Skip to content

test: add unit tests for FrameTracer and DivergenceDetector#211

Open
acailic wants to merge 3 commits into
mainfrom
issue/208-frame-tracer-divergence-tests
Open

test: add unit tests for FrameTracer and DivergenceDetector#211
acailic wants to merge 3 commits into
mainfrom
issue/208-frame-tracer-divergence-tests

Conversation

@acailic

@acailic acailic commented Jun 7, 2026

Copy link
Copy Markdown
Owner

Summary

Coverage

FrameTracer

  • TokenUsage arithmetic (__add__) and to_dict()
  • ExceptionInfo construction and serialization
  • FrameEvent dataclass defaults and to_dict() (with/without token_usage, exception, children)
  • FrameLifetimeTrace construction and to_dict()
  • build_frame_tree() — empty, single root, parent-child, multi-root
  • get_frame_by_id(), get_frames_at_depth(), filter_frames_by_name()
  • get_cost_breakdown() — duration aggregation, error counts, token sums
  • FrameCaptureContext — add_frame, enter/exit depth tracking, build_trace, parent-child linking
  • capture_function_call decorator — passthrough (no context), capture args/return, exception capture, nested calls
  • to_dict/from_dict round-trips (empty, with frames, with exception)

DivergenceDetector

  • DivergenceType and DivergenceSeverity enum string values
  • DivergencePoint dataclass and to_dict() (with/without timestamp, metadata, event IDs)
  • SessionComparison defaults and to_dict()
  • detect_divergences() — both empty, session ID extraction, identical sessions, count divergences, summary keys, score bounding, one empty session, JSON serializable output
  • compare_session_structures() — key presence, full similarity, empty vs empty, empty vs nonempty, event distribution counts
  • analyze_temporal_divergence() — empty, one empty, same timing, duration difference detection, key presence
  • analyze_behavioral_divergence() — empty, decision/tool counts, same behavior, key presence, tool divergence detection

Test plan

  • pytest -q tests/test_frame_tracer_divergence.py → 82 passed
  • ruff check . → all checks passed
  • Full suite pytest -q → 2756 passed, 25 skipped

🤖 Generated with Claude Code

acailic and others added 3 commits June 5, 2026 14:48
Makes `evidence` an optional keyword argument (default `None`, treated as
`[]`) in `RecordingMixin.record_decision`. All existing callers already
pass evidence explicitly so this is non-breaking.

Also adds lightweight drift-event collection to `record_decision` and
wires `_drift_events`/`_drift_compare_index` onto `TraceContext.restore`
so the previously-skipped drift-emission test now passes.

Closes #205

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ison fixes

- Add `*` after `chosen_action` in `record_decision` to make `evidence`
  and remaining params keyword-only, preventing accidental positional use
  and protecting existing positional callers
- Use clamped `event.confidence` instead of raw `confidence` in drift
  event_dict to match what is actually persisted
- Add `action` alias alongside `chosen_action` in drift event_dict so
  baselines using either key are matched
- Advance `_drift_compare_index` to the next decision event in the
  baseline (skipping non-decision events) to prevent index misalignment

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
82 tests covering TokenUsage arithmetic, FrameEvent/FrameLifetimeTrace
serialization, build_frame_tree, cost breakdown, FrameCaptureContext,
capture_function_call decorator, to_dict/from_dict round-trips,
DivergenceType/Severity enums, DivergencePoint/SessionComparison,
detect_divergences, compare_session_structures, analyze_temporal_divergence,
and analyze_behavioral_divergence.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 7, 2026 18:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: add unit tests for FrameTracer and DivergenceDetector (zero coverage)

2 participants