Answer stability round 1: 0 🔴, 3 🟡 (0 misread); drop the duplicate predicate test, say that finds_this_docker assumes run-heavy's PATH, say why resets_path matches broadly

This commit is contained in:
2026-11-08 11:14:13 +01:00
parent 2321f4930d
commit ed7f3eb949
2 changed files with 2 additions and 11 deletions
+2 -2
View File
@@ -37,10 +37,10 @@ def without_path_entry(path: str) -> str:
def finds_this_docker(word: str, before: list[str]) -> bool:
"""Whether a command that runs under run-heavy reaches this docker, given the word that names docker and the words before it: docker named bare, since a path names another, and no word before it resets the PATH that run-heavy set. Only where run-heavy knows the memory, as on Linux."""
"""Whether a command's docker is this one, given the word that names docker and the words before it, assuming run-heavy put this docker first on PATH, as it does on Linux. It is where docker is named bare, since a path names a different docker, and no word before it may reset PATH."""
return word == "docker" and not any(resets_path(earlier) for earlier in before)
def resets_path(word: str) -> bool:
"""Whether a word before docker drops the PATH run-heavy set: a PATH= of its own, env's -i or -u, or sudo or doas, which reset it."""
"""Whether a word before docker may drop the PATH run-heavy set. It errs towards yes, so that a command it matches must set its own memory limits: it matches a PATH= assignment, -i, --ignore-environment, -u or --unset whichever variable and launcher they belong to, and sudo or doas, which reset PATH."""
return word.startswith(("PATH=", "--unset")) or word in ("-i", "--ignore-environment", "-u") or tool_name(word) in ("doas", "sudo")
-9
View File
@@ -9,7 +9,6 @@ import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from run_heavy.capped_docker import finds_this_docker
from run_heavy import main
from machine_load.memory import read_memory
from machine_load.slots import slot_count, usable_cpus
@@ -142,14 +141,6 @@ class RunHeavy(unittest.TestCase):
self.assertEqual(helped.returncode, 0)
self.assertIn("usage: run-heavy <command>", helped.stdout)
def test_the_capped_docker_is_found_only_by_docker_named_bare_with_no_word_before_it_resetting_path(self):
for word, before in [("docker", []), ("docker", ["run-heavy"]), ("docker", ["run-heavy", "env", "X=1"]), ("docker", ["run-heavy", "nice", "-n", "19"])]:
with self.subTest(word=word, before=before):
self.assertTrue(finds_this_docker(word, before))
for word, before in [("/usr/bin/docker", []), ("docker", ["env", "PATH=/usr/bin"]), ("docker", ["env", "-i"]), ("docker", ["env", "-u", "PATH"]), ("docker", ["env", "--unset=PATH"]), ("docker", ["sudo"]), ("docker", ["/usr/bin/doas"])]:
with self.subTest(word=word, before=before):
self.assertFalse(finds_this_docker(word, before))
if __name__ == "__main__":
unittest.main()