From 7dcd9eb4770f9b6cdf16df027544af0174f21c9a Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Mon, 23 Nov 2026 15:31:41 -0700 Subject: [PATCH] Live finding: a shell write named by a variable is ordinary source; shell keywords before a command; scenario 1 reads only (building is scenario 3's). done: second live round / next: rerun, scenario 2 x6, stress, timing --- sisi/unitguard.py | 9 ++++++++- tests/test_integration.py | 9 +++++++++ tools/live_orchestration_check.py | 4 ++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/sisi/unitguard.py b/sisi/unitguard.py index fbe48e2..47d6cd5 100644 --- a/sisi/unitguard.py +++ b/sisi/unitguard.py @@ -624,7 +624,7 @@ def shell_targets(cmd, cwd): i += 1 words = [w for w in seg if w and not re.fullmatch(r"\d*(>>?|<\||&>>?)", w)] k = 0 - while k < len(words) and (re.match(r"^[A-Za-z_][A-Za-z0-9_]*=", words[k]) or words[k] in ("sudo", "command", "exec", "time", "nice")): + while k < len(words) and (re.match(r"^[A-Za-z_][A-Za-z0-9_]*=", words[k]) or words[k] in ("sudo", "command", "exec", "time", "nice", "do", "then", "else", "!", "{")): k += 1 if k >= len(words): continue @@ -850,6 +850,11 @@ def _before(payload): store.save_session(sid, sess) return None floor, _reasons = floor_of(paths_all, project) if paths_all else ("trivial", []) + # a write whose target is named by a shell variable or substitution cannot be told from the text (found by the + # live check: `for f in src/*; do sed -i ... "$f"; done`): it is ordinary source until shown otherwise + unresolved = [r for r in rels if kind == "shell" and re.search(r"[$`]", r)] + if unresolved and assure.ORDER[floor] < assure.ORDER["isolated"]: + floor = "isolated" if kind != "delegate" and floor == "trivial": have = sess.setdefault("ug_paths", []) for r in rels: @@ -866,6 +871,8 @@ def _before(payload): return None if kind == "delegate": what = "delegating this work to a worker" + elif unresolved: + what = "this call would change files its own text does not name (`%s`)" % unresolved[0] else: focus = next((x for x in paths_all if floor_of([x], project)[0] != "trivial"), paths_all[0]) what = ("this call would change `%s`" % focus) if focus in rels else \ diff --git a/tests/test_integration.py b/tests/test_integration.py index 822f38f..df8c20f 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -432,6 +432,15 @@ class NoDeadlockAfterARefusedEdit(TG.GuardCase): for cmd in ("sisi contract init > notes.txt", "sisi contract init | tee notes.txt"): self.assertIsNotNone(self.bash(cmd), cmd) + def test_a_write_named_by_a_shell_variable_is_ordinary_source(self): + """Found by the live check: `for f in src/*; do sed -i ... "$f"; done` slipped through as a trivial change.""" + msg = self.bash('for f in src/*.py; do sed -i "s/a/b/" "$f"; done') + self.assertIn("sisi contract init", msg) + self.assertIn("does not name", msg) + self.assertLessEqual(len(msg.splitlines()), 12) + self.open_unit() + self.assertIsNone(self.bash('for f in src/*.py; do sed -i "s/a/b/" "$f"; done')) + def test_a_cache_folder_is_as_ignorable_as_the_files_in_it(self): self.assertIsNone(self.bash("rm -rf src/__pycache__")) diff --git a/tools/live_orchestration_check.py b/tools/live_orchestration_check.py index 00f83bc..264761e 100644 --- a/tools/live_orchestration_check.py +++ b/tools/live_orchestration_check.py @@ -53,8 +53,8 @@ PROMPT3 = ("This project is in the current directory. Every function in src/ sho "f1 returns x + 1 today and should return x + 2, f2 returns x + 2 and should return x + 3, and so on for all " "fourteen modules (mod07 has a bug of its own, leave it as it is). Make the change, then tell me which files " "you changed. Nobody is available to answer questions during this run.") -PROMPT = ("This project is in the current directory. Find and fix the bug (a test in tests/ fails), then tell me " - "what each file in src/ does, one line per file.") +PROMPT = ("This project is in the current directory. Read the test in tests/ and every file in src/, then tell me " + "what each file in src/ does, one line per file, and whether the test would pass.") def build_project(root):