fix(work): import hashlib and wire heal subparser into main CLI

This commit is contained in:
operator
2026-10-09 23:13:43 +00:00
parent c3b4b1cd28
commit f75977ca6e
202 changed files with 4185 additions and 4142 deletions
+33 -1
View File
@@ -38,6 +38,7 @@ def _load(name, relpath):
exec_constrained = _load("exec_constrained_loop", "bin/exec-constrained.py")
box_ctl = _load("box_ctl_looptest", "bin/box-ctl.py")
def _box_ctl(*args):
@@ -46,6 +47,34 @@ def _box_ctl(*args):
capture_output=True, text=True, timeout=180)
class _InProcResult:
"""Minimal CompletedProcess stand-in (returncode/stdout only)."""
def __init__(self, returncode, stdout):
self.returncode = returncode
self.stdout = stdout
def _box_ctl_inproc(*args):
"""In-process _box_ctl for pure dry-run verbs (quality-validate).
Calls the real main(argv) -- identical argv parsing, dispatch, audit,
and stdout JSON -- with stdout captured, amortizing the ~80ms
per-spawn interpreter + module-exec cost over one import. Only valid
for verbs that never read stdin (quality-validate is a dry-run that
never consumes stdin payloads).
"""
import io
from contextlib import redirect_stdout
buf = io.StringIO()
returncode = 0
with redirect_stdout(buf):
try:
box_ctl.main(["box-ctl.py", *args])
except SystemExit as e:
returncode = e.code if isinstance(e.code, int) else 1
return _InProcResult(returncode, buf.getvalue())
class ExecLoopOpsTests(unittest.TestCase):
def test_ops_registered_and_side_effecting(self):
spec = exec_constrained.OPS
@@ -208,7 +237,10 @@ class BoxCtlLoopTests(unittest.TestCase):
(["vars-get", "has space"], False),
]
for args, valid in cases:
r = _box_ctl("quality-validate", *args)
# In-process dry-run: same main(argv) path and stdout JSON as a
# subprocess call, without the per-case spawn cost. Assertions
# below are unchanged.
r = _box_ctl_inproc("quality-validate", *args)
self.assertEqual(json.loads(r.stdout)["valid"], valid, args)