Answer principles round 1: 0 🔴, 5 🟡 (0 misread); require a swap limit beside the memory limit, ask in CLAUDE.md for both where rule-hook can't see the container, remove items 225 and 228 with a changelog entry; the -m finding was answered in the product-owner round 1 commit

This commit is contained in:
2026-10-24 00:42:39 +02:00
parent 2d219ff6c8
commit 196abe18a9
9 changed files with 26 additions and 28 deletions
+7 -5
View File
@@ -5,12 +5,14 @@ from shell_command import launched
# The options of docker, docker buildx and docker compose that take a value, so the value is not read as a subcommand.
DOCKER_VALUED = frozenset({"--ansi", "--builder", "--config", "--context", "--env-file", "--file", "--host", "--log-level", "--parallel", "--profile", "--progress", "--project-directory", "--project-name", "--tlscacert", "--tlscert", "--tlskey", "-c", "-f", "-H", "-l", "-p"})
# The subcommands that start a container, which takes the memory limit docker run's -m sets.
# The subcommands that make a container, whose memory limits docker reads from the same options.
STARTS_CONTAINER = (["container", "create"], ["container", "run"], ["create"], ["run"])
# A size as docker reads one, such as 4g, 512M or 1.5GiB: the pattern go-units' RAMInBytes parses.
SIZE = r"\d+(?:\.\d+)*[kKmMgGtTpP]?[iI]?[bB]?"
# -m4g is -m with its value attached; --memory-swap alone sets no limit.
# -m4g is -m with its value attached.
ATTACHED_LIMIT = re.compile(rf"(?:-m|--memory=){SIZE}")
# --memory-swap takes a size, or -1 for unlimited swap.
SWAP_LIMIT = re.compile(r"--memory-swap(=.*)?")
def docker_subcommand(arguments: list[str]) -> list[str]:
@@ -30,12 +32,12 @@ def docker_subcommand(arguments: list[str]) -> list[str]:
def unlimited(arguments: list[str]) -> bool:
"""Whether docker's arguments start a container, with docker run or docker create, and set it no memory limit.
"""Whether docker's arguments make a container, with docker run or docker create, and leave its memory or its swap without a limit.
A -m or --memory with a size among the container's own arguments, past its image, reads as the limit too: telling it apart needs every value-taking option of docker run. Taking only a size keeps python -m pytest from reading as one.
The container's own arguments, past its image, are read too: telling them apart needs every value-taking option of docker run. So a -m 4g there reads as a limit, while python -m pytest does not, since pytest is no size.
"""
subcommand = docker_subcommand(arguments)
return subcommand in STARTS_CONTAINER and not limited(arguments) and not helped(arguments, subcommand)
return subcommand in STARTS_CONTAINER and not (limited(arguments) and any(SWAP_LIMIT.fullmatch(word) for word in arguments)) and not helped(arguments, subcommand)
def limited(arguments: list[str]) -> bool: