Documentation
¶
Overview ¶
Package fakerelay is an in-process WebSocket server that speaks the routing half of the mobile↔relay protocol (docs/protocol-mobile.md § Authentication, § Routing envelope). It exists so daemon-side e2e tests can exercise the full WS roundtrip — binary ↔ relay ↔ phone — without depending on the pyrycode-relay binary or live infrastructure.
The package lives under internal/e2e/internal/ to visibility-fence it from non-e2e callers. The sibling fake-phone client (separate ticket) and the consuming roundtrip test (third ticket) wire up around it.
Wire contract ¶
Binary upgrades on /v1/server with header x-pyrycode-server (the claimed server-id). First-claim-wins: while a binary holds a server-id, further /v1/server upgrades for that id are rejected.
Phone upgrades on /v1/client with headers x-pyrycode-server, x-pyrycode-token, x-pyrycode-device-name. The relay does NOT validate the token contents; the binary owns that check. If no binary is bound to the requested server-id, the upgrade is rejected.
Each accepted phone receives a fresh, monotonically-numbered conn_id ("c-1", "c-2", …). The relay wraps every phone→binary frame as {"conn_id": "...", "frame": <phone-frame>} and unwraps every binary→phone frame, sending only the inner frame onto the phone WS.
Deviations from the production wire spec (deliberate) ¶
- Rejections happen pre-upgrade as HTTP 400/409/503 rather than as post-upgrade WS close codes (4409/4404/4401). The AC is satisfied by either form, and HTTP status surfaces directly in the dial error, which is simpler for consumer tests to assert against.
- No 30-second grace period on server-id release: when the binary disconnects, its server-id is immediately reusable.
- No TLS, no persistence, no rate limiting.
- Binary-direct "hello" envelopes (no conn_id) get a synthesized hello_ack reply so real pyry binaries can complete their binary↔relay handshake against the harness. Other binary-direct envelope types are dropped (the dispatcher slice consumes them).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a running fake relay. Construct with New; shut down with Close. Safe for concurrent use across handler goroutines; consumers observe behavior through the WS endpoints, not by reaching in.
func New ¶
New returns a running fake relay bound to a random localhost port. The returned Server is ready for connections; Close shuts it down. logger is required (Debug-level lifecycle and routing events); nil panics at construction.
func (*Server) ForceCloseBinary ¶
ForceCloseBinary closes the WS conn currently bound to serverID with websocket.StatusInternalError (1011), simulating a non-fatal relay-side drop. Returns true if a binary was bound and the close was issued; false if no binary is currently bound to serverID. Used by e2e tests to assert that the daemon's claude child survives a non-fatal close (transport reconnects, supervisor stays up).
func (*Server) LastBinaryHello ¶
LastBinaryHello returns the most recent binary-direct "hello" envelope observed from the binary that claimed serverID. The boolean is false when no hello has been observed for that server-id yet — callers poll in e2e tests to wait for the handshake to land.
func (*Server) RejectNextBinaryWith4409 ¶
func (s *Server) RejectNextBinaryWith4409()
RejectNextBinaryWith4409 arms a one-shot mode: the next /v1/server upgrade accepts the WS handshake and immediately closes with WS code 4409 ("server-id already claimed"). Subsequent connects follow normal logic. Used by e2e tests to drive the daemon's "fatal close → daemon shuts down" path without racing against the harness's HTTP-409 first-claim branch.