Files
eip4-web/recipe-render-smoke.sh
zhengwr 4b564c6316 test(e2e): executable AI-recipe render smoke gate (M-Gate)
把「手动用浏览器验 AI 生成页渲染成 house-style」codify 成可复用的可执行门,补上
critic 点名「playwright-render 名实不符(从不真渲染)」的缺口——不给后端加浏览器依赖。

- e2e/recipe-render-smoke.spec.ts:给定 templateId,从 served schema 自推期望
  (数据列 label + 所有按钮 label),再断言 amis 真渲染成无错 DOM:amis-host 可见
  且无 schema-error-card / 每列每动作出现 / tbody 无裸 true·false·ISO 串
  (列渲染类型生效)/ 0 console.error·pageerror。
- playwright.recipe-smoke.config.ts:复用已在跑的 5174,不自起 webServer。
- recipe-render-smoke.sh:一键端到端——登录→auto-develop 1 maintenance + 1 tree
  样例→对两页跑断言→DROP 表+删三真相行清理(trap 保证失败也清,sys_ai_* 保留)。

验证:./recipe-render-smoke.sh 端到端全绿(maintenance + tree 两页均 PASSED,
0 console error),库残留复查 0。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-19 20:28:32 +08:00

67 lines
3.9 KiB
Bash
Executable File
Raw Permalink 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
# ─────────────────────────────────────────────────────────────────────────────
# AI recipe 渲染冒烟门 —— 一键端到端(M-Gate 可执行化)。
#
# 把「手动用浏览器验 AI 生成页渲染成 house-style」codify 成一条命令:
# 1) 登录拿 admin token
# 2) 经 AI pipeline 生成 1 个 maintenance + 1 个 tree 隔离样例(auto-develop)
# 3) 用 recipe-render-smoke.spec 断言两页真渲染成无错 house-style DOM
# 4) DROP 表 + 删三真相行清理(trap 保证失败也清,sys_ai_* 审计保留)
#
# 前置:localhost:8093(后端 dev/eip4dev)+ localhost:5174(前端 dev)+ psql:5433。
# 跑: cd eip4-web && ./recipe-render-smoke.sh
# ─────────────────────────────────────────────────────────────────────────────
set -uo pipefail
BACKEND="${BACKEND:-http://localhost:8093}"
PGHOST="${PGHOST:-localhost}"; PGPORT="${PGPORT:-5433}"; PGUSER="${PGUSER:-zhengwr}"; PGDB="${PGDB:-eip4dev}"
export PGPASSWORD="${PGPASSWORD:-}"
SMOKE_TABLES=(EIP4AI_SMOKE_M EIP4AI_SMOKE_T)
psql_run() { psql -h "$PGHOST" -p "$PGPORT" -U "$PGUSER" -d "$PGDB" -v ON_ERROR_STOP=1 -At "$@"; }
cleanup() {
for t in "${SMOKE_TABLES[@]}"; do
local tpl tbl
tpl="$(echo "$t" | tr 'A-Z_' 'a-z-')" # EIP4AI_SMOKE_M → eip4ai-smoke-m (templateId)
tbl="$(echo "$t" | tr 'A-Z' 'a-z')" # EIP4AI_SMOKE_M → eip4ai_smoke_m (物理表,PG 折叠小写)
psql_run -c "DROP TABLE IF EXISTS eip3.${tbl};
DELETE FROM eip3.sys_entity WHERE upper(tablename)='${t}';
DELETE FROM eip3.sys_page_schema WHERE template_id='${tpl}';
DELETE FROM eip3.sys_serviceflow WHERE upper(sys_serviceflow_id) LIKE '${t}\\_%';
DELETE FROM eip3.sys_menu WHERE view_templateid='${tpl}';" >/dev/null 2>&1
done
echo "🧹 清理完成(${SMOKE_TABLES[*]})"
}
trap cleanup EXIT
login() {
curl -s -X POST "$BACKEND/api/auth/login" -H 'Content-Type: application/json' \
-d '{"account":"admin","password":"111111"}' \
| python3 -c "import sys,json;print(json.load(sys.stdin).get('token',''))"
}
# auto_dev <table> <templateId> <entityName> <recipe>
auto_dev() {
local table="$1" tpl="$2" name="$3" recipe="$4"
curl -s -X POST "$BACKEND/api/ai/features/auto-develop" \
-H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" \
-d "{\"feature\":{\"objective\":\"render-smoke\",\"featureName\":\"${name}维护\",\"tableName\":\"${table}\",\"entityName\":\"${name}\",\"templateId\":\"${tpl}\",\"menuName\":\"${name}\",\"fields\":[{\"column\":\"NAME\",\"label\":\"名称\",\"type\":\"string\",\"length\":100,\"required\":true},{\"column\":\"ENABLED\",\"label\":\"启用\",\"type\":\"boolean\",\"required\":false}],\"pageRecipe\":\"${recipe}\"},\"baseUrl\":\"${BACKEND}\",\"generateDeploymentPackage\":true,\"maxRepairAttempts\":2}" \
| python3 -c "import sys,json;d=json.load(sys.stdin);print((d.get('applyRun') or {}).get('status','?'))"
}
echo "🔑 登录…"; TOKEN="$(login)"
[ -n "$TOKEN" ] || { echo "❌ 登录失败"; exit 1; }
echo "🏗 生成 maintenance 样例…"; [ "$(auto_dev EIP4AI_SMOKE_M eip4ai-smoke-m 列渲染样例 maintenance-crud-v1)" = "PASSED" ] || { echo "❌ maintenance apply 未 PASSED"; exit 1; }
echo "🌲 生成 tree 样例…"; [ "$(auto_dev EIP4AI_SMOKE_T eip4ai-smoke-t 树样例 tree-crud-v1)" = "PASSED" ] || { echo "❌ tree apply 未 PASSED"; exit 1; }
rc=0
for tpl in eip4ai-smoke-m eip4ai-smoke-t; do
echo "🖥 渲染断言 $tpl …"
RECIPE_SMOKE_TEMPLATE="$tpl" npx playwright test --config=playwright.recipe-smoke.config.ts || rc=1
done
[ "$rc" = 0 ] && echo "✅ recipe 渲染冒烟全绿" || echo "❌ recipe 渲染冒烟有失败"
exit "$rc"