test: align websocket handler tests with session pipeline#10
Conversation
There was a problem hiding this comment.
Pull request overview
Updates the AiChatWebSocketHandler unit tests to match the new session-based streaming pipeline (StreamingPipelineOrchestrator + PipelineEvent) rather than the legacy AiStreamingService/voiceSessions flow.
Changes:
- Refactors tests to mock
StreamingPipelineOrchestrator.processVoiceMessage(...)and assertPipelineEvent-driven behavior. - Updates session lifecycle assertions to align with the handler’s
sessions+SessionStatemodel. - Adds coverage for forwarding binary WebSocket frames into the active audio sink.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| private void assertSessionAudioClosed() { | ||
| Object sessionState = sessions().get(SESSION_ID); | ||
| Object audioSink = ReflectionTestUtils.getField(sessionState, "audioSink"); | ||
| Object pipelineSubscription = ReflectionTestUtils.getField(sessionState, "pipelineSubscription"); | ||
| assertEquals(null, audioSink); | ||
| assertEquals(null, pipelineSubscription); |
There was a problem hiding this comment.
Use assertNull(...) (and optionally an assertion message) instead of assertEquals(null, ...) for clearer intent and better failure output when checking that audioSink / pipelineSubscription have been cleared.
| private void installSessionState(WebSocketSession session, StreamingPipelineOrchestrator orchestrator) throws Exception { | ||
| Class<?> sessionStateClass = Class.forName("com.vocata.ai.websocket.AiChatWebSocketHandler$SessionState"); | ||
| Constructor<?> constructor = sessionStateClass.getDeclaredConstructor(StreamingPipelineOrchestrator.class); | ||
| constructor.setAccessible(true); | ||
| Object sessionState = constructor.newInstance(orchestrator); | ||
|
|
There was a problem hiding this comment.
Test setup currently constructs the private inner class AiChatWebSocketHandler$SessionState via reflection (Class.forName + setAccessible). This couples the tests to handler internals and makes them brittle under refactors. If feasible, consider adding a small package-private/@VisibleForTesting hook on AiChatWebSocketHandler to register a mocked StreamingPipelineOrchestrator for a session (or extracting SessionState into a package-private type) so tests can avoid reflective access.
📌 变更内容
✅ 测试验证
PR 提交规范提醒: