Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
A comprehensive collection of Agent Skills for context engineering, multi-agent architectures, and production agent systems.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
examples/interleaved-thinking/tests/test_models.py
1"""Tests for data models."""23from datetime import datetime45from reasoning_trace_optimizer.models import (6AnalysisResult,7LoopResult,8OptimizationResult,9Pattern,10PatternType,11PromptDiff,12ReasoningTrace,13Severity,14ThinkingBlock,15ToolCall,16)171819def test_thinking_block_creation():20"""Test ThinkingBlock creation with defaults."""21block = ThinkingBlock(22content="This is a test thinking block.",23turn_index=0,24)25assert block.content == "This is a test thinking block."26assert block.turn_index == 027assert block.token_count == 028assert isinstance(block.timestamp, datetime)293031def test_tool_call_creation():32"""Test ToolCall creation."""33tc = ToolCall(34id="call_123",35name="get_weather",36input={"location": "San Francisco"},37turn_index=1,38)39assert tc.id == "call_123"40assert tc.name == "get_weather"41assert tc.input["location"] == "San Francisco"42assert tc.success is None434445def test_reasoning_trace_creation():46"""Test ReasoningTrace creation and methods."""47trace = ReasoningTrace(48session_id="test-session",49task="Test task",50system_prompt="Test prompt",51)5253# Add thinking block54block = ThinkingBlock(content="Thinking...", turn_index=0)55trace.thinking_blocks.append(block)5657# Add tool call58tc = ToolCall(59id="call_1",60name="test_tool",61input={},62turn_index=0,63)64trace.tool_calls.append(tc)6566# Test methods67assert trace.get_thinking_at_turn(0) == block68assert trace.get_thinking_at_turn(1) is None69assert len(trace.get_tool_calls_at_turn(0)) == 170assert len(trace.get_tool_calls_at_turn(1)) == 0717273def test_pattern_creation():74"""Test Pattern creation."""75pattern = Pattern(76type=PatternType.CONTEXT_DEGRADATION,77severity=Severity.HIGH,78description="Model lost track of goal",79evidence=["Evidence 1", "Evidence 2"],80turn_indices=[2, 3],81suggestion="Add explicit reminders",82confidence=0.85,83)84assert pattern.type == PatternType.CONTEXT_DEGRADATION85assert pattern.severity == Severity.HIGH86assert pattern.confidence == 0.85878889def test_analysis_result_creation():90"""Test AnalysisResult creation."""91result = AnalysisResult(trace_id="test-trace")92assert result.overall_score == 0.093assert len(result.patterns) == 094assert len(result.recommendations) == 0959697def test_optimization_result_creation():98"""Test OptimizationResult creation."""99result = OptimizationResult(100original_prompt="Original",101optimized_prompt="Optimized",102)103result.diffs.append(PromptDiff(104section="instructions",105original="Original text",106optimized="Improved text",107reason="Better clarity",108))109assert len(result.diffs) == 1110assert result.diffs[0].section == "instructions"111112113def test_loop_result_creation():114"""Test LoopResult creation."""115result = LoopResult(task="Test task")116assert result.total_iterations == 0117assert result.converged is False118assert result.improvement_percentage == 0.0119120121def test_pattern_types():122"""Test all PatternType values exist."""123expected_types = [124"context_degradation",125"tool_confusion",126"instruction_drift",127"hallucination",128"incomplete_reasoning",129"tool_misuse",130"goal_abandonment",131"circular_reasoning",132"premature_conclusion",133"missing_validation",134]135for type_name in expected_types:136assert PatternType(type_name) is not None137138139def test_severity_levels():140"""Test all Severity levels exist."""141assert Severity.LOW.value == "low"142assert Severity.MEDIUM.value == "medium"143assert Severity.HIGH.value == "high"144assert Severity.CRITICAL.value == "critical"145