thread-master/docs/product/haixun-backend/TESTING.md

67 lines
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 巡樓後端 · 測試政策Phase C
> 對齊 `spec.md` §9184 IDs與 §9.18。
> Task 入口:`tasks/INDEX.md`。
## 1. 為什麼
§9 是 **Given/When/Then 全量驗收**,不是示意清單。
「功能 task 做完 + 手測一下」**不算** P0/P1 過關。
## 2. 四層測試
| 層 | 位置 | 工具建議 | 必須 |
|----|------|----------|------|
| Unit | `apps/backend/internal/**/*_test.go` | `go test` | 邏輯guard計費規則**路徑根 = apps/backend** |
| API Integration | 同上 + `//go:build integration` 可選 | testkit + Mongo/Redis | 每條 §9 ID 主路徑 |
| Contract | `TestX_*` | 全站抽樣 | X-0106 |
| FE↔BE | `apps/web/tests/integration/**` | vitest 或 playwright + `LIVE_API_BASE` | live repo 契約(非 mock |
## 3. Case 命名(強制)
- Go`TestAU_01_LoginSuccess`、`TestOB_02_DueStep_PublishedViaTransport`
- JS`it('AU-04 me returns numeric uid via live repo')`
- 必須能被 `grep -E 'AU-01|TestAU_01'` 從測試樹找到
- 最終由 `T222` / `acceptance-matrix.md` + check script 機械對齊 **184**
## 4. 外部依賴
| 依賴 | 自動化 | 不可做 |
|------|--------|--------|
| Threads OAuthPublish | **fake HTTP server** 注入 | 只 `UpdateOne` 成 connected/published |
| AI / Exa | fake transport | 假成功空 data |
| 真 Meta真 xAI | 矩陣標 `manual`/可選 live | 取代 auto case |
## 5. 指令目標形狀M0 T108 落地)
```bash
# 後端
cd apps/backend
make test # go test ./...
make gen-api # 改 .api 後
# 前端 FE-BET220
cd apps/web
LIVE_API_BASE=http://127.0.0.1:8888 npm run test:integration
# 煙測T218
bash scripts/smoke-p0.sh
```
## 6. 里程碑閘門
| M 完成定義 | 除功能外必須 |
|------------|--------------|
| M0 | T107 testkit + T108 CI targets |
| M1 | T119 綠AU/AR/AP/AO/AD |
| M2 | T136 綠TH/JB |
| M3 | T156 綠ST/USG |
| M4 | T172 綠PE/PL/OB/OP |
| M5 | T196 綠IN/SC |
| M6 | T219T222 綠;矩陣 184 齊 |
## 7. 與 mock 前端的關係
- `createRepos('mock')` 的單元測 **不** 計 §9 live 驗收。
- live 驗收以 gateway + worker + `createRepos('live')` 為準。