Item 4: remove guarded seams and dead code between the merged pieces. done 4 / next 5 (grouped help)
This commit is contained in:
1 parent
ed018a364c
commit
6787ef0ae9
23 files changed
+82
-261
No files matched your search
@@ -983,7 +983,7 @@ class Store(Base):
|
||||
root = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
||||
bad = []
|
||||
for n in sorted(os.listdir(os.path.join(root, "sisi"))):
|
||||
if not n.endswith(".py") or n == "gate.py": # gate.py's retro.lessons_block is the live gate seam
|
||||
if not n.endswith(".py"):
|
||||
continue
|
||||
with open(os.path.join(root, "sisi", n)) as f:
|
||||
for i, line in enumerate(f, 1):
|
||||
@@ -992,6 +992,23 @@ class Store(Base):
|
||||
bad.append("%s:%d" % (n, i))
|
||||
self.assertEqual(bad, [])
|
||||
|
||||
def test_no_guarded_seams_between_modules_that_always_exist(self):
|
||||
"""Item 4: no `except ImportError` or `hasattr(module, ...)` probe stands in for a module of this
|
||||
package, and nothing names a removed seam. The one platform probe (fcntl, absent on Windows, in pdata) stays."""
|
||||
import re
|
||||
root = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
||||
bad = []
|
||||
for n in sorted(os.listdir(os.path.join(root, "sisi"))):
|
||||
if not n.endswith(".py"):
|
||||
continue
|
||||
with open(os.path.join(root, "sisi", n)) as f:
|
||||
for i, line in enumerate(f, 1):
|
||||
if n != "pdata.py" and re.search(r"except \(?ImportError|hasattr\((delivery|unit|gate|retro|learning|cycle)\b", line):
|
||||
bad.append("%s:%d" % (n, i))
|
||||
if re.search(r"retro\.(TEMPLATE|satisfied|lessons_block)|ensure_imported", line):
|
||||
bad.append("%s:%d" % (n, i))
|
||||
self.assertEqual(bad, [])
|
||||
|
||||
def test_no_resource_warnings_from_the_learning_commands(self):
|
||||
"""Item 13: file handles are closed; every learning command runs clean under -W always."""
|
||||
_contract(self)
|
||||
|
||||
+32
-1
@@ -19,6 +19,37 @@ def snapshot(root):
|
||||
return snap
|
||||
|
||||
|
||||
def remove_hooks(obj):
|
||||
"""Test oracle: strip our hook groups from a settings object (the product removes them structurally)."""
|
||||
changed = False
|
||||
hooks = obj.get("hooks")
|
||||
if not isinstance(hooks, dict):
|
||||
return False
|
||||
for ev, sub in (("SessionStart", "tick"), ("UserPromptSubmit", "prompt"), ("Stop", "gate"), ("SubagentStop", "gate"),
|
||||
("PreToolUse", "watch"), ("PostToolUse", "watch")):
|
||||
groups = hooks.get(ev)
|
||||
if not isinstance(groups, list):
|
||||
continue
|
||||
keep, ev_changed = [], False
|
||||
for g in groups:
|
||||
hs = g.get("hooks") if isinstance(g, dict) else None
|
||||
if isinstance(hs, list) and any(wiring._is_ours(h, sub) for h in hs):
|
||||
changed = ev_changed = True
|
||||
rest = [h for h in hs if not wiring._is_ours(h, sub)]
|
||||
if rest:
|
||||
g = dict(g, hooks=rest)
|
||||
else:
|
||||
continue
|
||||
keep.append(g)
|
||||
if keep:
|
||||
hooks[ev] = keep
|
||||
elif ev_changed:
|
||||
del hooks[ev]
|
||||
if changed and not hooks:
|
||||
del obj["hooks"]
|
||||
return changed
|
||||
|
||||
|
||||
class WiringBase(SisiCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
@@ -127,7 +158,7 @@ class WiringPropertyTests(WiringBase):
|
||||
if st is not None and st.strip():
|
||||
orig = json.loads(st)
|
||||
now = json.loads(self.path(".claude/settings.json") and open(self.path(".claude/settings.json"), "rb").read())
|
||||
wiring.remove_hooks(now)
|
||||
remove_hooks(now)
|
||||
|
||||
def norm(d): # empty hook lists/objects may legitimately disappear in the structural path
|
||||
h = d.get("hooks")
|
||||
|
||||
@@ -88,37 +88,6 @@ class DiscoveryTests(WorkerCase):
|
||||
self.assertFalse(tools["cursor-agent"]["usable"])
|
||||
|
||||
|
||||
class LedgerImportTests(WorkerCase):
|
||||
def test_existing_ledger_imported_once_losslessly(self):
|
||||
src = os.path.join(self.tmp, "orch-log.jsonl")
|
||||
rows = [
|
||||
{"kind": "attempt", "id": "abc123", "ts": 1700000000, "project": "p", "type": "impl",
|
||||
"difficulty": 2, "worker": "beta-1", "outcome": "accepted", "check": "tests",
|
||||
"minutes": 3, "tokens": None, "retry_of": None, "note": "keep me", "extra": [1, 2]},
|
||||
{"kind": "attempt", "id": "def456", "ts": 1700000100, "project": "p", "type": "impl",
|
||||
"difficulty": 2, "worker": "beta-1", "outcome": "rejected", "check": "read",
|
||||
"minutes": 4, "tokens": 9, "retry_of": "abc123", "note": None},
|
||||
{"kind": "amend", "id": "abc123", "ts": 1700000200, "note": "later wrong"},
|
||||
]
|
||||
with open(src, "w") as f:
|
||||
for row in rows:
|
||||
f.write(json.dumps(row) + "\n")
|
||||
before = open(src).read()
|
||||
r = self.sisi("workers", env=self.env(SISI_LEDGER=src))
|
||||
self.assertEqual(r.returncode, 0, r.stderr)
|
||||
self.assertIn("imported 3 rows", r.stdout)
|
||||
self.assertEqual(open(src).read(), before, "the original ledger must not be modified")
|
||||
got = [json.loads(l) for l in open(os.path.join(self.data, "delegations.jsonl"))]
|
||||
self.assertEqual(len(got), 3)
|
||||
for want, have in zip(rows, got):
|
||||
for k, v in want.items():
|
||||
self.assertEqual(have.get(k), v, k)
|
||||
# a second run imports nothing more
|
||||
self.sisi("workers", env=self.env(SISI_LEDGER=src))
|
||||
got2 = [json.loads(l) for l in open(os.path.join(self.data, "delegations.jsonl"))]
|
||||
self.assertEqual(len(got2), 3)
|
||||
|
||||
|
||||
class RouteTests(WorkerCase):
|
||||
def test_route_explains_and_skips_contributor_and_logged_out(self):
|
||||
r = self.sisi("route", "--kind", "impl", "--difficulty", "2", "--explain", env=self.env())
|
||||
|
||||
Reference in new issue
Block a user