chat_rudp test: a resend crosses the wire as the v3 kind and the mouth's refusal of it decodes; every refusal kind round-trips
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
65974e2196
commit
28b08e59ba
1 changed files with 20 additions and 1 deletions
|
|
@ -13,7 +13,7 @@ use std::thread::JoinHandle;
|
|||
use std::time::Duration;
|
||||
|
||||
use cultnet_rs::{CultNetMessage, CultNetRawDocumentRecord, CultNetRawPayloadEncoding, CultNetRudpSocketTransportConnection, CultNetRudpSocketTransportOptions};
|
||||
use mind_body::chat_client::{self, ReplyLink, ReplyViolation, Basis, Form, ChatRefusal, MouthRefused, Refusal, REFUSAL, ACK, Chat, ChatAck, ChatFetchReceipt, ChatFetchRequest, ChatOpenDirectReceipt, ChatOpenDirectRequest, DirectOutcome, FetchOutcome, FETCH_RECEIPT, FETCH_REQUEST, ReceiptMode, OPEN_DIRECT_RECEIPT, OPEN_DIRECT_REQUEST, ChatPending, ChatPendingRequest, ChatRead, ChatSendReceipt, ChatSendRequest, PENDING, PENDING_REQUEST, PENDING_REQUEST_V1, PENDING_REQUEST_V4, PENDING_V1, PENDING_V2, PENDING_V4, READ, SEND_RECEIPT, SEND_REQUEST};
|
||||
use mind_body::chat_client::{self, ReplyLink, ReplyViolation, Basis, Form, ChatRefusal, MouthRefused, Refusal, REFUSAL, ACK, Chat, ChatAck, ChatFetchReceipt, ChatFetchRequest, ChatOpenDirectReceipt, ChatOpenDirectRequest, DirectOutcome, FetchOutcome, FETCH_RECEIPT, FETCH_REQUEST, ReceiptMode, OPEN_DIRECT_RECEIPT, OPEN_DIRECT_REQUEST, ChatPending, ChatPendingRequest, ChatRead, ChatSendReceipt, ChatSendRequest, PENDING, PENDING_REQUEST, PENDING_REQUEST_V1, PENDING_REQUEST_V4, PENDING_V1, PENDING_V2, PENDING_V4, READ, SEND_RECEIPT, SEND_REQUEST, SEND_REQUEST_V3};
|
||||
use mind_body::chat_rudp::{RudpChat, connection_id};
|
||||
|
||||
const ACK_BYTES: &[u8] = include_bytes!("fixtures/persona-chat-v1/gamecult.persona.chat_ack.v1.msgpack");
|
||||
|
|
@ -131,6 +131,7 @@ fn serve(key: &str, bind: &str, pending_kind: &'static str, pending_bytes: &'sta
|
|||
}
|
||||
PENDING_REQUEST_V1 if pending_kind != PENDING && for_eureka(&chat_client::decode::<ChatPendingRequest>(&document.payload).unwrap().persona) => Some(answer(pending_kind, "eureka", pending_bytes)),
|
||||
SEND_REQUEST if for_eureka(&chat_client::decode::<ChatSendRequest>(&document.payload).unwrap().persona) => Some(answer(SEND_RECEIPT, &document.record_key, SEND_RECEIPT_BYTES)),
|
||||
SEND_REQUEST_V3 => Some(answer(SEND_RECEIPT, &document.record_key, &chat_client::encode(&ChatSendReceipt { request_id: document.record_key.clone(), event_id: None, refusal: Some(Refusal::ResendUnknown), newer: vec![] }).unwrap())),
|
||||
OPEN_DIRECT_REQUEST if for_eureka(&chat_client::decode::<ChatOpenDirectRequest>(&document.payload).unwrap().persona) => Some(answer(open.0, open.1.unwrap_or(&document.record_key), open.2)),
|
||||
FETCH_REQUEST if for_eureka(&chat_client::decode::<ChatFetchRequest>(&document.payload).unwrap().persona) => Some(if open.0 == REFUSAL { answer(open.0, open.1.unwrap_or(&document.record_key), open.2) } else { answer(FETCH_RECEIPT, &document.record_key, FETCH_POSTED_BYTES) }),
|
||||
_ => None,
|
||||
|
|
@ -463,3 +464,21 @@ fn a_fetch_refusal_of_another_reason_or_naming_another_persona_is_not_heard_as_n
|
|||
let error = client(&mouth, KEY, "eureka", Duration::from_secs(20)).fetch(&request).unwrap_err();
|
||||
assert!(error.downcast_ref::<MouthRefused>().is_none(), "the payload names another Persona: {error}");
|
||||
}
|
||||
|
||||
/// Soul s8 pins-on-the-wire. A resend crosses the wire as the v3 kind, not the v2 one a mouth would treat as a first send, and the mouth's refusal of it,
|
||||
/// `ResendUnknown`, decodes; a first send is the v2 kind.
|
||||
#[test]
|
||||
fn a_resend_crosses_real_rudp_as_the_v3_kind_and_the_mouths_resend_unknown_decodes() {
|
||||
let mouth = mouth(KEY);
|
||||
let chat = client(&mouth, KEY, "eureka", Duration::from_secs(5));
|
||||
let mut request = chat_client::decode::<ChatSendRequest>(SEND_REQUEST_BYTES).unwrap();
|
||||
request.resend = true;
|
||||
let receipt = chat.send(&request).unwrap();
|
||||
assert_eq!(receipt.refusal, Some(Refusal::ResendUnknown), "the v3 kind reached the mouth and its refusal decoded: {receipt:?}");
|
||||
request.resend = false;
|
||||
assert_eq!(chat.send(&request).unwrap().refusal, None, "a first send is the v2 kind");
|
||||
assert_eq!(kinds_seen(&mouth), [SEND_REQUEST_V3, SEND_REQUEST]);
|
||||
for refusal in Refusal::ALL {
|
||||
assert_eq!(chat_client::decode::<ChatSendReceipt>(&chat_client::encode(&ChatSendReceipt { request_id: "r".into(), event_id: None, refusal: Some(refusal), newer: vec![] }).unwrap()).unwrap().refusal, Some(refusal), "{} decodes", refusal.name());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue