Skip to content

test: add unit tests for FrameTracer and DivergenceDetector#212

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

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

Conversation

@acailic

@acailic acailic commented Jun 8, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #208

  • Adds tests/test_frame_tracer_divergence.py with 51 unit tests
  • Covers FrameTracer: TokenUsage arithmetic/serialization, FrameEvent/FrameLifetimeTrace construction and to_dict, build_frame_tree (empty/single/child/multi-root), FrameCaptureContext parent-child linking, capture_function_call decorator (success, exception capture, arg/return suppression), helper functions (get_frame_by_id, get_frames_at_depth, filter_frames_by_name, get_cost_breakdown), and serialization round-trip via to_dict/from_dict
  • Covers DivergenceDetector: DivergenceType/DivergenceSeverity enum values, DivergencePoint.to_dict (with/without timestamp), SessionComparison.to_dict, detect_divergences (empty, identical, count mismatch, session ID extraction, summary keys, critical severity), compare_session_structures, analyze_temporal_divergence, analyze_behavioral_divergence

Test plan

  • ruff check . — clean
  • .venv-ci/bin/python3 -m pytest -q tests/test_frame_tracer_divergence.py — 51 passed in 0.55s

🤖 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>
51 tests covering TokenUsage arithmetic, FrameEvent/FrameLifetimeTrace
serialization, build_frame_tree, FrameCaptureContext parent-child linking,
capture_function_call decorator (success/exception/options), helper
functions (get_frame_by_id, get_frames_at_depth, filter_frames_by_name,
get_cost_breakdown), serialization round-trip, DivergenceType/Severity
enums, DivergencePoint.to_dict, 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 8, 2026 08:50

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