5.3 KiB
5.3 KiB
Tasks — @suaveplan/api-saga
Every checkbox MUST reflect work actually done in this change.
0. Pre-flight (non-negotiable)
- 0.1 Confirm clean working tree (
git statusreports nothing) and no in-flight worktrees with uncommitted work (git worktree listthengit statusin each) - 0.2 If any worktrees exist under
.claude/worktrees/, account for each one: still-active agent, work-pending-merge, or stale-and-prune. Stale worktrees MUST be removed (git worktree remove) before opening a new one — code that has been lost twice on main is the failure mode this guards against. - 0.3 Confirm the package set in
MANIFEST.mdmatchesfind packages -maxdepth 3 -name package.jsoncount. Drift here means a prior change archived without regenerating the manifest.
1. Spec authoring
- 1.1 Read design doc §9.1 (sagas) and §9.3 (engine choice)
- 1.2 Read umbrella
openspec/changes/api-plugin-foundation/proposal.md(Stage 6 acceptance) - 1.3 Read
openspec/AGENTS.mdSections 13 and 14 - 1.4 Draft
proposal.mdfromopenspec/templates/proposal.md - 1.5 Draft
specs/api-saga/spec.mdfromopenspec/templates/spec-delta.md - 1.6 Every requirement carries a
**Verified by:**line naming concreteit(...)titles
2. Implementation
- 2.1 Scaffold
packages/api/api-saga/withpackage.json("version": "0.1.0","sideEffects": false),tsconfig.json,tsup.config.ts - 2.2
src/orchestrator/orchestrator.ts—createSagaOrchestrator(deps)factory +SagaOrchestratorclass - 2.3
src/registry/participant-registry.ts— owner + participant registration, validation of declared step → plugin → action wiring - 2.4
src/persistence/persistence.ts—SagaPersistenceinterface bound against host metadata DB; CRUD oversuaveplan_saga_instancesandsuaveplan_saga_steps - 2.5
src/recovery/recovery.ts— boot-time replay: query incomplete instances, resume each through orchestrator - 2.6
src/idempotency/idempotency.ts— per-step idempotency wrapper using@suaveplan/idempotencykeyed by{sagaId, stepName}; honour per-actionidempotency: "manual"opt-out - 2.7
src/events/events.ts— Zod schemas for every saga event payload (saga.step.requested,.completed,.failed,.compensated, plus.instance.*); typed emitter helpers - 2.8
src/compensation/compensation.ts— reverse-order compensation runner with retry up tomaxCompensationAttempts;compensation_failedterminal state - 2.9
src/tenant/cross-tenant.ts— capability check forsaga.cross-tenant; refuse step dispatch otherwise - 2.10
src/state/state-machine.ts—SagaInstanceState+SagaStepStatetransition table with invalid-transition guard - 2.11
src/instruments/instruments.ts— OTel instrument registration (span/counter/histogram/gauge per design §9.1) - 2.12
src/error-codes.ts— 10SAGA_*codes; every code thrown from at least one production path - 2.13
./testingsubpath —runSagaParticipantConformancesuite - 2.14
src/index.ts— explicit named re-exports
3. Tests
- 3.1 Unit tests per module (every
it(...){ timeout: 5000 }) - 3.2
src/orchestrator/orchestrator.spec-conformance.test.ts— runs the conformance suite against a reference participant - 3.3
src/persistence/persistence.test.ts— Postgres integration via@suaveplan/testing-integration-postgres({ timeout: 30000 }); pins recovery-after-restart - 3.4
tests/integration/cross-plugin-saga.test.ts— full two-plugin saga end-to-end with forced compensation ({ timeout: 60000 }) - 3.5 Every test imports test-runner primitives from
@suaveplan/testing/runner
4. Documentation
- 4.1 Sibling
.mdfor every implementation.ts(≥200 words, basic + advanced examples) - 4.2
README.mdat package root linking every co-located.mdunder## Modules; calls out owner-vs-participant model
5. Pre-archive verification (the 5-gate triple)
- 5.1
bun run check— Biome 0/0/0 - 5.2
bunx turbo lint typecheck test --filter=@suaveplan/api-saga— green - 5.3
bunx turbo test:coverage --filter=@suaveplan/api-saga— 100/100/100/100 - 5.4
bun scripts/openspec-conformance.ts @suaveplan/api-saga— exit 0 - 5.5
bunx turbo build --filter=@suaveplan/api-saga— green
6. Pre-archive 7-row checklist (AGENTS.md Section 13)
- 6.1 Generics threaded through
SagaOrchestrator<TInput, TOutput>;expectTypeOfassertions on every literal-type claim - 6.2 Zod schemas wired at every event-payload boundary and at the manifest-tree consumer
- 6.3 Every
SAGA_*error code thrown by at least one production path - 6.4 Strict-mode behaviour tested both on and off (idempotency manual-opt-out, cross-tenant gate)
- 6.5 OTel instruments emitted from production paths and asserted with a real in-memory
MeterProvider - 6.6 Lifecycle dedup tested: re-dispatching a completed step is a no-op; resume after restart does not double-fire
- 6.7 No retroactive tick — every box above reflects work done in this change
7. Archive
- 7.1 Fold spec delta into
openspec/specs/api-saga/spec.md - 7.2 Move
openspec/changes/api-saga/→openspec/archive/<yyyy-mm-dd>-api-saga/ - 7.3 Tick the Stage-6 row in umbrella
openspec/changes/api-plugin-foundation/tasks.md - 7.4 Refresh
MANIFEST.md