test(tui-03): add gap detection test for SnapshotPhaseReducer

This commit is contained in:
2026-05-25 11:44:24 +04:00
parent e5df09ef93
commit 919546f23b
@@ -33,6 +33,60 @@ class SnapshotPhaseReducerTest {
assertTrue(state.sessions.sessions.isEmpty())
}
@Test
fun `live event with sessionSequence at or below cursor is dropped`() {
val state = TuiState(snapshotPhase = false, cursors = mapOf("s1" to 5L))
val action = Action.ServerEventReceived(
ServerMessage.SessionStarted(
sessionId = SessionId("s1"),
workflowId = "wf",
sequence = 5L,
sessionSequence = 5L,
)
)
val result = SnapshotPhaseReducer.process(state, action)
assertTrue(result.actionsToDispatch.isEmpty())
assertEquals(5L, result.state.cursors["s1"])
}
@Test
fun `live event with sessionSequence one above cursor is applied and cursor advances`() {
val state = TuiState(snapshotPhase = false, cursors = mapOf("s1" to 5L))
val action = Action.ServerEventReceived(
ServerMessage.SessionStarted(
sessionId = SessionId("s1"),
workflowId = "wf",
sequence = 6L,
sessionSequence = 6L,
)
)
val result = SnapshotPhaseReducer.process(state, action)
assertEquals(listOf(action), result.actionsToDispatch)
assertEquals(6L, result.state.cursors["s1"])
}
@Test
fun `gap event is applied and cursor advances to incoming sequence`() {
val state = TuiState(snapshotPhase = false, cursors = mapOf("s1" to 5L))
val action = Action.ServerEventReceived(
ServerMessage.SessionStarted(
sessionId = SessionId("s1"),
workflowId = "wf",
sequence = 8L,
sessionSequence = 8L,
)
)
val result = SnapshotPhaseReducer.process(state, action)
assertEquals(listOf(action), result.actionsToDispatch)
assertEquals(8L, result.state.cursors["s1"])
}
@Test
fun `during snapshotPhase SessionSnapshot installs cursor and is forwarded to sub-reducers`() {
val state = TuiState(snapshotPhase = true)