test: add coverage for orchestrator + gitea client (diff gate 77% → 98%)
Three new unit test modules: - tests/unit/test_contrib_gitea_client.py — GiteaClient (urllib mocked) and GiteaForge delegation - tests/unit/orchestrator/test_main.py — __main__ run/status commands - tests/unit/orchestrator/test_bootstrap.py — _token, BotBottleStateStore, _to_forge_state/_to_record, make_forge, make_sidecar, build Augments to existing suites: - test_events: non-"created" comment action ignored - test_lifecycle: _iso_now callable, untracked-issue comment ignored, untracked-PR closed ignored (covers _find_by_pr return-None path) - test_runner: destroy command, _default_run via subprocess mock - test_sidecar: _jsonable dataclass/list branches, OpLog.read on missing file, drain_done_events on corrupted file, socket _Handler invalid-JSON and empty-line paths, serve() with pre-existing socket path - test_watchdog: _loop body covered by patching _TICK_SECS to 0.01s - test_webhook: unknown GET path returns 404 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import time
|
||||
import unittest
|
||||
import unittest.mock
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from bot_bottle.orchestrator.model import STATUS_FROZEN, STATUS_RUNNING, RunRecord
|
||||
@@ -61,6 +63,16 @@ class WatchdogSweepTest(unittest.TestCase):
|
||||
self.wd.start()
|
||||
self.wd.stop()
|
||||
|
||||
def test_loop_sweeps_stale_record(self):
|
||||
# Patch tick to near-zero so the loop iterates quickly.
|
||||
stale = (_NOW - timedelta(hours=1)).isoformat()
|
||||
self.store.upsert(_record(5, STATUS_RUNNING, stale))
|
||||
with unittest.mock.patch("bot_bottle.orchestrator.watchdog._TICK_SECS", 0.01):
|
||||
self.wd.start()
|
||||
time.sleep(0.05) # enough for several iterations at 0.01s tick
|
||||
self.wd.stop()
|
||||
self.assertEqual(STATUS_FROZEN, self.store.get("o", "r", 5).status)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user