From d6df38418adf975f7013432972f0349e7dad4453 Mon Sep 17 00:00:00 2001 From: kami Date: Mon, 25 May 2026 12:07:18 +0400 Subject: [PATCH] test(tui-03): verify Disconnected resets snapshot state and reaches ConnectionReducer --- .../correx/apps/tui/reducer/RootReducerTest.kt | 17 +++++++++++++++++ .../tui/reducer/SnapshotPhaseReducerTest.kt | 16 ++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/apps/tui/src/test/kotlin/com/correx/apps/tui/reducer/RootReducerTest.kt b/apps/tui/src/test/kotlin/com/correx/apps/tui/reducer/RootReducerTest.kt index 1232c77d..c7c76e1d 100644 --- a/apps/tui/src/test/kotlin/com/correx/apps/tui/reducer/RootReducerTest.kt +++ b/apps/tui/src/test/kotlin/com/correx/apps/tui/reducer/RootReducerTest.kt @@ -2,6 +2,7 @@ package com.correx.apps.tui.reducer import com.correx.apps.server.protocol.ClientMessage import com.correx.apps.tui.input.Action +import com.correx.apps.tui.state.ConnectionState import com.correx.apps.tui.state.InputMode import com.correx.apps.tui.state.TuiState import org.junit.jupiter.api.Assertions.assertEquals @@ -101,6 +102,22 @@ class RootReducerTest { assertEquals(1L, result.cursors["s2"]) } + @Test + fun `Disconnected resets snapshot state and sets connection to disconnected`() { + val state = TuiState( + snapshotPhase = false, + cursors = mapOf("s1" to 3L), + connection = ConnectionState(connected = true), + ) + + val (newState, _) = RootReducer.reduce(state, Action.Disconnected, fixedClock) + + assertEquals(true, newState.snapshotPhase) + assertTrue(newState.cursors.isEmpty()) + assertEquals(false, newState.connection.connected) + assertEquals(state.sessions.sessions, newState.sessions.sessions) + } + @Test fun `AppendChar followed by Backspace returns to original buffer`() { val initial = TuiState(inputMode = InputMode.ROUTER, inputBuffer = "ab") diff --git a/apps/tui/src/test/kotlin/com/correx/apps/tui/reducer/SnapshotPhaseReducerTest.kt b/apps/tui/src/test/kotlin/com/correx/apps/tui/reducer/SnapshotPhaseReducerTest.kt index 4dce6204..3958d530 100644 --- a/apps/tui/src/test/kotlin/com/correx/apps/tui/reducer/SnapshotPhaseReducerTest.kt +++ b/apps/tui/src/test/kotlin/com/correx/apps/tui/reducer/SnapshotPhaseReducerTest.kt @@ -87,6 +87,22 @@ class SnapshotPhaseReducerTest { assertEquals(8L, result.state.cursors["s1"]) } + @Test + fun `Disconnected resets snapshotPhase, pendingEvents, and cursors`() { + val state = TuiState( + snapshotPhase = false, + cursors = mapOf("s1" to 5L), + pendingEvents = listOf(ServerMessage.ProtocolError("x")), + ) + + val result = SnapshotPhaseReducer.process(state, Action.Disconnected) + + assertEquals(true, result.state.snapshotPhase) + assertTrue(result.state.pendingEvents.isEmpty()) + assertTrue(result.state.cursors.isEmpty()) + assertEquals(listOf(Action.Disconnected), result.actionsToDispatch) + } + @Test fun `during snapshotPhase SessionSnapshot installs cursor and is forwarded to sub-reducers`() { val state = TuiState(snapshotPhase = true)