71699b3ecd
- test_contrib_gitea_client: remove unused Any import, fix _mock_response to use return_value instead of lambda (unknown lambda type), narrow HTTPError hdrs type, add type annotations to fake_urlopen helpers, suppress protected-access for _request tests - test_bootstrap: annotate **kw as **kw: object, use dict literal, unpack server_address via index to avoid tuple type mismatch - test_main: remove unused MagicMock import - test_watchdog: guard store.get() result before accessing .status Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
89 lines
3.0 KiB
Python
89 lines
3.0 KiB
Python
"""Unit: __main__ CLI entry points (run and status commands)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import io
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
from bot_bottle.orchestrator.__main__ import main
|
|
from bot_bottle.orchestrator.config import Config
|
|
from bot_bottle.orchestrator.model import RunRecord
|
|
|
|
|
|
def _config() -> Config:
|
|
return Config.from_env({"HOME": "/tmp"})
|
|
|
|
|
|
class MainRunTest(unittest.TestCase):
|
|
def test_run_delegates_to_bootstrap(self):
|
|
config = _config()
|
|
with patch.object(Config, "from_env", return_value=config), \
|
|
patch("bot_bottle.orchestrator.bootstrap.run") as mock_run:
|
|
rc = main(["run"])
|
|
self.assertEqual(0, rc)
|
|
mock_run.assert_called_once_with(config)
|
|
|
|
def test_run_prints_listen_address_to_stderr(self):
|
|
config = _config()
|
|
err = io.StringIO()
|
|
with patch.object(Config, "from_env", return_value=config), \
|
|
patch("bot_bottle.orchestrator.bootstrap.run"), \
|
|
patch("sys.stderr", err):
|
|
main(["run"])
|
|
self.assertIn(str(config.webhook_port), err.getvalue())
|
|
|
|
|
|
class MainStatusTest(unittest.TestCase):
|
|
def test_status_empty_store(self):
|
|
config = _config()
|
|
with patch.object(Config, "from_env", return_value=config), \
|
|
patch("bot_bottle.orchestrator.bootstrap.BotBottleStateStore") as MockStore:
|
|
MockStore.return_value.all.return_value = []
|
|
rc = main(["status"])
|
|
self.assertEqual(0, rc)
|
|
|
|
def test_status_prints_records(self):
|
|
config = _config()
|
|
rec = RunRecord(
|
|
owner="o", repo="r", issue_number=1, slug="my-slug",
|
|
agent_name="a", pr_number=7, status="frozen",
|
|
)
|
|
out = io.StringIO()
|
|
with patch.object(Config, "from_env", return_value=config), \
|
|
patch("bot_bottle.orchestrator.bootstrap.BotBottleStateStore") as MockStore, \
|
|
patch("sys.stdout", out):
|
|
MockStore.return_value.all.return_value = [rec]
|
|
rc = main(["status"])
|
|
self.assertEqual(0, rc)
|
|
self.assertIn("my-slug", out.getvalue())
|
|
self.assertIn("PR#7", out.getvalue())
|
|
|
|
def test_status_no_pr_prints_dash(self):
|
|
config = _config()
|
|
rec = RunRecord(
|
|
owner="o", repo="r", issue_number=2, slug="s2",
|
|
agent_name="a", pr_number=None, status="running",
|
|
)
|
|
out = io.StringIO()
|
|
with patch.object(Config, "from_env", return_value=config), \
|
|
patch("bot_bottle.orchestrator.bootstrap.BotBottleStateStore") as MockStore, \
|
|
patch("sys.stdout", out):
|
|
MockStore.return_value.all.return_value = [rec]
|
|
main(["status"])
|
|
self.assertIn("-", out.getvalue())
|
|
|
|
|
|
class MainArgparseTest(unittest.TestCase):
|
|
def test_no_command_exits(self):
|
|
with self.assertRaises(SystemExit):
|
|
main([])
|
|
|
|
def test_unknown_command_exits(self):
|
|
with self.assertRaises(SystemExit):
|
|
main(["bogus"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|