Multi-tenant reverse-tunnel service ("ngrok for Claude Code" with E2E): a
host-agent dials OUT to an operator-run relay; external devices reach the host
THROUGH the relay, routed by per-tenant subdomain, forwarding ciphertext only
(the relay never sees plaintext). Lets a customer reach their own self-hosted
web-terminal from anywhere with zero networking setup.
Packages — all tsc-strict + vitest green (656 tests), cross-package integration verified:
- relay-contracts: frozen shared contracts (mux frame codec, data model,
capability token, E2E envelope, pairing) — the src/types.ts analog
- term-relay: native WS mux + stateless data plane (subdomain routing, ciphertext forward)
- agent: host-agent (pairing, per-host Ed25519 + mTLS dial-out, forwards to 127.0.0.1:3000)
- control-plane: accounts/hosts registry, pairing-code flow, routing table, provisioning
- relay-e2e: browser<->agent E2E (X25519 ECDH through relay, AEAD, anti-replay, recoverable replay key)
- relay-auth: Passkey/WebAuthn, capability tokens, per-host certs, deny-by-default tenant isolation
- relay-web: browser login + Web Crypto E2E + client-side preview rendering
Security invariants INV1-15 enforced; cross-tenant isolation CI tripwire live
(.github/workflows/relay-tripwire.yml). Design + implementation-level plans in
docs/PLAN_RELAY_*.md and docs/EXPLORE_RELAY_SERVICE.md.
NOTE: generated autonomously per the reviewed plans. The security-critical
packages (relay-e2e, relay-auth) REQUIRE expert security audit before any real
deployment — passing tests prove self-consistency, not resistance to attackers.
Base app (src/, public/) unchanged; concurrent desktop work left uncommitted.
59 lines
2.0 KiB
TypeScript
59 lines
2.0 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { decodeMuxFrame } from 'relay-contracts'
|
|
import { holdTunnel } from '../src/transport/tunnel.js'
|
|
import { createHeartbeat, HEARTBEAT_INTERVAL_MS } from '../src/transport/heartbeat.js'
|
|
import { FakeWs, FakeTimer } from './fixtures/fakes.js'
|
|
|
|
describe('Heartbeat (T9, §4.1)', () => {
|
|
it('replies PONG echoing the inbound PING token byte-exact', () => {
|
|
const ws = new FakeWs()
|
|
const tunnel = holdTunnel(ws)
|
|
const hb = createHeartbeat(tunnel, { timer: new FakeTimer() })
|
|
const token = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8])
|
|
hb.onPing(token)
|
|
const frame = decodeMuxFrame(ws.sent.at(-1)!)
|
|
expect(frame.header.type).toBe('pong')
|
|
expect(Buffer.from(frame.payload).equals(Buffer.from(token))).toBe(true)
|
|
})
|
|
|
|
it('fires onDead when no PONG arrives within the interval', () => {
|
|
const ws = new FakeWs()
|
|
const tunnel = holdTunnel(ws)
|
|
const timer = new FakeTimer()
|
|
const hb = createHeartbeat(tunnel, { timer, intervalMs: 1000 })
|
|
let dead = false
|
|
hb.onDead(() => {
|
|
dead = true
|
|
})
|
|
hb.start() // sends first ping, arms deadline
|
|
timer.advance(1000) // deadline fires, no pong seen
|
|
expect(dead).toBe(true)
|
|
})
|
|
|
|
it('does not fire onDead when PONG arrives in time', () => {
|
|
const ws = new FakeWs()
|
|
const tunnel = holdTunnel(ws)
|
|
const timer = new FakeTimer()
|
|
const hb = createHeartbeat(tunnel, { timer, intervalMs: 1000, genToken: () => new Uint8Array(8) })
|
|
let dead = false
|
|
hb.onDead(() => {
|
|
dead = true
|
|
})
|
|
hb.start()
|
|
hb.onPong(new Uint8Array(8)) // clears pending before the deadline
|
|
timer.advance(1000)
|
|
expect(dead).toBe(false)
|
|
})
|
|
|
|
it('exposes the frozen 15s interval', () => {
|
|
expect(HEARTBEAT_INTERVAL_MS).toBe(15_000)
|
|
})
|
|
|
|
it('stop() cancels timers (no leak)', () => {
|
|
const ws = new FakeWs()
|
|
const hb = createHeartbeat(holdTunnel(ws), { timer: new FakeTimer(), intervalMs: 1000 })
|
|
hb.start()
|
|
expect(() => hb.stop()).not.toThrow()
|
|
})
|
|
})
|