Initial Commit

This commit is contained in:
2026-05-27 23:29:53 +01:00
commit fbc70f96e6
10000 changed files with 1102152 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
# Tasks: serialize-spec-conformance
## 1. New tests pinning implicit scenarios
- [x] 1.1 Add `src/codec/json/json-encode.spec-conformance.test.ts` covering SZ-02 typed-array round-trip (`Int8Array`/`Int16Array`/`Int32Array`/`Uint16Array`/`Uint32Array`/`Float32Array`/`Float64Array`) and SZ-03 envelope-shape contract for `Date`.
- [x] 1.2 Add `src/codec/msgpack/msgpack-encode.spec-conformance.test.ts` covering SZ-06 byte-identical output for the same structured input across two encode calls.
## 2. Spec annotations
- [x] 2.1 Add `**Verified by:**` line under every `### SZ-NN —` block in `openspec/specs/serialization/spec.md` (12 requirements).
## 3. Close in scope: SZ-10 wire-format + options validation
- [x] 3.1 Add `src/codec/wire/wire.schemas.ts` with `WireNodeSchema`, `TaggedEnvelopeSchema`, and `validateWireNode` covering tagged-envelope and recursive plain-record shapes. Include strict envelope rejection (extra keys, non-string `__t`).
- [x] 3.2 Tighten `src/codec/json/json.schemas.ts` to `.strict()` and add `signal` field validation (duck-typed `AbortSignal`).
- [x] 3.3 Wire `SerializeOptionsSchema` / `DeserializeOptionsSchema` `.safeParse` into the public `serialize` / `deserialize` / `encodeBinary` / `decodeBinary` entry points; on rejection throw `InvalidOptionsError` (new code `SERIALIZE.OPTIONS.INVALID`).
- [x] 3.4 Wire `validateWireNode` into the public `deserialize` and `decodeBinary` entry points; on rejection throw `MalformedWireError` (new code `SERIALIZE.CODEC.MALFORMED_WIRE`). Preserve `__proto__` round-trip by re-using the original parsed value when validation passes.
- [x] 3.5 Add `MalformedWireError` and `InvalidOptionsError` to `src/errors/serialize-error.ts`; register codes via `defineCodes`; export from `src/index.ts`.
- [x] 3.6 Add `src/codec/wire/wire.schemas.test.ts` pinning rejection of malformed JSON / msgpack inputs, invalid options, and the schema acceptance set. Add `__proto__` regression coverage.
## 4. Close in scope: SZ-11 OTel instrumentation
- [x] 4.1 Add `src/observability/metrics.ts` exporting `getSerializeMetrics()` and `resetSerializeMetrics()` with the lazy `metrics.getMeter('suaveplan.serialize')` singleton pattern from `@suaveplan/i18n` / `@suaveplan/logger`.
- [x] 4.2 Wire histograms (`serialize.encode.bytes`, `serialize.decode.bytes`, `serialize.payload_bytes`, `serialize.encode.duration_ms`, `serialize.decode.duration_ms`) and counter (`serialize.error.total` with `code` + `format` labels) into all four public entry points.
- [x] 4.3 Add `src/observability/metrics.test.ts` using a real in-memory `MeterProvider` implementation (conforming class hierarchy, not `vi.mock`) that records all instrument creation + measurement calls.
## 5. Close in scope: generic threading on public deserialize entry points
- [x] 5.1 Thread `<T = unknown>` through `deserialize`, `decodeBinary`, `legacyDeserialize`, and `deserializeEvalSafe`. Type-only change; runtime unchanged.
- [x] 5.2 Add `expectTypeOf` assertions to `wire.schemas.test.ts`, `legacy.test.ts`, and `eval-safe.test.ts`.
## 6. Verify
- [x] 6.1 `bunx turbo lint typecheck test --filter=@suaveplan/serialize` green.
- [x] 6.2 `bunx turbo test:coverage --filter=@suaveplan/serialize` 100/100/100/100.
- [x] 6.3 `bun scripts/openspec-conformance.ts @suaveplan/serialize` exits 0.