Route the stop control's interrupt through one tested builder
Extract the single chat_interrupt frame into ChatProtocol.interruptRequest and have PipelinesRepository.chatInterrupt send it, so production and its unit test share the one wire shape instead of the repository building it inline. Add chatInterruptRequestCarriesTheRunningSession, which asserts the frame the stop control sends is chat_interrupt carrying the running session's id (and no chat prompt/reply) and that it survives the client's JSON round-trip. Document the slice and its emulator-5556 evidence in android/README.md.
This commit is contained in:
@@ -8,6 +8,7 @@ import kotlinx.serialization.json.JsonElement
|
||||
import net.awan.pipelines.data.protocol.ChatCreateRequest
|
||||
import net.awan.pipelines.data.protocol.ChatMessage
|
||||
import net.awan.pipelines.data.protocol.ChatPromptRequest
|
||||
import net.awan.pipelines.data.protocol.ChatProtocol
|
||||
import net.awan.pipelines.data.protocol.ChatQuery
|
||||
import net.awan.pipelines.data.protocol.ChatReplyRequest
|
||||
import net.awan.pipelines.data.protocol.ChatSession
|
||||
@@ -174,7 +175,7 @@ class PipelinesRepository(
|
||||
|
||||
suspend fun chatInterrupt(sessionId: String) {
|
||||
if (sessionId.isBlank()) throw ProtocolException("Select a chat session first.")
|
||||
client.call(Message(type = Protocol.CHAT_INTERRUPT, chatQuery = ChatQuery(sessionId = sessionId)))
|
||||
client.call(ChatProtocol.interruptRequest(sessionId))
|
||||
}
|
||||
|
||||
suspend fun chatReply(sessionId: String, requestId: String, decision: String, message: String = "") {
|
||||
|
||||
@@ -195,4 +195,12 @@ object ChatProtocol {
|
||||
TOOL_STREAMING, TOOL_RUNNING -> true
|
||||
else -> false
|
||||
}
|
||||
|
||||
/**
|
||||
* The `chat_interrupt` frame the composer's stop control sends: the server
|
||||
* aborts the in-flight turn for [sessionId]. Built here (not inline in the
|
||||
* repository) so production and its unit test share the one wire shape.
|
||||
*/
|
||||
fun interruptRequest(sessionId: String): Message =
|
||||
Message(type = Protocol.CHAT_INTERRUPT, chatQuery = ChatQuery(sessionId = sessionId))
|
||||
}
|
||||
|
||||
@@ -202,6 +202,27 @@ class ChatProtocolTest {
|
||||
assertEquals(ChatProtocol.DECISION_ONCE, decodedReply.chatReply!!.decision)
|
||||
}
|
||||
|
||||
/**
|
||||
* The stop control's interrupt request: pressing it while a turn is in flight
|
||||
* must send a `chat_interrupt` carrying the running session's id and nothing
|
||||
* else, and the frame must survive the wire round-trip the client performs.
|
||||
* Uses the same [ChatProtocol.interruptRequest] builder the repository sends,
|
||||
* so this test cannot drift from the production frame.
|
||||
*/
|
||||
@Test
|
||||
fun chatInterruptRequestCarriesTheRunningSession() {
|
||||
val request = ChatProtocol.interruptRequest("ses_1")
|
||||
assertEquals(Protocol.CHAT_INTERRUPT, request.type)
|
||||
assertEquals("ses_1", request.chatQuery!!.sessionId)
|
||||
|
||||
val encoded = PipelinesJson.encodeToString(Message.serializer(), request.copy(id = "android-9"))
|
||||
val decoded = PipelinesJson.decodeFromString(Message.serializer(), encoded)
|
||||
assertEquals(Protocol.CHAT_INTERRUPT, decoded.type)
|
||||
assertEquals("ses_1", decoded.chatQuery!!.sessionId)
|
||||
assertNull(decoded.chatPrompt)
|
||||
assertNull(decoded.chatReply)
|
||||
}
|
||||
|
||||
/** A non-chat envelope leaves every chat field null, so the two never cross-talk. */
|
||||
@Test
|
||||
fun nonChatEnvelopeHasNoChatPayload() {
|
||||
|
||||
Reference in New Issue
Block a user