Initial Commit
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
# OpenSpec Change: network-plugin-registry
|
||||
|
||||
- **Change ID**: network-plugin-registry
|
||||
- **Package**: `@suaveplan/network-plugin-registry` (new)
|
||||
- **Status**: PROPOSED
|
||||
- **Type**: new-package
|
||||
- **Date**: 2026-04-29
|
||||
|
||||
## Why
|
||||
|
||||
The tiered network requires a small, fixed-size registry of group peers. The genesis `bitpacker` package provides the binary serialization needed for compact messages (62 bytes vs ~200 bytes JSON). The genesis `storage` package provides the KV backing. This plugin provides the registry operations: `add`, `remove`, `get`, `list`, plus `BinaryMessageEncoder` for compact wire format. It is the authoritative replacement for the suaveplan `network-registry` package.
|
||||
|
||||
## What changes
|
||||
|
||||
- **ADDED**: `RegistryPlugin` class implementing `NetworkPlugin`.
|
||||
- **ADDED**: `Registry` — CRUD on a fixed-capacity in-memory registry.
|
||||
- **ADDED**: `BinaryMessageEncoder` — packs `DynamicData` into bit-packed binary using `@suaveplan/bitpacker`.
|
||||
- **ADDED**: `RegistryMessage` — union type for `add`, `remove`, `get`, `list` operations.
|
||||
- **ADDED**: `RegistrySyncManager` — periodically syncs registry state to `NetworkBus`.
|
||||
- **ADDED**: `NETWORK_REG_CODES` — frozen error registry.
|
||||
|
||||
## Out of scope
|
||||
|
||||
- Distributed consensus for registry consistency → groups are small; eventual consistency via bus is sufficient.
|
||||
- Persistent registry storage → future `network-plugin-registry-persistence` using `@suaveplan/storage`.
|
||||
- Cross-group registry federation → future scope.
|
||||
|
||||
## Source mapping
|
||||
|
||||
This change derives from `../suaveplan/enterprise/network-registry.md` and `../suaveplan/packages/universal/network-registry/`.
|
||||
|
||||
| Requirement | Source lines | Notes |
|
||||
|---|---|---|
|
||||
| Fixed-capacity registry (32 peers) | `network-registry/README.md` §Registry | verbatim |
|
||||
| `add`, `remove`, `get`, `list` | `network-registry/README.md` §Registry | verbatim |
|
||||
| Binary message encoder (62 bytes) | `network-registry/README.md` §Binary Message Encoder | verbatim; uses `@suaveplan/bitpacker` |
|
||||
| `registry:update` bus event | `network-registry/README.md` §Registry | reworded; emits on `NetworkBus` |
|
||||
|
||||
### Requirements with no source line
|
||||
|
||||
| Requirement | Justification |
|
||||
|---|---|
|
||||
| `RegistrySyncManager` with periodic sync | Defensive — ensures registry converges after partition |
|
||||
| `NETWORK_REG_CODES` | Required by spec-conformance for every enterprise package |
|
||||
|
||||
## Verification approach
|
||||
|
||||
- `src/registry/registry.spec-conformance.test.ts` — pins add/remove/get/list, capacity limit.
|
||||
- `src/encoder/encoder.spec-conformance.test.ts` — pins binary format, roundtrip, size ≤ 62 bytes.
|
||||
- `src/sync/sync.spec-conformance.test.ts` — pins periodic sync, deduplication.
|
||||
- `tests/dep-graph.test.ts` — pins direct import of `@suaveplan/bitpacker`.
|
||||
|
||||
## Migration impact
|
||||
|
||||
None — additive only.
|
||||
@@ -0,0 +1,77 @@
|
||||
# Tasks — network-plugin-registry
|
||||
|
||||
> Blocked on: `network-core`.
|
||||
|
||||
## 1. Scaffold
|
||||
|
||||
- [x] 1.1 `packages/network/network-plugin-registry/` with `package.json` (`@suaveplan/network-plugin-registry@0.0.0`), `tsconfig.json`, `vitest.config.ts`, `README.md`.
|
||||
- [x] 1.2 Workspace deps: `@suaveplan/network`, `@suaveplan/error`, `@suaveplan/types`, `@suaveplan/events`, `@suaveplan/bitpacker`, `@suaveplan/storage`, `@suaveplan/timing`, `@opentelemetry/api`, `zod`.
|
||||
- [x] 1.3 `sideEffects: false`.
|
||||
|
||||
## 2. Types
|
||||
|
||||
- [x] 2.1 `src/types/registry.types.ts` — `RegistryEntry`, `RegistryConfig`, `RegistryMessage`.
|
||||
- [x] 2.2 `src/types/encoder.types.ts` — `DynamicData`, `EncodedMessage`.
|
||||
- [x] 2.3 `src/error-codes.ts` — `defineCodes("NET_REG", [...])`.
|
||||
|
||||
## 3. Registry
|
||||
|
||||
- [x] 3.1 `src/registry/registry.ts` — `Registry` with fixed capacity (default 32).
|
||||
- [x] 3.2 `add(entry)`, `remove(peerId)`, `get(peerId)`, `list()`.
|
||||
- [x] 3.3 `RegistryCapacityExceededError` when capacity reached.
|
||||
- [x] 3.4 Emits `registry:update` on `NetworkBus`.
|
||||
|
||||
## 4. Binary message encoder
|
||||
|
||||
- [x] 4.1 `src/encoder/binary-message-encoder.ts` — `BinaryMessageEncoder`.
|
||||
- [x] 4.2 Packs `DynamicData` into `BitPacker` format.
|
||||
- [x] 4.3 Target ≤ 62 bytes per message.
|
||||
- [x] 4.4 Roundtrip encoding/decoding with `BinaryMessageDecoder`.
|
||||
|
||||
## 5. Sync manager
|
||||
|
||||
- [x] 5.1 `src/sync/registry-sync-manager.ts` — `RegistrySyncManager`.
|
||||
- [x] 5.2 Periodic full sync on `NetworkBus`.
|
||||
- [x] 5.3 Deduplication by hash.
|
||||
|
||||
## 6. Plugin wrapper
|
||||
|
||||
- [x] 6.1 `src/plugin/registry-plugin.ts` — `RegistryPlugin` implements `NetworkPlugin`.
|
||||
- [x] 6.2 Installs registry, encoder, sync manager on `install()`.
|
||||
|
||||
## 7. Spec
|
||||
|
||||
- [x] 7.1 Update `openspec/specs/network/spec.md` with `NET-12`, `NET-13`.
|
||||
|
||||
## 8. Conformance tests
|
||||
|
||||
- [x] 8.1 `src/registry/registry.spec-conformance.test.ts` — add/remove/get/list, capacity limit.
|
||||
- [x] 8.2 `src/encoder/encoder.spec-conformance.test.ts` — binary format, roundtrip, size ≤ 62 bytes.
|
||||
- [x] 8.3 `src/sync/sync.spec-conformance.test.ts` — periodic sync, deduplication.
|
||||
- [x] 8.4 `src/error-codes.spec-conformance.test.ts` — frozen registry.
|
||||
|
||||
## 9. Verify
|
||||
|
||||
- [x] 9.1 `bunx turbo lint typecheck test --filter=@suaveplan/network-plugin-registry` green.
|
||||
- [x] 9.2 `bunx turbo test:coverage --filter=@suaveplan/network-plugin-registry` 100/100/100/100.
|
||||
- [x] 9.3 `bun scripts/openspec-conformance.ts @suaveplan/network-plugin-registry` PASS.
|
||||
|
||||
---
|
||||
|
||||
## Audit Note (2026-05-02)
|
||||
|
||||
**Status**: DEFERRED.
|
||||
|
||||
State at audit:
|
||||
|
||||
- Package scaffold is in place at `packages/network/network-plugin-registry/` with `src/registry/`, `src/encoder/`, `src/sync/`, plus `error-codes.ts`, `registry-plugin.ts`, and barrel `index.ts`. README, vite + vitest configs, tsconfig all exist.
|
||||
- `bunx turbo test --filter=@suaveplan/network-plugin-registry` is green (9 tests across `registry.spec-conformance.test.ts`, `encoder.spec-conformance.test.ts`, `dep-graph.test.ts`).
|
||||
- `bunx turbo test:coverage` **fails the 100/100/100/100 gate**: stmts 67.92 / branch 61.53 / funcs 52.38 / lines 67.92. `src/sync/sync.ts` is 0% covered (lines 11–30); `src/registry-plugin.ts` is 0% (lines 7–33); `src/registry/registry.ts` has one uncovered branch on line 14.
|
||||
|
||||
Outstanding to ship:
|
||||
|
||||
1. **Task 8.3** — author `src/sync/sync.spec-conformance.test.ts` covering periodic full-sync + dedup-by-hash; takes `RegistrySyncManager` to 100%.
|
||||
2. **Task 8.4** — author `src/error-codes.spec-conformance.test.ts` proving the `defineCodes("NET_REG", [...])` registry is frozen.
|
||||
3. **Tasks 6.1 / 6.2** — exercise `RegistryPlugin.install()` from a test (`src/registry-plugin.ts` is currently uncovered).
|
||||
4. **Task 3.3** — verify the `RegistryCapacityExceededError` branch (line 14 of `registry.ts`).
|
||||
5. Re-run `bunx turbo test:coverage --filter=@suaveplan/network-plugin-registry` and confirm 100/100/100/100, then archive.
|
||||
Reference in New Issue
Block a user