refactor(supervise): make Supervisor a service class the orchestrator calls
tracker-policy-pr / check-pr (pull_request) Successful in 12s
test / integration-docker (pull_request) Successful in 19s
lint / lint (push) Failing after 55s
test / unit (pull_request) Successful in 2m8s
test / integration-firecracker (pull_request) Successful in 3m25s
test / coverage (pull_request) Successful in 39s
test / publish-infra (pull_request) Has been skipped

Turn the loose queue/audit functions in orchestrator/supervisor/queue.py into
methods on a concrete Supervisor service. The Orchestrator now owns an
injectable `self._supervisor` and calls `self._supervisor.write_proposal(...)`
etc., instead of module-level free functions — the supervise dependency is
explicit and mockable, and a Supervisor can be scoped to a `db_path` (defaults
to the host DB) so tests can point it at a temp database.

  - Supervisor (in the package __init__) drops the ABC and gains write_proposal,
    read_proposal, list_pending_proposals, list_all_pending_proposals,
    write_response, read_response, archive_all_proposals, write_audit_entry,
    read_audit_entries, plus the launch-time prepare().
  - render_diff / sha256_hex are pure and stateless, so they move to
    orchestrator/supervisor/util.py (re-exported from the facade) rather than
    becoming methods.
  - queue.py is deleted; service.py + the supervise tests call through a
    Supervisor instance.

Full unit suite green (2243).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-24 14:52:17 -04:00
parent 27a122e24b
commit 8abccf7ffe
9 changed files with 183 additions and 210 deletions
+14 -16
View File
@@ -17,14 +17,12 @@ from bot_bottle.orchestrator.supervisor import (
AuditEntry,
Proposal,
STATUS_APPROVED,
Supervisor,
TOOL_EGRESS_ALLOW,
list_pending_proposals,
read_audit_entries,
read_proposal,
read_response,
write_audit_entry,
)
_SV = Supervisor()
def _proposal() -> Proposal:
return Proposal.new(
@@ -47,21 +45,21 @@ class TestReadMalformed(unittest.TestCase):
with patch.dict("os.environ", {"HOME": d}):
QueueStore("slug").migrate()
with self.assertRaises(FileNotFoundError):
read_proposal("slug", "p")
_SV.read_proposal("slug", "p")
def test_read_response_missing_row(self) -> None:
with tempfile.TemporaryDirectory() as d:
with patch.dict("os.environ", {"HOME": d}):
QueueStore("slug").migrate()
with self.assertRaises(FileNotFoundError):
read_response("slug", "p")
_SV.read_response("slug", "p")
def test_list_pending_reads_db_only(self) -> None:
with tempfile.TemporaryDirectory() as d:
with patch.dict("os.environ", {"HOME": d}):
QueueStore("slug").migrate()
supervise.write_proposal(_proposal())
pending = list_pending_proposals("slug")
_SV.write_proposal(_proposal())
pending = _SV.list_pending_proposals("slug")
self.assertEqual(1, len(pending))
self.assertEqual("slug", pending[0].bottle_slug)
@@ -70,26 +68,26 @@ class TestReadMalformed(unittest.TestCase):
with patch.dict("os.environ", {"HOME": d}):
QueueStore("slug").migrate()
p = _proposal()
supervise.write_proposal(p)
supervise.write_response("slug", supervise.Response(
_SV.write_proposal(p)
_SV.write_response("slug", supervise.Response(
proposal_id=p.id,
status=STATUS_APPROVED,
notes="",
))
self.assertEqual([], list_pending_proposals("slug"))
self.assertEqual([], _SV.list_pending_proposals("slug"))
class TestReadAuditEntries(unittest.TestCase):
def test_missing_log_returns_empty(self) -> None:
with tempfile.TemporaryDirectory() as home, \
patch.dict("os.environ", {"HOME": home}):
self.assertEqual([], read_audit_entries("egress", "nope"))
self.assertEqual([], _SV.read_audit_entries("egress", "nope"))
def test_reads_entries_from_db(self) -> None:
with tempfile.TemporaryDirectory() as home, \
patch.dict("os.environ", {"HOME": home}):
AuditStore().migrate()
write_audit_entry(AuditEntry(
_SV.write_audit_entry(AuditEntry(
timestamp="t",
bottle_slug="slug",
component="egress",
@@ -98,7 +96,7 @@ class TestReadAuditEntries(unittest.TestCase):
justification="",
diff="",
))
write_audit_entry(AuditEntry(
_SV.write_audit_entry(AuditEntry(
timestamp="t",
bottle_slug="other",
component="egress",
@@ -107,7 +105,7 @@ class TestReadAuditEntries(unittest.TestCase):
justification="",
diff="",
))
entries = read_audit_entries("egress", "slug")
entries = _SV.read_audit_entries("egress", "slug")
self.assertEqual(1, len(entries))
self.assertEqual("approve", entries[0].operator_action)