Kill the endless-wait message mutants
CI / tests (pull_request) Successful in 3m5s

This commit is contained in:
2026-11-18 20:39:10 +01:00
parent a25b346ccb
commit 39de100a34
2 changed files with 7 additions and 6 deletions
+4 -3
View File
@@ -24,16 +24,17 @@ SIGNAL = re.compile(r"-(?:\d+|[A-Z]{2,})")
VALUED = frozenset("dFgGPrstuU")
VALUED_LONG = frozenset({"--delimiter", "--euid", "--group", "--ns", "--nslist", "--parent", "--pgroup", "--pidfile", "--runstates", "--session", "--signal", "--terminal", "--uid"})
HOW = "use `~/.claude/bin/wait-for <file> [<pattern>] --timeout <seconds>`"
# What the refusal of a self-matching pgrep or pkill suggests first. Only a pgrep waits, so only it is pointed to wait-for.
INSTEAD = {"pgrep": f"{HOW}, a `pgrep -x` on the process name", "pkill": "use a `pkill -x` on the process name"}
def endless_waits(command: str, simples: list[Simple], capped: bool = False) -> list[tuple[str, str]]:
def endless_waits(command: str, simples: list[Simple], capped: bool) -> list[tuple[str, str]]:
"""Each endless wait the command starts, as its detail and the directory it runs in. capped is whether something ends every loop in the simple commands: a Monitor call's timeout_ms, or a `timeout` around the shell, as in `timeout 60 bash -c '…'`."""
found = [] if capped else [(f"a loop that sleeps, `{' '.join(loop[0].words)[:60]}`, has neither a time limit nor a count cap; {HOW}, or give the loop a deadline compared with `date` or $SECONDS, or a counter, as in `for i in $(seq 1 40)`", loop[0].directory) for loop in loops(simples) if endless(loop, command)]
for simple in simples:
if (found_match := self_match(simple.words, command)) is not None:
tool, pattern = found_match
instead = "a `pgrep -x` on the process name" if tool == "pgrep" else "a `pkill -x` on the process name"
found.append((f"`{pattern}` matches the command line that holds this `{tool} -f`, so `{tool}` finds the shell that runs the command; {HOW + ', ' if tool == 'pgrep' else 'use '}{instead}, or a pattern the command doesn't contain, such as `[c]hunk` for `chunk`", simple.directory))
found.append((f"`{pattern}` matches the command line that holds this `{tool} -f`, so `{tool}` finds the shell that runs the command; {INSTEAD[tool]}, or a pattern the command doesn't contain, such as `[c]hunk` for `chunk`", simple.directory))
if (script := shell_script(simple.words)) is not None:
found += endless_waits(command, [Simple(words, simple.directory) for words in segments(script)], capped or launched(simple.words, {"timeout"}) is not None)
return found