3.5 KiB
3.5 KiB
Tasks: enterprise-server-network-trystero-server
Change ID: enterprise-server-network-trystero-server
Package: @suaveplan/network-trystero-server
Target path: server/network/network-trystero-server
Prerequisites on Verdaccio: @suaveplan/error, @suaveplan/types, @suaveplan/events, @suaveplan/logger
1. Scaffold
- Create directory tree per
proposal.md. package.jsonat0.1.0,"sideEffects": false, exports"."+adapter.- Deps: workspace + catalog deps as listed in proposal.
- DevDeps:
vitest catalog:testing,@vitest/coverage-istanbul catalog:testing,@suaveplan/testing workspace:^. tsconfig.jsonextendinglibrary-node.json;vitest.config.tswithpool: 'forks'.- Scripts:
lint,typecheck,test,test:coverage,build,docs:check.
2. Types and errors
- Define
TrysteroServerOptions,TrysteroServerOptionsSchemainsrc/types/trystero-server.types.ts. - Write
trystero-server.types.md(≥200 words). src/error-codes.ts: four codes;registerTrysteroErrorCodes(); eager call.
3. Adapter implementation
- Implement
TrysteroServerAdapterinsrc/adapter/trystero-server-adapter/trystero-server-adapter.ts:- Maintain a
Map<roomId, { room: TrysteroRoom; channels: Map<channelName, DataChannel>; peers: Set<string> }>. join(roomId): call TrysterojoinRoom(config, roomId); registeronPeerJoin/onPeerLeavehandlers; update peer set. ThrowNETWORK_TRYSTERO_JOIN_FAILEDon error.leave(roomId): callroom.leave(); remove from map. ThrowNETWORK_TRYSTERO_LEAVE_FAILEDon error.send(roomId, channelName, data, peerId?): get or create data channel viaroom.makeAction(channelName); callsend(data, peerId). ThrowNETWORK_TRYSTERO_SEND_FAILEDon missing room.onData(roomId, channelName, handler): register action handler; return unsubscribe fn.onPeerJoin/onPeerLeave: register peer lifecycle handlers; return unsubscribe.peers(roomId): return[...peerSet]or[].leaveAll(): iterate all rooms, callleaveon each.- OTel gauge
network_trystero.peer_count; counternetwork_trystero.messages_total.
- Maintain a
- Write
trystero-server-adapter.types.ts. - Write
trystero-server-adapter.test.ts(≤500 lines): unit tests using a mocked TrysterojoinRoomthat returns a fake room object — verify all adapter state management, handler registration, unsubscribe. Use DI for Trystero factory to inject mock. Guard network integration tests withSKIP_NETWORK_TESTS=1. - Write
trystero-server-adapter.md(≥200 words, simple + advanced, API reference).
4. Integration tests
tests/integration.test.ts: skip unlessRUN_TRYSTERO_INTEGRATION=1. Two adapters join same room (torrent strategy); one sends, other receives viaonData.{ timeout: 30000 }.
5. OTel + docs
- All OTel instrumentation per proposal.
- Root
README.md: strategy comparison table, quick-start torrent example, API table.
6. Verify and publish
bunx turbo lint --filter=@suaveplan/network-trystero-server— zero errors.bunx turbo typecheck --filter=@suaveplan/network-trystero-server— zero errors.bunx turbo test --filter=@suaveplan/network-trystero-server— all pass.bunx turbo test:coverage --filter=@suaveplan/network-trystero-server— 100%.bun scripts/publish.ts --package @suaveplan/network-trystero-server.- Update
CLAUDE.md; archive toopenspec/archive/2026-04-24-enterprise-server-network-trystero-server/.