mopac-pdf v0: markdown to beautiful PDFs via digest-pinned typst

Go CLI that turns the markdown currency of this stack (Redmine notes,
Discourse posts, briefing output) into typeset PDFs: two embedded typst
templates (report with title page/TOC/headers, dense brief), front-matter
(title/subtitle/author/date/classification/template), GFM tables, and
bar charts rendered in pure Go (go-chart) from fenced chart data blocks.
Engine is a prebuilt typst 0.15.1 container pinned by digest and run
--network none; PDF bytes to stdout or -o. Exit codes 0/1/2.

All dev in docker (dev.sh/Makefile); unit tests + golden typst fixtures
plus a host-side smoke against the real engine container.

Generated with Crush

Assisted-by: Crush:glm-5.2
This commit is contained in:
2026-08-29 05:44:24 -05:00
parent 97c8e340ab
commit 10e930e46d
147 changed files with 30793 additions and 0 deletions
Executable
+66
View File
@@ -0,0 +1,66 @@
#!/bin/sh
# mopac-pdf end-to-end smoke (runs on the HOST): builds via dev.sh, drives
# the real CLI against the REAL digest-pinned typst container, checks PDF
# magic + page counts via the CLI's own -pages helper, exercises stdin,
# stdout and the error paths. Never pkills anything broad.
set -e
cd "$(dirname "$0")/.."
mkdir -p out
fails=0
ok() { echo "ok $1"; }
bad() { echo "FAIL $1"; fails=$((fails+1)); }
./dev.sh build || { bad "build"; exit 1; }
pages() { ./bin/mopac-pdf -pages "$1"; }
# 1. report template fixture -> file
./bin/mopac-pdf -o out/sample-report.pdf testdata/sample-report.md \
&& ok "report compile" || bad "report compile"
n=$(pages out/sample-report.pdf 2>/dev/null || echo 0)
[ "$n" -ge 3 ] && ok "report pages=$n" || bad "report pages=$n (want >=3)"
# 2. brief template fixture -> file
./bin/mopac-pdf -o out/sample-brief.pdf testdata/sample-brief.md \
&& ok "brief compile" || bad "brief compile"
n=$(pages out/sample-brief.pdf 2>/dev/null || echo 0)
[ "$n" -ge 1 ] && [ "$n" -le 3 ] && ok "brief pages=$n (dense 1-3)" || bad "brief pages=$n (want 1-3)"
# 3. stdin -> stdout piped to file
./bin/mopac-pdf < testdata/sample-brief.md > out/stdin-brief.pdf \
&& ok "stdin->stdout" || bad "stdin->stdout"
head -c 4 out/stdin-brief.pdf | grep -q "%PDF" && ok "stdout PDF magic" || bad "stdout PDF magic"
# 4. -t override wins over front-matter template key
./bin/mopac-pdf -t report -o out/override-report.pdf testdata/sample-brief.md \
&& ok "-t override" || bad "-t override"
# 5. usage error exits 1
if ./bin/mopac-pdf --bogus >/dev/null 2>&1; then bad "usage exit code"; else ok "usage exit=1"; fi
# 6. unknown template exits 1
if ./bin/mopac-pdf -t nope testdata/sample-brief.md >/dev/null 2>&1; then bad "unknown template exit"; else ok "unknown template exit=1"; fi
# 7. engine failure exits 2 (image that cannot resolve)
if MOPAC_PDF_ENGINE=registry.invalid/nope:1 ./bin/mopac-pdf testdata/sample-brief.md >/dev/null 2>&1; then
bad "engine exit code"
else
rc=$?
[ "$rc" = 2 ] && ok "engine failure exit=2" || bad "engine failure exit=$rc (want 2)"
fi
# 8. custom template dir (-T)
mkdir -p out/custom-tpl
sed 's/#1f4e79/#7a1f1f/' templates/report.typ > out/custom-tpl/report.typ
./bin/mopac-pdf -T out/custom-tpl -o out/custom-report.pdf testdata/sample-report.md \
&& ok "-T custom template" || bad "-T custom template"
echo
if [ "$fails" = 0 ]; then
echo "smoke: all checks passed; samples in out/"
else
echo "smoke: $fails FAILED"
exit 1
fi