|
| 1 | +# CDK package — agent context |
| 2 | + |
| 3 | +Parent guide: [../AGENTS.md](../AGENTS.md) |
| 4 | + |
| 5 | +You are an **ABCA platform engineer** for the `@abca/cdk` package: Lambda handlers, orchestration, CDK stacks/constructs, IAM, and shared API types. |
| 6 | + |
| 7 | +## Commands (run these) |
| 8 | + |
| 9 | +```bash |
| 10 | +mise //cdk:compile # TypeScript compile |
| 11 | +mise //cdk:test # Jest unit tests |
| 12 | +mise //cdk:synth # synth to cdk/cdk.out/ |
| 13 | +mise //cdk:eslint # ESLint --fix (run after merging main) |
| 14 | +mise //cdk:deploy # deploy stack (requires AWS creds) |
| 15 | +mise //cdk:diff # diff vs deployed |
| 16 | +mise //cdk:destroy # destroy stack |
| 17 | +``` |
| 18 | + |
| 19 | +## Testing |
| 20 | + |
| 21 | +- **Full suite:** `mise //cdk:test` |
| 22 | +- **Single file:** `cd cdk && npx jest test/handlers/shared/validation.test.ts` |
| 23 | +- **Pattern:** `cd cdk && npx jest --testPathPattern=orchestrate-task` |
| 24 | + |
| 25 | +**Extend tests when you change:** |
| 26 | + |
| 27 | +| Code | Test location | |
| 28 | +|------|---------------| |
| 29 | +| Shared handler logic | `cdk/test/handlers/shared/*.test.ts` | |
| 30 | +| Handler entrypoints | `cdk/test/handlers/orchestrate-task.test.ts`, `create-task.test.ts`, `webhook-create-task.test.ts` | |
| 31 | +| Constructs | `cdk/test/constructs/task-orchestrator.test.ts`, `task-api.test.ts` | |
| 32 | + |
| 33 | +Construct tests: synthesize each distinct stack config once in `beforeAll`, assert against cached `Template` — do not re-synth per test. Bundling is disabled globally via `test/setup/disable-bundling.ts` (see Common mistakes). |
| 34 | + |
| 35 | +## Primary locations |
| 36 | + |
| 37 | +| Path | Access | Purpose | |
| 38 | +|------|--------|---------| |
| 39 | +| `cdk/src/handlers/` | WRITE | Lambda handlers | |
| 40 | +| `cdk/src/stacks/` | WRITE | Stack definitions | |
| 41 | +| `cdk/src/constructs/` | WRITE | Reusable constructs | |
| 42 | +| `cdk/src/handlers/shared/types.ts` | WRITE | API types (mirror to `cli/src/types.ts`) | |
| 43 | +| `cdk/test/` | WRITE | Unit / snapshot tests | |
| 44 | +| `cli/src/types.ts` | WRITE (sync) | Must match shared types | |
| 45 | + |
| 46 | +## Code style |
| 47 | + |
| 48 | +**API responses** — use `successResponse` / `errorResponse` from `shared/response.ts`; never hand-roll JSON envelopes: |
| 49 | + |
| 50 | +```typescript |
| 51 | +// ✅ Good — contract envelope + typed ErrorCode |
| 52 | +import { successResponse, errorResponse, ErrorCode } from '../shared/response'; |
| 53 | + |
| 54 | +return successResponse(200, { task_id: taskId }, requestId); |
| 55 | +return errorResponse(422, ErrorCode.VALIDATION_ERROR, 'Invalid workflow_ref', requestId); |
| 56 | + |
| 57 | +// ❌ Bad — ad-hoc body, no request ID |
| 58 | +return { statusCode: 400, body: JSON.stringify({ error: 'bad' }) }; |
| 59 | +``` |
| 60 | + |
| 61 | +**Unit tests** — colocate under `cdk/test/`, descriptive `describe`/`test` names: |
| 62 | + |
| 63 | +```typescript |
| 64 | +// ✅ Good |
| 65 | +describe('parseBody', () => { |
| 66 | + test('returns null for invalid JSON', () => { |
| 67 | + expect(parseBody('not json')).toBeNull(); |
| 68 | + }); |
| 69 | +}); |
| 70 | + |
| 71 | +// ❌ Bad — vague name, no edge cases |
| 72 | +test('works', () => { expect(parseBody('{}')).toBeTruthy(); }); |
| 73 | +``` |
| 74 | + |
| 75 | +**Construct tests** — cache synth output: |
| 76 | + |
| 77 | +```typescript |
| 78 | +// ✅ Good |
| 79 | +let template: Template; |
| 80 | +beforeAll(() => { |
| 81 | + const app = new App(); |
| 82 | + template = Template.fromStack(new MyStack(app, 'Test')); |
| 83 | +}); |
| 84 | +``` |
| 85 | + |
| 86 | +## Boundaries |
| 87 | + |
| 88 | +- ✅ **Always:** Update `cli/src/types.ts` when changing `shared/types.ts`; add/extend tests in `cdk/test/`; use mise tasks not raw `cdk` CLI |
| 89 | +- ⚠️ **Ask first:** New stacks or constructs, IAM policy changes, DynamoDB schema changes, enabling Lambda bundling in unit tests |
| 90 | +- 🚫 **Never:** Bump `@cedar-policy/cedar-wasm` without bumping `cedarpy` and refreshing `contracts/cedar-parity/` fixtures; re-enable global Lambda bundling in tests; use constructor `context` for `aws:cdk:bundling-stacks` (use `postCliContext` instead — see #366) |
| 91 | + |
| 92 | +## Common mistakes |
| 93 | + |
| 94 | +- **Lambda bundling in unit tests** — `Template.fromStack()` synths the stack but bundling is disabled via `CDK_CONTEXT_JSON`. Do not re-enable globally; opt in per-test with `postCliContext` only when asserting on bundle output. Details: `test/setup/disable-bundling.ts`, #366. |
| 95 | +- **Cedar engine drift** — `@cedar-policy/cedar-wasm` and `cedarpy` share a Rust core. Bump both + parity fixtures in one commit. See `docs/design/CEDAR_HITL_GATES.md` §15.6 and `mise.toml` parity banner. |
| 96 | +- **Types out of sync** — `cdk/src/handlers/shared/types.ts` and `cli/src/types.ts` must match; CI runs `check-types-sync`. |
0 commit comments