Files
VoelinClient/crates/tsc-core/tests/live.rs
T
Claude 8b274cf36f M5 (part 1): tsc-core engine
Engine with Command/Event API for the UI. One actor per server session
merges three sources:
- voice: tsclientlib connection, book -> Presence, chat, talking
  indicators, move/mute, audio packets
- gateway: tsgw client (identity login, presence, relayed chat)
- query: own ServerQuery credentials via tsc-observer (observer + relays)
Presence authority voice > gateway > query; chat routing (voice for own
channel/server/private, else gateway, else query) and cross-source
dedup; stale source events are dropped by generation.
Audio thread keeps cpal devices off the runtime: capture -> linear
resample -> Opus (push-to-talk or VAD), incoming -> mixer -> playback.
Live test (TSC_LIVE=1, part of the smoke script) covers voice, query
presence and relay chat both ways on TS3 and TS6.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G
2026-09-25 14:38:08 +00:00

123 lines
3.6 KiB
Rust

//! Engine against the development servers (dev/docker-compose.yml).
//! Runs only with `TSC_LIVE=1`; `scripts/it-smoke.sh` sets it.
use std::time::Duration;
use tokio::sync::broadcast::Receiver;
use tokio::time::{Instant, timeout_at};
use tsc_core::{Command, Engine, Event, ObserveState, Source, VoiceOptions, VoiceState};
use tsc_model::ChatTarget;
fn live() -> bool {
std::env::var("TSC_LIVE").is_ok_and(|v| v == "1")
}
/// Wait for an event matching `f`, failing after 20 s.
async fn wait_for(
rx: &mut Receiver<Event>,
what: &str,
mut f: impl FnMut(&Event) -> bool,
) -> Event {
let deadline = Instant::now() + Duration::from_secs(20);
loop {
match timeout_at(deadline, rx.recv()).await {
Ok(Ok(e)) if f(&e) => return e,
Ok(Ok(Event::Error { message, .. })) => eprintln!("engine error: {message}"),
Ok(_) => {}
Err(_) => panic!("timed out waiting for {what}"),
}
}
}
async fn engine_roundtrip(voice_addr: &str, query: tsc_query::Connect) {
let engine = Engine::start();
let mut events = engine.subscribe();
let nick = format!("engine-{}", std::process::id() % 10_000);
// Session 1: voice.
engine.send(Command::ConnectVoice {
session: 1,
options: Box::new(VoiceOptions::new(voice_addr, &nick)),
});
wait_for(&mut events, "voice connected", |e| {
matches!(e, Event::State { session: 1, state } if state.voice == VoiceState::Connected && state.own_channel.is_some())
})
.await;
// Session 2: invisible, through own query credentials.
engine.send(Command::ObserveQuery { session: 2, connect: Box::new(query) });
let (mut observing, mut sees_voice_client) = (false, false);
wait_for(&mut events, "query presence with the voice client", |e| {
match e {
Event::State { session: 2, state } => {
observing = state.observe == ObserveState::Observing
&& state.presence_source == Some(Source::Query);
}
Event::Presence { session: 2, presence } => {
sees_voice_client = presence.clients.values().any(|c| c.nickname == nick);
}
_ => {}
}
observing && sees_voice_client
})
.await;
// Channel chat: voice -> relay.
engine.send(Command::OpenChat { session: 2, target: ChatTarget::Channel(1) });
tokio::time::sleep(Duration::from_secs(2)).await;
engine.send(Command::SendChat {
session: 1,
target: ChatTarget::Channel(1),
text: "engine-hello".into(),
});
wait_for(&mut events, "relayed channel message", |e| {
matches!(e, Event::Chat { session: 2, message } if message.text == "engine-hello" && message.target == ChatTarget::Channel(1))
})
.await;
// And back: relay -> voice.
engine.send(Command::SendChat {
session: 2,
target: ChatTarget::Channel(1),
text: "from-query".into(),
});
wait_for(
&mut events,
"message posted by the relay",
|e| matches!(e, Event::Chat { session: 1, message } if message.text.ends_with("from-query")),
)
.await;
engine.send(Command::CloseSession { session: 1 });
engine.send(Command::CloseSession { session: 2 });
tokio::time::sleep(Duration::from_millis(500)).await;
}
fn query(transport: tsc_query::Transport, addr: &str) -> tsc_query::Connect {
tsc_query::Connect {
transport,
addr: addr.into(),
user: "serveradmin".into(),
secret: Some("tsc-dev-admin".into()),
server_port: Some(9987),
server_id: None,
line: tsc_query::LineOptions { rate_limit: None, ..Default::default() },
}
}
#[tokio::test(flavor = "multi_thread")]
async fn ts6_engine() {
if !live() {
return;
}
engine_roundtrip("127.0.0.1:9988", query(tsc_query::Transport::Ssh, "127.0.0.1:10022")).await;
}
#[tokio::test(flavor = "multi_thread")]
async fn ts3_engine() {
if !live() {
return;
}
engine_roundtrip("127.0.0.1:9987", query(tsc_query::Transport::Raw, "127.0.0.1:10011")).await;
}