From 42765282a3c190eb61ee4acf878b2a8b84073ff9 Mon Sep 17 00:00:00 2001 From: JianFeeeee Date: Fri, 23 Oct 2026 09:19:27 +0800 Subject: [PATCH] =?UTF-8?q?test(criteria):=20=E5=88=A4=E6=8D=AE=E8=87=AA?= =?UTF-8?q?=E8=A1=8C=E8=A1=A5=E9=BD=90=E5=89=8D=E7=AB=AF=E5=B5=8C=E5=85=A5?= =?UTF-8?q?=E4=BA=A7=E7=89=A9=EF=BC=8C=E4=BF=9D=E8=AF=81=E5=9C=A8=E5=B9=B2?= =?UTF-8?q?=E5=87=80=20clone=20=E4=B8=8A=E5=8F=AF=E5=A4=8D=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit internal/httpapi 用 //go:embed all:dist 嵌入前端,dist 是构建期产物且被 .gitignore 排除。干净 clone 上直接 go build 会报 "pattern all:dist: no matching files found"——这是基线既有状态,与本判据 要验证的东西无关,但会让判据在任意 checkout 上都红,失去可复现性。 现在若 dist 缺失就先 cd web 构建并拷回 internal/httpapi/dist(无 npm 时 给出明确的失败原因与手工步骤)。已实测:删掉 dist 后跑判据可自动补齐并全绿。 --- scripts/criteria/config-startup.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/scripts/criteria/config-startup.sh b/scripts/criteria/config-startup.sh index a429ddd..a9ea422 100755 --- a/scripts/criteria/config-startup.sh +++ b/scripts/criteria/config-startup.sh @@ -37,6 +37,21 @@ assert_died_before_listen() { fi } +# ---- 0. 前端嵌入产物 ---- +# internal/httpapi 用 //go:embed all:dist 嵌入前端,而 dist 是构建期产物、 +# 被 .gitignore 排除。干净 clone 上不先构建前端,go build 会直接报 +# "pattern all:dist: no matching files found"——那是基线既有状态,与本判据 +# 无关,所以这里先补齐,让判据在任何 checkout 上都能复现。 +if [ ! -f internal/httpapi/dist/index.html ]; then + command -v npm >/dev/null 2>&1 \ + || fail "缺少前端构建产物 internal/httpapi/dist 且没有 npm;请在有 node 的环境跑,或先手工 cd web && npm ci && npm run build && cp -r dist ../internal/httpapi/dist" + ( cd web \ + && { [ -d node_modules ] || npm ci --no-audit --no-fund >/dev/null 2>&1; } \ + && npm run build >/dev/null 2>&1 ) || fail "前端构建失败(cd web && npm run build)" + rm -rf internal/httpapi/dist && mkdir -p internal/httpapi/dist + cp -r web/dist/. internal/httpapi/dist/ || fail "拷贝前端产物失败" +fi + # ---- 1. 构建与全量测试 ---- go build ./... || fail "go build ./..." go test ./... > "$WORK/test.log" 2>&1 || { cat "$WORK/test.log"; fail "go test ./..."; }