diff --git a/sisi/cycle.py b/sisi/cycle.py index f99f1f4..18c7f68 100644 --- a/sisi/cycle.py +++ b/sisi/cycle.py @@ -339,6 +339,11 @@ def brief_text(): base = L.store_base(rows) flagged = {r["id"] for r in L.flagged(rows)} todo = _rank([r for r in proposed(rows) if r["id"] not in flagged] + L.flagged(rows)) + if not todo: + backlog = sum(1 for r in rows if r.get("status") == "backlog") + waiting = sum(1 for r in rows if r.get("status") == "pending-approval") + return ("Learning cycle brief: no learning a cycle can act on (%d on the backlog for sisi itself, %d waiting " + "for the owner). Nothing to write.\n" % (backlog, waiting)) text = "Learning cycle brief.\n" + format_text(base) blocks, left = [], 0 for r in todo[:BRIEF_MAX_LEARNINGS]: @@ -347,7 +352,7 @@ def brief_text(): r["id"], r.get("recurrences_after_promotion", 0)) else: blk = _learning_block(r) - if len(text) + sum(len(b) + 1 for b in blocks) + len(blk) + 120 > BRIEF_MAX_CHARS and r["id"] not in flagged: + if len(text) + sum(len(b) + 1 for b in blocks) + len(blk) + 120 > BRIEF_MAX_CHARS: left += 1 continue blocks.append(blk) diff --git a/sisi/overlay.py b/sisi/overlay.py index 40b9277..9e8301b 100644 --- a/sisi/overlay.py +++ b/sisi/overlay.py @@ -796,6 +796,10 @@ def _rule_change_waits(action): ok, msg = documents.check_budgets(render_with({rid: parse_rule_file(action["rule_text"], rid)})) if not ok: raise OverlayError(msg) + waiting = cycle._waiting()[1].get(rid) + if waiting: + raise OverlayError("rule %s already has a change waiting for the owner (%s); a second one waits until that " + "is decided" % (rid, waiting)) pid = cycle.park_rule_change(action, ["%s %s: changing or disabling an existing rule needs the owner" % (action["action"], rid)]) print("%s %s waits for the owner: nothing changed. The owner decides in a terminal: `sisi approve %s --yes`" % (action["action"], rid, pid)) diff --git a/tests/test_cycle_hardening.py b/tests/test_cycle_hardening.py index 9745a18..4cc13a1 100644 --- a/tests/test_cycle_hardening.py +++ b/tests/test_cycle_hardening.py @@ -918,3 +918,34 @@ class DueCounter(Base): with open(p, "w") as f: json.dump(rec, f) self.assertIn("cycle is due (6 proposed", cycle.due_notice()) + + +class Odds(Base): + """R-11.5-11, R-11.1-14 (items 5 and 8): the edges.""" + + def test_the_overlay_command_cannot_stack_a_second_change_on_a_rule_that_has_one_waiting(self): + _contract(self) + text = "## Deliver {#deliver-fast}\n\nShip it.\n\nWhy: speed.\n" + with open(os.path.join(self.tmp, "r.md"), "w") as f: + f.write(text) + r = self.sisi("overlay", "replace-rule", "deliver-fast", os.path.join(self.tmp, "r.md")) + self.assertEqual(r.returncode, 0, r.stderr) + r = self.sisi("overlay", "replace-rule", "deliver-fast", os.path.join(self.tmp, "r.md")) + self.assertEqual(r.returncode, 1) + self.assertIn("already has a change waiting", r.stderr) + self.assertEqual(len(self.pending()), 1) + + def test_an_empty_brief_says_so_in_one_line_and_flagged_learnings_never_break_the_limit(self): + _contract(self) + out = self.sisi("cycle").stdout + self.assertEqual(len(out.splitlines()), 1) + self.assertIn("Nothing to write", out) + for n in range(8): + self.another(n) + rows = self.rows() + for r in rows: + r["flagged_not_working"] = True + L.save_learnings(rows, "t", touched=rows, via="test") + text = self.sisi("cycle").stdout + self.assertLessEqual(len(text), 6000) + self.assertEqual(text.count("FLAGGED NOT WORKING"), 8)