Files
2026-05-27 23:29:53 +01:00

82 lines
6.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Tasks — QR code batch generator
> Every checkbox MUST reflect work actually done in this change. Do not retroactively tick boxes.
## 0. Pre-flight (non-negotiable)
- [ ] 0.1 Confirm clean working tree (`git status` reports nothing) and no in-flight worktrees with uncommitted work (`git worktree list` then `git status` in 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.md` matches `find packages -maxdepth 3 -name package.json` count. Drift here means a prior change archived without regenerating the manifest.
## 1. Spec authoring
- [x] 1.1 Read `../suaveplan/packages/universal/qrcode/src/batch/batch-generator.ts` end-to-end
- [x] 1.2 Read `openspec/specs/qrcode/spec.md` (does not exist yet — capability spec authored fresh in this change)
- [x] 1.3 Read `openspec/AGENTS.md` Sections 13, 13a, 14, 14a
- [x] 1.4 Draft `proposal.md` from `openspec/templates/proposal.md`
- [x] 1.5 Fill in `## Source mapping` table — every requirement cites a line range OR appears in the "no source line" table with justification
- [x] 1.6 Draft `specs/qrcode/spec.md` from `openspec/templates/spec-delta.md`
- [x] 1.7 Every requirement in the spec delta carries a `**Verified by:**` line naming concrete `it(...)` titles
## 2. Implementation
- [ ] 2.1 Add `src/core/batch/batch-generator.ts` exporting `BatchQrCodeRequest`, `BatchQrCodeResult`, `BatchQrCodeOptions`, `BatchQrCodeSummary`, `generateBatch`, `generateBatchAsync`, `BatchQrCodeGenerator`
- [ ] 2.2 Add `src/core/batch/batch-generator.types.ts` with shared interface declarations and Zod schemas (`BatchQrCodeRequestSchema`, `BatchQrCodeOptionsSchema`)
- [ ] 2.3 Wire `QRCODE.BATCH_ABORTED` into `src/errors/qrcode-error.ts::QRCODE_CODES`; throw `QRCodeError` (never plain `Error`) from the abort path and from per-item failures
- [ ] 2.4 Concurrency limiter — clamp to `[1, 64]`; sequential default for `generateBatch`; `generateBatchAsync` honours `concurrency` strictly; both honour `AbortSignal` between items
- [ ] 2.5 OTel instrumentation: `qrcode.batch.items_total` (counter), `qrcode.batch.items_failed` (counter), `qrcode.batch.duration_ms` (histogram)
- [ ] 2.6 Inject `Clock` via constructor dependency on `BatchQrCodeGenerator`; free functions use the default real clock
- [ ] 2.7 Add `./batch` subpath to `package.json` `exports`
- [ ] 2.8 Re-export new symbols from `src/index.ts`
## 3. Tests
- [ ] 3.1 `src/core/batch/batch-generator.test.ts` — all scenarios from spec delta (in-order results, completion-order async iterable, failure isolation, concurrency clamp, `onItem`, abort, version-1-through-10 coverage)
- [ ] 3.2 `src/core/batch/batch-generator.spec-conformance.test.ts` — injectable `Clock`, Zod `BatchQrCodeRequest` rejection with structured `ZodError`, `QRCODE.BATCH_ABORTED` code emission, OTel counters/histogram asserted via in-memory `MeterProvider`
- [ ] 3.3 Property test (fast-check): for any `Array<{ value }>` of length ≤ 50 where every value fits a valid encoding, `generateBatch` SHALL return `succeeded === input.length` and `failed === 0`
- [ ] 3.4 Every `it(...)` carries `{ timeout: 5000 }` (or 30000 for genuinely async)
## 4. Documentation
- [ ] 4.1 `src/core/batch/batch-generator.md` — sibling doc, ≥200 words, basic + advanced examples (sequential, async iterable, concurrent, abort, custom clock), full API reference for every public export, implementation notes covering concurrency clamping and per-item isolation
- [ ] 4.2 README links the new co-located `.md` under `## Modules`
- [ ] 4.3 Update `CLAUDE.md` `qrcode` listing to mention "batch generation with per-item failure isolation"
## 5. Pre-archive verification (the 5-gate triple)
- [ ] 5.1 `bun run check` — Biome 0 errors / 0 warnings / 0 info
- [ ] 5.2 `bunx turbo lint typecheck test --filter=@suaveplan/qrcode` — green
- [ ] 5.3 `bunx turbo test:coverage --filter=@suaveplan/qrcode` — 100/100/100/100
- [ ] 5.4 `bun scripts/openspec-conformance.ts @suaveplan/qrcode` — exit 0, no `error` findings
- [ ] 5.5 `bunx turbo build --filter=@suaveplan/qrcode` — green
## 6. Pre-archive 7-row checklist (AGENTS.md Section 13)
- [ ] 6.1 Generics threaded; `expectTypeOf` assertions on `BatchQrCodeResult` discriminated-union narrowing
- [ ] 6.2 Zod schemas wired at every public boundary (`generateBatch`, `generateBatchAsync`, `BatchQrCodeGenerator.generate`, `.stream`)
- [ ] 6.3 Every error code in `error-codes.ts` thrown by at least one production path (`QRCODE.BATCH_ABORTED` covered by abort scenario)
- [ ] 6.4 Strict-mode behaviors tested both on and off (concurrency 1 vs > 1; failure isolation always on)
- [ ] 6.5 OTel instruments emitted from production paths and asserted with a real in-memory `MeterProvider`
- [ ] 6.6 Lifecycle dedup tested where claimed (`BatchQrCodeGenerator.generate` and `.stream` are stateless across calls — verified by parallel-call test)
- [ ] 6.7 No retroactive tick — every box above reflects work done in this change
## 7. Archive
- [ ] 7.1 Fold spec delta into `openspec/specs/qrcode/spec.md` (creates the canonical capability spec from scratch since none exists)
- [ ] 7.2 Move `openspec/changes/qrcode-batch-generator/` → `openspec/archive/<yyyy-mm-dd>-qrcode-batch-generator/`
- [ ] 7.3 Refresh `MANIFEST.md` if package set or deps changed (no change expected — purely additive feature)
---
## Audit Note (2026-05-02)
**Status**: DEFERRED.
State at audit:
- `@suaveplan/qrcode` package itself is shipped and green, but the batch-generator feature has **not** been authored. No `src/core/batch/` directory exists. The current `src/core/` only contains `encoder/`, `mask/`, `matrix/`, `reed-solomon/`, `renderer/`, `tables/`, plus the top-level `qrcode.ts` orchestrator.
- Section 1 (spec authoring) is checked, so the proposal + spec delta exist; Sections 2–7 (implementation, tests, docs, verification, archive) are entirely unchecked.
- `QRCODE.BATCH_ABORTED` is not yet wired into `src/errors/qrcode-error.ts::QRCODE_CODES`.
Resuming work: execute Sections 2–7 in order. Reference upstream `../suaveplan/packages/universal/qrcode/src/batch/batch-generator.ts` (read in Section 1.1). Note this proposal additionally requires `generateBatchAsync` (completion-order async iterable) which the barcode equivalent does not.