|
| 1 | +"""Tests for the reasoning tools (think, critique, plan).""" |
| 2 | + |
| 3 | +from server.tools.reasoning import critique, plan, think |
| 4 | + |
| 5 | + |
| 6 | +def test_think_returns_recorded_thought(): |
| 7 | + out = think("I should search for primary sources first.") |
| 8 | + assert "[THOUGHT RECORDED]" in out |
| 9 | + assert "primary sources" in out |
| 10 | + |
| 11 | + |
| 12 | +def test_critique_short_answer_scores_low(): |
| 13 | + result = critique("Yes.", "Why does DDIM sample faster than DDPM?") |
| 14 | + assert result["completeness"] == "low" |
| 15 | + assert result["recommendation"] == "revise" |
| 16 | + assert "explanation of reasoning" in result["missing_aspects"] |
| 17 | + |
| 18 | + |
| 19 | +def test_critique_long_relevant_answer_accepted(): |
| 20 | + question = "How does DDIM sampling work?" |
| 21 | + answer = ( |
| 22 | + "DDIM sampling works by defining a non-Markovian forward process that " |
| 23 | + "shares the same marginals as DDPM. Because the reverse process becomes " |
| 24 | + "deterministic, sampling can skip steps along a sub-sequence of the " |
| 25 | + "original diffusion trajectory. This is why DDIM achieves comparable " |
| 26 | + "quality with far fewer steps. The process starts from pure noise and " |
| 27 | + "iteratively denoises using the trained noise-prediction network, " |
| 28 | + "stepping through a chosen subset of timesteps until a clean sample emerges." |
| 29 | + ) |
| 30 | + result = critique(answer, question) |
| 31 | + assert result["completeness"] in ("medium", "high") |
| 32 | + assert result["recommendation"] == "accept" |
| 33 | + assert result["missing_aspects"] == [] |
| 34 | + |
| 35 | + |
| 36 | +def test_critique_confidence_bounded(): |
| 37 | + result = critique("word " * 200, "anything?") |
| 38 | + assert 0.0 <= result["confidence"] <= 0.97 |
| 39 | + |
| 40 | + |
| 41 | +def test_plan_detects_research_strategy(): |
| 42 | + result = plan("Research the history of transformers in NLP") |
| 43 | + assert result["strategy"] == "research" |
| 44 | + assert result["total_steps"] == len(result["steps"]) > 0 |
| 45 | + |
| 46 | + |
| 47 | +def test_plan_detects_comparison_strategy(): |
| 48 | + result = plan("Compare PostgreSQL versus MySQL for OLTP workloads") |
| 49 | + assert result["strategy"] == "comparison" |
| 50 | + |
| 51 | + |
| 52 | +def test_plan_detects_implementation_strategy(): |
| 53 | + result = plan("Build a rate limiter in Python") |
| 54 | + assert result["strategy"] == "implementation" |
| 55 | + |
| 56 | + |
| 57 | +def test_plan_falls_back_to_general(): |
| 58 | + result = plan("What is the meaning of life?") |
| 59 | + assert result["strategy"] == "general" |
0 commit comments