[loop-cycle-154] refactor: extract _annotate_confidence helper — DRY 3x duplication (#369) (#376)
All checks were successful
Tests / lint (push) Successful in 4s
Tests / test (push) Successful in 1m35s

This commit was merged in pull request #376.
This commit is contained in:
2026-03-18 22:01:51 -04:00
parent 996ccec170
commit c1af9e3905
2 changed files with 69 additions and 13 deletions

View File

@@ -19,6 +19,53 @@ def _reset_session_singleton():
mod._agent = None
# ---------------------------------------------------------------------------
# _annotate_confidence() helper
# ---------------------------------------------------------------------------
class TestAnnotateConfidence:
"""Unit tests for the DRY confidence annotation helper."""
def test_below_threshold_adds_tag(self):
from timmy.session import _annotate_confidence
result = _annotate_confidence("Hello world", 0.55)
assert "[confidence: 55%]" in result
def test_above_threshold_no_tag(self):
from timmy.session import _annotate_confidence
result = _annotate_confidence("Hello world", 0.85)
assert "[confidence:" not in result
assert result == "Hello world"
def test_at_threshold_no_tag(self):
from timmy.session import _annotate_confidence
result = _annotate_confidence("Hello world", 0.7)
assert "[confidence:" not in result
def test_none_confidence_no_tag(self):
from timmy.session import _annotate_confidence
result = _annotate_confidence("Hello world", None)
assert "[confidence:" not in result
assert result == "Hello world"
def test_zero_confidence_adds_tag(self):
from timmy.session import _annotate_confidence
result = _annotate_confidence("Hello world", 0.0)
assert "[confidence: 0%]" in result
def test_preserves_original_text(self):
from timmy.session import _annotate_confidence
result = _annotate_confidence("Original text here", 0.3)
assert result.startswith("Original text here")
# ---------------------------------------------------------------------------
# chat()
# ---------------------------------------------------------------------------