refactor(supervise): hash the proposed file inside Proposal.new; sha256_hex → root util
tracker-policy-pr / check-pr (pull_request) Successful in 16s
test / integration-docker (pull_request) Successful in 39s
test / unit (pull_request) Successful in 53s
lint / lint (push) Failing after 1m3s
test / integration-firecracker (pull_request) Successful in 3m35s
test / coverage (pull_request) Successful in 19s
test / publish-infra (pull_request) Has been skipped
tracker-policy-pr / check-pr (pull_request) Successful in 16s
test / integration-docker (pull_request) Successful in 39s
test / unit (pull_request) Successful in 53s
lint / lint (push) Failing after 1m3s
test / integration-firecracker (pull_request) Successful in 3m35s
test / coverage (pull_request) Successful in 19s
test / publish-infra (pull_request) Has been skipped
Move sha256_hex out of orchestrator/supervisor/util.py to the root bot_bottle.util (it's a generic string hash, not supervise-specific), and have Proposal.new take the proposed file contents and compute current_file_hash itself instead of every caller passing sha256_hex(proposed_file). Every call site set current_file_hash to the hash of the proposed file, and nothing reads the field except the DB round-trip (schema + _row_to_proposal + from_dict, all untouched), so folding the hash into the factory is behavior-preserving and removes the boilerplate. Callers now pass just the file; the orchestrator no longer imports sha256_hex at all. Full unit suite green (2243). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -41,7 +41,6 @@ from .supervisor import (
|
||||
TOOL_EGRESS_BLOCK,
|
||||
Supervisor,
|
||||
render_diff,
|
||||
sha256_hex,
|
||||
)
|
||||
|
||||
|
||||
@@ -216,7 +215,6 @@ class Orchestrator:
|
||||
tool=tool,
|
||||
proposed_file=proposed_file,
|
||||
justification=justification,
|
||||
current_file_hash=sha256_hex(proposed_file),
|
||||
)
|
||||
self._supervisor.write_proposal(proposal)
|
||||
return proposal.id
|
||||
|
||||
@@ -8,8 +8,8 @@ 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`
|
||||
/ `sha256_hex` helpers (`util`), so orchestrator-side callers import from one
|
||||
place. The data plane must NOT import this package — it imports
|
||||
helper (`util`), so orchestrator-side callers import from one place. 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 +24,7 @@ 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, sha256_hex # noqa: F401 — re-exported for callers
|
||||
from .util import render_diff # noqa: F401 — re-exported for callers
|
||||
|
||||
|
||||
class Supervisor:
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
"""Pure supervise helpers — diff rendering and content hashing.
|
||||
"""Pure supervise helpers — diff rendering.
|
||||
|
||||
Stateless utilities used alongside the `Supervisor` service. Kept as plain
|
||||
functions (not methods) because they carry no state and are also handy to
|
||||
callers that only need to hash or diff.
|
||||
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
|
||||
import hashlib
|
||||
|
||||
|
||||
def render_diff(before: str, after: str, *, label: str = "config") -> str:
|
||||
@@ -25,7 +24,3 @@ def render_diff(before: str, after: str, *, label: str = "config") -> str:
|
||||
if not parts:
|
||||
return ""
|
||||
return "".join(p if p.endswith("\n") else p + "\n" for p in parts).rstrip("\n")
|
||||
|
||||
|
||||
def sha256_hex(content: str) -> str:
|
||||
return hashlib.sha256(content.encode("utf-8")).hexdigest()
|
||||
|
||||
Reference in New Issue
Block a user