From 0f2cb3557f087a7b21a626bddf2e14aa1204e77b Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 14 Nov 2026 16:56:58 +0100 Subject: [PATCH] =?UTF-8?q?Answer=20stability=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=204=20=F0=9F=9F=A1=20(0=20misread);=20stop=20a=20?= =?UTF-8?q?slow=20shim=20inside=20the=20container,=20test=20a=20crashing?= =?UTF-8?q?=20shim,=20and=20drop=20two=20tests=20that=20repeated=20others?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/adf_codec/node_shim/Dockerfile | 4 +++- bin/adf_codec/test_adf_codec.py | 21 ++++----------------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/bin/adf_codec/node_shim/Dockerfile b/bin/adf_codec/node_shim/Dockerfile index f138df4d..eeca65e9 100644 --- a/bin/adf_codec/node_shim/Dockerfile +++ b/bin/adf_codec/node_shim/Dockerfile @@ -4,4 +4,6 @@ COPY package.json package-lock.json ./ RUN npm ci --ignore-scripts --omit=dev COPY shim.mjs ./ USER node -ENTRYPOINT ["node", "shim.mjs"] +# The deadline is inside the container, since a timeout in the caller kills only the docker client and leaves the container running. +# It is under convert.py's RUN_SECONDS, so it fires first. +ENTRYPOINT ["timeout", "50", "node", "shim.mjs"] diff --git a/bin/adf_codec/test_adf_codec.py b/bin/adf_codec/test_adf_codec.py index 8a910835..470b288f 100644 --- a/bin/adf_codec/test_adf_codec.py +++ b/bin/adf_codec/test_adf_codec.py @@ -1,5 +1,4 @@ import json -import re import shutil import subprocess @@ -51,7 +50,7 @@ def test_a_shim_that_could_not_run_becomes_a_failure_with_its_stderr(): assert failure == Failure("the adf-codec shim failed with exit 1: Unexpected token") -def test_a_container_that_was_killed_for_memory_says_so(): +def test_a_shim_killed_for_memory_becomes_a_failure_with_its_exit_status(): failure = convert.markdown_to_adf("x", fake(137)) assert isinstance(failure, Failure) and "137" in failure.reason @@ -73,14 +72,6 @@ def test_a_failure_from_the_runner_passes_through(): assert convert.markdown_to_adf("x", run) == Failure("docker is not installed") -def test_the_container_has_a_memory_and_swap_limit_and_no_network(): - args = convert.docker_args("image:1", "to-adf") - assert args[:3] == ["docker", "run", "--rm"] - assert args[args.index("--memory") + 1] == args[args.index("--memory-swap") + 1] - assert args[args.index("--network") + 1] == "none" - assert args[-2:] == ["image:1", "to-adf"] - - def test_the_image_tag_changes_with_the_shim_files(tmp_path): for name in convert.SHIM_FILES: (tmp_path / name).write_text("a") @@ -101,12 +92,6 @@ def test_a_refusal_at_the_root_says_the_document(): assert failure == Failure("adf-codec refused the input with not-an-adf-document: no type (at the document)") -def test_the_image_tag_is_a_12_digit_hash_of_the_shim_files(tmp_path): - for name in convert.SHIM_FILES: - (tmp_path / name).write_text("a") - assert re.fullmatch(r"claude-config-adf-codec:[0-9a-f]{12}", convert.image_tag(tmp_path)) - - def test_docker_passes_the_text_on_stdin_and_returns_the_output(): seen = {} @@ -189,7 +174,7 @@ def test_container_run_passes_an_image_failure_through(tmp_path): assert convert.container_run("to-adf", "text", scripted(down), shim_dir(tmp_path)) == down -@pytest.mark.skipif(shutil.which("docker") is None or subprocess.run(["docker", "info"], capture_output=True).returncode != 0, reason="needs a docker daemon") +@pytest.mark.skipif(shutil.which("docker") is None or subprocess.run(["docker", "info"], capture_output=True, timeout=20).returncode != 0, reason="needs a docker daemon") def test_round_trip_through_the_real_container(): doc = convert.markdown_to_adf("# Title\n\nSome **bold** text.\n") assert isinstance(doc, dict) and doc["type"] == "doc" and doc["content"][0]["type"] == "heading" @@ -197,3 +182,5 @@ def test_round_trip_through_the_real_container(): assert isinstance(markdown, str) and markdown.startswith("# Title") and "**bold**" in markdown refused = convert.adf_to_markdown({"type": "nope"}) assert isinstance(refused, Failure) and "not-an-adf-document" in refused.reason + crashed = convert.answer("to-markdown", "not json", convert.container_run) + assert isinstance(crashed, Failure) and crashed.reason.startswith("the adf-codec shim failed with exit 1: ")