with one click
contract-test-assistant
[UDS] 引導 API 和微服務的合約測試策略
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Menu
[UDS] 引導 API 和微服務的合約測試策略
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
[UDS] 引導 CI/CD 管線設計、配置和優化
Guide CI/CD pipeline design, configuration, and optimization. Use when: setting up pipelines, optimizing build times, configuring deployment stages. Keywords: CI/CD, pipeline, GitHub Actions, deployment, build.
在编写规格前进行结构化 AI 辅助头脑风暴。 使用时机:功能规划、创意发想、问题定义。 关键字:brainstorm, persona, multi-critic, HMW, SCAMPER, 头脑风暴, 发想。
[UDS] 在撰寫規格前進行結構化 AI 輔助腦力激盪
[UDS] Structured AI-assisted brainstorming before spec creation
[UDS] 从规格衍生 BDD 场景、TDD 骨架或 ATDD 表格
| name | contract-test-assistant |
| source | ../../../../skills/contract-test-assistant/SKILL.md |
| source_version | 1.0.0 |
| source_hash | f67623eb913a |
| translation_version | 1.0.0 |
| last_synced | "2026-06-01T00:00:00.000Z" |
| status | current |
| description | [UDS] 引導 API 和微服務的合約測試策略 |
語言: English | 繁體中文
引導 API 和微服務的合約測試策略選擇、設定和驗證。
合約測試透過測試消費者和提供者之間的協議(合約)來驗證服務間的通訊正確性,不需要所有服務同時運行。
| 策略 | 適用場景 | 工具 |
|---|---|---|
| 消費者驅動(Consumer-Driven) | 內部微服務,團隊同時擁有兩端 | Pact |
| 提供者驅動(Provider-Driven) | 公開 API,OpenAPI 優先設計 | OpenAPI + Prism |
| 雙向(Bi-Directional) | 混合所有權,漸進採用 | Pact + OpenAPI |
ASSESS ──► CHOOSE ──► DEFINE ──► IMPLEMENT ──► VERIFY
評估架構 選擇策略 定義合約 實作測試 驗證合約
| 指令 | 說明 |
|---|---|
/contract-test | 互動式策略選擇 |
/contract-test consumer | 引導消費者測試設定 |
/contract-test provider | 引導提供者測試設定 |
/contract-test verify | 檢查合約覆蓋率 |
## 合約覆蓋率報告
| 消費者 | 提供者 | 端點 | 狀態 |
|--------|--------|------|------|
| web-app | user-api | GET /users/:id | ✅ 已驗證 |
| web-app | user-api | POST /users | ✅ 已驗證 |
| mobile-app | auth-api | POST /login | ⚠️ 僅消費者端 |
| admin-ui | report-api | GET /reports | ❌ 無合約 |
**覆蓋率**:50%(2/4 個端點兩端皆驗證)
| 技能 | 整合方式 |
|---|---|
/api-design | 設計時定義 API 合約 |
/ci-cd | 管線中加入合約驗證 |
/testing | 合約測試作為測試策略一部分 |
/migrate | API 遷移時捕獲 legacy response fixture,驗證新實作保持結構性等價 |
當 API endpoint 從一個技術棧遷至另一個(PHP → .NET、Express → Spring 等),對 legacy 參考 fixture 的 contract test 可捕捉「缺漏欄位」「rename」「層級漂移」等新 DTO 單元測試無法覆蓋的缺陷。詳見 migration-assistant § API Migration Contract Tests 取得 fixture 捕獲協議與稽核檢查清單。
/contract-test 完成後:
合約測試引導完成。建議下一步:
- 執行
/ci-cd將合約驗證加入 CI 管線- 執行
/api-design完善 API 設計- 執行
/testing整合到整體測試策略
當 /contract-test 被呼叫時:
verify 子指令,掃描合約並回報覆蓋率