* fix(#206): read clarify.request question/choices from gateway The Hermes TUI gateway sends clarify.request payloads with "question" and "choices" fields, but the Android parser was looking for "text" and "options" — so the text was always null and the dialog showed only the input box. Fix reads "question"/"choices" first, falls back to "text"/"options" for backward compat. Test added for the new field names; existing test for legacy names still passes. * fix(#206): clear default text in clarify input field The input box was pre-filled with the clarify question text because the initial state was set to clarify.text instead of empty string. * fix: use JsonRpcResponse instead of undefined WsResponse in EventParserTest --------- Co-authored-by: M57 <hy4ri@users.noreply.github.com>
This commit is contained in:
1 parent
e7b2973c1c
commit
1bd56270b3
3 files changed
+35
-3
No files matched your search
@@ -81,8 +81,14 @@ object EventParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
"clarify.request" -> {
|
"clarify.request" -> {
|
||||||
val text = payload?.get("text") as? String
|
// Gateway sends "question"/"choices" — fall back to "text"/"options" for any
|
||||||
val rawOptions = payload?.get("options")
|
// older client or test that still uses the legacy field names. (Issue #206)
|
||||||
|
val text =
|
||||||
|
payload?.get("question") as? String
|
||||||
|
?: payload?.get("text") as? String
|
||||||
|
val rawOptions =
|
||||||
|
payload?.get("choices")
|
||||||
|
?: payload?.get("options")
|
||||||
val clarifyId = payload?.get("clarify_id") as? String ?: payload?.get("request_id") as? String
|
val clarifyId = payload?.get("clarify_id") as? String ?: payload?.get("request_id") as? String
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
|||||||
@@ -842,7 +842,7 @@ private fun ClarifyDialog(
|
|||||||
onOptionSelected: (String) -> Unit,
|
onOptionSelected: (String) -> Unit,
|
||||||
onDismiss: () -> Unit,
|
onDismiss: () -> Unit,
|
||||||
) {
|
) {
|
||||||
var typedText by rememberSaveable(clarify.text) { mutableStateOf(clarify.text) }
|
var typedText by rememberSaveable(clarify.text) { mutableStateOf("") }
|
||||||
|
|
||||||
AlertDialog(
|
AlertDialog(
|
||||||
onDismissRequest = onDismiss,
|
onDismissRequest = onDismiss,
|
||||||
|
|||||||
@@ -173,6 +173,32 @@ class EventParserTest {
|
|||||||
assertEquals(listOf("Yes", "No"), clarifyEvent.options)
|
assertEquals(listOf("Yes", "No"), clarifyEvent.options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testParseClarifyRequest_withQuestionFields_parsesSuccessfully() {
|
||||||
|
val response =
|
||||||
|
JsonRpcResponse(
|
||||||
|
jsonrpc = "2.0",
|
||||||
|
id = null,
|
||||||
|
result = null,
|
||||||
|
error = null,
|
||||||
|
method = "event",
|
||||||
|
params =
|
||||||
|
mapOf(
|
||||||
|
"type" to "clarify.request",
|
||||||
|
"payload" to
|
||||||
|
mapOf(
|
||||||
|
"question" to "Which environment?",
|
||||||
|
"choices" to listOf("staging", "production"),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
val event = EventParser.parse(response)
|
||||||
|
assertTrue(event is WsEvent.ClarifyRequest)
|
||||||
|
val clarifyEvent = event as WsEvent.ClarifyRequest
|
||||||
|
assertEquals("Which environment?", clarifyEvent.text)
|
||||||
|
assertEquals(listOf("staging", "production"), clarifyEvent.options)
|
||||||
|
}
|
||||||
|
|
||||||
// ── TEST-07: Untested subtypes ─────────────────────────────────────
|
// ── TEST-07: Untested subtypes ─────────────────────────────────────
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in new issue
Block a user