Prove the always decision through the shared approval reply builder

Extend ChatApprovalTest so once, always and reject each go through the same
ChatProtocol.replyRequest builder plus one encode/decode round trip using the
DECISION_* constants, so no decision is asserted more weakly than another, and
add answeringAlwaysUpdatesTheCardInPlace (settled card, no actions, risk panel
retired, request still visible). Refresh the android/README.md verification
notes: 267 tests, the rebuilt APK's sha256 and byte size, the 147/3 artifact
path and LAN URL, and the emulator/device-lock notes for this pass.
This commit is contained in:
2026-10-16 16:57:57 +01:00
parent 305714c30f
commit ee5cd742c2
2 changed files with 70 additions and 42 deletions
@@ -65,24 +65,28 @@ class ChatApprovalTest {
}
@Test
fun onceAndRejectSendTheRightDecision() {
fun onceAlwaysAndRejectSendTheRightDecision() {
// The same builder the repository sends, so the card's actions and this
// assertion cannot drift from the wire frame.
val once = ChatProtocol.replyRequest("ses_1", "req_9", ChatProtocol.DECISION_ONCE)
assertEquals(Protocol.CHAT_REPLY, once.type)
assertEquals("ses_1", once.chatReply!!.sessionId)
assertEquals("req_9", once.chatReply!!.requestId)
assertEquals("once", once.chatReply!!.decision)
// assertion cannot drift from the wire frame. Every decision goes through
// the identical encode/decode round trip, so none is asserted more weakly
// than another.
for (decision in listOf(
ChatProtocol.DECISION_ONCE,
ChatProtocol.DECISION_ALWAYS,
ChatProtocol.DECISION_REJECT,
)) {
val reply = ChatProtocol.replyRequest("ses_1", "req_9", decision)
assertEquals(Protocol.CHAT_REPLY, reply.type)
assertEquals("ses_1", reply.chatReply!!.sessionId)
assertEquals("req_9", reply.chatReply!!.requestId)
assertEquals(decision, reply.chatReply!!.decision)
val decodedOnce = PipelinesJson.decodeFromString(
Message.serializer(),
PipelinesJson.encodeToString(Message.serializer(), once.copy(id = "android-1")),
)
assertEquals(ChatProtocol.DECISION_ONCE, decodedOnce.chatReply!!.decision)
val reject = ChatProtocol.replyRequest("ses_1", "req_9", ChatProtocol.DECISION_REJECT)
assertEquals("reject", reject.chatReply!!.decision)
assertEquals("req_9", reject.chatReply!!.requestId)
val decoded = PipelinesJson.decodeFromString(
Message.serializer(),
PipelinesJson.encodeToString(Message.serializer(), reply.copy(id = "android-1")),
)
assertEquals(decision, decoded.chatReply!!.decision)
}
}
@Test
@@ -99,6 +103,22 @@ class ChatApprovalTest {
assertEquals("req_9", store.value.thread("ses_1")!!.permission!!.requestId)
}
@Test
fun answeringAlwaysUpdatesTheCardInPlace() {
val store = storeWithPermission(frame())
store.answerPermission("ses_1", "req_9", ChatProtocol.DECISION_ALWAYS)
val settled = card(store)
assertEquals(ApprovalState.ANSWERED, settled.state)
assertFalse(settled.actionable)
assertEquals(ChatProtocol.DECISION_ALWAYS, settled.decision)
assertEquals("Always allowed", settled.headline)
// The request stays visible but stops asking; only a denial keeps the
// amber review panel, so an allow-always retires it.
assertFalse(settled.showRisk)
assertEquals("req_9", store.value.thread("ses_1")!!.permission!!.requestId)
}
@Test
fun rejectingKeepsTheRiskReviewWhileItSettles() {
val store = storeWithPermission(frame())