From b76e340b02e02e535ed4003d6c44511b711a6fa4 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Mon, 23 Nov 2026 15:20:53 -0700 Subject: [PATCH] Fixes A-D: deep freshness ignores .sisi/, send-back names why the profile applies, backup copy ignores vanished files, no recipe on a machine's message; tests/test_integration.py. done: fixes / next: full suite, lint, 30x runs, live scenarios --- sisi/deep.py | 11 + sisi/gate.py | 18 +- sisi/harvest.py | 6 +- sisi/hookio.py | 3 +- sisi/lifecycle.py | 34 ++- sisi/prompt.py | 34 ++- sisi/risk.py | 5 +- sisi/verify.py | 15 +- tests/test_integration.py | 497 ++++++++++++++++++++++++++++++++++++++ 9 files changed, 593 insertions(+), 30 deletions(-) create mode 100644 tests/test_integration.py diff --git a/sisi/deep.py b/sisi/deep.py index b538828..96ba243 100644 --- a/sisi/deep.py +++ b/sisi/deep.py @@ -16,6 +16,17 @@ def _lock_path(project): return os.path.join(paths.state(), "locks", "deep-" + key(project) + ".lock") +def tree_fp(project): + """What deep results are fresh against: the working tree as the work, never sisi's own records. Everything + under .sisi/ (the contract included) is left out, as it is from the fast checks' reuse fingerprint, so + recording a pause or a note does not make a fresh deep result stale.""" + from . import gitutil + try: + return gitutil.fingerprint(project) + except Exception: + return None + + def deep_items(c): return [x for x in c.get("checks", []) + c.get("invariants", []) if x.get("tier") == "deep" and x.get("cmd") and x.get("rung", 3) not in (5, 6)] diff --git a/sisi/gate.py b/sisi/gate.py index b923e02..9faf020 100644 --- a/sisi/gate.py +++ b/sisi/gate.py @@ -378,7 +378,7 @@ def _decide(payload): if req.get("all_checks") and c is not None and not errs: try: from . import deep as D - ds = D.deep_state(c, project, fp) + ds = D.deep_state(c, project, D.tree_fp(project)) except Exception as e: store.log_error("gate-deep", e) failing = V.blocking(results) @@ -485,14 +485,26 @@ def _close(stop, cwd, c, path, project, profile, note): return stop.allow(cwd, "\n".join(x for x in (note, cyc) if x) or None) +def profile_reason(profile, info, reasons): + """Why this profile applies: the first reason a changed path gives; when no path gave one (nothing changed + yet, or the unit stands on its declared profile), say that the contract declares it, or the floor's reason.""" + real = [r for r in reasons or [] if r and r != risk.NO_PATHS] + if real: + return real[0] + if info.get("declared") == profile: + return "the contract declares the %s profile" % profile + return None + + def _send_back(stop, cwd, c, path, project, profile, info, reasons, miss, failing, results): uid = c["id"] if c else None why = ["%s" % m[0] for m in miss] + ["%s failed" % f["id"] for f in failing] if stop.exhausted(): return _release(stop, cwd, c, path, project, why) lines = ["sisi: this %s change is not ready to hand over (send-back {n})." % profile] - if reasons: - lines[0] = lines[0][:-1] + " because %s." % reasons[0][:160] + because = profile_reason(profile, info, reasons) + if because: + lines[0] = lines[0][:-1] + " because %s." % because[:160] if info.get("refused"): lines.append("The contract declares %r, but the change is %r; add risk.why to lower it on the record." % (info.get("declared"), info.get("floor"))) diff --git a/sisi/harvest.py b/sisi/harvest.py index e0622a0..079a7cc 100644 --- a/sisi/harvest.py +++ b/sisi/harvest.py @@ -118,6 +118,10 @@ _PLACEHOLDERS = [re.compile(r"\[Image[^\]]*\]"), re.compile(r"\[File:[^\]]*\]"), _NOT_HUMAN_PREFIX = ("(.*?)", re.S) @@ -152,7 +156,7 @@ def typed_text(d, queued_prompt=None): s = content.strip() if s.startswith("[Request interrupted by user"): return None, 0, True - if s.startswith(_NOT_HUMAN_PREFIX): + if s.startswith(_NOT_HUMAN_PREFIX) or _MACHINE_NOTICE.match(s): return None, 0, False if s.startswith(("\ncompleted\ncut a new release and tag it\n', + 'Scheduled wake-up: cut a new release and tag it when the build is green') + + def test_a_person_gets_the_recipe(self): + self.mk() + self.assertIn("recipe `release`", self.ask("cut a new release and tag it")) + + def test_a_machines_notice_gets_no_recipe(self): + self.mk() + for text in self.NOTICES: + with self.subTest(text=text[:40]): + self.assertNotIn("recipe", self.ask(text)) + + def test_learnings_in_scope_still_go_through_for_a_notice(self): + lid = self.mk() + ctx = self.ask('Delegated task "publish the release: check the tag, the manifest version and the changelog" ' + '[completed]: ready to publish') + self.assertIn(lid, ctx) + self.assertNotIn("Done means", ctx) + + def test_the_test_is_the_one_delivery_uses_and_it_defaults_to_no_recipe(self): + from sisi import harvest + for text in self.NOTICES: + self.assertIsNone(harvest.typed_text({}, queued_prompt=text)[0], text) + self.assertTrue(prompt.is_request("cut a new release and tag it")) + with mock.patch.object(harvest, "typed_text", side_effect=RuntimeError("cannot tell")): + self.assertFalse(prompt.is_request("cut a new release and tag it")) + self.assertFalse(prompt.is_request("cut a new release and tag it", {"origin": {"kind": "task-notification"}})) + + +if __name__ == "__main__": + unittest.main()