|
| 1 | +# 12 — API Contract Validation |
| 2 | + |
| 3 | +An end-to-end API contract validation pipeline that uses PR-triggered |
| 4 | +validation, scheduled compatibility audits, and a multi-step consumer |
| 5 | +update pipeline to catch and resolve breaking API changes. |
| 6 | + |
| 7 | +## Use Case |
| 8 | + |
| 9 | +Detect breaking changes in API definitions (OpenAPI, protobuf, GraphQL) |
| 10 | +when PRs are opened, run weekly audits for unreleased drift, and |
| 11 | +coordinate migration across consumer repositories when intentional |
| 12 | +breaking changes are approved. |
| 13 | + |
| 14 | +AI agents add value beyond static diff tools by reasoning about semantic |
| 15 | +intent, analyzing real consumer impact, proposing backward-compatible |
| 16 | +alternatives, and generating targeted migration guides. |
| 17 | + |
| 18 | +## Resources |
| 19 | + |
| 20 | +| File | Kind | Purpose | |
| 21 | +|------|------|---------| |
| 22 | +| `credentials-secret.yaml` | Secret | Anthropic API key for the agent | |
| 23 | +| `github-token-secret.yaml` | Secret | GitHub token for cloning and PR creation | |
| 24 | +| `workspace.yaml` | Workspace | Git repository containing API definitions | |
| 25 | +| `agentconfig.yaml` | AgentConfig | Shared instructions for the API validator agent | |
| 26 | +| `taskspawner-webhook.yaml` | TaskSpawner | PR-triggered validation via `/validate-api` comment | |
| 27 | +| `taskspawner-cron.yaml` | TaskSpawner | Weekly cross-service compatibility audit | |
| 28 | +| `pipeline.yaml` | Task (x2) | Consumer impact analysis and migration guide pipeline | |
| 29 | + |
| 30 | +## Configurations |
| 31 | + |
| 32 | +### 1. PR-Triggered API Validation (Webhook) |
| 33 | + |
| 34 | +Listens for `/validate-api` comments on PRs. The agent checks out the PR |
| 35 | +branch, runs structural diff tools if available, classifies each change, |
| 36 | +and posts a review summarizing findings with backward-compatible |
| 37 | +alternatives for any breaking changes. |
| 38 | + |
| 39 | +### 2. Scheduled Compatibility Audit (Cron) |
| 40 | + |
| 41 | +Runs every Monday at 8:00 AM UTC. The agent compares the current API |
| 42 | +surface against the latest tagged release, identifies unreleased breaking |
| 43 | +changes and API hygiene issues, and creates a GitHub issue with findings. |
| 44 | + |
| 45 | +### 3. Consumer Update Pipeline (Task Dependencies) |
| 46 | + |
| 47 | +A two-stage pipeline for coordinating migration after an intentional |
| 48 | +breaking change is approved: |
| 49 | + |
| 50 | +``` |
| 51 | +identify-consumers (Task) |
| 52 | + │ analyzes which consumers use the affected endpoints |
| 53 | + │ outputs: migration-plan.md |
| 54 | + │ |
| 55 | + ▼ |
| 56 | +generate-migration-guide (Task, dependsOn: [identify-consumers]) |
| 57 | + │ reads migration-plan.md |
| 58 | + │ generates step-by-step migration guide with code examples |
| 59 | + │ opens a PR with the guide |
| 60 | +``` |
| 61 | + |
| 62 | +## Steps |
| 63 | + |
| 64 | +1. **Edit the secrets** — replace placeholders in `credentials-secret.yaml` |
| 65 | + and `github-token-secret.yaml`. |
| 66 | + |
| 67 | +2. **Edit `workspace.yaml`** — set your API service repository URL. |
| 68 | + |
| 69 | +3. **Review `agentconfig.yaml`** — customize the agent instructions for your |
| 70 | + API format and conventions. |
| 71 | + |
| 72 | +4. **Deploy the webhook-triggered validator:** |
| 73 | + |
| 74 | +```bash |
| 75 | +kubectl apply -f credentials-secret.yaml -f github-token-secret.yaml \ |
| 76 | + -f workspace.yaml -f agentconfig.yaml -f taskspawner-webhook.yaml |
| 77 | +``` |
| 78 | + |
| 79 | +5. **Deploy the scheduled audit (optional):** |
| 80 | + |
| 81 | +```bash |
| 82 | +kubectl apply -f taskspawner-cron.yaml |
| 83 | +``` |
| 84 | + |
| 85 | +6. **Run the consumer update pipeline (when needed):** |
| 86 | + |
| 87 | +```bash |
| 88 | +kubectl apply -f pipeline.yaml |
| 89 | +``` |
| 90 | + |
| 91 | +7. **Trigger a validation** — comment `/validate-api` on any PR in the |
| 92 | + configured repository. |
| 93 | + |
| 94 | +8. **Watch spawned Tasks:** |
| 95 | + |
| 96 | +```bash |
| 97 | +kubectl get tasks -w |
| 98 | +``` |
| 99 | + |
| 100 | +9. **Cleanup:** |
| 101 | + |
| 102 | +```bash |
| 103 | +kubectl delete -f examples/12-api-contract-validation/ |
| 104 | +``` |
| 105 | + |
| 106 | +## Complementary Issues |
| 107 | + |
| 108 | +This use case works with current Kelos primitives but would benefit from |
| 109 | +proposed API extensions: |
| 110 | + |
| 111 | +| Issue | Enhancement | Benefit | |
| 112 | +|-------|-------------|---------| |
| 113 | +| #778 | `filePatterns` filter | Auto-trigger on API file changes instead of manual `/validate-api` | |
| 114 | +| #884 | Cross-repo propagation | Create migration PRs directly in consumer repos | |
| 115 | +| #842 | `readOnlyWorkspaces` | Read consumer repos without full write access | |
| 116 | +| #881 | `contextSources` | Inject previous audit results into validation prompts | |
| 117 | + |
| 118 | +## Notes |
| 119 | + |
| 120 | +- The webhook TaskSpawner uses `issue_comment` with `bodyContains` as a |
| 121 | + workaround until `filePatterns` filtering (#778) is available. |
| 122 | +- The pipeline Tasks share the same `branch` value, which serializes them |
| 123 | + automatically in addition to the explicit `dependsOn` ordering. |
| 124 | +- Adjust `maxConcurrency` on the webhook TaskSpawner based on your expected |
| 125 | + PR volume. |
0 commit comments