#!/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