feat(relay): rendezvous-relay service — 7 packages + plans (contracts/transport/agent/control-plane/e2e/auth/web)
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.
This commit is contained in:
62
agent/test/backoff.test.ts
Normal file
62
agent/test/backoff.test.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { createBackoff, reconnectLoop, BACKOFF_CAP_MS } from '../src/transport/backoff.js'
|
||||
import type { Tunnel } from '../src/transport/tunnel.js'
|
||||
|
||||
describe('createBackoff (T10)', () => {
|
||||
it('follows 1s,2s,4s…cap 30s', () => {
|
||||
const b = createBackoff()
|
||||
const seq = [b.nextDelayMs(), b.nextDelayMs(), b.nextDelayMs(), b.nextDelayMs(), b.nextDelayMs(), b.nextDelayMs(), b.nextDelayMs()]
|
||||
expect(seq).toEqual([1000, 2000, 4000, 8000, 16000, 30000, 30000])
|
||||
expect(BACKOFF_CAP_MS).toBe(30_000)
|
||||
})
|
||||
|
||||
it('reset() returns to 1s', () => {
|
||||
const b = createBackoff()
|
||||
b.nextDelayMs()
|
||||
b.nextDelayMs()
|
||||
b.reset()
|
||||
expect(b.nextDelayMs()).toBe(1000)
|
||||
})
|
||||
|
||||
it('jitter stays within [0.5×, 1×]', () => {
|
||||
const b = createBackoff({ jitter: true, rng: () => 0 })
|
||||
expect(b.nextDelayMs()).toBe(500) // 1000 * 0.5
|
||||
const b2 = createBackoff({ jitter: true, rng: () => 1 })
|
||||
expect(b2.nextDelayMs()).toBe(1000) // 1000 * 1.0
|
||||
})
|
||||
})
|
||||
|
||||
describe('reconnectLoop (T10, INV12)', () => {
|
||||
const fakeTunnel = {} as Tunnel
|
||||
|
||||
it('resolves on the first successful dial and resets backoff', async () => {
|
||||
const dial = vi.fn().mockRejectedValueOnce(new Error('down')).mockResolvedValueOnce(fakeTunnel)
|
||||
const backoff = createBackoff()
|
||||
const reset = vi.spyOn(backoff, 'reset')
|
||||
const sleeps: number[] = []
|
||||
const result = await reconnectLoop(dial, backoff, () => false, async (ms) => {
|
||||
sleeps.push(ms)
|
||||
})
|
||||
expect(result).toBe(fakeTunnel)
|
||||
expect(sleeps).toEqual([1000])
|
||||
expect(reset).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('a revoked host does not reconnect (INV12)', async () => {
|
||||
const dial = vi.fn().mockResolvedValue(fakeTunnel)
|
||||
const result = await reconnectLoop(dial, createBackoff(), () => true, async () => {})
|
||||
expect(dial).not.toHaveBeenCalled()
|
||||
expect(result).toBeNull()
|
||||
})
|
||||
|
||||
it('stops retrying once revoked mid-loop', async () => {
|
||||
let revoked = false
|
||||
const dial = vi.fn(async () => {
|
||||
revoked = true
|
||||
throw new Error('down')
|
||||
})
|
||||
const result = await reconnectLoop(dial, createBackoff(), () => revoked, async () => {})
|
||||
expect(result).toBeNull()
|
||||
expect(dial).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user