Skip to content

Refactor: extract Discovery interface from SymNode - #4

Merged
sym-bot merged 2 commits into
mainfrom
refactor/discovery-interface
Mar 30, 2026
Merged

Refactor: extract Discovery interface from SymNode#4
sym-bot merged 2 commits into
mainfrom
refactor/discovery-interface

Conversation

@sym-bot

@sym-bot sym-bot commented Mar 30, 2026

Copy link
Copy Markdown
Owner

Summary

Extract networking (TCP server + Bonjour discovery) from SymNode into a pluggable Discovery interface. SymNode drops from 929 to 762 lines. Networking is now separately testable.

Before: SymNode owned TCP server, dns-sd processes, bonjour-service, and peer handshakes inline. Tests couldn't exercise lifecycle without real networking.

After: Three Discovery implementations:

  • BonjourDiscovery — existing LAN behavior (TCP + dns-sd/bonjour-service)
  • NullDiscovery — no-op for relay-only nodes and tests
  • Discovery — base class (EventEmitter interface)

SymNode accepts opts.discovery for injection. Defaults: BonjourDiscovery (normal) or NullDiscovery (relayOnly).

MMP Spec Compliance

Section 5 — Connection (Layer 2): Discovery behavior unchanged. The interface boundary matches the spec's separation between transport (L1) and connection (L2).

Testing

77 tests total (10 new), all passing:

  • discovery.test.js: NullDiscovery, BonjourDiscovery TCP server, handshake validation, non-handshake rejection
  • node.test.js: updated to inject NullDiscovery — validates business logic without networking

Checklist

  • All tests pass (npm test) — 77 pass, 0 fail
  • Changes comply with the MMP specification
  • No breaking changes to public API (opts.discovery is optional, defaults preserved)

sym-bot and others added 2 commits March 30, 2026 06:41
SymNode was 929 lines with TCP server + Bonjour discovery + business
logic tightly coupled. Tests couldn't exercise lifecycle without
spawning child processes and opening network sockets.

Refactoring:
- Extract Discovery base class (EventEmitter interface)
- BonjourDiscovery: TCP server + dns-sd/bonjour-service (existing behavior)
- NullDiscovery: no-op for relay-only nodes and tests
- SymNode accepts opts.discovery for injection (defaults based on relayOnly)
- SymNode: 929 → 762 lines. Discovery: 258 lines (new file)

Testability improvements:
- Node tests inject NullDiscovery — no network, no child processes
- Discovery tests validate TCP server, handshake protocol, rejection
- 77 tests total (10 new), all passing on macOS and Linux CI

Design principle: separate what changes (networking) from what doesn't
(memory, coupling, encoding). Each can now evolve independently.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
bonjour-service's multicast UDP socket leaks on destroy() (upstream issue),
preventing clean process exit on Linux CI. Add mdns: false option for
server-only mode — tests validate TCP handshake protocol without mDNS.

Default is mdns: true (full Bonjour behavior unchanged for production).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@sym-bot
sym-bot merged commit c2632ed into main Mar 30, 2026
2 checks passed
@sym-bot
sym-bot deleted the refactor/discovery-interface branch March 31, 2026 23:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant