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
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:
@@ -17,19 +17,15 @@ from bot_bottle.orchestrator.supervisor import (
|
||||
STATUS_APPROVED,
|
||||
STATUS_MODIFIED,
|
||||
STATUS_REJECTED,
|
||||
Supervisor,
|
||||
TOOL_EGRESS_ALLOW,
|
||||
TOOL_GITLEAKS_ALLOW,
|
||||
list_pending_proposals,
|
||||
read_audit_entries,
|
||||
read_proposal,
|
||||
read_response,
|
||||
render_diff,
|
||||
sha256_hex,
|
||||
write_audit_entry,
|
||||
write_proposal,
|
||||
write_response,
|
||||
)
|
||||
|
||||
_SV = Supervisor()
|
||||
|
||||
|
||||
FIXED_TS = datetime(2026, 5, 25, 12, 0, 0, tzinfo=timezone.utc)
|
||||
|
||||
@@ -123,26 +119,26 @@ class TestQueueIO(unittest.TestCase):
|
||||
|
||||
def test_write_and_read_proposal(self):
|
||||
p = _proposal()
|
||||
path = write_proposal(p)
|
||||
path = _SV.write_proposal(p)
|
||||
self.assertTrue(path.exists())
|
||||
self.assertEqual(host_db_path(), path)
|
||||
self.assertEqual(0o600, path.stat().st_mode & 0o777)
|
||||
loaded = read_proposal(self.slug, p.id)
|
||||
loaded = _SV.read_proposal(self.slug, p.id)
|
||||
self.assertEqual(p, loaded)
|
||||
|
||||
def test_list_pending_excludes_responded(self):
|
||||
a = _proposal(justification="first")
|
||||
b = _proposal(justification="second")
|
||||
write_proposal(a)
|
||||
write_proposal(b)
|
||||
write_response(self.slug, Response(
|
||||
_SV.write_proposal(a)
|
||||
_SV.write_proposal(b)
|
||||
_SV.write_response(self.slug, Response(
|
||||
proposal_id=a.id, status=STATUS_APPROVED, notes="",
|
||||
))
|
||||
pending = list_pending_proposals(self.slug)
|
||||
pending = _SV.list_pending_proposals(self.slug)
|
||||
self.assertEqual([b.id], [p.id for p in pending])
|
||||
|
||||
def test_list_pending_returns_empty_for_missing_slug(self):
|
||||
self.assertEqual([], list_pending_proposals("nope"))
|
||||
self.assertEqual([], _SV.list_pending_proposals("nope"))
|
||||
|
||||
def test_list_pending_sorted_by_arrival(self):
|
||||
# Fabricate two with explicit timestamps.
|
||||
@@ -159,15 +155,15 @@ class TestQueueIO(unittest.TestCase):
|
||||
now=datetime(2026, 5, 25, 14, 0, 0, tzinfo=timezone.utc),
|
||||
)
|
||||
# Write in reverse order.
|
||||
write_proposal(b)
|
||||
write_proposal(a)
|
||||
ordered = list_pending_proposals(self.slug)
|
||||
_SV.write_proposal(b)
|
||||
_SV.write_proposal(a)
|
||||
ordered = _SV.list_pending_proposals(self.slug)
|
||||
self.assertEqual([a.id, b.id], [p.id for p in ordered])
|
||||
|
||||
def test_write_and_read_response(self):
|
||||
r = Response(proposal_id="xyz", status=STATUS_REJECTED, notes="no")
|
||||
write_response(self.slug, r)
|
||||
self.assertEqual(r, read_response(self.slug, "xyz"))
|
||||
_SV.write_response(self.slug, r)
|
||||
self.assertEqual(r, _SV.read_response(self.slug, "xyz"))
|
||||
|
||||
|
||||
class TestAuditLog(unittest.TestCase):
|
||||
@@ -193,15 +189,15 @@ class TestAuditLog(unittest.TestCase):
|
||||
justification="agent needed gh-api token",
|
||||
diff="--- before\n+++ after\n",
|
||||
)
|
||||
path = write_audit_entry(e)
|
||||
path = _SV.write_audit_entry(e)
|
||||
self.assertEqual(host_db_path(), path)
|
||||
self.assertEqual(0o600, path.stat().st_mode & 0o777)
|
||||
loaded = read_audit_entries("cred-proxy", "dev")
|
||||
loaded = _SV.read_audit_entries("cred-proxy", "dev")
|
||||
self.assertEqual([e], loaded)
|
||||
|
||||
def test_appends_one_line_per_entry(self):
|
||||
for i in range(3):
|
||||
write_audit_entry(AuditEntry(
|
||||
_SV.write_audit_entry(AuditEntry(
|
||||
timestamp=f"2026-05-25T12:00:0{i}+00:00",
|
||||
bottle_slug="dev",
|
||||
component="egress",
|
||||
@@ -210,7 +206,7 @@ class TestAuditLog(unittest.TestCase):
|
||||
justification="",
|
||||
diff="",
|
||||
))
|
||||
entries = read_audit_entries("egress", "dev")
|
||||
entries = _SV.read_audit_entries("egress", "dev")
|
||||
self.assertEqual(3, len(entries))
|
||||
self.assertEqual(
|
||||
["2026-05-25T12:00:00+00:00", "2026-05-25T12:00:01+00:00",
|
||||
@@ -219,7 +215,7 @@ class TestAuditLog(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_separate_logs_per_component_slug(self):
|
||||
write_audit_entry(AuditEntry(
|
||||
_SV.write_audit_entry(AuditEntry(
|
||||
timestamp="t",
|
||||
bottle_slug="dev",
|
||||
component="cred-proxy",
|
||||
@@ -228,7 +224,7 @@ class TestAuditLog(unittest.TestCase):
|
||||
justification="",
|
||||
diff="",
|
||||
))
|
||||
write_audit_entry(AuditEntry(
|
||||
_SV.write_audit_entry(AuditEntry(
|
||||
timestamp="t",
|
||||
bottle_slug="dev",
|
||||
component="egress",
|
||||
@@ -237,7 +233,7 @@ class TestAuditLog(unittest.TestCase):
|
||||
justification="",
|
||||
diff="",
|
||||
))
|
||||
write_audit_entry(AuditEntry(
|
||||
_SV.write_audit_entry(AuditEntry(
|
||||
timestamp="t",
|
||||
bottle_slug="other",
|
||||
component="cred-proxy",
|
||||
@@ -246,12 +242,12 @@ class TestAuditLog(unittest.TestCase):
|
||||
justification="",
|
||||
diff="",
|
||||
))
|
||||
self.assertEqual(1, len(read_audit_entries("cred-proxy", "dev")))
|
||||
self.assertEqual(1, len(read_audit_entries("egress", "dev")))
|
||||
self.assertEqual(1, len(read_audit_entries("cred-proxy", "other")))
|
||||
self.assertEqual(1, len(_SV.read_audit_entries("cred-proxy", "dev")))
|
||||
self.assertEqual(1, len(_SV.read_audit_entries("egress", "dev")))
|
||||
self.assertEqual(1, len(_SV.read_audit_entries("cred-proxy", "other")))
|
||||
|
||||
def test_read_audit_entries_missing_log_returns_empty(self):
|
||||
self.assertEqual([], read_audit_entries("cred-proxy", "no-such-bottle"))
|
||||
self.assertEqual([], _SV.read_audit_entries("cred-proxy", "no-such-bottle"))
|
||||
|
||||
|
||||
class TestDiffAndHash(unittest.TestCase):
|
||||
|
||||
Reference in New Issue
Block a user