refactor(util): make render_diff generic (caller supplies side titles); move to root util
tracker-policy-pr / check-pr (pull_request) Successful in 8s
test / integration-docker (pull_request) Successful in 36s
test / unit (pull_request) Successful in 43s
lint / lint (push) Successful in 56s
test / integration-firecracker (pull_request) Successful in 3m27s
test / coverage (pull_request) Successful in 21s
test / publish-infra (pull_request) Has been skipped

Generalize render_diff so it isn't supervise-flavored: the "(current)" /
"(proposed)" side titles are no longer baked in — callers pass `before_title`
and `after_label` (required). Move it from orchestrator/supervisor/util.py to
the base bot_bottle.util alongside sha256_hex, and delete the now-empty
supervisor/util.py.

The supervise callsite (Orchestrator.supervise_respond) assigns
before_title="current", after_label="proposed"; the facade no longer re-exports
render_diff (callers import from bot_bottle.util). Behavior at the supervise
callsite is unchanged.

Full unit suite green (2243).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-24 15:09:27 -04:00
parent db6a151803
commit d41236c376
5 changed files with 38 additions and 36 deletions
@@ -7,9 +7,10 @@ object — optionally scoped to a `db_path` — makes the orchestrator's supervi
dependency explicit and injectable in tests.
For convenience this package also re-exports the neutral vocabulary
(`bot_bottle.supervisor`'s types + `SupervisePlan`) and the pure `render_diff`
helper (`util`), so orchestrator-side callers import from one place. The data
plane must NOT import this package — it imports
(`bot_bottle.supervisor`'s types + `SupervisePlan`), so orchestrator-side
callers import from one place. (Generic helpers like `render_diff` /
`sha256_hex` live in `bot_bottle.util`.) The data plane must NOT import this
package — it imports
`bot_bottle.supervisor` (neutral) directly and reaches the queue over the
control-plane RPC.
"""
@@ -24,7 +25,6 @@ from ..store.store_manager import StoreManager
from ..store.queue_store import QueueStore
from ...store.audit_store import AuditStore
from ...supervisor.types import AuditEntry, Proposal, Response
from .util import render_diff # noqa: F401 — re-exported for callers
class Supervisor:
@@ -1,26 +0,0 @@
"""Pure supervise helpers — diff rendering.
Stateless utility used alongside the `Supervisor` service. Kept as a plain
function (not a method) because it carries no state. (Content hashing is a
generic helper — `bot_bottle.util.sha256_hex`.)
"""
from __future__ import annotations
import difflib
def render_diff(before: str, after: str, *, label: str = "config") -> str:
"""Unified diff suitable for the audit log + TUI. Empty diff (no changes)
renders as the empty string."""
diff = difflib.unified_diff(
before.splitlines(keepends=True),
after.splitlines(keepends=True),
fromfile=f"{label} (current)",
tofile=f"{label} (proposed)",
lineterm="",
)
parts = list(diff)
if not parts:
return ""
return "".join(p if p.endswith("\n") else p + "\n" for p in parts).rstrip("\n")