Files
chanora/apps/chanora_flutter/test/beta_e2e_test.dart
T
EdisonJwa 4c19410556 test+diag: SWE.4 unit tests for Rust paths, Dart service tests, diagnostics audio.android section
Verification + diagnostics:

- apps/chanora_flutter/test/services/back_intent_policy_test.dart:
  8-case truth table for the BackIntentPolicy pure function
  (SWE4-UV-042).
- apps/chanora_flutter/test/services/back_intent_service_test.dart:
  5 channel-routing tests (SWE4-UV-042, SWE5-IV-019 unit slice).
- apps/chanora_flutter/test/services/android_permissions_service_test.dart:
  12 tests covering inbound channel events, outbound requests,
  state-machine transitions, and non-Android short-circuit
  (SWE4-UV-041).
- SDD/SRS trace headers added to alpha_e2e_test.dart,
  beta_e2e_test.dart, widget_test.dart so the existing test ↔ ID
  mapping is discoverable by grep.
- chanora_diagnostics: extends DiagnosticExport with android_audio:
  Option<String> for the SDD-116 evidence schema (requested /
  achieved performance mode + sharing mode + input preset + sample
  rate + frames per burst, per-effect engagement, latency tier).
  The bridge's export_diagnostics() now embeds the Android section
  when current_android_audio_diagnostics() returns Some.

All 93 workspace Rust tests and 26 Dart test/services tests pass.

Trace: SDD-090, SDD-112, SDD-113, SDD-116, SWE4-UV-041, SWE4-UV-042,
SWE4-UV-045, SWE4-UV-047, SWE4-UV-048, SWE4-UV-049, SWE4-UV-051,
SWE4-UV-052, SWE5-IV-019.
2026-05-18 12:48:28 +08:00

83 lines
3.3 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.
//
// Requirement trace (SWE.5 / SWE.6 — end-to-end voice + PTT path):
// SRS-061..SRS-090 (voice send/receive, PTT, mute/deaf), SRS-156 (PTT control),
// SRS-195..SRS-203 (desktop PTT semantics; FocusedPttBackend collapse on mobile),
// SAD-034 (audio subsystem), SAD-071..SAD-079 (PTT subsystem),
// SDD-048 (voice view-model), SDD-081..SDD-092 (PTT trait + backends + watchdog).
// Verification-plan rows: SWE5-IV-010, SWE5-IV-015 (swe5-software-integration-verification-plan.md);
// SWE6-SV-003, SWE6-SV-004, SWE6-SV-017 (swe6-software-verification-plan.md).
// 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: '');
// Zero out the release tail so set_ptt(false) takes effect
// synchronously — the default 200 ms tail (SDD-096) would
// otherwise delay the assertion below.
await rust.setReleaseTailMs(ms: 0);
// 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);
// Give the release-tail (set to 0 above) one tick to settle.
await Future<void>.delayed(const Duration(milliseconds: 50));
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)));
}