kulono / doom-loop
blob · tests/test_doom.py · python
tests/test_doom.pypython
1import asyncio23from doom_loop import DoomLoopConfig, DoomLoopDetector, RecoveryAction456def make_detector():7 return DoomLoopDetector(DoomLoopConfig(8 warn_threshold_base=2, critical_threshold_base=3, adaptive_enabled=False,9 ))101112def feed_failures(d, n=6):13 for _ in range(n):14 d.record_tool_call("run_tests", {})15 d.record_tool_outcome("run_tests", {}, "FAILED: 3 errors")161718def test_no_loop_initially():19 d = make_detector()20 d.record_tool_call("read_file", {"path": "/a"})21 d.record_tool_outcome("read_file", {"path": "/a"}, "file contents here")22 res = d.detect()23 assert not res.stuck242526def test_repeat_loop_detected():27 d = make_detector()28 feed_failures(d)29 res = d.detect()30 assert res.stuck313233def test_recovery_callback_fires():34 d = make_detector()35 fired = []3637 async def on_recover(result):38 fired.append(result)39 return True4041 # generic_repeat loops recover via SWITCH_TOOL by default42 d.register_recovery_callback(RecoveryAction.SWITCH_TOOL, on_recover)43 feed_failures(d)44 res = d.detect()45 assert res.stuck46 ok = asyncio.run(d.execute_recovery(res))47 assert len(fired) == 148 # the loop pattern is still in the call history, so post-recovery49 # validation escalates and reports failure (by design)50 assert ok is False51
100%