fix(trunk): trait imports + remove unused (AudioSink/AudioSource) in session tests (T4 cleanup)

Signed-off-by: Aaron D. Lee <himself@adlee.work>
This commit is contained in:
2026-07-05 03:36:20 -04:00
parent a6abe24995
commit b76f0dcc4b

View File

@@ -21,9 +21,10 @@
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use rutster_media::{AudioSink, AudioSource};
use tracing::{info, warn}; use tracing::{info, warn};
use crate::session::{TrunkSession, IDLE_TIMEOUT, OUTBOUND_TICK}; use crate::session::{IDLE_TIMEOUT, OUTBOUND_TICK, TrunkSession};
/// One iteration of the trunk-leg driver. Mirrors `rutster_media::loop_driver::drive` /// One iteration of the trunk-leg driver. Mirrors `rutster_media::loop_driver::drive`
/// minus str0m. Returns the sleep-until-next-tick budget. /// minus str0m. Returns the sleep-until-next-tick budget.
@@ -56,11 +57,7 @@ pub fn drive<P: rutster_media::AudioPipe + Send>(
// Brain reply PCM; push to the WSS pump task for µ-law encode // Brain reply PCM; push to the WSS pump task for µ-law encode
// + Twilio Media Streams JSON "media" frame emission. try_send; // + Twilio Media Streams JSON "media" frame emission. try_send;
// drop + observe on full (hot-path policy). // drop + observe on full (hot-path policy).
if session if session.outbound_to_twilio_tx.try_send(reply_frame).is_err() {
.outbound_to_twilio_tx
.try_send(reply_frame)
.is_err()
{
warn!( warn!(
channel_id = %session.channel.id, channel_id = %session.channel.id,
"outbound_to_twilio_tx full; dropping brain reply frame" "outbound_to_twilio_tx full; dropping brain reply frame"
@@ -98,8 +95,7 @@ mod tests {
// Given: a TrunkSession with an EchoAudioPipe inner + an inbound // Given: a TrunkSession with an EchoAudioPipe inner + an inbound
// mpsc carrying one PCM frame. // mpsc carrying one PCM frame.
let now = Instant::now(); let now = Instant::now();
let (mut session, inbound_tx, _out_rx) = let (mut session, inbound_tx, _out_rx) = trunk_session_with_echo_pipe_and_mpsc(now);
trunk_session_with_echo_pipe_and_mpsc(now);
let mut frame = PcmFrame::zeroed(); let mut frame = PcmFrame::zeroed();
frame.samples[0] = 4242; frame.samples[0] = 4242;
@@ -121,7 +117,10 @@ mod tests {
// The EchoAudioPipe holds exactly one frame (the one we pushed). // The EchoAudioPipe holds exactly one frame (the one we pushed).
// If the tick route worked, we get Some back; if the inbound // If the tick route worked, we get Some back; if the inbound
// mpsc was never drained, we get None (the echopipe is empty). // mpsc was never drained, we get None (the echopipe is empty).
assert!(out_frame.is_some(), "tick must drain inbound mpsc to the pipe"); assert!(
out_frame.is_some(),
"tick must drain inbound mpsc to the pipe"
);
} }
#[tokio::test] #[tokio::test]
@@ -130,8 +129,7 @@ mod tests {
// holds a frame (pushed via on_pcm_frame), and the outbound mpsc // holds a frame (pushed via on_pcm_frame), and the outbound mpsc
// ready to receive. // ready to receive.
let now = Instant::now(); let now = Instant::now();
let (mut session, _in_tx, mut out_rx) = let (mut session, _in_tx, mut out_rx) = trunk_session_with_echo_pipe_and_mpsc(now);
trunk_session_with_echo_pipe_and_mpsc(now);
// Prime the inner echo pipe with a frame. // Prime the inner echo pipe with a frame.
let mut frame = PcmFrame::zeroed(); let mut frame = PcmFrame::zeroed();
@@ -146,15 +144,17 @@ mod tests {
// Then: outbound mpsc has the frame (try_recv returns it). // Then: outbound mpsc has the frame (try_recv returns it).
let drained = out_rx.try_recv(); let drained = out_rx.try_recv();
assert!(drained.is_ok(), "tick must push brain reply PCM to outbound mpsc"); assert!(
drained.is_ok(),
"tick must push brain reply PCM to outbound mpsc"
);
} }
#[tokio::test] #[tokio::test]
async fn idle_timeout_closes_session_after_60s_silence() { async fn idle_timeout_closes_session_after_60s_silence() {
// Given: a session whose last_idle_rx is 90s in the past. // Given: a session whose last_idle_rx is 90s in the past.
let now = Instant::now(); let now = Instant::now();
let (mut session, _in_tx, _out_rx) = let (mut session, _in_tx, _out_rx) = trunk_session_with_echo_pipe_and_mpsc(now);
trunk_session_with_echo_pipe_and_mpsc(now);
session.last_idle_rx = now - Duration::from_secs(90); session.last_idle_rx = now - Duration::from_secs(90);
// When: drive() runs one tick. // When: drive() runs one tick.
@@ -174,8 +174,7 @@ mod tests {
// Given: a TrunkSession with an inbound frame ready; last_idle_rx // Given: a TrunkSession with an inbound frame ready; last_idle_rx
// is currently in the past. // is currently in the past.
let now = Instant::now(); let now = Instant::now();
let (mut session, inbound_tx, _out_rx) = let (mut session, inbound_tx, _out_rx) = trunk_session_with_echo_pipe_and_mpsc(now);
trunk_session_with_echo_pipe_and_mpsc(now);
session.last_idle_rx = now - Duration::from_secs(30); session.last_idle_rx = now - Duration::from_secs(30);
inbound_tx.send(PcmFrame::zeroed()).await.unwrap(); inbound_tx.send(PcmFrame::zeroed()).await.unwrap();