# task-023

status:
- done

## goal
Test RouterFacade — verify end-to-end orchestration for both CHAT and STEERING modes using faked dependencies.

## target artifact
testing/deterministic/src/test/kotlin/RouterFacadeTest.kt

## execution steps
- Create `RouterFacadeTest` in `testing/deterministic/src/test/kotlin/RouterFacadeTest.kt`
  - Use fakes for all four dependencies: `RouterRepository`, `RouterContextBuilder`, `InferenceRouter`, `EventStore`
  - **CHAT mode tests:**
    - `handleChat with CHAT mode returns inference response content without emitting steering event`
    - `handleChat with CHAT mode sets steeringEmitted = false`
    - `handleChat with CHAT mode does not call eventStore.append`
  - **STEERING mode tests:**
    - `handleChat with STEERING mode returns inference response content with steeringEmitted = true`
    - `handleChat with STEERING mode calls eventStore.append with SteeringNoteAddedEvent`
    - `handleChat with STEERING mode passes correct sessionId, content, and stageId to SteeringNoteAddedEvent`
  - **Orchestration integration tests:**
    - `handleChat passes state from repository to context builder`
    - `handleChat passes budget from config to context builder`
    - `handleChat uses provided stageId when given`
    - `handleChat falls back to state.currentStageId when stageId is null`
    - `handleChat falls back to StageId("none") when currentStageId is null`
    - `handleChat creates new InferenceRequestId per call`
    - `handleChat uses correct GenerationConfig defaults (temp=0.7, topP=0.9, maxTokens=512)`
- Verify compilation with `./gradlew :testing:deterministic:compileTestKotlin`
- Run tests with `./gradlew :testing:deterministic:test --tests RouterFacadeTest --rerun-tasks`

## changed artifacts
- `testing/deterministic/src/test/kotlin/RouterFacadeTest.kt` — new file (17 tests, all passing)
- `testing/deterministic/src/test/kotlin/RouterFacadeTest.kt` — fix: `facadeWithMocks()` wrapper now returns `RouterFacade` interface and delegates `handleChat` with the captured `chatMode` parameter to the real facade (previously the parameter was accepted but never used)

## blockers
- None

## notes
- 5 tests initially failed because `facadeWithMocks()` accepted a `chatMode` parameter but never passed it to `handleChat()` — `handleChat()` defaulted to `ChatMode.CHAT`, causing all STEERING mode tests to receive `steeringEmitted = false` and no `EventStore.append` calls
- Fix: wrapped `DefaultRouterFacade` in an anonymous `RouterFacade` object that hardcodes `chatMode` into the `handleChat()` delegation call, and added `RouterFacade` to the imports
- Fakes are created as anonymous inner classes / inline objects to avoid polluting the fixtures module
- `runBlocking` from kotlinx-coroutines is used to call suspend functions in JUnit tests
