Fix command-name substitution and rules move with duplicate at destination
ci / test (push) Waiting to run

This commit is contained in:
swaits committed 2026-12-02 11:49:32 -07:00
1 parent 6477fc66d2
commit cb442e7d6f
4 files changed
+17 -4

No files matched your search

+1 -1
View File
@@ -88,7 +88,7 @@ def own(command):
def say(text): def say(text):
"""A hook message, naming sisi by its full path when `sisi` is not on PATH.""" """A hook message, naming sisi by its full path when `sisi` is not on PATH."""
import shutil import shutil
return text if shutil.which("sisi") else re.sub(r"(?<![\w/-])sisi(?= [a-z-])", os.path.join(store.LIB, "current", "bin", "sisi"), text) return text if shutil.which("sisi") else "`".join(p if i % 2 == 0 else re.sub(r"(?<![\w/-])sisi(?= (?!chore:|node:)[a-z-])", os.path.join(store.LIB, "current", "bin", "sisi"), p) for i, p in enumerate(text.split("`")))
def _begin(state, cwd): def _begin(state, cwd):
+2 -1
View File
@@ -648,12 +648,13 @@ def move(args, cwd):
start, to, to_cwd = " ".join(args[0].split()), args[1], top or cwd start, to, to_cwd = " ".join(args[0].split()), args[1], top or cwd
forms = [f for f in ([start, start[2:]] if start.startswith("- ") else [start]) if f] forms = [f for f in ([start, start[2:]] if start.startswith("- ") else [start]) if f]
homes = {path(lv, c): (lv, c) for lv, c in [(CORE, cwd), (USER, cwd)] + [(PROJECT, c) for c in (cwd, top) if c and has_project(c)]} homes = {path(lv, c): (lv, c) for lv, c in [(CORE, cwd), (USER, cwd)] + [(PROJECT, c) for c in (cwd, top) if c and has_project(c)]}
dst = path(to, to_cwd) if to != "canon" else None
hits = [(p, lv, l) for p, (lv, c) in homes.items() for l in dict.fromkeys(scope_lines(lv, c) if lv == PROJECT else lines(p)) if any(" ".join(l[2:].split()).startswith(f) for f in forms)] hits = [(p, lv, l) for p, (lv, c) in homes.items() for l in dict.fromkeys(scope_lines(lv, c) if lv == PROJECT else lines(p)) if any(" ".join(l[2:].split()).startswith(f) for f in forms)]
hits = [h for h in hits if any(" ".join(h[2][2:].split()) == f for f in forms)] or hits hits = [h for h in hits if any(" ".join(h[2][2:].split()) == f for f in forms)] or hits
hits = [h for h in hits if h[0] != dst] or hits
if len(hits) != 1: if len(hits) != 1:
return "no rule line starts with that; run `sisi rules` to see the rules" if not hits else "more than one rule starts with that; give more of it:\n" + "\n".join(" [%s] %s" % (lv, l) for _, lv, l in hits) return "no rule line starts with that; run `sisi rules` to see the rules" if not hits else "more than one rule starts with that; give more of it:\n" + "\n".join(" [%s] %s" % (lv, l) for _, lv, l in hits)
src, lv, line = hits[0] src, lv, line = hits[0]
dst = path(to, to_cwd) if to != "canon" else None
if to == "canon" and lv != CORE: if to == "canon" and lv != CORE:
return "only a rule queued for the product goes to canon, after it is added to canon/core.md; this is a %s rule" % lv return "only a rule queued for the product goes to canon, after it is added to canon/core.md; this is a %s rule" % lv
if src == dst: if src == dst:
+11
View File
@@ -4110,6 +4110,17 @@ cli.main(["tick"])
self.assertEqual(self.read(self.data, "rules", "user.md"), before) self.assertEqual(self.read(self.data, "rules", "user.md"), before)
self.assertFalse(os.path.exists(os.path.join(self.proj, ".sisi"))) self.assertFalse(os.path.exists(os.path.join(self.proj, ".sisi")))
def test_rules_move_succeeds_when_the_destination_already_has_the_line(self):
line = "- Duplicate destination rule stays once [owner 2026-11-20]"
self.user_file(line + "\n- Another user rule [retro 2026-11-21]\n")
other = self.project("other")
os.makedirs(os.path.join(other, ".sisi"), exist_ok=True)
proj_rules = self.write(os.path.join(other, ".sisi", "rules.md"), line + "\n")
rc, out, _ = self.sisi("rules", "move", "Duplicate destination rule", "project", "--project", other)
self.assertEqual(rc, 0, out)
self.assertEqual(self.read(self.data, "rules", "user.md"), "- Another user rule [retro 2026-11-21]\n")
self.assertEqual(self.read(proj_rules), line + "\n")
def test_move_prefers_the_exact_line_when_one_rule_is_a_prefix_of_another(self): # undo review A def test_move_prefers_the_exact_line_when_one_rule_is_a_prefix_of_another(self): # undo review A
self.user_file("- Check logs\n") self.user_file("- Check logs\n")
self.write(os.path.join(self.data, "rules", "core.md"), "- Check logs in CI\n") self.write(os.path.join(self.data, "rules", "core.md"), "- Check logs in CI\n")
+3 -2
View File
@@ -1,5 +1,5 @@
"""The plan: a dependency graph recorded before any work is handed out, and the hooks that hold the lead to it.""" """The plan: a dependency graph recorded before any work is handed out, and the hooks that hold the lead to it."""
import io, json, os, sys, unittest import io, json, os, shutil, sys, unittest
from unittest import mock from unittest import mock
try: # the module, not its class: its tests must not run twice try: # the module, not its class: its tests must not run twice
from tests import test_core from tests import test_core
@@ -570,7 +570,8 @@ class Plan(unittest.TestCase):
rc, out, _ = self.hook("gate") rc, out, _ = self.hook("gate")
self.assertIn('"block"', out) self.assertIn('"block"', out)
self.assertIn("nodes a, b are ready and not started", out) self.assertIn("nodes a, b are ready and not started", out)
self.assertIn("`sisi pick --node a` `sisi pick --node b`", out) exe = "sisi" if shutil.which("sisi") else os.path.join(self.tmp, "lib", "current", "bin", "sisi")
self.assertIn("`%s pick --node a` `%s pick --node b`" % (exe, exe), out)
def test_gate_lets_the_turn_end_while_nodes_only_run(self): def test_gate_lets_the_turn_end_while_nodes_only_run(self):
self.ready_plan() self.ready_plan()