From c8464e075cc66704c0f9210113a3b852121c5d2a Mon Sep 17 00:00:00 2001
From: cai <cai@nbcai.cc>
Date: Sat, 08 Aug 2026 18:55:07 +0800
Subject: [PATCH] test: cover participant binding rejection

---
 src/main.rs |   25 +++++++++++++++++++++----
 1 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index eeb7158..9b08934 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -737,6 +737,10 @@
     })
 }
 
+fn is_bound_user_participant(identity: &str, expected: Option<&str>) -> bool {
+    expected.is_none_or(|value| identity == value)
+}
+
 async fn observe_user_audio_events(
     mut events: UnboundedReceiver<RoomEvent>,
     call_id: String,
@@ -771,10 +775,10 @@
                 publication: _,
                 participant,
             } => {
-                if user_participant_identity
-                    .as_deref()
-                    .is_some_and(|expected| participant.identity().to_string() != expected)
-                {
+                if !is_bound_user_participant(
+                    &participant.identity().to_string(),
+                    user_participant_identity.as_deref(),
+                ) {
                     warn!(call_id = %call_id, trace_id = %trace_id,
                         metadata_status = "wrong_participant",
                         "runtime helper ignored non-user audio participant");
@@ -4036,6 +4040,19 @@
     }
 
     #[test]
+    fn production_observer_rejects_wrong_participant_before_vad_session() {
+        assert!(!is_bound_user_participant(
+            "participant-other",
+            Some("participant-user")
+        ));
+        assert!(is_bound_user_participant(
+            "participant-user",
+            Some("participant-user")
+        ));
+        assert!(is_bound_user_participant("participant-any", None));
+    }
+
+    #[test]
     fn reply_chunk_marker_state_emits_turn_first_once_and_later_segment_first_once() {
         let mut state = ReplyChunkMarkerState::default();
 

--
Gitblit v1.9.3