Initial Commit
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
# OpenSpec Change: mime-spec-conformance
|
||||
|
||||
- **Change ID**: mime-spec-conformance
|
||||
- **Package**: `@suaveplan/mime`
|
||||
- **Status**: PROPOSED
|
||||
- **Date**: 2026-04-26
|
||||
|
||||
## Summary
|
||||
|
||||
Add `**Verified by:**` lines to every requirement in `openspec/specs/mime/spec.md`, fix two pieces of real implementation drift inline (MIME-07: `registerMimeEntry` did not validate against `MimeEntrySchema`; MIME-12 / MIME-16: `detect` did not validate against `DetectInputSchema`), pin both fixes plus the MIME-20 benchmark layout with `src/db/db.spec-conformance.test.ts`, and annotate the schemas that describe wire-only / cross-process shapes with `// schema: boundary-only`.
|
||||
|
||||
## Current state
|
||||
|
||||
`@suaveplan/mime` ships magic-byte detection, RFC 7231 Content-Type parsing/serialisation, the BUILTIN_DB registry, BOM/HTML/XML charset sniffers, the `detect()` orchestrator, the legacy `getMimeType` shim, OTel meter helpers, structured errors, and Zod schemas. 21 requirements, ~317 tests, 100% coverage. Three gaps blocked conformance:
|
||||
|
||||
1. `registerMimeEntry` accepted any object — spec said it MUST validate against `MimeEntrySchema` and throw `ParseError`.
|
||||
2. `detect` had no schema invocation — spec said it MUST use `DetectInputSchema` for boundary validation.
|
||||
3. No requirement carried a `**Verified by:**` annotation.
|
||||
|
||||
The `// schema: boundary-only` warns for the result schemas (`MagicBytesResultSchema`, `ExtensionDetectionResultSchema`, etc.) and the wire-form `SignatureSchema` are by-design — those schemas describe cross-process serialisation shapes and are exported for downstream consumers.
|
||||
|
||||
## What changes
|
||||
|
||||
1. Wire `MimeEntrySchema.safeParse` into `registerMimeEntry` and throw `ParseError` on failure.
|
||||
2. Wire `DetectInputSchema.safeParse` into `detect` and throw `ParseError` on failure (preserving the existing "empty input returns octet-stream default" behaviour by treating the at-least-one-source refinement as non-fatal).
|
||||
3. Add `// schema: boundary-only` annotations to the wire-only result schemas.
|
||||
4. Annotate every requirement (MIME-01 through MIME-21) in the folded spec with a `**Verified by:**` line.
|
||||
5. Add `src/db/db.spec-conformance.test.ts` covering MIME-07 (ParseError on invalid entry shape), MIME-12/16 (ParseError on invalid `DetectInput.extension`), and MIME-20 (benchmark file existence).
|
||||
6. `bun scripts/openspec-conformance.ts @suaveplan/mime` reports zero errors. Schema-at-boundaries warns remain by design (annotated).
|
||||
|
||||
## Impact
|
||||
|
||||
- `registerMimeEntry` now throws `ParseError` on malformed input (was silently accepted).
|
||||
- `detect` now throws `ParseError` on type-mismatched inputs (was silently coerced).
|
||||
- One new test file (~50 lines).
|
||||
- `openspec/specs/mime/spec.md` gains 21 `**Verified by:**` blocks.
|
||||
- Coverage stays 100/100/100/100.
|
||||
@@ -0,0 +1,44 @@
|
||||
# Capability Spec Delta: mime (spec-conformance)
|
||||
|
||||
**Package**: `@suaveplan/mime`
|
||||
**Status**: PROPOSED
|
||||
|
||||
This delta annotates each existing requirement in `openspec/specs/mime/spec.md` with a `**Verified by:**` line and rectifies two pieces of implementation drift (MIME-07 and MIME-12 / MIME-16 schema invocation). No requirement semantics change.
|
||||
|
||||
## MODIFIED Requirements
|
||||
|
||||
(See `openspec/specs/mime/spec.md` for the full requirement bodies.)
|
||||
|
||||
| Requirement | Verified by |
|
||||
|---|---|
|
||||
| MIME-01 Magic-byte detection via compiled trie | `src/detection/detection.magic.test.ts` |
|
||||
| MIME-02 All-matches magic-byte detection | `src/detection/detection.magic.test.ts` |
|
||||
| MIME-03 RFC 7231 Content-Type parsing | `src/content-type/content-type.test.ts` |
|
||||
| MIME-04 Content-Type round-trip serialisation | `src/content-type/content-type.test.ts` (incl. property-based) |
|
||||
| MIME-05 Content-Type equality and matching | `src/content-type/content-type.test.ts` |
|
||||
| MIME-06 Curated IANA-sourced registry | `src/db/db.test.ts` |
|
||||
| MIME-07 Runtime registry extension | `src/db/db.test.ts` AND `src/db/db.spec-conformance.test.ts` |
|
||||
| MIME-08 Reverse lookups | `src/reverse/reverse.test.ts` |
|
||||
| MIME-09 BOM charset sniffing | `src/charset/charset.test.ts` |
|
||||
| MIME-10 HTML meta charset sniffing | `src/charset/charset.test.ts` |
|
||||
| MIME-11 XML declaration charset sniffing | `src/charset/charset.test.ts` |
|
||||
| MIME-12 Unified detect() | `src/detection/detection.extension-contenttype.test.ts` AND `src/db/db.spec-conformance.test.ts` |
|
||||
| MIME-13 detectFromStream() interim shim | `src/detection/stream.test.ts` |
|
||||
| MIME-14 Signature registry extension | `src/detection/from-magic-bytes/registry.test.ts` AND signature-pack tests |
|
||||
| MIME-15 Structured errors | `src/error-codes.test.ts` AND `src/errors/errors.test.ts` |
|
||||
| MIME-16 Zod schemas | `src/schemas/mime.schemas.test.ts` AND `src/db/db.spec-conformance.test.ts` |
|
||||
| MIME-17 OTel instrumentation | `src/telemetry/meters.test.ts` |
|
||||
| MIME-18 Legacy shim | `src/legacy/legacy.test.ts` |
|
||||
| MIME-19 Property-based tests | `src/content-type/content-type.test.ts` (round-trip property) AND `src/detection/detection.magic.test.ts::"always returns MagicBytesResult or undefined — never throws"` AND `src/db/db.test.ts::"every registered entry is retrievable by mime"` |
|
||||
| MIME-20 Benchmarks | `src/db/db.spec-conformance.test.ts::"src/__benchmarks__/ exists with the documented bench suites"` |
|
||||
| MIME-21 sideEffects: false + 100% coverage | `tests/tree-shake.test.ts` AND `tests/no-disallowed.test.ts` AND coverage gate |
|
||||
|
||||
## Newly added tests in this change
|
||||
|
||||
- `src/db/db.spec-conformance.test.ts` — pins `registerMimeEntry` ParseError on invalid shape (MIME-07), `detect` ParseError on invalid input field types (MIME-12 / MIME-16), and `__benchmarks__/mime.bench.ts` existence (MIME-20).
|
||||
|
||||
## Drift fixed inline
|
||||
|
||||
- `src/db/registry.ts::registerMimeEntry` now invokes `MimeEntrySchema.safeParse` and throws `ParseError` on failure.
|
||||
- `src/detection/detect.ts::detect` now invokes `DetectInputSchema.safeParse` and throws `ParseError` on field-type mismatches; the at-least-one-source refinement is treated as non-fatal so the documented `detect({})` → `application/octet-stream` default is preserved.
|
||||
- `SignatureSchema`, `MagicBytesResultSchema`, `ExtensionDetectionResultSchema`, `ContentTypeDetectionResultSchema`, `StreamDetectionResultSchema`, and `DetectResultSchema` carry `// schema: boundary-only` markers — they describe cross-process serialisation shapes, not runtime arguments.
|
||||
10
openspec/archive/2026-04-29-mime-spec-conformance/tasks.md
Normal file
10
openspec/archive/2026-04-29-mime-spec-conformance/tasks.md
Normal file
@@ -0,0 +1,10 @@
|
||||
# Tasks — mime-spec-conformance
|
||||
|
||||
- [x] Wire `MimeEntrySchema.safeParse` into `registerMimeEntry`; throw `ParseError` on failure.
|
||||
- [x] Wire `DetectInputSchema.safeParse` into `detect`; throw `ParseError` on type-mismatched inputs (allow empty-input default per existing behaviour).
|
||||
- [x] Add `// schema: boundary-only` annotations to wire-only result schemas.
|
||||
- [x] Add `**Verified by:**` line under every `MIME-NN` requirement in `openspec/specs/mime/spec.md`.
|
||||
- [x] Add `src/db/db.spec-conformance.test.ts` covering MIME-07 / MIME-12 / MIME-16 / MIME-20.
|
||||
- [x] Confirm `bun scripts/openspec-conformance.ts @suaveplan/mime` reports zero errors.
|
||||
- [x] Confirm `bunx turbo lint typecheck test --filter=@suaveplan/mime` is green.
|
||||
- [x] Confirm `bunx turbo test:coverage --filter=@suaveplan/mime` reports 100/100/100/100.
|
||||
Reference in New Issue
Block a user