api-contract-testing
Skill này làm gì
Công cụ này giúp kiểm tra xem các thay đổi trong hợp đồng API (quy tắc giao tiếp của hệ thống) có gây ra vấn đề không. Nó đảm bảo bên cung cấp và bên sử dụng API vẫn hoạt động cùng nhau sau khi có thay đổi.
Khi nào nên dùng
- ✓Khi một trường hoặc quy tắc trong phản hồi API thay đổi.
- ✓Khi code biên dịch được nhưng việc giao tiếp hệ thống thất bại lúc chạy.
- ✓Khi cần biết một thay đổi có phá vỡ tính tương thích hay chỉ là tính năng mới.
Liên kết skill
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/api-contract-testing/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Hãy xem xét thay đổi API này. Liệt kê các bên tiêu thụ bị ảnh hưởng và các tổ hợp phiên bản được hỗ trợ. Thêm các bài kiểm thử hợp đồng cục bộ cho phản hồi hợp lệ, không hợp lệ và lỗi bằng trình chạy kiểm thử hiện có. Báo cáo những kiểm tra thực sự đã chạy và những gì còn cần bằng chứng.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Công cụ so sánh định nghĩa API chính thức với hành vi thực tế, tạo các bài kiểm thử nhỏ với dữ liệu giả. Điều này đảm bảo thay đổi không làm hỏng giao tiếp giữa các hệ thống dùng API.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
API Contract Testing
Overview
Turn an API change into explicit provider and consumer checks. Start from the actual contract and affected clients, then verify wire-level behavior rather than relying on generated types or a successful build. Default to local fixtures and existing test tools; this skill does not provision a testing service.
When to Use
- A response field, endpoint, event schema or error envelope changes.
- A client and server build successfully but disagree at runtime.
- A team needs to distinguish a breaking change from a compatible extension.
- A reported regression needs a minimal provider/consumer reproduction.
Do not use this as authorization to call production endpoints, bypass access controls or publish a new API version.
How It Works
1. Bind the contract and scope
Identify the provider, transport, contract source and version, known consumers and the requested behavior. Read the real OpenAPI/JSON Schema/protobuf definition or documented examples and the corresponding server/client code. Record missing consumers and stale specifications as coverage gaps; do not invent interfaces or claim complete coverage from one client.
Keep these distinct: documented schema, actual provider output, generated client types and runtime parsing. A type assertion alone is not validation. Preserve the existing protocol and test runner instead of introducing a new platform by default.
2. Classify the change
Review fields, requiredness, nullability, enum values, status codes, headers, content type, pagination and error behavior. Inspect whether clients tolerate extra fields and unknown enum values. Even an added optional field can break a strict consumer. Explicitly identify affected versions and assumptions before calling a change compatible.
For events, include duplicate delivery, ordering and version envelopes. For request changes, check serialization and server validation as well as responses.
3. Build a small test matrix
Use deterministic synthetic fixtures for:
- Valid success, including optional and empty values.
- Missing required fields, wrong types and explicit nulls.
- Extra fields and unknown enums according to the actual compatibility policy.
- Declared error envelopes, non-success statuses and malformed bodies.
- Old consumer against new provider and new consumer against retained old provider, where those combinations are supported.
Assert the behavior promised by the contract. Do not silently coerce malformed values or make the fixture match a defect just to get a passing test.
4. Verify each boundary
Run the existing schema validator against fixtures. Exercise the provider handler locally and pass its serialized result through the real consumer parser. Check failure cases reject or map errors as specified. Use an authorized isolated integration environment only when fixtures cannot establish the required property; report that boundary explicitly.
A mock verifies assumptions encoded in the mock. It does not establish that the real provider implements them. Record exact commands, fixture versions and observed outcomes separately from unrun checks.
5. Report and hand off
Deliver the change classification, affected consumers, test matrix, observed failures, minimal reproduction and remaining coverage gaps. For a breaking change, propose versioning, a compatibility adapter or a staged migration with owners and rollback criteria. Deployment and consumer migration require their own task authorization.
Example
Synthetic documented response:
{"id":"invoice-demo","amount_minor":1250,"currency":"EUR"}
Contract: id and currency are strings; amount_minor is a non-negative integer in minor units. This fixture does not represent an actual customer or payment.
| Fixture change | Expected check |
|---|---|
amount_minor becomes "1250" |
Runtime parser rejects the string; compile-time generated types alone cannot detect wire drift. |
amount_minor is missing or null |
Reject when the field is required and non-nullable. |
Extra display_label field |
Verify the consumer's documented extra-field policy before declaring compatibility. |
| HTTP error with an HTML body | Produce the declared transport/protocol error, rather than treating it as a valid invoice. |
Reusable prompt:
Review this API change against the actual contract and supplied client/server code.
…
Câu hỏi thường gặp
“API contract” là gì?
Đó là tài liệu xác định cách một hệ thống (bên cung cấp) giao tiếp với hệ thống khác (bên sử dụng), quy định định dạng dữ liệu, endpoint và quy tắc mong đợi.
Tại sao không dùng dữ liệu thật trên production?
Dùng dữ liệu thật có thể làm lộ thông tin nhạy cảm và không đảm bảo mọi kịch bản lỗi đều được kiểm thử. Dữ liệu tối thiểu, tổng hợp sẽ an toàn và hiệu quả hơn.
Công cụ này có triển khai hoặc quản lý API không?
Không, công cụ này tập trung vào lập kế hoạch và xác minh hợp đồng API. Nó không triển khai API hay quản lý dịch vụ kiểm thử.
Chi tiết
Mô tả gốc của tác giả
Design and review API contract tests across providers and consumers. Use for schema changes, compatibility regressions and client integration failures.
Độ phổ biến
- Sao GitHub
- 48k
- Vị trí xếp hạng
- #3765
- Giấy phép
- MIT
- Cập nhật
- 15/10/2026
Bình luận
- …
Thêm skill từ kho mã này
00-andruia-consultant
48kGiúp agent của bạn bắt đầu hoặc cải thiện các dự án AI. Phân tích mã, gợi ý công cụ và lập kế hoạch hành động bằng tiếng Tây Ban Nha.
007
48kCho phép agent của bạn thực hiện kiểm toán bảo mật và mô hình hóa mối đe dọa. Hữu ích để bảo vệ dự án khỏi các cuộc tấn công và lỗ hổng.
10-andruia-skill-smith
48kGiúp agent của bạn tạo hoặc cải thiện các công cụ AI. Xác định cách công cụ hoạt động, viết tài liệu và kiểm tra cấu trúc.
20-andruia-niche-intelligence
48kGiúp agent của bạn tạo bản tóm tắt về một ngành cụ thể. Hữu ích để hiểu bối cảnh, quy tắc, cách người dùng tương tác và rủi ro của dự án.
Skill tương tự
test-driven-development
311kDạy agent của bạn viết kiểm thử thất bại trước, xem nó thất bại, rồi viết đoạn mã ngắn nhất để vượt qua trước khi làm bất kỳ tính năng hay bản sửa nào.
verification-before-completion
311kDạy agent của bạn chạy kiểm tra thực tế và đọc kết quả đầu ra trước khi khẳng định một việc, bản sửa hoặc bản build đã hoàn thành hay vượt qua.
migrate-to-shoehorn
310kThay các ép kiểu rủi ro trong tệp kiểm thử bằng thư viện shoehorn, để các bài kiểm thử dùng dữ liệu một phần vẫn qua được kiểm tra kiểu.