Files
chanora/apps/chanora_flutter/test/beta_e2e_test.dart
T
EdisonJwa ba444d94bd feat(audio,bridge,flutter): v1 audio + PTT lifecycle implementation (SDD-094..097)
Implement the SDD-094 / SDD-095 / SDD-096 / SDD-097 detailed designs
committed in dfa84ee.

Rust side
- chanora_audio::TransmitMode enum (Ptt/Continuous/VoiceActivity) with
  serde-friendly u8 repr (SDD-095).
- chanora_audio::TransmitModeSelector: lock-free Atomic-backed selector
  that is the sole writer of transmit_active (per SAD-083), applying
  hard_mute as a final clamp. VoiceActivity falls through to Continuous
  for v1 (DEC-030 placeholder).
- chanora_audio::ReleaseTailTimer: tokio-task-owning struct driving the
  selector's ptt_held input; default 200 ms tail, configurable 0–500 ms
  with AtomicU32 hot read; pending JoinHandle held in a std::sync::Mutex
  touched only on PTT edge transitions (SDD-096).
- chanora_storage: AudioMeta persisted as audio_meta.json next to
  identity.dek; get/set_transmit_mode + get/set_release_tail_ms with
  0..=500 clamp on write.
- chanora_core::ChanoraSession: voice_join(channel, password) and
  voice_leave() are the new lifecycle entry points; ensure_audio_running
  and shutdown_audio_if_idle are private helpers around the existing
  Option<AudioEngine> field. SessionEvent::VoiceState carries the
  in_channel / transmit_mode / mute / release_tail_ms tuple. Selector
  state survives reconnect; supervisor rewires it to each fresh engine
  gate.
- chanora_bridge: drop start_audio; add voice_join, voice_leave,
  set/get_transmit_mode, set/get_release_tail_ms, set_hard_mute.
  BridgeEvent::VoiceState mirrors the core event. AudioStarted/Stopped
  kept for backwards compat but Flutter ignores them in the new UI.

Flutter side
- New apps/chanora_flutter/lib/widgets/voice_bar.dart replaces the
  legacy _AudioControls widget. Renders channel pill, mode badge,
  mute toggle, level meter, PttCapabilityBadge, leave button. No
  manual Start affordance anywhere.
- New apps/chanora_flutter/lib/widgets/voice_settings.dart dialog with
  TransmitMode radio group (VoiceActivity disabled with 'Coming soon'
  trailing label per DEC-030), bind-key button, release-tail slider
  0–500 ms step 25.
- main.dart: state fields _inChannel, _transmitMode, _hardMute,
  _releaseTailMs driven by BridgeEvent_VoiceState. Channel-tap now
  calls voiceJoin instead of moveToChannel. Removed _onStartAudio,
  _audioStarted-gated branch, and the FilledButton.
- l10n: 11 new strings in app_en.arb + app_zh.arb.

Verification
- cargo check --workspace: clean.
- cargo test --workspace --lib: 72 passed / 0 failed / 1 ignored
  (chanora_audio: +12 new tests for TransmitMode/Selector/ReleaseTail;
  chanora_storage: +2 new tests for audio_meta round-trip).
- flutter analyze: 0 errors, 0 warnings; 6 infos are the Flutter 3.32
  Radio.groupValue deprecation (pre-existing API usage).
- FRB Dart/Rust bindings regenerated via flutter_rust_bridge_codegen.

Follow-up (intentionally deferred)
- PttController and per-platform PTT backends still drive AudioTransmitGate
  directly via the legacy set_ptt path; routing those key edges through
  ChanoraSession::release_tail_timer().{key_down,key_up} so the tail
  applies to native PTT input is a contained wiring change in a follow-up.
- Real audio-level RMS in BridgeAudioStats (current meter is binary).
- VoiceActivity backend (DEC-030).
2026-05-15 23:05:37 +08:00

69 lines
2.4 KiB
Dart

// Beta end-to-end verification test.
//
// Runs the full Dart → FRB → Rust → tsclientlib → cn.teamspeak.app
// path, including the audio engine. Verifies:
// 1. Connect + snapshot still work (Alpha regression).
// 2. Audio engine starts.
// 3. PTT toggles successfully.
// 4. Encoder produces Opus frames while PTT is held.
// 5. Disconnect cleans both protocol and audio.
//
// Network-dependent. Quietly tolerates a server that rejects voice
// (e.g. because the test account is not yet allowed to talk).
import 'package:flutter_test/flutter_test.dart';
import 'package:chanora_flutter/src/rust/api.dart' as rust;
import 'package:chanora_flutter/src/rust/frb_generated.dart';
void main() {
setUpAll(() async {
await RustLib.init();
});
test('connect → start_audio → PTT cycle → disconnect', () async {
// Defensive cleanup in case a previous test left state.
try {
await rust.disconnect();
} catch (_) {}
final snap = await rust.connect(
host: 'cn.teamspeak.app',
nickname: 'ChanoraBetaTest',
password: '',
);
expect(snap.serverName, isNotEmpty);
expect(snap.channels, isNotEmpty);
await rust.voiceJoin(channelId: snap.channels.first.id, password: '');
// Initial stats: PTT off, no frames sent yet.
final s0 = await rust.audioStats();
expect(s0.pttActive, isFalse);
expect(s0.framesSent, 0);
// Press PTT, wait ~250 ms, then read stats. If the host has a
// real microphone the encoder will emit ~10-12 frames. If the
// host has only a null source (typical headless), capture will
// have logged a warning at startAudio time and run in
// playback-only mode; framesSent stays at 0. Either outcome is
// a successful test of the wiring — what we actually verify
// here is that the PTT flag changes and no exception is thrown.
await rust.setPtt(active: true);
await Future<void>.delayed(const Duration(milliseconds: 250));
final s1 = await rust.audioStats();
expect(s1.pttActive, isTrue);
await rust.setPtt(active: false);
final s2 = await rust.audioStats();
expect(s2.pttActive, isFalse);
await rust.disconnect();
final connectedAfter = await rust.isConnected();
expect(connectedAfter, isFalse);
// ignore: avoid_print
print('Beta E2E: TX=${s1.framesSent} frames, RX=${s1.framesReceived} frames');
}, timeout: const Timeout(Duration(seconds: 30)));
}