import { An as IDuplexCarrierSource } from "../ChannelAcceptor-Cmu6jyhn.mjs"; import { IInMemoryServerEndpoint } from "@nice-code/wire"; //#region src/testing-transport/chaosLink.d.ts /** * The chaos controls for one {@link chaosLink} — everything a resilience test does to the link. * All controls apply to the *current* connection and persist across redials (a link that redials * while `hold()` is active comes up held too). */ interface IChaosLinkControls { /** * Stop delivering frames in BOTH directions while keeping the link "open" — the half-open * socket: `isOpen()` stays true, sends vanish. This is the case a browser's offline mode * creates and the staleness probe / wire keepalive exist to detect. */ hold(): void; /** Deliver every held frame in order and resume normal delivery (heal without a drop). */ releaseHeld(): void; /** Discard the held frames (lost on the wire) and resume delivery — a lossy blip. */ dropHeld(): void; /** * Force-close the current connection — both ends observe a real close (unlike `hold()`), so * the connector's keep-alive redials and the acceptor sees the drop. */ closeLink(): void; /** * While `true`, every new dial fails — an unreachable server. Combine with {@link closeLink} * for "drop, and stay down": the keep-alive backoff loop keeps failing until you allow dials * again. */ refuseDials(refuse: boolean): void; /** Genuine dials so far — a keep-alive redial is observable as an increment. */ readonly dialCount: number; /** Frames currently held by {@link hold} (both directions), for assertions. */ readonly heldCount: number; } interface IChaosLink { /** The connector end — pass as a `carrier` in one of `connectChannel`'s `transports`. */ carrier: IDuplexCarrierSource; /** * Acceptor-side wiring, called once per dial (so a redial re-wires naturally). Use the endpoint * itself as the acceptor's connection key: * * ```ts * const acceptor = createChannelAcceptor({ * send: (conn, frame) => conn.send(frame), * // ... * }); * link.onConnection((endpoint) => { * endpoint.onMessage((frame) => acceptor.receive(endpoint, frame)); * endpoint.onClose(() => acceptor.drop(endpoint)); * }); * ``` * * Must be registered before the first dial — a dial with no acceptor wiring would silently * swallow the handshake, so it throws instead. */ onConnection(handler: (endpoint: IInMemoryServerEndpoint, dialIndex: number) => void): void; chaos: IChaosLinkControls; } /** * A reconnectable in-memory link with chaos controls — the transport the library's own resilience * suites use, exported so consumers can verify "my app survives a flaky link" without * rediscovering it (resilience-surface §2). Each dial mints a fresh in-process pair (no sockets), * so the keep-alive redial, `reconnectLink()`, and the staleness-probe escalation all behave * exactly as they do over a real carrier — but the test controls the weather: hold frames * (half-open link), drop held frames (loss), force a close, or refuse redials (sustained outage). * * For chaos over a *real* WebSocket instead, see `wsCarrier`'s `createWebSocket` option and * `connector.debug.dropLink()`. */ declare function chaosLink(): IChaosLink; //#endregion export { type IChaosLink, type IChaosLinkControls, chaosLink }; //# sourceMappingURL=index.d.mts.map