Answer stability round 1: 0 🔴, 4 🟡 (0 misread); stop a slow shim inside the container, test a crashing shim, and drop two tests that repeated others
This commit is contained in:
@@ -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"]
|
||||
|
||||
@@ -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: ")
|
||||
|
||||
Reference in New Issue
Block a user