Answer prose round 1: 1 🔴, 3 🟡 (0 misread); sort the README entry, and reword the docstrings and comments the reviewer misread
CI / tests (pull_request) Successful in 2m56s

This commit is contained in:
2026-11-14 16:56:58 +01:00
parent 0f2cb3557f
commit 2fb0e7be5a
2 changed files with 10 additions and 12 deletions
+9 -11
View File
@@ -1,8 +1,6 @@
"""Converts markdown to ADF (Atlassian Document Format, the rich text of Jira Cloud and Confluence) and back.
It runs @larvit/adf-codec's portable calls in a throwaway container, since adf-codec is a Node package:
`portableMarkdownToAdf` to write ADF and `adfToPortableMarkdown` to read it. The container holds node_shim/shim.mjs,
whose exit status says what happened: 0 answered, 2 adf-codec refused the input (its error code is in the Failure), 1 the shim itself failed.
It runs @larvit/adf-codec, a Node package, in a throwaway container that holds node_shim/shim.mjs; the shim's header says what its exit status means.
"""
import dataclasses
import hashlib
@@ -15,7 +13,7 @@ from failure import Failure
SHIM = pathlib.Path(__file__).resolve().parent / "node_shim"
SHIM_FILES = ("Dockerfile", "package.json", "package-lock.json", "shim.mjs")
# Both limits are equal, so the container can't swap: a document too big for it ends in a Failure, not in a slow machine.
# `--memory` and `--memory-swap` both take this, so the container can't swap: a document too big for it ends in a Failure.
MEMORY = "256m"
RUN_SECONDS = 60
BUILD_SECONDS = 300
@@ -29,14 +27,14 @@ class Ran:
err: str
# Runs the shim in the given mode (`to-adf` or `to-markdown`) on a text, or fails to start it.
# Runs the shim in the given mode (`to-adf` or `to-markdown`) on a text, or fails to run it.
Run = typing.Callable[[str, str], Ran | Failure]
# Runs a docker command line on a text, in at most the given seconds, or fails to start it.
# Runs a docker command line on a text, in at most the given seconds, or fails to run it.
Docker = typing.Callable[[list[str], str, int], Ran | Failure]
def image_tag(shim: pathlib.Path) -> str:
"""A tag that changes with every file the image is built from, so an edited shim or a bumped adf-codec rebuilds it."""
"""A tag that changes with every file the image is built from, so an edited shim or a bumped adf-codec builds a new image."""
digest = hashlib.sha256()
for name in SHIM_FILES:
digest.update((shim / name).read_bytes())
@@ -58,7 +56,7 @@ def docker(args: list[str], text: str, seconds: int, call: typing.Callable[...,
def ensure_image(shim: pathlib.Path, run_docker: Docker = docker) -> str | Failure:
"""The tag of the shim's image, built from node_shim/ first where this machine has no image under that tag."""
"""The tag of the image for the shim folder, built from that folder first where this machine has no image under that tag."""
tag = image_tag(shim)
found = run_docker(["docker", "image", "inspect", tag], "", RUN_SECONDS)
if isinstance(found, Failure) or found.status == 0:
@@ -79,7 +77,7 @@ def container_run(mode: str, text: str, run_docker: Docker = docker, shim: pathl
def answer(mode: str, text: str, run: Run) -> str | Failure:
"""What the shim printed for text, or a Failure saying why it printed none."""
"""What the shim printed for text, or a Failure saying why it gave no answer."""
ran = run(mode, text)
if isinstance(ran, Failure):
return ran
@@ -100,7 +98,7 @@ def refusal(out: str) -> Failure:
def markdown_to_adf(markdown: str, run: Run = container_run) -> dict[str, typing.Any] | Failure:
"""The ADF document markdown reads as."""
"""The ADF document for the markdown."""
out = answer("to-adf", markdown, run)
if isinstance(out, Failure):
return out
@@ -112,5 +110,5 @@ def markdown_to_adf(markdown: str, run: Run = container_run) -> dict[str, typing
def adf_to_markdown(document: dict[str, typing.Any], run: Run = container_run) -> str | Failure:
"""The markdown an ADF document reads as."""
"""The markdown for the ADF document."""
return answer("to-markdown", json.dumps(document), run)