Refuse in rule-hook a Bash or Monitor wait that has no end
CI / tests (pull_request) Failing after 3m3s
CI / tests (pull_request) Failing after 3m3s
This commit is contained in:
@@ -6,13 +6,14 @@ import typing
|
||||
from review_rules.round_titles import CAP, COUNTS, EXAMPLE, lacks_counts, OPENING, RELEASE_REVIEW_CAP
|
||||
from git_cli.git_command import CommitCall
|
||||
from run_heavy.capped_docker import finds_this_docker
|
||||
from rule_hook.endless_wait import endless_waits
|
||||
from rule_hook.heavy_command import heavy
|
||||
from command_lines.shell_command import launched, LAUNCHERS, Simple
|
||||
from review_rules.review_folder import REPORTS
|
||||
from project_config import templates
|
||||
from command_lines.docker_command import unlimited
|
||||
|
||||
RuleName = typing.Literal["action-pin", "commit-one-line", "commit-title", "docker-run-memory", "env-file-read", "ignorefile-sorted", "image-pin", "no-ai-attribution", "repeat-read", "reviewer-report", "reviewer-rung", "round-cap", "round-title-counts", "run-heavy", "todo-rank-check", "transcript-read"]
|
||||
RuleName = typing.Literal["action-pin", "commit-one-line", "commit-title", "docker-run-memory", "endless-wait", "env-file-read", "ignorefile-sorted", "image-pin", "no-ai-attribution", "repeat-read", "reviewer-report", "reviewer-rung", "round-cap", "round-title-counts", "run-heavy", "todo-rank-check", "transcript-read"]
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
@@ -40,6 +41,10 @@ RULES: dict[RuleName, Rule] = {
|
||||
"a container made with docker run or docker create has a memory limit and a swap limit, as large as its work needs, such as `--memory 4g --memory-swap 4g`, so a runaway container fails alone instead of starving the machine; a swap limit equal to the memory limit keeps it out of swap",
|
||||
"docker run, docker create, docker container run and docker container create, whether direct or through a launcher such as nice or timeout. One under run-heavy passes, as run-heavy's docker adds the limits on Linux, unless it names docker by its path, or changes or clears PATH, as env -i, sudo or doas do. A container a script or docker compose starts is not checked",
|
||||
),
|
||||
"endless-wait": Rule(
|
||||
"a wait ends: a loop that sleeps has a time limit or a count cap, and a `pgrep -f` or `pkill -f` has a pattern its own command line doesn't match, since such a pattern finds the shell that runs the command and the wait never ends, and the session that waits on it hangs; wait with `~/.claude/bin/wait-for <file> [<pattern>] --timeout <seconds>`, or find a process by name with `pgrep -x`",
|
||||
"a Bash or Monitor command with an `until`, `while` or `for ((;;))` loop that runs `sleep` and has no `timeout`, no `date` or $SECONDS comparison and no counter compared with -lt, -le, -gt or -ge, or a `pgrep -f` or `pkill -f` whose pattern, read as a regular expression, matches the command's text; the same inside the script of a `bash -c`, unless a `timeout` runs the shell. A loop over a list, such as `for i in $(seq 1 40)`, is a count and passes",
|
||||
),
|
||||
# A marker would let the credentials into the transcript all the same, so no marker waives it.
|
||||
"env-file-read": Rule(
|
||||
"an agent never reads ~/.claude/.env or a project's env-file, the file of credentials the project's config names, since a value the agent reads lands in its transcript, which loop-claude archives and the backups copy; it leaves a tool that needs a credential to read the file itself, gets the file's path from `~/.claude/bin/project-config env-file`, and spells the path another way, such as \"the .env in ~/.claude\", in a command that must mention it without reading it, such as a commit's title, and searches only a folder without it",
|
||||
@@ -163,6 +168,7 @@ def command_breaches(command: str, simples: list[Simple]) -> list[Breach]:
|
||||
publishing = [simple for simple in simples if posixpath.basename(simple.words[0]) in ("chunk-pr", "gh", "git", "tea")]
|
||||
if publishing and ATTRIBUTION.search(command):
|
||||
breaches.append(Breach("no-ai-attribution", "the command carries an attribution", publishing[0].directory))
|
||||
breaches += [Breach("endless-wait", detail, directory) for detail, directory in endless_waits(command, simples)]
|
||||
for simple in simples:
|
||||
if heavy(simple.words):
|
||||
breaches.append(Breach("run-heavy", f"run `{' '.join(simple.words)[:80]}` under `~/.claude/bin/run-heavy`, in the background", simple.directory))
|
||||
|
||||
Reference in New Issue
Block a user