From 4e007a5fb0e1bfd90c3dc6857eb460c00b2058ed Mon Sep 17 00:00:00 2001 From: William Dunn Date: Wed, 11 Nov 2026 22:06:11 -0500 Subject: [PATCH] craft-esign add the missing regression test for the capabilities race The is_caps_reply guard from the earlier commit had no test of its own. A reply from a replaced backend now provably cannot overwrite the new backend's capabilities, responsible party or linked state. --- crates/ui/src/esign/coderabbit_repro.rs | 33 ++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/crates/ui/src/esign/coderabbit_repro.rs b/crates/ui/src/esign/coderabbit_repro.rs index 88d875d29..c7c954002 100644 --- a/crates/ui/src/esign/coderabbit_repro.rs +++ b/crates/ui/src/esign/coderabbit_repro.rs @@ -6,9 +6,40 @@ use craft_esign::{Envelope, EnvelopeStatus}; -use super::review_repro::{envelope_for, ready, send, who}; +use super::review_repro::{Hold, envelope_for, ready, send, who}; use super::*; +/// Only one capabilities probe is ever outstanding for the current backend. +/// `set_backend` clears `caps_seq`, but a reply already in flight from the +/// backend being replaced keeps its old sequence number: it must not +/// overwrite capabilities, responsible or linked for the new backend when +/// it finally arrives. +#[test] +fn a_capabilities_reply_from_a_replaced_backend_does_not_overwrite_the_new_ones() { + let hold_a = Hold::default(); + let mut dialog = EsignDialog::default(); + dialog.set_backend(hold_a.clone()); + dialog.pump(0.0); + let (_, caps_a) = hold_a.take(|r| matches!(r, Request::Capabilities)); + + // The backend is replaced before A's capabilities probe answers. + let hold_b = Hold::default(); + dialog.set_backend(hold_b.clone()); + dialog.pump(0.1); + let (_, caps_b) = hold_b.take(|r| matches!(r, Request::Capabilities)); + + caps_b.answer(Answer::Capabilities { capabilities: vec![EsignCapability::Envelopes], responsible_party: "B".into(), linked: true }); + dialog.pump(0.2); + assert_eq!(dialog.responsible.as_deref(), Some("B")); + + // A's reply, from the replaced backend, arrives after B's already installed. + caps_a.answer(Answer::Capabilities { capabilities: vec![EsignCapability::Void], responsible_party: "A".into(), linked: false }); + dialog.pump(0.3); + + assert_eq!(dialog.responsible.as_deref(), Some("B"), "a stale Capabilities reply from a replaced backend overwrote the new backend's"); + assert!(dialog.linked, "a stale Capabilities reply from a replaced backend turned linked back off"); +} + /// A document's revision changing is itself a context change: a reply for /// the bytes under the old `document_etag` must not install under the new /// one, even though the document id never changed.