fix(tui): use takeLast(3) for events, add bridge/TUI tests for snapshot recentEvents
- Change EventHistoryStrip take(3) to takeLast(3) so it shows the 3 most recent events instead of the 3 oldest (chronological order is oldest-first) - Add bridge test confirming replaySnapshot populates recentEvents from the event store (with 3 different event types mapped correctly) - Add TUI SessionsReducer test confirming processSessionSnapshotMessage maps EventEntryDto entries from the snapshot into TuiEventEntry on the summary
This commit is contained in:
@@ -36,7 +36,7 @@ fun eventHistoryStripWidget(state: TuiState): Paragraph {
|
||||
|
||||
// Recent events (plain text, compact format) — capped to fit allocated height.
|
||||
// Line 0 = stage info, lines 1-3 = events (max 3).
|
||||
val events = selectedSession.recentEvents.take(3)
|
||||
val events = selectedSession.recentEvents.takeLast(3)
|
||||
if (events.isEmpty()) {
|
||||
add(Line.from(Span.styled("no events", dimStyle)))
|
||||
} else {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.correx.apps.tui.reducer
|
||||
import com.correx.apps.server.protocol.ApprovalDecision
|
||||
import com.correx.apps.server.protocol.ApprovalDto
|
||||
import com.correx.apps.server.protocol.ClientMessage
|
||||
import com.correx.apps.server.protocol.EventEntryDto
|
||||
import com.correx.apps.server.protocol.PauseReason
|
||||
import com.correx.apps.server.protocol.RiskSummaryDto
|
||||
import com.correx.apps.server.protocol.ServerMessage
|
||||
@@ -363,4 +364,29 @@ class SessionsReducerTest {
|
||||
val (state, _) = reduce(action = Action.ServerEventReceived(msg))
|
||||
assertEquals(null, state.sessions[0].pendingApproval)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `SessionSnapshot recentEvents are mapped to TuiEventEntry on summary`() {
|
||||
val msg = ServerMessage.SessionSnapshot(
|
||||
sessionId = SessionId("s1"),
|
||||
workflowId = "wf-1",
|
||||
state = SessionStateDto("COMPLETED", null, null),
|
||||
pendingApprovals = emptyList(),
|
||||
recentEvents = listOf(
|
||||
EventEntryDto(timestamp = 1000L, type = "StageStarted", detail = "stage-1"),
|
||||
EventEntryDto(timestamp = 2000L, type = "InferenceCompleted", detail = "stage-1"),
|
||||
EventEntryDto(timestamp = 3000L, type = "SessionCompleted", detail = ""),
|
||||
),
|
||||
lastSequence = 1L,
|
||||
lastSessionSequence = 1L,
|
||||
)
|
||||
val (state, _) = reduce(action = Action.ServerEventReceived(msg))
|
||||
val events = state.sessions[0].recentEvents
|
||||
assertEquals(3, events.size)
|
||||
assertEquals("StageStarted", events[0].type)
|
||||
assertEquals("stage-1", events[0].detail)
|
||||
assertEquals("InferenceCompleted", events[1].type)
|
||||
assertEquals("SessionCompleted", events[2].type)
|
||||
assertEquals("", events[2].detail)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user