Loading pair-programming exercise

Repair the AI API Reliability Tests

A product API calls an external model provider and must handle rate limits without multiplying user actions.

Testing model-provider failures without retrying everything

The gateway retries transient provider errors, refuses permanent errors, and falls back only after transient attempts are exhausted.

Your task

The application code is complete and read only. Repair only tests/test_ai_gateway.py so its expectations match the documented contract and still catch real regressions.

Pairing tasks

  1. Read the implementation and written contract before running the suite.
  2. Identify which expectations misunderstand the production behavior.
  3. Repair only the editable pytest file; do not weaken or delete assertions.
  4. Make every corrected test pass the working implementation and fail its matching regression.

Explain the production contract before editing a test. For every change, state why the old expectation was wrong and which regression the corrected assertion detects.

Interviewer follow-up questions

  • Which provider failures are safe to retry?
  • Why can retries duplicate side effects?
  • When is fallback worse than returning an error?

Skills: AI APIs · Retries · Fallbacks · Idempotency

Exercises

Pair Programming22 exercises