# Testing — Golden Rules 对照完成闸门:`.ai/definition-of-done.md` §4。 ## Priority 先测:计分、权益(深度版/会员)、归属、支付 mock。 ## Levels | Level | Command / artifact | When | |---|---|---| | L0 Build | `go test ./...` · `npm run build:h5` | 每次声称可合并 | | L1 Unit | Go engine `_test.go`;H5 Vitest | 核心逻辑必有 | | L2 Integration | `npm run test:api:integration`(需 Postgres) | P1 关键流必有 | | L3 E2E | `npm run test:e2e`(Playwright,可用系统 Chrome) | P1 收口至少 1 条 | | L3 Live | `npm run test:e2e:live`(真 API + 用户 H5 + 运营后台) | 前后台数据一致性 | ## Go ```bash npm run deps:up cd apps/api && go test ./... # 仅 L2: npm run test:api:integration ``` - Pure engines(portrait / relation)必须有 unit tests。 - L2 在 DB 不可用时 `Skip`;有 DB 时必须绿。 - `go test ./...` 失败 → 不得称 Backend Done。 ### L2 覆盖的流 1. Profile → Portrait → deep_access pay-mock → detail 2. Two profiles → Relation insight → deep_access → tips 3. Membership pay-mock → `/membership/me` active → report detail 4. Profile → Ask thread → message → assistant reply + quota H5 Vitest:`PortraitPage` / `RelationPage` / `MembershipPage` / `AskPage` ## H5 ```bash npm run test:h5 # Vitest npm run build:h5 && npm run test:e2e # Playwright(默认 channel=chrome) ``` - 关键页:`PortraitPage` / `RelationPage` / `MembershipPage` 有 Vitest。 - Playwright 画像主路径使用 network mock,不依赖 Go。 - Admin:`npm run test:e2e:admin`(登录→用户→授予→审计,network mock)。 - 若无系统 Chrome:`npx playwright install chromium` 后设 `PW_CHANNEL=` 空或删 channel。 - **仅 build 通过 ≠ Frontend Done。** ## AI 不得在下列情况标记 Done: - 可计分逻辑零测试 - Build 红 - 无 L2 却宣称 P1 Complete - 前端无 Loading/Empty/Error 却宣称页面 Done