From 594d7aa3f24cc5a5fa6a12f68718cd2851059bac Mon Sep 17 00:00:00 2001
From: cai <cai@nbcai.cc>
Date: Tue, 11 Aug 2026 21:30:36 +0800
Subject: [PATCH] test(helper): cover pre-audio probe order

---
 src/main.rs |   95 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 94 insertions(+), 1 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index 94b6589..43d1737 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4345,7 +4345,7 @@
 mod tests {
     use super::*;
     use std::{
-        collections::HashSet,
+        collections::{HashMap, HashSet},
         io::{Read, Write},
         net::TcpListener,
         sync::{
@@ -4356,6 +4356,54 @@
         thread,
         time::Duration,
     };
+
+    #[derive(Debug)]
+    enum PreAudioOrderEvent {
+        DataReceived {
+            sender: String,
+            sequence: String,
+        },
+        TrackSubscribed {
+            participant: String,
+            attributes: HashMap<String, String>,
+        },
+    }
+
+    fn drive_pre_audio_order_test_seam(events: &[PreAudioOrderEvent]) -> Vec<&'static str> {
+        let mut pending_sequence = None;
+        let mut effects = Vec::new();
+        for event in events {
+            match event {
+                PreAudioOrderEvent::DataReceived { sender, sequence } if sender == "user-1" => {
+                    pending_sequence = Some(sequence.as_str());
+                }
+                PreAudioOrderEvent::TrackSubscribed {
+                    participant,
+                    attributes,
+                } => {
+                    let pending = pending_sequence.is_some();
+                    let probe_result = pending_sequence.map(|sequence| {
+                        classify_controlled_fixture_attributes(
+                            participant,
+                            Some("user-1"),
+                            attributes,
+                            sequence,
+                        )
+                        .is_ok()
+                    });
+                    if controlled_fixture_observer_gate(pending, probe_result) {
+                        if pending && probe_result == Some(true) {
+                            effects.push("ack_observed");
+                        }
+                        effects.push("observer_started");
+                    }
+                    pending_sequence = None;
+                }
+                PreAudioOrderEvent::DataReceived { .. } => {}
+            }
+        }
+        effects
+    }
 
     #[test]
     fn production_vad_session_boundary_reads_updated_attributes() {
@@ -5020,4 +5068,49 @@
         assert!(!controlled_fixture_observer_gate(true, Some(false)));
         assert!(!controlled_fixture_observer_gate(true, None));
     }
+
+    #[test]
+    fn production_event_order_probe_then_track_publishes_ack_before_observer() {
+        let attributes = HashMap::from([
+            (
+                "inputSourceCategory".to_string(),
+                "controlled_fixture".to_string(),
+            ),
+            (
+                "clientFixtureSequence".to_string(),
+                "fixture-01".to_string(),
+            ),
+        ]);
+        let effects = drive_pre_audio_order_test_seam(&[
+            PreAudioOrderEvent::DataReceived {
+                sender: "user-1".to_string(),
+                sequence: "fixture-01".to_string(),
+            },
+            PreAudioOrderEvent::TrackSubscribed {
+                participant: "user-1".to_string(),
+                attributes,
+            },
+        ]);
+        assert_eq!(effects, ["ack_observed", "observer_started"]);
+    }
+
+    #[test]
+    fn production_event_order_negative_probe_has_no_observer_or_session_effect() {
+        let mut invalid = HashMap::new();
+        invalid.insert(
+            "inputSourceCategory".to_string(),
+            "ordinary_mic".to_string(),
+        );
+        let effects = drive_pre_audio_order_test_seam(&[
+            PreAudioOrderEvent::DataReceived {
+                sender: "user-1".to_string(),
+                sequence: "fixture-01".to_string(),
+            },
+            PreAudioOrderEvent::TrackSubscribed {
+                participant: "user-1".to_string(),
+                attributes: invalid,
+            },
+        ]);
+        assert!(effects.is_empty());
+    }
 }

--
Gitblit v1.9.3