From ad9ba4c2a439c8ef464e34c19696300519e134b6 Mon Sep 17 00:00:00 2001
From: cai <cai@nbcai.cc>
Date: Sat, 08 Aug 2026 18:53:33 +0800
Subject: [PATCH] test: assert per-session ASR NDJSON metadata
---
src/main.rs | 100 +++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 87 insertions(+), 13 deletions(-)
diff --git a/src/main.rs b/src/main.rs
index eed3859..eeb7158 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3043,25 +3043,14 @@
if !was_in_speech && is_in_speech {
let turn_id = format!("turn-{:04}", vad.turn_index);
- let ingress_metadata = match AudioIngressMetadata::from_participant(
- &participant.attributes(),
- ) {
- Ok(value) => value,
- Err(reason) => {
- warn!(call_id = %call_id, trace_id = %trace_id,
- turn_id = %turn_id, metadata_status = "invalid", reason = reason,
- "runtime helper ignored invalid audio ingress metadata");
- None
- }
- };
- match RealtimeAsrUpload::start(
+ match RealtimeAsrUpload::start_with_participant_attributes(
http.clone(),
turn_bridge_config.realtime_asr_config(),
&call_id,
&trace_id,
&turn_id,
&vad.speech_samples,
- ingress_metadata.as_ref(),
+ || participant.attributes(),
) {
Ok(upload) => {
info!(
@@ -3962,6 +3951,91 @@
use std::collections::HashSet;
#[test]
+ fn production_vad_session_boundary_reads_updated_attributes() {
+ let config = SimpleVadConfig {
+ rms_threshold: 0.001,
+ peak_threshold: 0.01,
+ start_frames: 2,
+ end_silence_ms: 100,
+ min_speech_ms: 1,
+ max_turn_ms: 1_000,
+ initial_ignore_ms: 0,
+ };
+ let mut vad = SimpleVad::new(config);
+ let samples = vec![1_000i16; 160];
+ let frame = AudioFrame {
+ data: samples.as_slice().into(),
+ sample_rate: 16_000,
+ num_channels: 1,
+ samples_per_channel: 160,
+ };
+ let mut attributes = std::collections::HashMap::from([
+ (
+ "inputSourceCategory".to_string(),
+ "controlled_fixture".to_string(),
+ ),
+ (
+ "clientFixtureSequence".to_string(),
+ "fixture-01".to_string(),
+ ),
+ ]);
+ let mut starts = Vec::new();
+ for (session_index, sequence) in [(1, "fixture-01"), (2, "fixture-02")] {
+ let was_in_speech = vad.in_speech;
+ vad.observe_frame(
+ "call-001",
+ "trace-001",
+ "participant",
+ "track",
+ session_index * 2 - 1,
+ 1_000 * session_index,
+ &frame,
+ );
+ vad.observe_frame(
+ "call-001",
+ "trace-001",
+ "participant",
+ "track",
+ session_index * 2,
+ 1_000 * session_index + 10,
+ &frame,
+ );
+ let is_in_speech = vad.in_speech;
+ assert!(!was_in_speech && is_in_speech);
+ attributes.insert("clientFixtureSequence".to_string(), sequence.to_string());
+ let metadata = AudioIngressMetadata::from_participant(&attributes)
+ .expect("valid participant attributes")
+ .expect("controlled fixture metadata");
+ let session_line = asr_realtime::session_start_line(
+ "call-001",
+ "trace-001",
+ &format!("turn-{session_index:04}"),
+ "nonce-001",
+ Some(&metadata),
+ )
+ .expect("session start line");
+ let session_json: serde_json::Value =
+ serde_json::from_slice(&session_line).expect("session start json");
+ assert_eq!(sequence, session_json["clientFixtureSequence"]);
+ starts.push(metadata.client_fixture_sequence);
+ vad.reset_current_turn();
+ }
+ assert_eq!(vec!["fixture-01", "fixture-02"], starts);
+ attributes.insert("inputSourceCategory".to_string(), "other".to_string());
+ assert!(AudioIngressMetadata::from_participant(&attributes).is_err());
+ assert!(
+ AudioIngressMetadata::from_participant(&std::collections::HashMap::new())
+ .expect("missing attributes is absent")
+ .is_none()
+ );
+ attributes.insert(
+ "clientFixtureSequence".to_string(),
+ "fixture-01".to_string(),
+ );
+ assert!(AudioIngressMetadata::from_participant(&attributes).is_err());
+ }
+
+ #[test]
fn reply_chunk_marker_state_emits_turn_first_once_and_later_segment_first_once() {
let mut state = ReplyChunkMarkerState::default();
--
Gitblit v1.9.3