RoomConformanceSuite

abstract class RoomConformanceSuite

Reusable contract test suite for RoomFactory implementations.

Subclass and implement newHarness to bind a RoomFactory under test. Every Test encodes a required invariant of the Room lifecycle state machine.

Lives in commonMain of :kuilt-conformance (not a module's commonTest) so every RoomFactory adapter can subclass it from its own test source set.

Virtual time convention: all partition tests advance in 100 ms steps using fastHeartbeatConfig (interval=100ms, timeout=200ms, reconnectWindow=500ms):

Scope contract: newHarness receives the test's CoroutineScope (typically backgroundScope from runTest) so FaultyLoom and SeamRoomFactory are correctly structured under the test's virtual-time scheduler.

Fault injection: tests that require partition or teardown behaviour go through RoomHarness.faults, a two-armed FaultInjection fixture. A harness that cannot break its own links declares FaultInjection.Unsupported with a tracking URL — it cannot decline silently, because the arm has nowhere to put a refusal that is not also a declaration (#2306).

Every wait is bounded, and names what it saw. The population running this suite is by definition implementors whose fabric does not work yet, so no obligation here may be guarded by a suspending wait that simply never returns. Waits go through awaitRoster / awaitEvent / awaitFrame, each bounded by awaitBudget in virtual time and each failing with an AssertionError that prints the roster (or the events) actually observed — see #2284, where a fabric that never admitted burned the whole runTest ceiling and then reported UncompletedCoroutinesError, naming neither the room nor its roster.

No obligation here returns silently — #2306

There is no skip API in common kotlin-test, so an obligation that early-returns reports PASS — worse than a JVM-visible @Ignore, because nothing anywhere records that it did not run. This suite had four such returns and, until #2306, exactly one subclass: the reference. Every escape hatch had therefore fired zero times in its life, and nothing had ever checked that a harness taking one survives the suite at all.

They were closed by three different mechanisms, chosen by whose limitation the missing state was. Two went with the surface they guarded: a loud precondition on the joiner's resume credential, retired with it (#3215), and a refusal property for a credential naming another room, retired when the credential stopped being presented (#3159 Task 1.7). The one left:

  • Fault injection — a two-armed sealed fixture (FaultInjection). Here the missing state genuinely belongs to the harness: a room over a fabric whose links the test cannot reach cannot be partitioned by anyone. A nullable hook was the wrong shape for it — null moves the vacuity one level up, where it is a value nobody has to justify. The sealed arm makes declining representable only together with its declaration, so the pairing is the compiler's job rather than a meta-test's, and the arm that declines still ends in an assertion (injectorOrDeclaredGap) rather than in a bare return.

What the fixture still cannot detect, said plainly. A harness that could fault-inject and declares FaultInjection.Unsupported anyway is invisible here — there is no capability on RoomFactory to check the claim against, and inventing one would put a knob in the contract no consumer asked for. What the arm does buy is that the claim now exists, is attributable, and carries a URL somebody has to keep alive. The residual is narrower, not gone.

Mutation receipt

JVM, --rerun-tasks (27/27 EXECUTED). Subjects: InMemoryRoomConformanceTest (the reference, 14 tests) and RoomConformanceGapDeclarationTest (6). Real = a defect an implementation could plausibly ship; synthetic = a change made purely to reach an assertion no real defect reaches; rig = a mutation of this suite itself. The "before" column is the measurement of the hole — what the pre-#2306 suite did under the same mutation.

Two rows, M1 and M4, are gone: they measured properties of the resume credential, which #3159 Task 1.7 and #3215 retired along with the credential.

#MutationKindafterbefore
M2injectorOrDeclaredGap drops its assertion — i.e. the pre-#2306 silent ?: return@runTest, exactlyrigRED: all four blankTrackingUrl* as measured — the set was seven from #2501, six since #3159 Task 1.7, five since #3215all green; the four gated obligations passed under a gap declaring nothing
M3delete the proof.roomId != roomId check in KeyAdmission.checkProof — a proof for another room admitsrealre-pointed (#3212): RED in :kuilt-session's KeyAdmissionTest.proofForAnotherRoomIsRejected, 1 of 23, 2 of its assertions. The controller's own guard, this row's old subject, reds nothing in this suite (40 of 40 green) — see belowevery pre-existing test of this suite green

M3's claim is narrower than it looks, and the narrowing matters. It used to delete the room-id guard in DefaultJoinerReconnectController.tryResume. That guard is now unreachable through a room: the room builds every ProvenResume from its own id, on a proof whose room id it has already checked. Measured on #3212: deleting it reds :kuilt-session's own JoinerReconnectControllerTest (2 of 19) and nothing in this suite (40 of 40 green). Since #3215 retired the Resume frame, the room-id property rests on one room check, the proof's, which proofForAnotherRoomIsRejected pins. Either way the defect is visible to the tree but not to the contract, which is precisely what a second RoomFactory inherits nothing of: an implementation's private suite is not a conformance obligation.

One assertion has no red anywhere, and that is correct: RoomConformanceGapDeclarationTest.aDeclaredGapSkipsEveryGatedObligationCleanly. It does not describe behaviour under test — it is the survivability check, and its falsifying input is a future edit that moves work above the gate (a suspending wait, a links[0] access), not any defect present today. Stating it rather than hiding it: an all-red table would mean the table was measuring blast radius instead of diagnoses.

Mutation receipt — Room.leave's two obligations (#2501)

JVM, --rerun-tasks, subjects InMemoryRoomConformanceTest (19 tests) and RoomConformanceGapDeclarationTest (9). Same kinds as above. All five new properties are green against unmutated main, and that is correct — SeamRoom.leave calls seam.close(...) unguarded, so nothing mints today; these are live guards, not regression tests for a fix.

Every row below was re-measured after theTeardownFaultReallyFires moved its arms onto links no Room owns. One verdict changed, and it changed to a narrower one — see the T7 note.

#MutationKindverdict
T1SeamRoom.leave wraps its seam.close(...) in withTimeout(100.milliseconds)realRED — leaveDoesNotMintACancellationWhenTeardownIsSlow, 1 of its 2 assertions: Got: kotlinx.coroutines.TimeoutCancellationException: Timed out after 100ms of _virtual_ … time. Nothing else moves.
T2closed = true moves out of leave's opening lock.withLock to after seam.close(...)realRED — leaveIsIdempotentEvenWhenTeardownFails, 1 of 2, naming both calls' failures. leaveIsIdempotent stays GREEN.
T3leave's if (closed) return fast path deleted outrightrealRED — leaveIsIdempotentEvenWhenTeardownFails only. Both ungated properties GREEN.
T4TeardownFault.Fails delegates but does not throwrigRED — theTeardownFaultReallyFires, 1 of 4: Got: no exception — the close completed. leaveIsIdempotentEvenWhenTeardownFails goes GREEN BY ABSENCE.
T5TeardownFault.Slow does not delayrigRED — theTeardownFaultReallyFires, 1 of 4: Expected at least 1000 ms of virtual time to pass, got 0 ms.
T6T1 and T5 togetherrigRED — theTeardownFaultReallyFires only. leaveDoesNotMintACancellationWhenTeardownIsSlow is GREEN — T1's real defect has gone invisible.
T7leave throws IllegalStateException("already left") on a second callsyntheticRED — leaveIsIdempotent, leaveDoesNotReportFailureAsCancellation, leaveIsIdempotentEvenWhenTeardownFails and aDeclaredGapDoesNotExcuseTheUngatedObligations, each on the raw throw. theTeardownFaultReallyFires is not among them — see below.

T3 is the measurement of the gap this whole section closes, and it is the most damning row. Deleting leave's idempotency guard entirely is invisible to leaveIsIdempotent — because on a reference whose close is synchronous and infallible, re-running the whole teardown is simply harmless. Only the fault-gated companion sees it. That is the #2244 shape stated as a measurement rather than as a worry: a property whose reference cannot reach the failure does not test the failure, and the ungated half of an obligation is not a substitute for the gated half.

T2 says the same thing from the other side. A successful teardown still reaches the flag, so the happy-path property cannot distinguish "idempotent" from "idempotent only when the first call succeeded". The contrast between T2/T3 and T7 is why both halves are here.

T4 is exactly what theTeardownFaultReallyFires exists for, and it also shows what the rig-fired counter alone does not buy. Under T4 the counter still increments — the arm was selected — so leaveIsIdempotentEvenWhenTeardownFails's own precondition holds and its remaining assertion passes on a leave that never failed. The two mechanisms divide the labour cleanly: FaultySeam.teardownFaultsFired proves the fault reached this seam, and only this test proves the fault does anything. Neither subsumes the other.

T5 and T6 are why the Slow arm is measured at all — and T5 was GREEN in the first draft. This test originally measured only TeardownFault.Fails, and a no-op Slow reddened nothing anywhere in the tree: SeamRoom.leave bounds nothing today, so a zero-duration teardown mints no cancellation either. T6 is the proof that the omission mattered rather than a guess about it — with Slow silently no-op, T1's genuine defect stops being detectable at all. The fix for one vacuity had landed one level up inside itself, which is the recurrence this repo's conventions warn about, caught by asking of the fix what the fix was now unpinned on.

T7 is marked synthetic because no real implementation refuses a second leave on purpose — it is here to show the two ungated properties can red, since T1–T6 never touch them.

T7's blast radius is the receipt for theTeardownFaultReallyFires's bare links. As first measured, T7 also reddened that test: the fixture then armed its fault on a seam a room owned, so closing it made the room self-leave in reaction and the trailing explicit leave() was the second one. That was blast radius rather than a diagnosis — the row said four tests while the prose explained a fifth, which is a receipt disagreeing with itself. Re-measured after the fixture moved to links no Room owns, the fifth hit is gone: nothing self-leaves, because nothing owns the links being closed. The row is four, and it is four for a structural reason rather than because the number was edited to agree with a prediction.

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
sealed interface FaultInjection

Whether this harness can break and heal the links under the rooms it builds — and, when it cannot, where that is written down.

Link copied to clipboard
data class RoomHarness(val hostFactory: RoomFactory, val joinerFactory: RoomFactory, val faults: RoomConformanceSuite.FaultInjection, val clock: () -> Instant, val advanceClock: (Long) -> Unit)

A harness that bundles host and joiner RoomFactorys plus its FaultInjection fixture.

Properties

Link copied to clipboard

How long awaitRoster / awaitEvent / awaitFrame wait before failing with the state they observed — virtual time, null to wait unbounded.

Link copied to clipboard

Fast heartbeat config shared by all tests so virtual-time advancement is cheap. Advancing 4 × 100 ms triggers MembershipEvent.Partitioned; advancing 9 × 100 ms exhausts the reconnect window (PeerLost / HostLost).

Link copied to clipboard
open val memberInboxCapacity: Int = 64

How many unread frames the rooms under test hold per member for Room.incomingFrom — the depth the boundary and overflow obligations (4c)–(4e) measure against.

Functions

A device whose key store was cleared while its peer id persisted comes back under that id with a key it never held, while the host holds the old seat partitioned. The host lets that seat go and admits the newcomer as an ordinary new member under the new key (Decided 18, 23): the old membership leaves PartitionExpired, a new one joins, and the old key holds nothing. The only app call is the relaunch's join.

A joiner presenting the host's own key — the host's second tab — gets a joiner seat of its own, and the host stays the host (Decided 30, the design's host-key row): the host decides that key against the joiner seats it holds, never against its own membership. So the first tab is admitted beside the host rather than refused or taken for it, and a second tab, arriving while the first is connected, gets an additional seat. A member present for both hears two Joineds, and still lists the host under its own id and key.

As aRenewalTheLinkLostStillLetsTheDeviceBackUnvetted, but HOST_DEPARTURES_KEPT other devices leave after the device's seat went, which pushes its record out (spec Membership and the wire: at most that many, oldest out first). The host no longer holds the pass it signed, the device holds only the one that ran out, and the policy is asked once, about its key.

As aRenewalTheLinkLostStillLetsTheDeviceBackUnvetted, but the host revokes the device from just after it signed the lost renewal. The pass it kept is void like any other issued before the cutoff (Decided 14, 27), so the policy is asked once, about the device's key.

Superseded is promised to the members present for it (plan Amendment G). A member that was away when another device's process came back under a fresh id and took its old seat over hears neither half of the takeover: the host's Farewell naming the successor went down its dead link. When it comes back inside the host's hold, the host restores its seat and re-sends the burst, so it hears Joined(new) from the burst, and its roster rebuild then drops the old id as LeaveReason.Unobserved. It never says Superseded, which would claim a takeover it did not see, and keeps no ghost of the old id. The away member's app makes no call.

After the device's seat went, a different key comes in under the device's old id: a device whose key store was cleared while its peer id persisted (Decided 18). The host's record of the lost pass names the device's key, so it is no pass for this one: the policy is asked about it, and it is not marked as a return. The record is still the device's, which comes back on it unvetted.

A known gap, pinned on purpose (Decided 33, option A): a bystander can take a partitioned member's peer id under a key of its own, and the member then cannot get back in.

Link copied to clipboard

A pass naming the host as issuer, for the device presenting it and for this room, whose signature the host never made, is ignored. It is PlantedPassRig.hostPass's pass with the last byte of its signature changed, so every field the host reads before the signature is good: the row reds on a host that checks a pass's fields and never its signature.

Link copied to clipboard

The control arm: a planted pass the host signed, for the device presenting it and for this room, lets a device that never held a seat in with no call to the admission policy, marked as returning with no id the host remembers.

Link copied to clipboard

A process comes up under the peer id of a dead process of its device, with the device's key, after a newer id took that seat over (gate finding I1, Decided 32). The host answers its Hello with a Reject naming the successor: the process ends Left(self, Superseded(by)) without ever being seated or failing its admission, the successor keeps the key's one seat, and the admission policy is not asked.

A readmitted device rebuilds its roster from the host's admission burst: a member who left while its link was down — whose departure went down that link and never arrived — is dropped with LeaveReason.Unobserved, and a member who stayed connected throughout is still listed (plan Amendment G).

The headline (#3745): the link loses the device's renewal, the device is killed and its seat let go, and it comes back after the pass it holds ran out but inside the one its link lost. The host signed that one, so it lets the device back without asking the admission policy, and marks it as the device returning.

Link copied to clipboard

As aRenewalTheLinkLostStillLetsTheDeviceBackUnvetted, but the device comes back after the lost renewal ran out too. The host never lengthens a pass it signed, so the policy is asked once, about the device's key.

Link copied to clipboard

A device whose link heals only after the host let its seat go is admitted afresh, and its room says so: Readmitted(self), never Recovered(host) (plan Amendment G). The room stays in session, the host sees the old membership leave and a new one join, and the app makes no call.

Link copied to clipboard

A second live process on one device — a second tab over the same key store — gets a seat of its own (Decided 30): the host meets a known key under a new id while that key's only seat is still connected, so it adds a seat and supersedes nothing. Both processes stay members under the one key, and each lists the other.

Link copied to clipboard
fun channelStateTornAfterLeave(): TestResult

A room that has left reads SeamState.Torn on its channel views, on both roles (#3129).

Link copied to clipboard

A different device presenting a connected member's id is refused KeyConflict, terminally, and the member keeps its seat and its key (Decided 18). Then the impostor's hold ends: the member's link to the host is torn, and its room comes back through its own reconnect — a re-weave, a Hello, the seat handed back — before its app makes any call.

Link copied to clipboard
fun expiredGrantIsVetted(): TestResult

A pass runs out, and a device that comes back after it is decided as a newcomer: the admission policy is asked once, about the device's key, and the new membership is not marked (#3223; the design's Testing, "grant expired → vetting runs").

Link copied to clipboard

A pass the host signed for the device presenting it, but for another room, is ignored.

Link copied to clipboard

A pass the host signed for this room, but naming another device's key, is ignored. The other device is a member admitted first, so the key is one the host knows.

Link copied to clipboard
fun hostFactoryAssignsHostRole(): TestResult

Losing the host ends a joiner's room the same way, so the same inference has to hold.

Link copied to clipboard
Link copied to clipboard

A host knows which room it is at construction — Room.roomId is non-null the moment RoomFactory.host returns, with no round trip and nothing to wait for.

The first collection is cancelled at the instant a frame reaches the member's inbox, and the next collection still receives that frame.

(4i) cancels the reader before it resumes, so it cannot see a room that suspends between taking a frame and handing it over — the second window in which a frame can leave an inbox unseen. Here the reader runs on a StepDispatcher. The frame is routed on the test scheduler, which queues exactly one task for the parked reader; the reader runs exactly that task and is cancelled wherever it left off. Across that collection and the next, both frames must arrive exactly once, in order: delivered by the cancelled collection, or left for the next one — never lost.

A peer with no current admission reads as an empty, completed stream — never a failure. From a consumer's side "there is no admission" and "the admission just ended" are the same fact, and a consumer claiming from a roster snapshot legitimately races both (a snapshot read just before an eviction, or just before its own Room.leave).

Link copied to clipboard

Two members, and each Room.incomingFrom holds only its own member's frames. The second member speaks first, so a room that put every frame in every inbox would hand the first member's reader the second member's frame at the head of its stream.

Frames an admitted member sends before anything collects Room.incomingFrom still reach the collector that starts afterwards, in arrival order.

Link copied to clipboard

A joiner has no identity until it is admitted, then reads the host's — one transition, to the value the host already held.

Link copied to clipboard

No cancellation may be minted when the transport's teardown SUSPENDS — the #2286 mechanism, reachable only with the injector.

Link copied to clipboard

UNGATED CORE. No leave() may report its failure as a cancellation (#1826).

"This member's reader completed while it is still listed" means a newer admission, and nothing else: eviction updates the roster before it closes the inbox. A room's own Room.leave has to keep that sentence true, or a consumer holding one reader per member reads the end of the room as a re-admission, claims again, completes at once, and spins.

The same contract from a joiner's seat, whose one member is its host.

Link copied to clipboard
fun leaveIsIdempotent(): TestResult

UNGATED CORE. leave() twice must not throw — on a host and on a joiner, whose paths differ: a joiner's leave announces a Goodbye on the still-live seam first.

Link copied to clipboard

Idempotent even when the first call FAILED — the half leaveIsIdempotent cannot reach.

Link copied to clipboard
open fun newHarness(scope: CoroutineScope): RoomConformanceSuite.RoomHarness

Provide a fresh RoomHarness for one test, using scope as the coroutine scope for background loops (SeamRoomFactory, FaultyLoom).

Link copied to clipboard
abstract fun newReturnHarness(scope: TestScope): ReturnFixture

Bind the return rows — the friction bar (#3159, Task 1.9) — to the implementation under test.

Faults only the host's FaultySeam (0) with FaultProfile.DropAll in both directions. The joiner's seam (1) stays Healthy, mirroring us.tractat.kuilt.session.PartitionRoleTest's proven partition/recovery pattern.

Link copied to clipboard

A process killed without a goodbye and started again on the same device, under the same peer id, inside the host's hold, gets the held seat back. The only app call is the relaunch's join: no token, no resume.

Link copied to clipboard

A process killed and started again under a fresh peer id, while the host holds its old seat, inherits that seat: the old id leaves Superseded(by) the new one, which joins — one pair of events, heard by the host and by a member who stayed — and the key holds one seat, not two.

Link copied to clipboard
fun rejoinAfterLeaveWorks(): TestResult
Link copied to clipboard

Resumed marks the end of a partition, once per partition (plan Amendment E): two drops, two Resumeds on the host, and the device's room says it was restored each time. Then a return the host never saw as a partition — a process killed and relaunched under the same id before the host noticed it go — gets its seat back with no Resumed at all, since nothing was partitioned.

Link copied to clipboard
fun returnInsideGrantNoVetting(): TestResult

The headline relaunch (#3222): an app killed without a goodbye, and gone past the host's hold, is opened again. The new process presents a fresh peer id over the device's one key store, and comes back on the pass the first one kept: the admission policy is not asked, and the host and a member who stayed both hear Joined(new, ReturningMark(old)), naming the id the seat had. The relaunch's join is the app's only call.

Link copied to clipboard

A device whose link tears and heals comes back to the seat the host held for it: the same id, the same key, one Resumed, and no departure or new member — with no call from the app.

Link copied to clipboard
fun revokedSubjectIsVetted(): TestResult

A device revoked after its pass was issued is decided as a newcomer when it comes back: the pass is void, so the admission policy is asked once and the membership is not marked (Decided 14, 27). Revoking voids passes and is not a ban: the admission gives the device a fresh pass, dated after the cutoff, and on that one it comes back unvetted.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun untrustedIssuerIsIgnored(): TestResult

A pass for the device presenting it and for this room, signed by a key that is not the host's, is ignored.