render: dot generation + svg pipeline + api image toolchain #9
Loading…
Reference in a new issue
No description provided.
Delete branch "agent/render"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fulfills the
[agent] renderbrief in docs/TASKS.md. Closes #6.What changed
crates/rgxr-render/src/lib.rs— implemented both stubs (signatures unchanged):to_dot(&Fa): deterministic DOT per BTree iteration order. Unlabeled point node → initial state (the automaton arrow),peripheries=2on accepting states, one edge per (src, target) pair labeled with the comma-joined sorted symbol set ("a, b"). All state names/symbols emitted as quoted DOT strings with",\\,\n,\r,\tescaped (user input). The arrow-source node name is picked to never collide with a user state (a state named__startbumps the node to___start, etc.). Invalid FAs (failedFa::validate) →RenderError::Dot, not a silently-wrong graph.render_svg(fa, Fast):dot -Tsvgviatokio::process::Command, stdin-fed, stdout captured, 5s hard timeout (kill_on_drop(true)), nonzero exit →RenderError::Failedwith a 500-char stderr snippet. Spawn failure (no graphviz) →RenderError::Unavailable("dot").render_svg(fa, Latex): gated onRGXR_LATEX_ENABLED(unset/false/0/no/off →Unavailable("latex"); default off per contract). Pipeline:dot2tex --format=tikz→ extract thetikzpicture→ wrap in a minimalstandalonedoc →pdflatex -interaction=nonstopmode -halt-on-error→dvisvgm --pdf --no-fonts→ read SVG. 20s hard timeout per subprocess, everything in atempfilescratch dir, clean propagation of every failure asFailed/Unavailable.crates/rgxr-render/Cargo.toml— addedtempfile = "3"(explicit version, inside this crate only; root manifest untouched).deploy/api.Dockerfile— build stage untouched; runtime stage addspython3,dot2tex,texlive-latex-base,texlive-latex-recommended,texlive-latex-extra,texlive-pictures,texlive-extra-utils,dvisvgm.dvisvgmpullslibgs10transitively (needed for--pdf), so no explicit ghostscript package.cfg_attrtest exemption. Workspace tests: 19 green.Docker verification (real build + in-container checks)
docker build -f deploy/api.Dockerfile -t rgxr-api:dev .from the worktree root: success, image is 814 MB (target < 2GB)./renderroute at all yet (not even 501 — the api PR is in flight), so per the brief I verified the toolchain directly in the container:echo "digraph{a->b}" | dot -Tsvg→<?xml version="1.0" ...?>✓--pdf --no-fonts) on the exactto_dotoutput of the CONTRACT example FA → valid SVG, tightly cropped (290×66pt) ✓POST /rendershould work in this image out of the box forengine=fast;engine=latexneedsRGXR_LATEX_ENABLED=truein the environment (compose does not set it yet — integrator call, see semantic decisions).Gate results
cargo fmt --check✅cargo clippy --workspace --all-targets✅ 0 warningscargo test --workspace✅ 19 passed (7 core + 12 render)Semantic decisions (flag for review)
", "(comma+space) — brief says "comma-joined"; CONTRACT only specifies","for derived state names, which is a different context. Rendered labels read better with the space. Golden test pins it.to_dotvalidates the FA first (RenderError::Doton failure). Rationale: rendering an FA with undeclared transition targets would silently draw a graph that disagrees with the wire data. The api can still 400 before calling render by validating itself (which the openapi flow implies).dvisvgm --pdfflag added (brief/contract just saydvisvgm): pdflatex emits PDF, and dvisvgm needs--pdffor PDF input. bookworm's dvisvgm 3.0.3 handles it fine via libgs10.standalonewrapper: dot2tex's output template is version-dependent — 2.12 (host) wraps instandalone, bookworm's 2.11.3 wraps in a full-pagearticle(\enlargethispage{100cm}→ A4-sized SVG with a tiny graph in the corner). Extracting the picture and wrapping it ourselves gives tight crops on both.style="double"on accepting states (dot2tex dropsperipheriesbut passes DOTstylethrough to tikz) so the accepting double ring survives the tikz conversion. The publicto_dotoutput keeps canonicalperipheries=2only — golden test pins that.RGXR_LATEX_ENABLEDaccepted truthy values:1/true/yes/on(case-insensitive) enable; anything else, incl. unset/empty/non-UTF-8, disables (contract default).dotbinary on the fast path →Unavailable("dot")(→ 503render_unavailable) rather thanFailed; matches the contract's semantics for unrenderable-deployment, while actual tool failures/timeouts stayFailed(→ 500internal).deploy/docker-compose.ymldoesn)t setRGXR_LATEX_ENABLED; now that the image ships texlive, the integrator may flip it on there (default staysfalseper contract — I did not touch compose, it)s outside my ownership).- to_dot: deterministic DOT from Fa — initial arrow via a collision-free point node, peripheries=2 for accepting states, per-(src,target) edges labeled with comma-joined sorted symbol sets, quoted+escaped user input, validate() gate (RenderError::Dot) - render_svg fast: dot -Tsvg via tokio::process, 5s hard timeout, kill_on_drop, Failed on nonzero exit with truncated stderr snippet - render_svg latex: dot2tex --format=tikz -> extract tikzpicture -> standalone wrapper -> pdflatex -> dvisvgm --pdf --no-fonts, 20s per step, gated on RGXR_LATEX_ENABLED (default off per contract); style="double" added for accepting states since dot2tex drops peripheries - deploy/api.Dockerfile: runtime layer adds python3, dot2tex, texlive-latex-{base,recommended,extra}, texlive-pictures, texlive-extra-utils, dvisvgm (814MB image); both render paths verified inside the built image Closes #6a2082c5f1eda2d18f274