cc-codeconductor 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +18 -0
- package/README.md +319 -0
- package/dist/index.js +12741 -0
- package/package.json +51 -0
- package/policy.yml +124 -0
- package/presets/claude/CLAUDE.md +598 -0
- package/presets/claude/commands/cc/feature.md +115 -0
- package/presets/claude/commands/cc/fix.md +121 -0
- package/presets/claude/commands/cc/refactor.md +148 -0
- package/presets/claude/commands/cc/review.md +126 -0
- package/presets/claude/commands/cc/tdd-cycle.md +226 -0
- package/presets/claude/commands/cc/test-plan.md +138 -0
- package/presets/claude/settings.json +37 -0
- package/presets/claude/skills/api-versioning/SKILL.md +389 -0
- package/presets/claude/skills/django-orm/SKILL.md +455 -0
- package/presets/claude/skills/django-testing/SKILL.md +409 -0
- package/presets/claude/skills/jpa-postgres/SKILL.md +618 -0
- package/presets/claude/skills/python/SKILL.md +606 -0
- package/presets/claude/skills/python-django-stack/SKILL.md +492 -0
- package/presets/claude/skills/python-fastapi-stack/SKILL.md +457 -0
- package/presets/claude/skills/spring-boot-feature/SKILL.md +558 -0
- package/presets/claude/skills/spring-boot-kotlin/SKILL.md +400 -0
- package/presets/claude/skills/sqlalchemy/SKILL.md +466 -0
- package/presets/claude/skills/testing-strategy/SKILL.md +479 -0
- package/presets/codex/AGENTS.md +883 -0
- package/presets/codex/README.md +102 -0
- package/presets/codex/skills/api-versioning/SKILL.md +389 -0
- package/presets/codex/skills/django-orm/SKILL.md +455 -0
- package/presets/codex/skills/django-testing/SKILL.md +409 -0
- package/presets/codex/skills/jpa-postgres/SKILL.md +618 -0
- package/presets/codex/skills/python/SKILL.md +606 -0
- package/presets/codex/skills/python-django-stack/SKILL.md +492 -0
- package/presets/codex/skills/python-fastapi-stack/SKILL.md +457 -0
- package/presets/codex/skills/spring-boot-feature/SKILL.md +558 -0
- package/presets/codex/skills/spring-boot-kotlin/SKILL.md +400 -0
- package/presets/codex/skills/sqlalchemy/SKILL.md +466 -0
- package/presets/codex/skills/testing-strategy/SKILL.md +479 -0
- package/presets/opencode/README.md +191 -0
- package/presets/opencode/agents/architect.md +133 -0
- package/presets/opencode/agents/docs.md +113 -0
- package/presets/opencode/agents/implementer.md +116 -0
- package/presets/opencode/agents/orchestrator.md +248 -0
- package/presets/opencode/agents/repo-explorer.md +119 -0
- package/presets/opencode/agents/reviewer.md +130 -0
- package/presets/opencode/agents/task-coach.md +103 -0
- package/presets/opencode/agents/tester.md +269 -0
- package/presets/opencode/commands/cc-feature.md +114 -0
- package/presets/opencode/commands/cc-fix.md +123 -0
- package/presets/opencode/commands/cc-refactor.md +148 -0
- package/presets/opencode/commands/cc-review.md +141 -0
- package/presets/opencode/commands/cc-tdd-cycle.md +225 -0
- package/presets/opencode/commands/cc-test-plan.md +144 -0
- package/presets/opencode/opencode.jsonc +89 -0
- package/presets/opencode/prompts/v0.1.0/architect.md +213 -0
- package/presets/opencode/prompts/v0.1.0/docs.md +181 -0
- package/presets/opencode/prompts/v0.1.0/implementer.md +154 -0
- package/presets/opencode/prompts/v0.1.0/orchestrator.md +169 -0
- package/presets/opencode/prompts/v0.1.0/repo-explorer.md +102 -0
- package/presets/opencode/prompts/v0.1.0/reviewer.md +183 -0
- package/presets/opencode/prompts/v0.1.0/task-coach.md +142 -0
- package/presets/opencode/prompts/v0.1.0/tester.md +160 -0
- package/presets/opencode/prompts/v0.2.0/architect.md +219 -0
- package/presets/opencode/prompts/v0.2.0/docs.md +187 -0
- package/presets/opencode/prompts/v0.2.0/implementer.md +160 -0
- package/presets/opencode/prompts/v0.2.0/orchestrator.md +238 -0
- package/presets/opencode/prompts/v0.2.0/repo-explorer.md +108 -0
- package/presets/opencode/prompts/v0.2.0/reviewer.md +190 -0
- package/presets/opencode/prompts/v0.2.0/task-coach.md +153 -0
- package/presets/opencode/prompts/v0.2.0/tester.md +249 -0
- package/presets/opencode/skills/api-versioning/SKILL.md +388 -0
- package/presets/opencode/skills/astro/SKILL.md +313 -0
- package/presets/opencode/skills/code-review/SKILL.md +202 -0
- package/presets/opencode/skills/django-orm/SKILL.md +455 -0
- package/presets/opencode/skills/django-testing/SKILL.md +408 -0
- package/presets/opencode/skills/django-uv/SKILL.md +400 -0
- package/presets/opencode/skills/jpa-postgres/SKILL.md +617 -0
- package/presets/opencode/skills/nextjs-typescript/SKILL.md +385 -0
- package/presets/opencode/skills/python/SKILL.md +605 -0
- package/presets/opencode/skills/python-django-stack/SKILL.md +491 -0
- package/presets/opencode/skills/python-fastapi-stack/SKILL.md +456 -0
- package/presets/opencode/skills/security/SKILL.md +376 -0
- package/presets/opencode/skills/spring-boot-feature/SKILL.md +557 -0
- package/presets/opencode/skills/spring-boot-kotlin/SKILL.md +399 -0
- package/presets/opencode/skills/spring-boot-testing-strategy/SKILL.md +470 -0
- package/presets/opencode/skills/sqlalchemy/SKILL.md +465 -0
- package/presets/opencode/skills/testing-tdd/SKILL.md +586 -0
- package/src/presets/council/council.yml +59 -0
- package/src/presets/manifests/claude.yml +23 -0
- package/src/presets/manifests/codex.yml +12 -0
- package/src/presets/manifests/opencode.yml +18 -0
- package/src/presets/models/claude.yml +37 -0
- package/src/presets/models/codex.yml +38 -0
- package/src/presets/models/opencode.yml +37 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# Codex Preset for CodeConductor
|
|
2
|
+
|
|
3
|
+
This preset adapts the CodeConductor multi-agent workflow for **OpenAI Codex
|
|
4
|
+
CLI** — the terminal-based coding agent from OpenAI.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## What's Included
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
presets/codex/
|
|
12
|
+
├── AGENTS.md # All 8 agent contracts + routing policy + hard rules
|
|
13
|
+
├── README.md # This file
|
|
14
|
+
└── skills/ # Domain-specific knowledge files (11 skills)
|
|
15
|
+
├── api-versioning/SKILL.md
|
|
16
|
+
├── django-orm/SKILL.md
|
|
17
|
+
├── django-testing/SKILL.md
|
|
18
|
+
├── jpa-postgres/SKILL.md
|
|
19
|
+
├── python/SKILL.md
|
|
20
|
+
├── python-django-stack/SKILL.md
|
|
21
|
+
├── python-fastapi-stack/SKILL.md
|
|
22
|
+
├── spring-boot-feature/SKILL.md
|
|
23
|
+
├── spring-boot-kotlin/SKILL.md
|
|
24
|
+
├── sqlalchemy/SKILL.md
|
|
25
|
+
└── testing-strategy/SKILL.md
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
### 1. Copy AGENTS.md to your project root
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
cp presets/codex/AGENTS.md /path/to/your/project/AGENTS.md
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
If your project already has an `AGENTS.md`, merge the CodeConductor sections
|
|
39
|
+
into it. Keep a single authoritative `AGENTS.md` per directory scope.
|
|
40
|
+
|
|
41
|
+
### 2. Install skills in the layout that matches your project
|
|
42
|
+
|
|
43
|
+
**Codex-only project**
|
|
44
|
+
|
|
45
|
+
Copy the preset `skills/` directory into `.codex/`, or install only the
|
|
46
|
+
subdirectories relevant to your stack if you want a minimal setup.
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
cp -r presets/codex/skills /path/to/your/project/.codex/
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**Codex + OpenCode combined project**
|
|
53
|
+
|
|
54
|
+
Do not duplicate skill files. Reuse the existing `.opencode/skills/`
|
|
55
|
+
installation and invoke skills from that path.
|
|
56
|
+
|
|
57
|
+
### 3. Follow the manual installation guide
|
|
58
|
+
|
|
59
|
+
Use
|
|
60
|
+
[docs/guides/manual-install-codex.md](../../docs/guides/manual-install-codex.md)
|
|
61
|
+
for the full installation flow, verification checklist, and first-task examples.
|
|
62
|
+
|
|
63
|
+
## How to Use
|
|
64
|
+
|
|
65
|
+
Codex does not load custom slash commands from this preset. Use these natural
|
|
66
|
+
language trigger phrases:
|
|
67
|
+
|
|
68
|
+
| Workflow | Trigger phrase |
|
|
69
|
+
| ------------ | ------------------------------------------------- |
|
|
70
|
+
| Full feature | `Run the feature workflow for: [description]` |
|
|
71
|
+
| Bug fix | `Run the fix workflow for: [description]` |
|
|
72
|
+
| Refactor | `Run the refactor workflow for: [scope]` |
|
|
73
|
+
| Code review | `Run a structured review of: [target]` |
|
|
74
|
+
| Test plan | `Create a test plan for: [scope]` |
|
|
75
|
+
| Task intake | `Help me define a Task Card for: [vague request]` |
|
|
76
|
+
| Codebase map | `Explore the codebase and produce a Repo Map` |
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## Runtime Notes
|
|
81
|
+
|
|
82
|
+
- Codex uses `AGENTS.md` plus any installed skill files under
|
|
83
|
+
`.codex/skills/*/SKILL.md` or `.opencode/skills/*/SKILL.md`.
|
|
84
|
+
- This preset does not provide separate runtime agent files or custom slash
|
|
85
|
+
commands.
|
|
86
|
+
- For `context_scope: isolated` tasks, start a new Codex session before
|
|
87
|
+
beginning the task.
|
|
88
|
+
- The workflow contract remains the same as the rest of CodeConductor: Task Card
|
|
89
|
+
first, then risk classification, routing, implementation, verification, and
|
|
90
|
+
human review.
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## Compatibility
|
|
95
|
+
|
|
96
|
+
Skills in `presets/codex/skills/` declare Codex compatibility in frontmatter and
|
|
97
|
+
are intended to work across the supported presets. At install time they live in
|
|
98
|
+
`.codex/skills/` for Codex-only projects or remain in `.opencode/skills/` for
|
|
99
|
+
combined projects.
|
|
100
|
+
|
|
101
|
+
The `AGENTS.md` and skill formats may evolve. Check current Codex documentation
|
|
102
|
+
if runtime behavior changes.
|
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: api-versioning
|
|
3
|
+
version: 1.0.0
|
|
4
|
+
name: API Versioning
|
|
5
|
+
description:
|
|
6
|
+
Provides expert knowledge for designing, implementing, and managing REST API
|
|
7
|
+
versioning strategies with deprecation workflows.
|
|
8
|
+
|
|
9
|
+
compatibility:
|
|
10
|
+
tools: [claude, codex, opencode]
|
|
11
|
+
stacks:
|
|
12
|
+
languages: [kotlin, java, typescript, python, go]
|
|
13
|
+
frameworks: [spring-boot, spring-mvc, express, fastapi]
|
|
14
|
+
|
|
15
|
+
risk:
|
|
16
|
+
level: high
|
|
17
|
+
can_execute_shell: false
|
|
18
|
+
can_modify_files: true
|
|
19
|
+
requires_network: false
|
|
20
|
+
|
|
21
|
+
inputs:
|
|
22
|
+
- source_files
|
|
23
|
+
- openapi spec files
|
|
24
|
+
- existing controller classes
|
|
25
|
+
|
|
26
|
+
outputs:
|
|
27
|
+
- versioned controller classes
|
|
28
|
+
- OpenAPI spec updates
|
|
29
|
+
- deprecation headers
|
|
30
|
+
- changelog entries
|
|
31
|
+
- contract test scaffolding
|
|
32
|
+
|
|
33
|
+
quality:
|
|
34
|
+
reviewed_by: codeconductor-core
|
|
35
|
+
version: 0.1.0
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
# API Versioning
|
|
39
|
+
|
|
40
|
+
## Versioning Strategies
|
|
41
|
+
|
|
42
|
+
### URL Path Versioning (recommended for breaking changes)
|
|
43
|
+
|
|
44
|
+
```text
|
|
45
|
+
GET /api/v1/users
|
|
46
|
+
GET /api/v2/users
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Tradeoffs:
|
|
50
|
+
|
|
51
|
+
- Explicit and visible in logs, proxies, and browser history
|
|
52
|
+
- Easy to cache at the CDN level — the URL uniquely identifies the resource
|
|
53
|
+
version
|
|
54
|
+
- Easy to route at the load balancer
|
|
55
|
+
- Results in some duplication of controller code
|
|
56
|
+
- Changing the URL violates REST HATEOAS principles, though in practice this is
|
|
57
|
+
acceptable
|
|
58
|
+
|
|
59
|
+
Use this when: you have breaking changes and need maximum visibility and
|
|
60
|
+
cacheability.
|
|
61
|
+
|
|
62
|
+
### Header Versioning
|
|
63
|
+
|
|
64
|
+
```text
|
|
65
|
+
GET /api/users
|
|
66
|
+
Accept: application/vnd.myapp+json;version=1
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Tradeoffs:
|
|
70
|
+
|
|
71
|
+
- Cleaner URLs
|
|
72
|
+
- Harder to test manually — browsers and curl require extra flags
|
|
73
|
+
- Cannot be bookmarked or linked directly
|
|
74
|
+
- CDN caching requires `Vary: Accept` header, which reduces cache hit rates
|
|
75
|
+
|
|
76
|
+
Use this when: you need clean URLs and your clients are all programmatic (no
|
|
77
|
+
browsers).
|
|
78
|
+
|
|
79
|
+
### Query Parameter Versioning (avoid)
|
|
80
|
+
|
|
81
|
+
```text
|
|
82
|
+
GET /api/users?version=1
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
This approach contaminates resource URLs with transport concerns. The version is
|
|
86
|
+
not part of the resource identity. Do not use it. The only valid exception is
|
|
87
|
+
temporary backward-compat support during a migration window.
|
|
88
|
+
|
|
89
|
+
## When to Version
|
|
90
|
+
|
|
91
|
+
Version when the change is breaking. Not every change requires a version bump.
|
|
92
|
+
|
|
93
|
+
**Breaking — requires new version:**
|
|
94
|
+
|
|
95
|
+
- Removing a field from a response
|
|
96
|
+
- Renaming a field
|
|
97
|
+
- Changing a field's type (e.g., `string` to `object`)
|
|
98
|
+
- Changing the meaning of an existing field
|
|
99
|
+
- Removing an endpoint
|
|
100
|
+
- Changing required fields in a request
|
|
101
|
+
- Changing status codes in a non-additive way
|
|
102
|
+
|
|
103
|
+
**Not breaking — no version bump needed:**
|
|
104
|
+
|
|
105
|
+
- Adding an optional field to a response
|
|
106
|
+
- Adding a new endpoint
|
|
107
|
+
- Adding an optional request parameter
|
|
108
|
+
- Deprecating a field (marking it, but still returning it)
|
|
109
|
+
- Performance improvements
|
|
110
|
+
- Bug fixes that restore documented behavior
|
|
111
|
+
|
|
112
|
+
## Deprecation Process
|
|
113
|
+
|
|
114
|
+
When a version or endpoint is being phased out, follow this process:
|
|
115
|
+
|
|
116
|
+
**Step 1: Mark in OpenAPI.**
|
|
117
|
+
|
|
118
|
+
```yaml
|
|
119
|
+
paths:
|
|
120
|
+
/api/v1/users/{id}:
|
|
121
|
+
get:
|
|
122
|
+
deprecated: true
|
|
123
|
+
description: |
|
|
124
|
+
Deprecated since 2026-05-07. Use /api/v2/users/{id} instead.
|
|
125
|
+
Sunset date: 2026-11-07.
|
|
126
|
+
summary: Get user by ID (deprecated)
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
**Step 2: Add deprecation headers to responses.**
|
|
130
|
+
|
|
131
|
+
```kotlin
|
|
132
|
+
@GetMapping("/{id}")
|
|
133
|
+
fun getUserV1(@PathVariable id: UUID, response: HttpServletResponse): ResponseEntity<UserV1Response> {
|
|
134
|
+
response.addHeader("Deprecation", "date=\"Wed, 07 May 2026 00:00:00 GMT\"")
|
|
135
|
+
response.addHeader("Sunset", "Mon, 07 Nov 2026 00:00:00 GMT")
|
|
136
|
+
response.addHeader("Link", "</api/v2/users/$id>; rel=\"successor-version\"")
|
|
137
|
+
return ResponseEntity.ok(userService.getById(id).toV1Response())
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
**Step 3: Document in CHANGELOG.**
|
|
142
|
+
|
|
143
|
+
```markdown
|
|
144
|
+
## Deprecated
|
|
145
|
+
|
|
146
|
+
- `GET /api/v1/users/{id}` — deprecated in favor of `GET /api/v2/users/{id}`.
|
|
147
|
+
Sunset: 2026-11-07.
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**Step 4: Maintain dual support.**
|
|
151
|
+
|
|
152
|
+
Keep at least two active major versions at all times. When v3 ships, v1 can be
|
|
153
|
+
removed (v2 and v3 remain active).
|
|
154
|
+
|
|
155
|
+
**Step 5: Communicate the sunset date.**
|
|
156
|
+
|
|
157
|
+
Notify consumers before the sunset date through:
|
|
158
|
+
|
|
159
|
+
- API changelog
|
|
160
|
+
- Developer portal announcements
|
|
161
|
+
- Deprecation headers (machine-readable)
|
|
162
|
+
- Direct contact if you have consumer registration data
|
|
163
|
+
|
|
164
|
+
Do not remove a version without a minimum 6-month notice period. 3 months is the
|
|
165
|
+
absolute minimum if forced.
|
|
166
|
+
|
|
167
|
+
## OpenAPI Conventions
|
|
168
|
+
|
|
169
|
+
### One file per version (simple cases)
|
|
170
|
+
|
|
171
|
+
```text
|
|
172
|
+
openapi-v1.yaml
|
|
173
|
+
openapi-v2.yaml
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Each file is self-contained and independently valid.
|
|
177
|
+
|
|
178
|
+
### Single file with version in info (evolving APIs)
|
|
179
|
+
|
|
180
|
+
```yaml
|
|
181
|
+
openapi: '3.1.0'
|
|
182
|
+
info:
|
|
183
|
+
title: Users API
|
|
184
|
+
version: '2.0.0'
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Use `$ref` to share schemas across versions without duplication.
|
|
188
|
+
|
|
189
|
+
### Cross-version schema reuse
|
|
190
|
+
|
|
191
|
+
```yaml
|
|
192
|
+
# schemas/user-base.yaml
|
|
193
|
+
UserBase:
|
|
194
|
+
type: object
|
|
195
|
+
properties:
|
|
196
|
+
id:
|
|
197
|
+
type: string
|
|
198
|
+
format: uuid
|
|
199
|
+
email:
|
|
200
|
+
type: string
|
|
201
|
+
|
|
202
|
+
# openapi-v1.yaml
|
|
203
|
+
components:
|
|
204
|
+
schemas:
|
|
205
|
+
UserResponse:
|
|
206
|
+
allOf:
|
|
207
|
+
- $ref: './schemas/user-base.yaml#/UserBase'
|
|
208
|
+
- properties:
|
|
209
|
+
full_name:
|
|
210
|
+
type: string
|
|
211
|
+
|
|
212
|
+
# openapi-v2.yaml — splits full_name into first_name + last_name
|
|
213
|
+
components:
|
|
214
|
+
schemas:
|
|
215
|
+
UserResponse:
|
|
216
|
+
allOf:
|
|
217
|
+
- $ref: './schemas/user-base.yaml#/UserBase'
|
|
218
|
+
- properties:
|
|
219
|
+
first_name:
|
|
220
|
+
type: string
|
|
221
|
+
last_name:
|
|
222
|
+
type: string
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Documenting breaking changes
|
|
226
|
+
|
|
227
|
+
Put the breaking change in the endpoint description, not just in a changelog:
|
|
228
|
+
|
|
229
|
+
```yaml
|
|
230
|
+
/api/v2/users/{id}:
|
|
231
|
+
get:
|
|
232
|
+
description: |
|
|
233
|
+
Returns user details.
|
|
234
|
+
|
|
235
|
+
Breaking changes from v1:
|
|
236
|
+
- `full_name` has been replaced by `first_name` and `last_name`
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## Spring Boot Implementation
|
|
240
|
+
|
|
241
|
+
### URL path versioning
|
|
242
|
+
|
|
243
|
+
```kotlin
|
|
244
|
+
// V1 controller — never modify once published
|
|
245
|
+
@RestController
|
|
246
|
+
@RequestMapping("/api/v1/users")
|
|
247
|
+
class UserV1Controller(private val userService: UserService) {
|
|
248
|
+
|
|
249
|
+
@GetMapping("/{id}")
|
|
250
|
+
@Deprecated("Use /api/v2/users/{id}", ReplaceWith("UserV2Controller.getUser()"))
|
|
251
|
+
fun getUser(
|
|
252
|
+
@PathVariable id: UUID,
|
|
253
|
+
response: HttpServletResponse
|
|
254
|
+
): ResponseEntity<UserV1Response> {
|
|
255
|
+
response.addHeader("Deprecation", "date=\"Wed, 07 May 2026 00:00:00 GMT\"")
|
|
256
|
+
response.addHeader("Sunset", "Mon, 07 Nov 2026 00:00:00 GMT")
|
|
257
|
+
return when (val result = userService.getById(id)) {
|
|
258
|
+
is UserResult.Found -> ResponseEntity.ok(result.user.toV1Response())
|
|
259
|
+
is UserResult.NotFound -> ResponseEntity.notFound().build()
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// V2 controller — new version, new controller, shared service
|
|
265
|
+
@RestController
|
|
266
|
+
@RequestMapping("/api/v2/users")
|
|
267
|
+
class UserV2Controller(private val userService: UserService) {
|
|
268
|
+
|
|
269
|
+
@GetMapping("/{id}")
|
|
270
|
+
fun getUser(@PathVariable id: UUID): ResponseEntity<UserV2Response> {
|
|
271
|
+
return when (val result = userService.getById(id)) {
|
|
272
|
+
is UserResult.Found -> ResponseEntity.ok(result.user.toV2Response())
|
|
273
|
+
is UserResult.NotFound -> ResponseEntity.notFound().build()
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
Rules:
|
|
280
|
+
|
|
281
|
+
- Create a new controller for each new version — do not modify the existing one
|
|
282
|
+
- The service layer is shared across versions — only the controller and DTO
|
|
283
|
+
change
|
|
284
|
+
- DTO mapper functions are version-specific: `toV1Response()`, `toV2Response()`
|
|
285
|
+
- Never delete a versioned controller until after the sunset date
|
|
286
|
+
|
|
287
|
+
### DTO versioning
|
|
288
|
+
|
|
289
|
+
```kotlin
|
|
290
|
+
// V1 — original shape
|
|
291
|
+
data class UserV1Response(
|
|
292
|
+
val id: UUID,
|
|
293
|
+
val email: String,
|
|
294
|
+
val full_name: String
|
|
295
|
+
)
|
|
296
|
+
|
|
297
|
+
// V2 — breaking change: split full_name
|
|
298
|
+
data class UserV2Response(
|
|
299
|
+
val id: UUID,
|
|
300
|
+
val email: String,
|
|
301
|
+
val first_name: String,
|
|
302
|
+
val last_name: String
|
|
303
|
+
)
|
|
304
|
+
|
|
305
|
+
// Extension functions for mapping
|
|
306
|
+
fun User.toV1Response(): UserV1Response = UserV1Response(
|
|
307
|
+
id = id,
|
|
308
|
+
email = email,
|
|
309
|
+
full_name = "$firstName $lastName"
|
|
310
|
+
)
|
|
311
|
+
|
|
312
|
+
fun User.toV2Response(): UserV2Response = UserV2Response(
|
|
313
|
+
id = id,
|
|
314
|
+
email = email,
|
|
315
|
+
first_name = firstName,
|
|
316
|
+
last_name = lastName
|
|
317
|
+
)
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
## Contract Testing
|
|
321
|
+
|
|
322
|
+
Contract tests verify that your API does not break existing consumers before
|
|
323
|
+
changes reach production.
|
|
324
|
+
|
|
325
|
+
**When to run:** in CI, before merging any change that touches a controller,
|
|
326
|
+
DTO, or OpenAPI spec.
|
|
327
|
+
|
|
328
|
+
**Tool: Pact (consumer-driven contracts)**
|
|
329
|
+
|
|
330
|
+
Consumer writes a pact:
|
|
331
|
+
|
|
332
|
+
```kotlin
|
|
333
|
+
// In the consumer service test
|
|
334
|
+
@ExtendWith(PactConsumerTestExt::class)
|
|
335
|
+
class UserServiceConsumerTest {
|
|
336
|
+
|
|
337
|
+
@Pact(consumer = "order-service", provider = "user-service")
|
|
338
|
+
fun getUserPact(builder: PactDslWithProvider): RequestResponsePact {
|
|
339
|
+
return builder
|
|
340
|
+
.given("user with id exists")
|
|
341
|
+
.uponReceiving("a request for user by id")
|
|
342
|
+
.path("/api/v1/users/123e4567-e89b-12d3-a456-426614174000")
|
|
343
|
+
.method("GET")
|
|
344
|
+
.willRespondWith()
|
|
345
|
+
.status(200)
|
|
346
|
+
.body(LambdaDsl.newJsonBody { body ->
|
|
347
|
+
body.uuid("id")
|
|
348
|
+
body.stringType("email")
|
|
349
|
+
body.stringType("full_name")
|
|
350
|
+
}.build())
|
|
351
|
+
.toPact()
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
Provider verifies the pact:
|
|
357
|
+
|
|
358
|
+
```kotlin
|
|
359
|
+
@Provider("user-service")
|
|
360
|
+
@PactFolder("pacts")
|
|
361
|
+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
|
362
|
+
class UserServiceProviderTest {
|
|
363
|
+
|
|
364
|
+
@TestTarget
|
|
365
|
+
lateinit var target: HttpTestTarget
|
|
366
|
+
|
|
367
|
+
@BeforeEach
|
|
368
|
+
fun setUp(@LocalServerPort port: Int) {
|
|
369
|
+
target = HttpTestTarget("localhost", port)
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
**Rule:** run contract tests in CI before any merge that touches an API surface.
|
|
375
|
+
A broken contract test means a consumer will break in production.
|
|
376
|
+
|
|
377
|
+
## Test Structure Per Version
|
|
378
|
+
|
|
379
|
+
Each API version must have its own test class:
|
|
380
|
+
|
|
381
|
+
```text
|
|
382
|
+
src/test/kotlin/{package}/user/
|
|
383
|
+
controller/
|
|
384
|
+
UserV1ControllerTest.kt # tests for v1 endpoints
|
|
385
|
+
UserV2ControllerTest.kt # tests for v2 endpoints
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
Do not share test cases across versions. V1 behavior must be tested
|
|
389
|
+
independently from V2 — they can diverge.
|