Răsfoiți Sursa

B-39: Fix skipTests false + CI guard to prevent test false positives (surefire report count > 0 required)

Sisyphus 1 săptămână în urmă
părinte
comite
0109444372
2 a modificat fișierele cu 23 adăugiri și 8 ștergeri
  1. 18 6
      .gitlab-ci.yml
  2. 5 2
      cfc-backend/pom.xml

+ 18 - 6
.gitlab-ci.yml

@@ -12,9 +12,10 @@
 #   - langgraph pytest  : tests/ 11 文件 / 47 方法可拉起(24 pass / 19 fail 为既有 schema 漂移)
 #   - Playwright e2e    : 74 spec 文件 / 2418 用例收集成功;ci-smoke.spec.js headless 冒烟 1 passed
 #
-# 🔴 关键坑(必须保留):cfc-backend/pom.xml 第 28 行 <skipTests>true</skipTests>,
-#    直接 `mvn test` 会**静默跳过全部测试(假绿)**。因此后端 job 必须显式
-#    `-DskipTests=false`,否则 CI 绿灯是假的。
+# 🔴 关键坑(B-39,已修复但必须保留守卫):cfc-backend/pom.xml 曾默认 <skipTests>true</skipTests>,
+#    直接 `mvn test` 会**静默跳过全部测试(假绿)**。B-39 已将 pom 默认改 false,
+#    且 backend-contract-junit 在 `mvn test` 后断言 surefire-reports/TEST-*.xml 数量>0(为 0 则 job 失败)。
+#    后端 job 仍显式 `-DskipTests=false` 双保险;如需跳过必须显式传 -DskipTests=true。
 #
 # 🔴 启用前置(本机实测,runner 侧待平台核实):
 #    1) runner 需 JDK8 + Maven + node18/20/22 + npm + Python3.11+ + 可拉依赖网络
@@ -124,7 +125,10 @@ web-jest:
 # ---------------------------------------------------------------------------
 # Job 4 — 后端契约/单测 JUnit(G1,G0 编译门禁的测试侧补充)
 # ---------------------------------------------------------------------------
-#   - 必须 -DskipTests=false 覆盖 pom:28 假绿(否则 mvn test 静默跳测 = 假绿)
+#   - B-39 守卫:显式 -DskipTests=false(pom 默认已改 false,仍双保险覆盖);
+#     并在 mvn test 后断言 target/surefire-reports/TEST-*.xml 数量>0,
+#     否则 job 失败——杜绝「零用例仍 BUILD SUCCESS」的假绿黑洞
+#   - -o 离线:依赖 .m2 缓存(Job1 backend-g0-compile 预热同 cache key)
 #   - 排除 **/integration/**(46 个 @SpringBootTest 中需内网 MySQL 的类在 CI 无法跑)
 #   - 既有失败:契约漂移(expected 500 vs 5001 等)为 P-2 已知红,allow_failure 兜底
 # ---------------------------------------------------------------------------
@@ -138,8 +142,16 @@ backend-contract-junit:
       - .m2/repository
   script:
     - cd cfc-backend
-    # 必须 -DskipTests=false(pom.xml:28 默认 true = 假绿);排除需 DB 的 integration 包
-    - mvn -B test -DskipTests=false -Dtest='!**/integration/**'
+    # B-39:显式 -DskipTests=false(pom.xml 默认已改 false,双保险);-o 离线;排除需 DB 的 integration 包
+    - mvn -o -B test -DskipTests=false -Dtest='!**/integration/**'
+    # B-39 守卫:断言 surefire-reports/TEST-*.xml 数量>0,否则 job 失败(防假绿黑洞)
+    - |
+      report_count=$(find target/surefire-reports -name 'TEST-*.xml' 2>/dev/null | wc -l)
+      if [ "${report_count}" -eq 0 ]; then
+        echo "ERROR(B-39): target/surefire-reports/TEST-*.xml 数量=0,mvn test 疑似零用例假绿"
+        exit 1
+      fi
+      echo "OK(B-39): target/surefire-reports/TEST-*.xml 数量=${report_count}"
   after_script:
     - echo "契约/单测结果见 surefire-reports" || true
   artifacts:

+ 5 - 2
cfc-backend/pom.xml

@@ -25,7 +25,9 @@
         <jwt.version>0.11.5</jwt.version>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
-        <skipTests>true</skipTests>
+        <!-- B-39: 默认执行测试(false)。如需跳过必须在命令行显式传 -DskipTests=true,
+             否则 mvn test 会静默跳过全部用例却仍 BUILD SUCCESS(假绿黑洞)。 -->
+        <skipTests>false</skipTests>
     </properties>
 
     <dependencies>
@@ -223,7 +225,8 @@
                     </annotationProcessorPaths>
                 </configuration>
             </plugin>
-            <!-- Skip test compilation by default -->
+            <!-- B-39: surefire 由 <skipTests>${skipTests}</skipTests> 驱动,默认 false=执行测试;
+                 显式 -DskipTests=true 才跳过(不再默认跳过,杜绝假绿) -->
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-surefire-plugin</artifactId>