diff --git a/crates/ui/src/esign/coderabbit_round2_repro.rs b/crates/ui/src/esign/coderabbit_round2_repro.rs index 96fe9d1f5..8eae9a84b 100644 --- a/crates/ui/src/esign/coderabbit_round2_repro.rs +++ b/crates/ui/src/esign/coderabbit_round2_repro.rs @@ -70,3 +70,35 @@ fn reset_capabilities_reprobes_the_same_backend_after_an_out_of_band_sign_in() { assert!(dialog.linked, "reset_capabilities did not pick up the backend's new linked state"); } + +/// The captured send context belongs only to the create submission that +/// answers a taken [`SendRequest`]. A status refresh submitted for the +/// current document while another document's send is still outstanding must +/// carry the current context, or `pump` drops its reply as belonging to the +/// abandoned send. +#[test] +fn status_for_the_current_document_is_not_consumed_by_an_outstanding_send_from_another() { + let (mut dialog, hold) = ready(); + + // Document A's send is taken by the app but never submitted: its captured + // context stays pending. + dialog.open("doc-A".into(), "A.pdf".into(), None, who("alice")); + send(&mut dialog, b"A bytes"); + + // The dialog moves on to document B, which already has an envelope the + // host wants a status for. + dialog.open("doc-B".into(), "B.pdf".into(), None, who("alice")); + dialog.envelope = Some(envelope_for("doc-B", "alice")); + let env_id = dialog.envelope.as_ref().map(|e| e.id.clone()).unwrap_or_default(); + + dialog.submit_request(Request::Status { envelope: env_id }); + let (_, status) = hold.take(|r| matches!(r, Request::Status { .. })); + status.answer(Answer::Status(Envelope { status: EnvelopeStatus::Completed, ..envelope_for("doc-B", "alice") })); + dialog.pump(1.0); + + assert_eq!( + dialog.envelope.as_ref().map(|e| e.status), + Some(EnvelopeStatus::Completed), + "B's status reply was dropped because the status request consumed A's outstanding send context" + ); +} diff --git a/crates/ui/src/esign/mod.rs b/crates/ui/src/esign/mod.rs index 244db54ba..64087bbd5 100644 --- a/crates/ui/src/esign/mod.rs +++ b/crates/ui/src/esign/mod.rs @@ -378,7 +378,16 @@ impl EsignDialog { /// install under whichever context happens to be current when this is /// finally called. pub fn submit_request(&mut self, request: Request) { - let context = self.pending_send_context.take().unwrap_or_else(|| self.current_context()); + // The captured send context belongs to the create submission answering + // a taken [`SendRequest`], and to nothing else. A status refresh (or + // any other request) submitted while that send is still outstanding is + // the current document's business: tagging it with the old send's + // context would make `pump` drop its reply as stale. + let context = if matches!(request, Request::Create { .. }) { + self.pending_send_context.take().unwrap_or_else(|| self.current_context()) + } else { + self.current_context() + }; // A public `Request::Status` submission is request-specific routing // state too: without this, `pump`'s `status_seq` guard never sees // this sequence and drops the reply that comes back for it.