fix: complete all P2 audit findings — dead code, NPE guard, hygiene
P2-1: Guard SessionId NPE with safe-call in SessionsReducer
P2-2: Remove 16 dead event classes + reducer branches; replace with live orchestration events in tests
P2-3: Standardize ChatInput divergences — guard CancelSession, single-arg ProtocolError
P2-4: Remove dead TuiToolRecord.diff and ToolDisplayStatus.REQUESTED
P2-5: Remove dead streamLive from SessionEventBridge
P2-6: Extract SessionsReducerContext data class for 6+ param method
P2-7: Replace StageId("none") sentinel with TypeId.NONE
P2-9: Add TypeId.random() factory on all type-alias IDs
P2-10: Add KDoc on schemaVersion documenting reserved-for-migration
P2-8: Verified RouterReducer string-template already correct (TypeId value class toString)
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
import com.correx.core.events.events.SessionCompletedEvent
|
||||
import com.correx.core.events.events.SessionFailedEvent
|
||||
import com.correx.core.events.events.SessionPausedEvent
|
||||
import com.correx.core.events.events.SessionResumedEvent
|
||||
import com.correx.core.events.events.SessionStartedEvent
|
||||
import com.correx.core.events.events.OrchestrationPausedEvent
|
||||
import com.correx.core.events.events.OrchestrationResumedEvent
|
||||
import com.correx.core.events.events.StageCompletedEvent
|
||||
import com.correx.core.events.events.StageFailedEvent
|
||||
import com.correx.core.events.events.StageStartedEvent
|
||||
import com.correx.core.events.events.TransitionExecutedEvent
|
||||
import com.correx.core.events.events.WorkflowCompletedEvent
|
||||
import com.correx.core.events.events.WorkflowFailedEvent
|
||||
import com.correx.core.events.events.WorkflowStartedEvent
|
||||
import com.correx.core.events.types.SessionId
|
||||
import com.correx.core.events.types.StageId
|
||||
import com.correx.core.events.types.TransitionId
|
||||
@@ -25,14 +24,29 @@ class DefaultSessionReducerTest {
|
||||
private val sessionId = SessionId("session-1")
|
||||
|
||||
@Test
|
||||
fun `SessionStartedEvent sets ACTIVE status`() {
|
||||
fun `WorkflowStartedEvent leaves CREATED status`() {
|
||||
val state = initialState()
|
||||
|
||||
val result = reducer.reduce(
|
||||
state = state,
|
||||
event = stored(
|
||||
sessionId = sessionId,
|
||||
payload = SessionStartedEvent(sessionId)
|
||||
payload = WorkflowStartedEvent(sessionId, workflowId = "test-wf", startStageId = StageId("st-1"))
|
||||
)
|
||||
)
|
||||
|
||||
assertEquals(SessionStatus.CREATED, result.status)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `OrchestrationPausedEvent leaves ACTIVE status`() {
|
||||
val state = activeState()
|
||||
|
||||
val result = reducer.reduce(
|
||||
state = state,
|
||||
event = stored(
|
||||
sessionId = sessionId,
|
||||
payload = OrchestrationPausedEvent(sessionId, stageId = StageId("st-1"), reason = "APPROVAL_PENDING")
|
||||
)
|
||||
)
|
||||
|
||||
@@ -40,14 +54,14 @@ class DefaultSessionReducerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `SessionPausedEvent sets PAUSED status`() {
|
||||
val state = activeState()
|
||||
fun `OrchestrationResumedEvent leaves PAUSED status`() {
|
||||
val state = pausedState()
|
||||
|
||||
val result = reducer.reduce(
|
||||
state = state,
|
||||
event = stored(
|
||||
sessionId = sessionId,
|
||||
payload = SessionPausedEvent(sessionId)
|
||||
payload = OrchestrationResumedEvent(sessionId, stageId = StageId("st-1"))
|
||||
)
|
||||
)
|
||||
|
||||
@@ -55,14 +69,14 @@ class DefaultSessionReducerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `SessionResumedEvent sets ACTIVE status`() {
|
||||
val state = pausedState()
|
||||
fun `WorkflowCompletedEvent leaves ACTIVE status`() {
|
||||
val state = activeState()
|
||||
|
||||
val result = reducer.reduce(
|
||||
state = state,
|
||||
event = stored(
|
||||
sessionId = sessionId,
|
||||
payload = SessionResumedEvent(sessionId)
|
||||
payload = WorkflowCompletedEvent(sessionId, terminalStageId = StageId("st-1"), totalStages = 0)
|
||||
)
|
||||
)
|
||||
|
||||
@@ -70,46 +84,32 @@ class DefaultSessionReducerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `SessionCompletedEvent sets COMPLETED status`() {
|
||||
fun `WorkflowFailedEvent leaves ACTIVE status`() {
|
||||
val state = activeState()
|
||||
|
||||
val result = reducer.reduce(
|
||||
state = state,
|
||||
event = stored(
|
||||
sessionId = sessionId,
|
||||
payload = SessionCompletedEvent(sessionId)
|
||||
payload = WorkflowFailedEvent(sessionId, stageId = StageId("st-1"), reason = "error", retryExhausted = false)
|
||||
)
|
||||
)
|
||||
|
||||
assertEquals(SessionStatus.COMPLETED, result.status)
|
||||
assertEquals(SessionStatus.ACTIVE, result.status)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `SessionFailedEvent sets FAILED status`() {
|
||||
val state = activeState()
|
||||
|
||||
val result = reducer.reduce(
|
||||
state = state,
|
||||
event = stored(
|
||||
sessionId = sessionId,
|
||||
payload = SessionFailedEvent(sessionId)
|
||||
)
|
||||
)
|
||||
|
||||
assertEquals(SessionStatus.FAILED, result.status)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `StageStartedEvent sets ACTIVE status`() {
|
||||
fun `TransitionExecutedEvent from StageStartedEvent sets ACTIVE status`() {
|
||||
val state = pausedState()
|
||||
|
||||
val result = reducer.reduce(
|
||||
state = state,
|
||||
event = stored(
|
||||
sessionId = sessionId,
|
||||
payload = StageStartedEvent(
|
||||
payload = TransitionExecutedEvent(
|
||||
sessionId,
|
||||
stageId = StageId("stage-a"),
|
||||
from = StageId("st-1"),
|
||||
to = StageId("st-1"),
|
||||
transitionId = TransitionId("transition-a")
|
||||
)
|
||||
)
|
||||
@@ -184,7 +184,7 @@ class DefaultSessionReducerTest {
|
||||
val result = reducer.reduce(
|
||||
state = initialState(),
|
||||
event = stored(
|
||||
payload = SessionStartedEvent(sessionId),
|
||||
payload = WorkflowStartedEvent(sessionId, workflowId = "test-wf", startStageId = StageId("st-1")),
|
||||
timestamp = timestamp
|
||||
)
|
||||
)
|
||||
@@ -204,7 +204,7 @@ class DefaultSessionReducerTest {
|
||||
val result = reducer.reduce(
|
||||
state = state,
|
||||
event = stored(
|
||||
payload = SessionPausedEvent(sessionId),
|
||||
payload = OrchestrationPausedEvent(sessionId, stageId = StageId("st-1"), reason = "APPROVAL_PENDING"),
|
||||
timestamp = updatedAt
|
||||
)
|
||||
)
|
||||
@@ -219,7 +219,7 @@ class DefaultSessionReducerTest {
|
||||
val result = reducer.reduce(
|
||||
state = activeState(),
|
||||
event = stored(
|
||||
payload = SessionPausedEvent(sessionId),
|
||||
payload = OrchestrationPausedEvent(sessionId, stageId = StageId("st-1"), reason = "APPROVAL_PENDING"),
|
||||
timestamp = timestamp
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user