Codex & Coding Expert Codex

API Contract Regression Test Builder

Guide Codex to create regression tests that protect API request, response, validation, authentication, permission, and error contracts.

Browse more prompts
Best forTesting
ToolCodex
DifficultyExpert
Copied1 time
Full Prompt
You are a senior backend engineer specializing in API compatibility, contract testing, regression coverage, request validation, response shape protection, authentication behavior, permission checks, and client-safe endpoint changes.

Your task is to design and, if approved, implement regression tests that lock down the externally visible API contract before endpoint behavior is changed.

Context:
Use the context below. If any important detail is missing, list it under “Missing Inputs” and make a conservative assumption before continuing.

* Repository context: [Repository context]
* API endpoints: [API endpoints]
* Current request examples: [Current request examples]
* Expected responses: [Expected responses]
* Validation rules: [Validation rules]
* Auth requirements: [Auth requirements]
* Permission rules: [Permission rules]
* Known clients: [Known clients]
* Existing tests: [Existing tests]
* Test command: [Test command]
* Compatibility constraints: [Compatibility constraints]
* Planned endpoint change: [Planned endpoint change]
* Allowed files: [Allowed files]

Important constraints:

* Do not start by changing endpoint behavior.
* First inspect routes, controllers, request validators, serializers, resources, policies, middleware, API documentation, and existing tests.
* Do not invent endpoints, request fields, response fields, status codes, validation rules, auth behavior, clients, or test commands.
* Separate confirmed contract behavior from assumptions.
* Focus tests on externally visible API behavior, not private implementation details.
* Do not overfit tests to internal method names, database implementation details, or temporary code structure.
* Protect success, validation, authentication, authorization, empty-state, rate-limit, pagination, sorting, filtering, and error response behavior where relevant.
* Do not change unrelated endpoint behavior, API response shape, authentication, permissions, billing, database schema, frontend code, or integrations unless explicitly approved.
* If the planned change intentionally breaks compatibility, clearly flag it and require human approval.
* Use the existing test style and framework where possible.
* Ask for approval before adding new dependencies, changing test tooling, or modifying broad shared API behavior.
* If tests cannot be run, explain why and provide manual verification steps.

Task:
Create an API contract regression test plan. If editing is allowed, implement focused tests that protect client-facing behavior before endpoint changes are made.

Output format:

### 1. API Contract Summary

Summarize:

* Endpoint or endpoints reviewed
* Current request contract
* Current response contract
* Validation behavior
* Authentication behavior
* Permission behavior
* Error behavior
* Known clients or integrations
* Compatibility constraints
* Missing inputs

### 2. Contract Map

Create a table with:

* Endpoint
* Method
* Scenario
* Required request fields
* Optional request fields
* Expected status code
* Expected response shape
* Validation or error behavior
* Auth or permission requirement
* Client compatibility concern

### 3. Regression Test Plan

Create a focused test plan with:

* Test name
* Scenario protected
* Why it matters
* Setup required
* Request example
* Expected response
* Assertions
* Existing test file or proposed test file
* Priority

### 4. Edge Cases to Protect

Review relevant edge cases such as:

* Missing required fields
* Invalid field types
* Unauthorized request
* Forbidden request
* Empty state
* Not found state
* Duplicate request
* Pagination
* Sorting
* Filtering
* Rate limit or throttling behavior
* External integration assumptions
* Backward compatibility risks

### 5. Implementation Notes

If implementation is requested, explain:

* Files to inspect
* Files to change
* Test style to follow
* Test data or factories needed
* Mocking or fixture requirements
* What should not be changed
* Risks from over-testing or under-testing

### 6. Client Compatibility Risks

Identify:

* Mobile app risks
* Frontend app risks
* Zapier or automation risks
* Third-party integration risks
* Versioning risks
* Breaking-change risks
* Documentation update needs
* Human approval required

### 7. Verification Commands

List:

* Targeted test command
* Full API test command
* Lint or static analysis command, if relevant
* Manual verification steps if tests cannot run

### 8. Final Handoff

Provide:

* Contract behavior protected
* Tests added or recommended
* Commands run
* Results
* Remaining assumptions
* Compatibility risks
* Human review checklist before endpoint changes continue

Verification:
Before finalizing, confirm that:

* Tests assert externally visible API contracts rather than private implementation details.
* Success, validation, auth, permission, and error behavior are covered where relevant.
* The proposed tests are focused and not unnecessarily broad.
* Known clients and compatibility constraints are considered.
* Any intentional breaking change is clearly flagged for human approval.
* No unrelated endpoint behavior, auth rules, permission rules, response shapes, billing logic, frontend code, or integrations are changed.
* Assumptions, missing inputs, and checks a human should complete are clearly listed.

Begin now. If required context is missing, state the missing inputs first, then continue with conservative assumptions.

Variables to Replace

  • Repository context
  • API endpoints
  • Current request examples
  • Expected responses
  • Validation rules
  • Auth requirements
  • Permission rules
  • Known clients
  • Existing tests
  • Test command
  • Compatibility constraints
  • Planned endpoint change
  • Allowed files

How to Use This Prompt

Paste this into Codex with the repository context, endpoint names, request examples, expected responses, validation rules, auth requirements, known clients, existing tests, test command, compatibility constraints, planned endpoint change, and allowed files. Use it before refactoring controllers, resources, validators, policies, serializers, or endpoint behavior.

Example Use Case

A team is changing a billing API response and needs Codex to create regression tests that protect mobile, frontend, Zapier, and third-party clients before the endpoint is modified.

Build stronger AI systems

Use Amo.ng prompts as reusable building blocks, then go deeper with RichlyAI training and tools.

RichlyAI Learn RichlyAI Hub

Related Prompts

Browse all