refactor(cleanup-05): remove flat approval/status fields from SessionSnapshot
This commit is contained in:
@@ -117,28 +117,26 @@ object SessionsReducer {
|
||||
sessionState: SessionsState,
|
||||
msg: ServerMessage.SessionSnapshot,
|
||||
): Pair<SessionsState, List<Effect>> {
|
||||
val approvalRequestId = msg.approvalRequestId
|
||||
val approvalInfo = if (msg.pendingApproval && approvalRequestId != null) {
|
||||
val firstPending = msg.pendingApprovals.firstOrNull()
|
||||
val approvalInfo = firstPending?.let {
|
||||
ApprovalInfo(
|
||||
requestId = approvalRequestId,
|
||||
requestId = it.requestId,
|
||||
sessionId = msg.sessionId.value,
|
||||
tier = msg.approvalTier ?: "T2",
|
||||
tier = it.tier,
|
||||
riskSummary = "unknown",
|
||||
toolName = msg.approvalToolName,
|
||||
preview = msg.approvalPreview,
|
||||
toolName = null,
|
||||
preview = null,
|
||||
)
|
||||
} else null
|
||||
}
|
||||
val status = if (firstPending != null) "PAUSED awaiting approval" else msg.state.status
|
||||
val summary = SessionSummary(
|
||||
id = msg.sessionId.value,
|
||||
status = when {
|
||||
msg.pendingApproval -> "PAUSED awaiting approval"
|
||||
else -> msg.status
|
||||
},
|
||||
workflowId = msg.workflowId,
|
||||
name = msg.workflowId,
|
||||
status = status,
|
||||
workflowId = msg.sessionId.value,
|
||||
name = msg.sessionId.value,
|
||||
lastEventAt = clock(),
|
||||
currentStage = msg.currentStageId,
|
||||
currentStageId = msg.currentStageId,
|
||||
currentStage = msg.state.currentStageId,
|
||||
currentStageId = msg.state.currentStageId,
|
||||
pendingApproval = approvalInfo,
|
||||
)
|
||||
val selected = sessionState.selectedId ?: msg.sessionId.value
|
||||
|
||||
@@ -290,42 +290,24 @@ class SessionsReducerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `SessionSnapshot with pendingApproval populates pendingApproval on summary`() {
|
||||
fun `SessionSnapshot with pendingApprovals populates pendingApproval on summary`() {
|
||||
val msg = ServerMessage.SessionSnapshot(
|
||||
sessionId = SessionId("s1"),
|
||||
workflowId = "wf",
|
||||
status = "PAUSED",
|
||||
currentStageId = null,
|
||||
pauseReason = null,
|
||||
pendingApproval = true,
|
||||
approvalRequestId = "r9",
|
||||
approvalTier = "T2",
|
||||
approvalToolName = "bash",
|
||||
approvalPreview = "preview text",
|
||||
state = com.correx.apps.server.protocol.SessionStateDto("PAUSED", null, null),
|
||||
pendingApprovals = emptyList(),
|
||||
pendingApprovals = listOf(com.correx.apps.server.protocol.ApprovalDto(requestId = "r9", tier = "T2")),
|
||||
lastSequence = 1L,
|
||||
lastSessionSequence = 1L,
|
||||
)
|
||||
val (state, _) = reduce(action = Action.ServerEventReceived(msg))
|
||||
assertEquals("r9", state.sessions[0].pendingApproval?.requestId)
|
||||
assertEquals("bash", state.sessions[0].pendingApproval?.toolName)
|
||||
assertEquals("PAUSED awaiting approval", state.sessions[0].status)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `SessionSnapshot without pendingApproval leaves pendingApproval null`() {
|
||||
fun `SessionSnapshot without pendingApprovals leaves pendingApproval null`() {
|
||||
val msg = ServerMessage.SessionSnapshot(
|
||||
sessionId = SessionId("s1"),
|
||||
workflowId = "wf",
|
||||
status = "ACTIVE",
|
||||
currentStageId = null,
|
||||
pauseReason = null,
|
||||
pendingApproval = false,
|
||||
approvalRequestId = null,
|
||||
approvalTier = null,
|
||||
approvalToolName = null,
|
||||
approvalPreview = null,
|
||||
state = com.correx.apps.server.protocol.SessionStateDto("PAUSED", null, null),
|
||||
state = com.correx.apps.server.protocol.SessionStateDto("ACTIVE", null, null),
|
||||
pendingApprovals = emptyList(),
|
||||
lastSequence = 1L,
|
||||
lastSessionSequence = 1L,
|
||||
|
||||
@@ -108,15 +108,6 @@ class SnapshotPhaseReducerTest {
|
||||
val state = TuiState(snapshotPhase = true)
|
||||
val snapshot = ServerMessage.SessionSnapshot(
|
||||
sessionId = SessionId("s1"),
|
||||
workflowId = "wf",
|
||||
status = "ACTIVE",
|
||||
currentStageId = null,
|
||||
pauseReason = null,
|
||||
pendingApproval = false,
|
||||
approvalRequestId = null,
|
||||
approvalTier = null,
|
||||
approvalToolName = null,
|
||||
approvalPreview = null,
|
||||
state = SessionStateDto(status = "ACTIVE", currentStageId = null, pauseReason = null),
|
||||
pendingApprovals = emptyList(),
|
||||
lastSequence = 1L,
|
||||
|
||||
Reference in New Issue
Block a user