From 5045f7a7e120e27f828570f36eb8e789868661b6 Mon Sep 17 00:00:00 2001 From: AetherNo2332 <130164460+AetherNo2332@users.noreply.github.com> Date: Mon, 21 Sep 2026 08:05:06 +0800 Subject: [PATCH] =?UTF-8?q?ci(quality):=20=E5=90=8E=E7=AB=AF=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=20-=20=E5=A4=87=E9=BD=90=20Postgres/Redis=20=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=E5=B9=B6=E7=A6=81=E6=AD=A2=E4=BE=9D=E8=B5=96=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E9=9D=99=E9=BB=98=E8=B7=B3=E8=BF=87=20(#571)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Original-Commit: 6bc6d5701f461a7306fd8171e18968c95d7da124 ci(quality): 后端测试 - 备齐 Postgres/Redis 依赖并禁止依赖用例静默跳过 Backend job 既没有 services 也没有 CANVAS_TEST_POSTGRES_DSN,也没装 redis-server, 于是 5 个用例默认静默跳过:PostgreSQL 迁移、素材字节修复、画布版本历史、Redis 租约、 缓存白名单——这些路径在 CI 上从来没被执行过,而 go test ./... 是全绿的。 - 起 postgres:16-alpine service(pg_isready 健康检查)+ 导出 CANVAS_TEST_POSTGRES_DSN; - 安装 redis-server 可执行文件(用例自起临时实例)并停掉系统服务; - 新增守卫:单独跑这 5 个用例,出现 --- SKIP 就 ::error:: 并失败; - 保留既有的 go test -json | tee 与 timings artifact 上传。 --- .github/workflows/quality.yml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index e63829da1..eac53dbfc 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -14,6 +14,24 @@ jobs: defaults: run: working-directory: backend + # 后端有 5 个用例默认会静默跳过:3 个需要 CANVAS_TEST_POSTGRES_DSN(PostgreSQL 迁移、 + # 素材字节修复、画布版本历史),2 个用 exec.LookPath("redis-server") 自起临时实例 + # (Redis 租约、缓存白名单)。只跑 go test ./... 而不备齐这两样,这些路径永远不会被执行。 + services: + postgres: + image: postgres:16-alpine + env: + POSTGRES_PASSWORD: canvas_test + POSTGRES_DB: canvas_test + ports: + - 5432:5432 + options: >- + --health-cmd "pg_isready -U postgres" + --health-interval 5s + --health-timeout 5s + --health-retries 12 + env: + CANVAS_TEST_POSTGRES_DSN: postgres://postgres:canvas_test@127.0.0.1:5432/canvas_test?sslmode=disable steps: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 @@ -21,6 +39,12 @@ jobs: go-version-file: backend/go.mod cache-dependency-path: backend/go.sum cache: true + - name: Install redis-server for integration tests + # 用例自己拉起临时 redis-server(unix socket),所以需要的是可执行文件而不是 redis 服务。 + run: | + sudo apt-get update -qq + sudo apt-get install -y -qq redis-server + sudo systemctl stop redis-server || true - name: Check formatting run: test -z "$(gofmt -l .)" - name: Run Go tests @@ -28,6 +52,17 @@ jobs: run: | set -o pipefail go test -json ./... | tee "$RUNNER_TEMP/go-tests.jsonl" + - name: Ensure dependency-backed tests were not skipped + shell: bash + run: | + set -o pipefail + go test ./internal/database/ ./internal/canvas/ ./internal/repository/ ./internal/platform/ ./internal/app/ \ + -run 'TestPostgresAssetIDMigration|TestRepairAssetBytesPostgres|TestCanvasRevision|TestRuntimeCoordinatorRedisLeasePreservesLongestTTL|TestClearAdminRuntimeCacheUsesRedisWhitelist' \ + -count=1 -v | tee "$RUNNER_TEMP/dependency-tests.log" + if grep -q -- "--- SKIP" "$RUNNER_TEMP/dependency-tests.log"; then + echo "::error::依赖外部服务的用例被跳过:请检查 CANVAS_TEST_POSTGRES_DSN 与 redis-server" + exit 1 + fi - name: Upload Go test timings if: always() uses: actions/upload-artifact@v4