Files
skill-gongwen-gbt9704/tests/visual-audit.sh
T
2026-09-10 22:07:19 +08:00

69 lines
5.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
set -euo pipefail
skill_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
if [[ $# -gt 1 ]]; then
echo "Usage: $0 [output-directory]" >&2
exit 2
fi
out_dir=${1:-$(mktemp -d "${TMPDIR:-/tmp}/gongwen-visual-audit.XXXXXX")}
mkdir -p "$out_dir/docx" "$out_dir/pdf" "$out_dir/png" "$out_dir/logs"
gen="$skill_dir/scripts/generate_gongwen_docx.mjs"
verify="$skill_dir/scripts/verify_gongwen_docx.mjs"
all="$skill_dir/tests/fixtures/visual-all.md"
long="$skill_dir/tests/fixtures/visual-long.md"
attach_a="$skill_dir/tests/fixtures/visual-attachment-a.md"
attach_b="$skill_dir/tests/fixtures/visual-attachment-b.md"
horizontal="$skill_dir/tests/fixtures/visual-horizontal.md"
node "$gen" --input "$all" --output "$out_dir/docx/ordinary.docx" --format ordinary --title "普通材料全要素实测" --page-number center
node "$gen" --input "$all" --output "$out_dir/docx/formal-digital-all.docx" --format formal --letterhead digital --copy-no 7 --secret "机密★3年" --urgent "特急" --org "示例单位文件" --doc-no "示例发〔20267号" --title "正式公文全要素实测" --to "各主送机关" --sender "示例单位" --date "2026年9月10日" --note "此件公开" --attachment-note "1. 数据清单;2. 实施计划。" --cc "办公室、财务部" --print-org "示例印发机关" --print-date "2026年9月10日" --page-number standard
node "$gen" --input "$all" --output "$out_dir/docx/formal-digital-upward.docx" --format formal --letterhead digital --org "示例单位文件" --doc-no "示例发〔20268号" --title "上行文双签发人实测" --upward true --signer "张三、李四" --page-number standard
node "$gen" --input "$all" --output "$out_dir/docx/formal-preprinted.docx" --format formal --letterhead preprinted --letterhead-reserve-mm 72 --copy-no 7 --secret "机密★3年" --urgent "特急" --doc-no "示例发〔20269号" --title "预印红头套打实测" --page-number standard
node "$gen" --input "$all" --output "$out_dir/docx/formal-seal.docx" --format formal --letterhead preprinted --letterhead-reserve-mm 72 --title "盖章公文实测" --sender "示例单位" --date "2026年9月10日" --seal-mode seal --page-number standard
node "$gen" --input "$all" --output "$out_dir/docx/formal-signed.docx" --format formal --letterhead preprinted --letterhead-reserve-mm 72 --title "签名章公文实测" --sender "示例单位" --date "2026年9月10日" --seal-mode signed --signer-title "主要负责人" --signer "张三" --page-number standard
node "$gen" --input "$all" --output "$out_dir/docx/formal-attachments.docx" --format formal --letterhead preprinted --letterhead-reserve-mm 72 --doc-no "示例发〔202610号" --title "多附件实测" --attachment-note "1. 数据清单;2. 实施计划。" --attachment-file "$attach_a" --attachment-file "$attach_b" --page-number standard
node "$gen" --input "$long" --output "$out_dir/docx/formal-long.docx" --format formal --letterhead preprinted --letterhead-reserve-mm 72 --doc-no "示例发〔202611号" --title "长文版记与单双页实测" --cc "办公室、财务部、审计部、采购部、法务部、信息中心" --print-org "示例印发机关" --print-date "2026年9月10日" --page-number standard
node "$gen" --input "$all" --output "$out_dir/docx/letter.docx" --format letter --org "示例机关" --doc-no "示例〔202612号" --title "信函格式实测" --page-number none
node "$gen" --input "$all" --output "$out_dir/docx/command.docx" --format command --org "示例机关命令" --doc-no "第1号" --title "命令格式实测" --page-number standard
node "$gen" --input "$all" --output "$out_dir/docx/minutes.docx" --format minutes --org "示例机关纪要" --title "纪要格式实测" --attendees "张三(办公室)、李四(财务部)" --absent "王五(审计部)" --observers "赵六(采购部)" --page-number standard
node "$gen" --input "$horizontal" --output "$out_dir/docx/table.docx" --format formal --letterhead preprinted --letterhead-reserve-mm 72 --doc-no "示例发〔202613号" --title "表格版式实测" --page-number standard
for file in "$out_dir/docx"/*.docx; do
base=$(basename "$file" .docx)
case "$base" in
ordinary) profile=ordinary ;;
letter) profile=letter ;;
command) profile=command ;;
minutes) profile=minutes ;;
*) profile=formal ;;
esac
case "$base" in
formal-digital-*) letterhead=digital ;;
*) letterhead=preprinted ;;
esac
node "$verify" --input "$file" --profile "$profile" --letterhead "$letterhead" >"$out_dir/logs/$base.verify.log"
done
if ! command -v soffice >/dev/null 2>&1 || ! command -v pdftoppm >/dev/null 2>&1; then
echo "LibreOffice (soffice) and pdftoppm are required for screenshot audit." >&2
exit 3
fi
soffice --headless --convert-to pdf --outdir "$out_dir/pdf" "$out_dir/docx"/*.docx >"$out_dir/logs/soffice.log" 2>&1
for file in "$out_dir/pdf"/*.pdf; do
base=$(basename "$file" .pdf)
pdftoppm -png -r 150 "$file" "$out_dir/png/$base" >"$out_dir/logs/$base.pdftoppm.log" 2>&1
done
{
echo -e "profile\tdocx\tpdf\tscreenshot_prefix"
for file in "$out_dir/docx"/*.docx; do
base=$(basename "$file" .docx)
pages=$(pdfinfo "$out_dir/pdf/$base.pdf" | awk '/^Pages:/ {print $2}')
echo -e "$base\t$file\t$out_dir/pdf/$base.pdf\t$out_dir/png/$base-1.png ... $out_dir/png/$base-$pages.png"
done
} >"$out_dir/manifest.tsv"
echo "Visual audit complete: $out_dir"
cat "$out_dir/manifest.tsv"