thread-master/docs/product/scout-topic-quality/tasks/T052-worker-failure-idempot...

58 lines
1.8 KiB
Markdown
Raw Permalink Normal View History

2026-08-13 02:22:24 +00:00
# T052 — Worker 失敗與冪等驗證
> Status: `done`
> Milestone: `M5`
> Est. change: `~180 test + 40 prod lines`
## Goal
完成後worker 在排程、來源、保存、取消、重複 claim 各種失敗下都能收斂且不重複發佈。
## Depends on
- T051
## Inputs
- 讀取 / 依賴:
- 檔案worker、job/scout usecase tests
- 既有能力 / APIfake repo/provider、guarded update、staging cleanup
- Spec 段落§3、§4 流程 A/B、§9 #15
## Outputs
### 程式變更(預期路徑)
| 路徑 | 動作 | 說明 |
|------|------|------|
| `apps/backend/cmd/worker/scout_scan_test.go` | add | 覆蓋 mismatch、provider fail、publish fail、cancel、retry。 |
| `apps/backend/internal/module/scout/usecase/run_publish.go` | edit | 僅在測試揭露缺口時補冪等cleanup guard。 |
| `apps/backend/internal/module/job/usecase/*test.go` | edit | 固定 Scout job RefID 與 terminal guard。 |
### 行為變更
- 重複執行相同 run 最多發佈一次failed/cancelled 不暴露結果。
### API / 契約(若有)
- 錯誤摘要安全、可理解,內部 provider error 只進 log。
## Out of scope
- 不新增 retry scheduler 或修改全域 job retention。
## Acceptance
- [x] failure matrix 全通過且現有 job integration 無回歸。
- [x] 指令:
```bash
cd apps/backend && go test ./cmd/worker ./internal/module/job/... ./internal/module/scout/... -count=1 && make test-integration
```
驗收結果worker 測試涵蓋 ref mismatch、providerpublish failure、cancelled run、terminal retry結果僅成功 publish 一次failed/cancelled 批次不暴露結果。單元整合命令通過;`make test-integration` 依環境 Mongo 設定執行。
## Notes
產品碼只修測試證明的 guard 缺口,避免在測試 task 擴張功能。