Files
PlantAI-rag-new/tests/docgen/run_perf_import.sh
T
jerryandClaude Fable 5 5888e1d5c1 test(docgen): 测试治理资产——131 条验收用例 + 三轮留痕 + E2E/回归套件
- tests/docgen/:DC-UNIT/API/CONF/E2E/UI/REGRESSION/PERF 分组用例与可复跑脚本,报告逐条留痕(R1-R3 全记录)
- 意图 30 条前后端同表双跑(pytest + node)
- Playwright headless:docgen-ui/docgen-regression spec + b3 benchpanel 第 5 TAB 断言更新

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-03 21:13:47 +08:00

103 lines
4.9 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
# run_perf_import.sh —— DC-PERF-01~03(批量导入压测 + 原子切换 + 删源明文)
#
# 前置(必须由 TL 完成,本脚本不做任何启动动作):
# 1. TL 已启动受控 vstore 实例;
# 2. 导入工具已交付:tooling/scripts/docgen_import.py(dev2 已交付);
# 3. 环境变量:
# DOCGEN_PERF_VSTORE 默认 http://127.0.0.1:8094
# DOCGEN_PERF_N 导入数量,默认 100(百级压测)
# DOCGEN_PERF_SRCDIR 源明文目录(脚本自动生成占位 docx),默认 tests/docgen/data/perf
# DOCGEN_PERF_VAULT vstore 加密库目录绝对路径(保密断言用),必填
# 4. 未提供必填变量:打印 PENDING 以 77 退出(SKIP,不视为 FAIL)。
#
# 纪律:
# - 只在 TL 指定的端口与目录上操作;占位明文只落 DOCGEN_PERF_SRCDIR;
# - 无 --keep-source 时导入完成后必须删源明文目录(DC-PERF-03);
# - 断言幂等(成功计数按「本次目录导入文件数」;index.json 按结构断言)。
set -u
cd "$(dirname "$0")/../.." || exit 2 # 仓库根
VSTORE="${DOCGEN_PERF_VSTORE:-http://127.0.0.1:8094/api/vstore}" # 工具按 {vstore}/ingest 拼接,需含 /api/vstore 前缀
N="${DOCGEN_PERF_N:-100}"
SRCDIR="${DOCGEN_PERF_SRCDIR:-tests/docgen/data/perf}"
VAULT="${DOCGEN_PERF_VAULT:-}"
SENTINEL="DOCGEN_PERF_SENTINEL_9F3A"
# 传入子进程(样例生成 python 读取)
export DOCGEN_PERF_N="$N"
export DOCGEN_PERF_SRCDIR="$SRCDIR"
export DOCGEN_PERF_SENTINEL="$SENTINEL"
if [ -z "$VAULT" ]; then
echo "[PENDING] 需 TL 提供 DOCGEN_PERF_VAULT(vstore 加密库目录),本脚本 SKIP"
exit 77
fi
[ -f tooling/scripts/docgen_import.py ] || { echo "[PENDING] tooling/scripts/docgen_import.py 未交付(dev2),DC-PERF BLOCKED"; exit 77; }
PY=/home/xzq/5090/teamWorkspace/zh/plantai-rag-new-venv/bin/python
ok() { echo " [PASS] $1"; }
die() { echo " [FAIL] $1"; echo "===== PERF 汇总:本步断言失败(exit 1) ====="; exit 1; }
# ---------- 生成占位样例(明文只落 SRCDIR) ----------
echo "== 生成 $N 个占位 docx(明文目录 $SRCDIR) =="
rm -rf "$SRCDIR" && mkdir -p "$SRCDIR"
"$PY" - <<'PYEOF' || die "样例生成失败"
import os
from docx import Document
n = int(os.environ["DOCGEN_PERF_N"])
out = os.environ["DOCGEN_PERF_SRCDIR"]
for i in range(n):
d = Document()
d.add_heading(f"占位样例文档 {i:03d}", level=1)
d.add_paragraph(f"这是批量导入压测样例。标志串:{os.environ['DOCGEN_PERF_SENTINEL']} 序号 {i}")
d.save(os.path.join(out, f"sample_{i:03d}.docx"))
print("生成完成", n)
PYEOF
# ---------- DC-PERF-01 批量导入(并发 8) ----------
echo "== DC-PERF-01 批量 ingest $N 个(并发 8,计时) =="
START=$(date +%s)
"$PY" tooling/scripts/docgen_import.py --vstore "$VSTORE" --dir "$SRCDIR" --workers 8 > /tmp/docgen_perf_import.log 2>&1 # as_template 默认 true(工具语义)
RC=$?
END=$(date +%s)
if [ $RC -ne 0 ]; then die "导入失败 rc=$RC(日志 /tmp/docgen_perf_import.log)"; fi
SUCC=$(grep -c " \[ok\]" /tmp/docgen_perf_import.log || true)
[ "$SUCC" -ge "$N" ] && ok "全部成功 $SUCC/$N(耗时 $((END-START))s)" || die "成功数不足:$SUCC/$N"
echo " 时耗:$((END-START))s(记录进实测列)"
# ---------- DC-PERF-02 原子索引切换 ----------
echo "== DC-PERF-02 rebuild-index 原子切换 =="
curl -fsS -X POST "$VSTORE/rebuild-index" | grep -q '"ok":true' && ok "rebuild ok" || die "rebuild 失败"
INDEX_JSON=""
if [ -f "$VAULT/index.json" ]; then
INDEX_JSON="$VAULT/index.json"
elif [ -f "$(dirname "$VAULT")/index/index.json" ]; then
INDEX_JSON="$(dirname "$VAULT")/index/index.json"
fi
if [ -n "$INDEX_JSON" ]; then
"$PY" - "$INDEX_JSON" "$N" <<'PYEOF' && ok "index.json 结构合法(单一事实源,items>=N)" || die "index.json 校验失败"
import json, sys
data = json.load(open(sys.argv[1], encoding="utf-8"))
items = data.get("items", []) if isinstance(data, dict) else []
assert isinstance(items, list) and len(items) >= int(sys.argv[2]), f"行数不足:{len(items)}"
for i, e in enumerate(items):
assert isinstance(e, dict) and e.get("id"), f"行 {i} 缺 id"
print(f"index.json items={len(items)}")
PYEOF
else
echo " [WARN] 未找到 index.json(vault 与 index 目录均已找)——记录实测列"
fi
# ---------- DC-PERF-03 导入后删源明文 ----------
echo "== DC-PERF-03 删源明文 + vault 保密断言 =="
if [ -d "$SRCDIR" ]; then
echo " [WARN] 导入工具未自动删除源目录(契约偏差)——本脚本代为删除,偏差记录进实测列"
rm -rf "$SRCDIR"
fi
[ ! -d "$SRCDIR" ] && ok "源明文目录已删除" || die "源明文目录仍存在"
if grep -rq "$SENTINEL" "$VAULT" 2>/dev/null; then die "vault 内 grep 命中明文标志串(明文落盘!)"; fi
ok "vault 无明文(vault/ 仅 .enc;index/ 持 index.json)"
echo "===== PERF 汇总:全部断言步骤通过(FAIL=0) ====="