Files
SuperTensor/scripts/preflight.sh
T
dela 866173a831 Add source linter, negative test fixtures, and fallback guidance
- scripts/lint.py: reject raw rectangles, absolute coordinates, hue-budget
  and callout/group/formula-order violations at the source level
- tests/invalid/ + tests/lint-invalid/: negative fixtures proving the
  package and linter reject bad input; test.sh now runs both directions
- references/fallback.md: degraded path when no LaTeX is available
- tests/group-callout.tex: exercise \stgroup and \stcallout
- agents/openai.yaml: agent config
- Docs and .sty updated to match
2026-08-05 16:41:22 +08:00

59 lines
2.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# Toolchain preflight for supertensor. Run this BEFORE drawing anything:
# it decides whether the TikZ path is available or the figure must fall back.
#
# ./scripts/preflight.sh human-readable report
# ./scripts/preflight.sh --quiet exit code only (0 = full TikZ path OK)
#
# Exit codes: 0 full path, 1 degraded (no CJK), 2 no LaTeX at all.
set -uo pipefail
QUIET=0
[[ "${1:-}" == "--quiet" ]] && QUIET=1
say() { [[ $QUIET -eq 1 ]] || echo -e "$*"; }
ok=0; warn=0; fail=0; cjk_warn=0; export_warn=0
check() { # name, command
local name="$1"; shift
if "$@" >/dev/null 2>&1; then say " ok $name"; ok=$((ok+1)); return 0
else say " MISS $name"; return 1; fi
}
say "supertensor preflight"
say "--- required ---"
check "xelatex" command -v xelatex || fail=$((fail+1))
check "standalone.cls" kpsewhich standalone.cls || fail=$((fail+1))
check "tikz.sty" kpsewhich tikz.sty || fail=$((fail+1))
check "xstring.sty" kpsewhich xstring.sty || fail=$((fail+1))
say "--- chinese figures ---"
check "ctex.sty" kpsewhich ctex.sty || { warn=$((warn+1)); cjk_warn=1; }
check "fandol font" kpsewhich FandolSong-Regular.otf || { warn=$((warn+1)); cjk_warn=1; }
say "--- raster / vector export ---"
check "pdftocairo" command -v pdftocairo || { warn=$((warn+1)); export_warn=1; }
check "latexmk (optional)" command -v latexmk || true
if [[ $fail -gt 0 ]]; then
say ""
say "RESULT: no usable LaTeX path."
say "Fall back to an SVG or matplotlib figure and say so explicitly in the"
say "delivery; do not silently ship a lower-fidelity figure as if it were TikZ."
exit 2
fi
if [[ $warn -gt 0 ]]; then
say ""
say "RESULT: degraded."
if [[ $cjk_warn -eq 1 ]]; then
say " - missing ctex/fandol -> English-label figures only; do not substitute"
say " an OS-specific CJK font without telling the user it costs portability."
fi
if [[ $export_warn -eq 1 ]]; then
say " - missing pdftocairo -> deliver PDF only, and say PNG/SVG were skipped."
fi
exit 1
fi
say ""
say "RESULT: full path available (TikZ + CJK + vector/raster export)."
exit 0