.gitlab-ci.yml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. # =============================================================================
  2. # 浠艾福 (XAF) — 最小 CI 管线(GitLab CI,仓库根,自动加载)
  3. # -----------------------------------------------------------------------------
  4. # 落地:2026-11-06(最小 CI 管线搭建)
  5. # 追加:2026-11-07(EVD-6 持续回归:契约 JUnit / langgraph pytest / Playwright e2e / tests jest)
  6. # 前置:remote = http://git.iwintrue.com/liaoxg/cfc(GitLab 系自托管)
  7. # 本机实测(2026-11-06~07,processor JDK8+Maven3.9.9/node22):
  8. # - 后端 G0 编译 : mvn test-compile -DskipTests=false → BUILD SUCCESS (2046+231 源)
  9. # - 后端契约/单测 : mvn test -DskipTests=false -Dtest='!**/integration/**' → 1794 例实测跑通
  10. # - cfc-frontend jest : 14 suites / 296 例全绿
  11. # - cfc-web jest : 12 suites / 90 例全绿
  12. # - langgraph pytest : tests/ 11 文件 / 47 方法可拉起(24 pass / 19 fail 为既有 schema 漂移)
  13. # - Playwright e2e : 74 spec 文件 / 2418 用例收集成功;ci-smoke.spec.js headless 冒烟 1 passed
  14. #
  15. # 🔴 关键坑(必须保留):cfc-backend/pom.xml 第 28 行 <skipTests>true</skipTests>,
  16. # 直接 `mvn test` 会**静默跳过全部测试(假绿)**。因此后端 job 必须显式
  17. # `-DskipTests=false`,否则 CI 绿灯是假的。
  18. #
  19. # 🔴 启用前置(本机实测,runner 侧待平台核实):
  20. # 1) runner 需 JDK8 + Maven + node18/20/22 + npm + Python3.11+ + 可拉依赖网络
  21. # 2) 本文件默认 when: manual(首次先手动触发跑通);确认 runner 能力后
  22. # 将各 job 的 `when: manual` 改为 `when: on_success`(或删除该行走默认自动)
  23. # 3) 若 runner .m2 已预热且无外网,可在 mvn 命令加 `-o`(离线)
  24. # 4) e2e-playwright 需 runner 具备 chromium 系统依赖(或 root 跑
  25. # `npx playwright install --with-deps chromium`)
  26. # 5) tests-jest 依赖 npm>=10 解析 "npm:@vue/babel-plugin-jsx@^1.1.1"(node22 自带 npm10)
  27. # -----------------------------------------------------------------------------
  28. # 设计说明(G0/G1 分层基线):
  29. # - G0 编译门禁(backend-g0-compile,必绿,最快信号)
  30. # - G1 各套件分层回归:
  31. # * backend-contract-junit:契约/单测(排除需 DB 的 integration 包);
  32. # 存在既有契约漂移红(如 StatsControllerTest 500 vs 5001),
  33. # allow_failure 兜底,拍板后移除
  34. # * langgraph-pytest:schema 漂移既有 19 红(respondent_name 等),allow_failure 兜底
  35. # * e2e-playwright:**CI 安全模式**——只做 `--list` 收集校验 + headless 冒烟;
  36. # 真实 UI e2e 依赖部署环境 + DB(globalSetup 会重置 192.168.16.251 测试库,
  37. # **严禁**在 CI 开启 playwright.config.js 默认 globalSetup)
  38. # * tests-jest:依赖 cfc-frontend(vue)依赖,npm10 才能装
  39. # - 前端/管理端用 jest --ci(已验证全绿,无外部依赖)
  40. # =============================================================================
  41. stages:
  42. - build
  43. - test
  44. variables:
  45. MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
  46. cache:
  47. key: "$CI_COMMIT_REF_SLUG"
  48. paths:
  49. - .m2/repository
  50. - cfc-frontend/node_modules/
  51. - cfc-web/node_modules/
  52. - tests/node_modules/
  53. # ---------------------------------------------------------------------------
  54. # Job 1 — 后端 G0 编译门禁
  55. # ---------------------------------------------------------------------------
  56. backend-g0-compile:
  57. stage: build
  58. when: manual # 首次手动;确认 runner 能力后改 on_success
  59. cache:
  60. key: "$CI_COMMIT_REF_SLUG"
  61. paths:
  62. - .m2/repository
  63. script:
  64. - cd cfc-backend
  65. # 必须 -DskipTests=false 覆盖 pom 默认假绿(pom.xml:28)
  66. - mvn test-compile -DskipTests=false
  67. artifacts:
  68. when: always
  69. expire_in: 7 days
  70. paths:
  71. - cfc-backend/target/classes/
  72. # 注:契约/单测复验(G1)暂由本地轮次承担(P-2 3 红未拍板,见 CI_READINESS)
  73. # ---------------------------------------------------------------------------
  74. # Job 2 — 小程序前端(cfc-frontend)jest 单测
  75. # ---------------------------------------------------------------------------
  76. frontend-jest:
  77. stage: test
  78. when: manual # 首次手动;确认 runner 能力后改 on_success
  79. cache:
  80. key: "$CI_COMMIT_REF_SLUG"
  81. paths:
  82. - cfc-frontend/node_modules/
  83. script:
  84. - cd cfc-frontend
  85. - npm ci || npm install
  86. - npx jest --ci
  87. artifacts:
  88. when: always
  89. expire_in: 7 days
  90. reports:
  91. junit:
  92. - cfc-frontend/junit.xml
  93. paths:
  94. - cfc-frontend/coverage/
  95. # ---------------------------------------------------------------------------
  96. # Job 3 — 管理端(cfc-web)jest 单测
  97. # ---------------------------------------------------------------------------
  98. web-jest:
  99. stage: test
  100. when: manual # 首次手动;确认 runner 能力后改 on_success
  101. cache:
  102. key: "$CI_COMMIT_REF_SLUG"
  103. paths:
  104. - cfc-web/node_modules/
  105. script:
  106. - cd cfc-web
  107. - npm ci || npm install
  108. - npx jest --ci
  109. artifacts:
  110. when: always
  111. expire_in: 7 days
  112. reports:
  113. junit:
  114. - cfc-web/junit.xml
  115. paths:
  116. - cfc-web/coverage/
  117. # ---------------------------------------------------------------------------
  118. # Job 4 — 后端契约/单测 JUnit(G1,G0 编译门禁的测试侧补充)
  119. # ---------------------------------------------------------------------------
  120. # - 必须 -DskipTests=false 覆盖 pom:28 假绿(否则 mvn test 静默跳测 = 假绿)
  121. # - 排除 **/integration/**(46 个 @SpringBootTest 中需内网 MySQL 的类在 CI 无法跑)
  122. # - 既有失败:契约漂移(expected 500 vs 5001 等)为 P-2 已知红,allow_failure 兜底
  123. # ---------------------------------------------------------------------------
  124. backend-contract-junit:
  125. stage: test
  126. when: manual # 首次手动;确认 runner 能力后改 on_success
  127. allow_failure: true # 既有契约漂移红(StatsControllerTest 500 vs 5001 等)未拍板
  128. cache:
  129. key: "$CI_COMMIT_REF_SLUG"
  130. paths:
  131. - .m2/repository
  132. script:
  133. - cd cfc-backend
  134. # 必须 -DskipTests=false(pom.xml:28 默认 true = 假绿);排除需 DB 的 integration 包
  135. - mvn -B test -DskipTests=false -Dtest='!**/integration/**'
  136. after_script:
  137. - echo "契约/单测结果见 surefire-reports" || true
  138. artifacts:
  139. when: always
  140. expire_in: 7 days
  141. reports:
  142. junit:
  143. - cfc-backend/target/surefire-reports/TEST-*.xml
  144. paths:
  145. - cfc-backend/target/surefire-reports/
  146. # ---------------------------------------------------------------------------
  147. # Job 5 — cfc-langgraph pytest(G1,AI 服务侧)
  148. # ---------------------------------------------------------------------------
  149. # - conftest 自动 import app.main(需全量依赖,requirements_frozen.txt 锁版本)
  150. # - --ignore=tests/qna(test_graph.py 引用不存在的 src.qna → collection error)
  151. # - 既有失败 19 红(schema 漂移:respondent_name/member_name、MemoryManager 签名等)
  152. # allow_failure 兜底,待测试侧修复后移除
  153. # ---------------------------------------------------------------------------
  154. langgraph-pytest:
  155. stage: test
  156. when: manual
  157. allow_failure: true # 既有 schema 漂移 19 红(respondent_name 等)待修复
  158. cache:
  159. key: "$CI_COMMIT_REF_SLUG"
  160. paths:
  161. - cfc-langgraph/.venv/
  162. script:
  163. - cd cfc-langgraph
  164. - python3 -m venv .venv || true
  165. - . .venv/bin/activate
  166. - pip install -q -r requirements_frozen.txt
  167. - python -m pytest tests/ -v --ignore=tests/qna --junitxml=junit.xml -p no:cacheprovider
  168. artifacts:
  169. when: always
  170. expire_in: 7 days
  171. reports:
  172. junit:
  173. - cfc-langgraph/junit.xml
  174. paths:
  175. - cfc-langgraph/junit.xml
  176. # ---------------------------------------------------------------------------
  177. # Job 6 — Playwright e2e(G1,前端侧,CI 安全模式)
  178. # ---------------------------------------------------------------------------
  179. # ⚠️ 严禁在 CI 使用 tests/playwright.config.js(其 globalSetup 会重置远程
  180. # 192.168.16.251 测试库)。CI 采用安全模式:
  181. # 1) `npx playwright test --list` — 校验 74 spec / 2418 用例可收集
  182. # 2) `-c playwright.config.smoke.js ci-smoke` — headless chromium 真实拉起冒烟
  183. # 真实 UI e2e 依赖部署环境 + DB(cfc.iwintrue.com),由测试负责人手动跑。
  184. # ---------------------------------------------------------------------------
  185. e2e-playwright:
  186. stage: test
  187. when: manual # 首次手动;确认 runner 能力后改 on_success
  188. cache:
  189. key: "$CI_COMMIT_REF_SLUG"
  190. paths:
  191. - tests/node_modules/
  192. script:
  193. - cd tests
  194. - npm ci || npm install
  195. - npx playwright install chromium || true
  196. # CI 安全模式:只做收集校验 + headless 冒烟(均不触发远程 DB 重置)
  197. - npx playwright test --list
  198. - npx playwright test e2e/ci-smoke.spec.js -c playwright.config.smoke.js
  199. artifacts:
  200. when: always
  201. expire_in: 7 days
  202. paths:
  203. - tests/test-results/
  204. # ---------------------------------------------------------------------------
  205. # Job 7 — tests/ 目录 jest(unit + integration,G1 补充)
  206. # ---------------------------------------------------------------------------
  207. # - tests/jest.config.js 依赖 cfc-frontend/__tests__/setup.js(vue),
  208. # 需先装 cfc-frontend 依赖;npm>=10 才能解析 "npm:@vue/babel-plugin-jsx@^1.1.1"
  209. # 本机 npm9.2.0 验证失败(node22 自带 npm10 可装)
  210. # - integration 部分需后端 API(localhost:9082)在 CI 无后端时仅跑能跑的
  211. # ---------------------------------------------------------------------------
  212. tests-jest:
  213. stage: test
  214. when: manual
  215. allow_failure: true # 需 npm10 + cfc-frontend(vue) 依赖;integration 需后端
  216. cache:
  217. key: "$CI_COMMIT_REF_SLUG"
  218. paths:
  219. - tests/node_modules/
  220. - cfc-frontend/node_modules/
  221. script:
  222. - cd cfc-frontend && npm ci || npm install # setup.js 需要 vue
  223. - cd ../tests && npm ci || npm install
  224. - npx jest --ci