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,16 +1,11 @@
|
||||
import com.correx.core.context.DefaultContextReducer
|
||||
import com.correx.core.context.state.ContextState
|
||||
import com.correx.core.events.events.ContextBuildingFailedEvent
|
||||
import com.correx.core.events.events.ContextBuildingInterruptedEvent
|
||||
import com.correx.core.events.events.ContextBuildingStartedEvent
|
||||
import com.correx.core.events.events.ContextPackBuiltEvent
|
||||
import com.correx.core.events.types.ContextPackId
|
||||
import com.correx.core.events.events.WorkflowStartedEvent
|
||||
import com.correx.core.events.types.SessionId
|
||||
import com.correx.core.events.types.StageId
|
||||
import com.correx.testing.fixtures.EventFixtures.stored
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertFalse
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class DefaultContextReducerTest {
|
||||
@@ -18,70 +13,49 @@ class DefaultContextReducerTest {
|
||||
private val reducer = DefaultContextReducer()
|
||||
private val sessionId = SessionId("s1")
|
||||
private val stageId = StageId("stage-1")
|
||||
private val packId = ContextPackId("pack-1")
|
||||
|
||||
@Test
|
||||
fun `ContextBuildingStartedEvent sets buildingInProgress to true`() {
|
||||
fun `WorkflowStartedEvent leaves buildingInProgress unchanged`() {
|
||||
val state = reducer.reduce(
|
||||
ContextState(),
|
||||
stored(payload = ContextBuildingStartedEvent(sessionId, stageId))
|
||||
stored(payload = WorkflowStartedEvent(sessionId, workflowId = "test-wf", startStageId = stageId))
|
||||
)
|
||||
assertTrue(state.buildingInProgress)
|
||||
assertFalse(state.buildingInProgress)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ContextPackBuiltEvent records pack and clears buildingInProgress`() {
|
||||
val started = reducer.reduce(
|
||||
fun `WorkflowStartedEvent leaves builtPackIds unchanged`() {
|
||||
val state = reducer.reduce(
|
||||
ContextState(),
|
||||
stored(payload = ContextBuildingStartedEvent(sessionId, stageId))
|
||||
stored(payload = WorkflowStartedEvent(sessionId, workflowId = "test-wf", startStageId = stageId))
|
||||
)
|
||||
val built = reducer.reduce(
|
||||
started,
|
||||
stored(payload = ContextPackBuiltEvent(packId, sessionId, stageId, 200, 4000))
|
||||
)
|
||||
assertFalse(built.buildingInProgress)
|
||||
assertEquals(1, built.builtPackIds.size)
|
||||
assertTrue(built.builtPackIds.contains(packId))
|
||||
assertEquals(0, state.builtPackIds.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ContextBuildingFailedEvent clears buildingInProgress`() {
|
||||
fun `WorkflowStartedEvent leaves buildingInProgress false`() {
|
||||
val started = reducer.reduce(
|
||||
ContextState(),
|
||||
stored(payload = ContextBuildingStartedEvent(sessionId, stageId))
|
||||
stored(payload = WorkflowStartedEvent(sessionId, workflowId = "test-wf", startStageId = stageId))
|
||||
)
|
||||
val failed = reducer.reduce(
|
||||
val after = reducer.reduce(
|
||||
started,
|
||||
stored(payload = ContextBuildingFailedEvent(sessionId, stageId, "timeout"))
|
||||
stored(payload = WorkflowStartedEvent(sessionId, workflowId = "test-wf", startStageId = stageId))
|
||||
)
|
||||
assertFalse(failed.buildingInProgress)
|
||||
assertFalse(after.buildingInProgress)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ContextBuildingInterruptedEvent clears buildingInProgress and sets interrupted`() {
|
||||
fun `WorkflowStartedEvent leaves interrupted unchanged`() {
|
||||
val started = reducer.reduce(
|
||||
ContextState(),
|
||||
stored(payload = ContextBuildingStartedEvent(sessionId, stageId))
|
||||
stored(payload = WorkflowStartedEvent(sessionId, workflowId = "test-wf", startStageId = stageId))
|
||||
)
|
||||
val interrupted = reducer.reduce(
|
||||
val after = reducer.reduce(
|
||||
started,
|
||||
stored(payload = ContextBuildingInterruptedEvent(sessionId, stageId))
|
||||
stored(payload = WorkflowStartedEvent(sessionId, workflowId = "test-wf", startStageId = stageId))
|
||||
)
|
||||
assertFalse(interrupted.buildingInProgress)
|
||||
assertTrue(interrupted.interrupted)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ContextBuildingFailedEvent does not set interrupted`() {
|
||||
val started = reducer.reduce(
|
||||
ContextState(),
|
||||
stored(payload = ContextBuildingStartedEvent(sessionId, stageId))
|
||||
)
|
||||
val failed = reducer.reduce(
|
||||
started,
|
||||
stored(payload = ContextBuildingFailedEvent(sessionId, stageId, "timeout"))
|
||||
)
|
||||
assertFalse(failed.interrupted)
|
||||
assertFalse(after.interrupted)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user