2.9 KiB
2.9 KiB
Tasks: add-import-sse-progress
1. OTel — extend instruments bundle
- Add
sseConnected: Counter(import.sse.connected) toImportInstruments. - Add
sseEventsSent: Counter(import.sse.events_sent) labelled bykind. - Add
sseDisconnected: Counter(import.sse.disconnected) labelled byreason. - Update
src/otel/instruments.mdto describe the three new counters. - Extend
src/otel/instruments.test.tsto assert the new counters round-trip through a freshMeterProvider.
2. Route — GET /:id/progress
- Create
src/routes/progress-sse/progress-sse.tsexportingcreateProgressSseHandler(deps). - Wire the handler into
createImportRoutesinsrc/routes/build-routes.ts. - Subscribe to
service.bus(import.progress,import.completed,import.failed) — NO polling. - Forward the request
AbortSignalto detach the listener on client disconnect. - Frame format:
id: <jobId>-<seq>,event: progress|complete|failed, JSON-stringifiedImportProgresspayload, double-newline terminator. - Initial frame: snapshot from
service.getJob(id, ownerId)so the client sees current state before the first bus tick. - Terminal events (
complete/failed) close the stream cleanly.
3. Errors
- Reuse
IMPORT.NOT_FOUNDfor foreign-owner / missing jobs (404 problem+json). - Reuse
AUTH.UNAUTHENTICATED(viarequireAuth()middleware already inbuild-routes.ts) for the 401 path. - No new error codes added.
4. Tests
src/routes/progress-sse/progress-sse.test.tscovering all eight canonical scenarios plus four coverage-completion scenarios (terminal initial state, signal pre-aborted, foreign-job filter, post-terminal abort idempotency, abort-mid-stream).- Tests use Hono's
app.request()returning aResponsewith a streamed body; assertions read viabody.getReader()and decode UTF-8. - No mocks. Real
ImportService, real Hono, real in-memoryMeterProvider.
5. Docs
src/routes/progress-sse/progress-sse.md(≥200 words, Purpose / Features / Usage Basic / Usage Advanced / API Reference / Implementation Notes).- Update
src/otel/instruments.mdFeatures list and API Reference for the three new counters.
6. Subpath export
- Add
./routes/progress-sse/progress-ssetopackage.json#exports.
7. Gates (in order)
bunx biome check src/— clean.bunx turbo lint typecheck test --filter=@suaveplan/api-plugin-import— green.bunx turbo test:coverage --filter=@suaveplan/api-plugin-import— 100/100/100/100.bun scripts/openspec-conformance.ts @suaveplan/api-plugin-import— 0 errors.bunx turbo build --filter=@suaveplan/api-plugin-import— green.
8. Archive
- Fold spec delta into
openspec/specs/api-plugin-import/spec.md. mv openspec/changes/add-import-sse-progress openspec/archive/2026-05-20-add-import-sse-progress.