fix(chat): support batch clarify.request payload and route question_id on respond (fixes #1045) (#1046)

This commit is contained in:
M57 authored and GitHub committed 2026-09-03 12:50:13 +03:00
1 parent dbd7008ee3
commit fa17c95296
6 files changed
+159 -1

No files matched your search

@@ -291,6 +291,42 @@ class EventParserTest {
assertEquals(listOf("staging", "production"), clarifyEvent.options)
}
@Test
fun testParseClarifyRequest_withBatchQuestions_parsesSuccessfully() {
val response =
createJsonRpcResponse(
jsonrpc = "2.0",
id = null,
result = null,
error = null,
method = "event",
params =
mapOf(
"type" to "clarify.request",
"payload" to
mapOf(
"request_id" to "req-batch-1",
"questions" to
listOf(
mapOf(
"qid" to "q0",
"question" to "Which database?",
"choices" to listOf("Postgres", "SQLite"),
"multi_select" to false,
),
),
),
),
)
val event = EventParser.parse(response)
assertTrue(event is WsEvent.ClarifyRequest)
val clarifyEvent = event as WsEvent.ClarifyRequest
assertEquals("Which database?", clarifyEvent.text)
assertEquals(listOf("Postgres", "SQLite"), clarifyEvent.options)
assertEquals("req-batch-1", clarifyEvent.clarifyId)
assertEquals("q0", clarifyEvent.questionId)
}
// ── TEST-07: Untested subtypes ─────────────────────────────────────
@Test
@@ -1217,6 +1217,54 @@ class ChatViewModelTest {
}
}
@Test
fun testClarifyRequestWithQuestionIdAndRespond() =
runTest {
val (viewModel, sessionId) = createViewModelWithSession()
mockEventsFlow.emit(
WsEvent.ClarifyRequest(
text = "Pick one:",
options = listOf("Option 1"),
clarifyId = "clarify-batch-1",
sessionId = sessionId,
questionId = "q0",
),
)
advanceUntilIdle()
assertEquals(
"Pick one:",
viewModel.uiState.value.clarifyRequest
?.text,
)
assertEquals(
"q0",
viewModel.uiState.value.clarifyRequest
?.questionId,
)
viewModel.respondToClarify("Option 1")
advanceUntilIdle()
assertNull(viewModel.uiState.value.clarifyRequest)
verify {
HermesWsClient.send(
method = WsMethods.CLARIFY_RESPOND,
params =
mapOf(
"session_id" to sessionId,
"response" to "Option 1",
"answer" to "Option 1",
"clarify_id" to "clarify-batch-1",
"request_id" to "clarify-batch-1",
"question_id" to "q0",
),
onSent = any(),
)
}
}
@Test
fun testClarifyRequestCustomResponse() =
runTest {
@@ -1316,6 +1364,53 @@ class ChatViewModelTest {
}
}
@Test
fun testClarifyDismissWithQuestionIdInformsAgent() =
runTest {
val (viewModel, sessionId) = createViewModelWithSession()
mockEventsFlow.emit(
WsEvent.ClarifyRequest(
"Please choose:",
listOf("Yes", "No"),
"clarify-789",
sessionId,
questionId = "q0",
),
)
advanceUntilIdle()
assertEquals(
"clarify-789",
viewModel.uiState.value.clarifyRequest
?.clarifyId,
)
assertEquals(
"q0",
viewModel.uiState.value.clarifyRequest
?.questionId,
)
viewModel.dismissClarify()
advanceUntilIdle()
assertNull(viewModel.uiState.value.clarifyRequest)
verify {
HermesWsClient.send(
method = WsMethods.CLARIFY_RESPOND,
params =
mapOf(
"session_id" to sessionId,
"response" to "The user cancelled — no answer provided.",
"answer" to "The user cancelled — no answer provided.",
"clarify_id" to "clarify-789",
"request_id" to "clarify-789",
"question_id" to "q0",
),
onSent = any(),
)
}
}
// ── Attachments ──────────────────────────────────────────────────────────
/** Add [count] dummy attachments so a test starts with a populated list. */