From f428243ba37627bc58da2fbded8ebe6e037e6612 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Mon, 23 Nov 2026 15:33:22 -0700 Subject: [PATCH] Live finding: a line the tokenizer cannot split that plainly writes is ordinary source; scenario 1 reads file by file. done / next: rerun live 1 and 3 --- sisi/unitguard.py | 8 +++++++- tests/test_integration.py | 7 +++++++ tools/live_orchestration_check.py | 5 +++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/sisi/unitguard.py b/sisi/unitguard.py index 47d6cd5..e5c53c0 100644 --- a/sisi/unitguard.py +++ b/sisi/unitguard.py @@ -589,6 +589,10 @@ def _norm_lines(cmd): return "\n".join(out) +UNPARSED = "$unparsed" +_WRITES = re.compile(r"(?:^|[\s;&|(])(?:sed|perl)\b[^;&|\n]*?\s-\w*i\b|(?:^|[\s;&|(])(?:tee|rm|mv|cp|install|ln|touch|dd)\s|[^<>\d&]>>?\s*[^\s&|;)>]") + + def shell_targets(cmd, cwd): """Best-effort paths a shell command writes: redirects, tee, sed/perl -i, cp/mv/install/ln, rm/touch/mkdir, dd of=. What cannot be told from the text (an interpreter, a script) is left to the after-tool snapshot.""" @@ -598,7 +602,9 @@ def shell_targets(cmd, cwd): lex.whitespace_split = True toks = list(lex) except ValueError: - return [] + # the line cannot be split into words (nested quotes, a loop with an embedded script): if it plainly + # writes, say so with a target that is named by nothing, so the guard treats it as ordinary source + return [UNPARSED] if _WRITES.search(cmd or "") else [] segs, cur = [], [] for t in toks: if t in (";", "&", "|", "&&", "||"): diff --git a/tests/test_integration.py b/tests/test_integration.py index df8c20f..206eb48 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -441,6 +441,13 @@ class NoDeadlockAfterARefusedEdit(TG.GuardCase): self.open_unit() self.assertIsNone(self.bash('for f in src/*.py; do sed -i "s/a/b/" "$f"; done')) + def test_a_line_that_cannot_be_split_but_plainly_writes_is_ordinary_source(self): + cmd = ("for i in 01 02; do sed -i \"s/a$i/b/\" src/mod$i.py; done && python3 -c \"\nimport sys\nprint(f'x{1}')\n\" ; " + "git diff | grep '^[-+] ' \"") # an unbalanced quote: no tokenizer reads it + self.assertEqual(G.shell_targets(cmd, self.proj), [G.UNPARSED]) + self.assertIn("sisi contract init", self.bash(cmd)) + self.assertEqual(G.shell_targets('echo "unbalanced; ls', self.proj), []) # nothing plainly writing: left to the snapshot + 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 264761e..740107e 100644 --- a/tools/live_orchestration_check.py +++ b/tools/live_orchestration_check.py @@ -53,8 +53,9 @@ 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. 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.") +PROMPT = ("This project is in the current directory. Open the test in tests/ and each of the fourteen modules in src/ " + "one file at a time, then tell me what each file in src/ does, one line per file, and whether the test would pass. " + "Change nothing.") def build_project(root):