FakeSeam

class FakeSeam(val selfId: PeerId = PeerId("self"), initialPeers: Set<PeerId> = setOf(selfId), initialState: SeamState = SeamState.Woven) : Seam

A test double for Seam with test-driver helpers for state mutation, frame delivery, and outgoing-frame inspection.

Defaults make FakeSeam() a ready-to-use, single-peer, SeamState.Woven seam in one line:

val seam = FakeSeam()
seam.deliver(PeerId("alice"), byteArrayOf(1, 2, 3))
val frame = seam.incoming.first()

For wired two-peer scenarios, prefer fakeSeamPair which cross-wires broadcast delivery between two seams.

Send semantics (matching the Seam contract):

Constructors

Link copied to clipboard
constructor(selfId: PeerId = PeerId("self"), initialPeers: Set<PeerId> = setOf(selfId), initialState: SeamState = SeamState.Woven)

Properties

Link copied to clipboard

All payloads passed to broadcast, in call order. Each read returns a fresh defensive snapshot; two reads may observe different snapshots if a broadcast lands between them.

Link copied to clipboard

All (peer, payload) pairs passed to sendTo, in call order. Each read returns a fresh defensive snapshot; two reads may observe different snapshots if a sendTo lands between them.

Link copied to clipboard
open override val incoming: Flow<Swatch>
Link copied to clipboard
open override val peers: StateFlow<Set<PeerId>>
Link copied to clipboard
open val plies: StateFlow<Map<PlyId, SeamState>>
Link copied to clipboard
open override val selfId: PeerId
Link copied to clipboard
open override val state: StateFlow<SeamState>

Functions

Link copied to clipboard
fun addPeer(peer: PeerId)

Add peer to the live peers set.

Link copied to clipboard
open suspend override fun broadcast(payload: ByteArray)
Link copied to clipboard
open suspend override fun close(reason: CloseReason)
Link copied to clipboard
suspend fun deliver(swatch: Swatch)

Push swatch directly into incoming.

suspend fun deliver(from: PeerId, payload: ByteArray)

Push a frame from from into incoming, stamping sender and a monotonically increasing sequence (receiver-local, starting at 1).

Link copied to clipboard
fun removePeer(peer: PeerId)

Remove peer from the live peers set.

Link copied to clipboard
open suspend override fun sendTo(peer: PeerId, payload: ByteArray)
Link copied to clipboard
fun tear(reason: CloseReason = CloseReason.Normal)

Transition state to SeamState.Torn with reason.

Link copied to clipboard
fun weave()

Transition state from SeamState.Weaving to SeamState.Woven.