Merge commit '5639e5cb057836100683e8f0c06c1bb70cd71bf0' into pipelines/run-20261113-1605-esc-keeps-background-tasks-stop-tasks-faa1

This commit is contained in:
2026-11-13 16:47:49 +00:00
27 changed files with 803 additions and 54 deletions
+11
View File
@@ -50,6 +50,17 @@ void main() {
expect(router.route, AppRoute.settings);
},
);
test('repeated chat deep links notify the mounted destination', () {
final router = delegate(AppRoute.chatSession('target'));
addTearDown(router.dispose);
var notifications = 0;
router.addListener(() => notifications++);
router.goTo(AppRoute.chatSession('target'));
expect(notifications, 1);
expect(router.route, AppRoute.chatSession('target'));
});
TestWidgetsFlutterBinding.ensureInitialized();
test('with nothing pushed the router leaves Back to the platform', () async {
for (final route in [
@@ -381,6 +381,75 @@ void main() {
},
);
testWidgets(
'a mounted chat notification route activates a different chat',
(tester) async {
tester.view.physicalSize = const Size(900, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final channel = FakeChannel()..readyCompleter.complete();
final client = PipelinesClient(channelFactory: (_) => channel);
final provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(uri: Uri.parse('/chat/old')),
);
addTearDown(provider.dispose);
await tester.pumpWidget(
PipelinesApp(
androidSupported: false,
server: webServer(),
client: client,
routeInformationProvider: provider,
),
);
await tester.pump();
await replyChatSessions(tester, channel, ['old', 'target']);
await replyChatHistory(
tester,
channel,
subscribeIndex: 0,
historyIndex: 0,
text: 'The retained chat.',
);
expect(find.text('The retained chat.'), findsOneWidget);
// This is the route delivered by a native chat notification, not a
// direct ChatScreen replacement.
await provider.didPushRouteInformation(
RouteInformation(uri: Uri.parse('/chat/target')),
);
await tester.pump();
expect(provider.value.uri.path, '/chat/target');
await replyChatHistory(
tester,
channel,
subscribeIndex: 1,
historyIndex: 1,
text: 'The notified chat.',
);
await tester.pumpAndSettle();
expect(requestOf(channel, 'chat_subscribe', index: 1)!['chat_subscribe'], {
'session_id': 'target',
});
expect(requestOf(channel, 'chat_messages', index: 1)!['chat_query'], {
'session_id': 'target',
'limit': 200,
'cursor': '',
});
expect(find.text('The notified chat.'), findsOneWidget);
expect(find.text('The retained chat.'), findsNothing);
expect(provider.value.uri.path, '/chat/target');
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
},
);
testWidgets(
'mobile Chats retap reopens the retained multi-pane workspace after tabs',
(tester) async {
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/transport/pipelines_client.dart';
import 'package:pipelines_app/features/chat/screen.dart';
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
import 'package:pipelines_app/features/search/search_screen.dart';
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
@@ -98,6 +99,14 @@ void main() {
expect(find.byType(SearchScreen), findsNothing);
final screen = tester.widget<ChatScreen>(find.byType(ChatScreen));
expect(screen.initialSessionId, _session);
expect(
tester
.widget<ChatWorkspace>(find.byType(ChatWorkspace))
.controller
.activePane
?.sessionId,
_session,
);
await reply(
tester,
@@ -3,6 +3,7 @@ import 'package:flutter_test/flutter_test.dart';
import '../../native_back.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/screen.dart';
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart'
show segmentedMoreKey;
@@ -188,4 +189,79 @@ void main() {
expect(gateway.count('chat_models'), 0);
},
);
for (final width in [390.0, 1200.0]) {
testWidgets(
'a new route opens the target after Chat is already mounted on $width px',
(tester) async {
final gateway = _ScreenGateway()
..sessions = [
{'id': 'old', 'title': 'Old chat'},
{'id': 'target', 'title': 'Target chat'},
];
tester.view.physicalSize = Size(width, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: ChatScreen(gateway: gateway, initialSessionId: 'old'),
),
),
);
await tester.pumpAndSettle();
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: ChatScreen(gateway: gateway, initialSessionId: 'target'),
),
),
);
await tester.pumpAndSettle();
final workspace = tester.widget<ChatWorkspace>(
find.byType(ChatWorkspace),
);
expect(workspace.controller.activePane?.sessionId, 'target');
expect(
find.byKey(const ValueKey('chat-session-target')),
findsOneWidget,
);
},
);
}
testWidgets(
'a repeated route reactivates its chat after another pane became active',
(tester) async {
final gateway = _ScreenGateway()
..sessions = [
{'id': 'a', 'title': 'Chat a'},
{'id': 'b', 'title': 'Chat b'},
];
await _pumpScreen(tester, gateway, initialSessionId: 'a');
final workspace = tester.widget<ChatWorkspace>(
find.byType(ChatWorkspace),
);
workspace.controller.splitActive('b', ChatSplitAxis.horizontal);
final b = workspace.controller.panes.firstWhere(
(pane) => pane.sessionId == 'b',
);
workspace.controller.activate(b.id);
await tester.pump();
expect(workspace.controller.activePane?.sessionId, 'b');
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: ChatScreen(gateway: gateway, initialSessionId: 'a'),
),
),
);
await tester.pumpAndSettle();
expect(workspace.controller.activePane?.sessionId, 'a');
},
);
}
@@ -179,4 +179,32 @@ void main() {
await tester.pumpWidget(const SizedBox.shrink());
await tester.pumpAndSettle();
});
testWidgets('repeated deep link reactivates the routed pane after restore', (
tester,
) async {
tester.view.physicalSize = const Size(1800, 1000);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final saved = ChatWorkspaceController()..open('a');
saved.splitActive('b', ChatSplitAxis.vertical);
SharedPreferences.setMockInitialValues({
chatWorkspacePreferenceKey: saved.snapshot()!.encode(),
});
final gateway = _Gateway()..history = (_) async => chatPage([]);
addTearDown(gateway.close);
await _mount(tester, gateway, route: 'a');
final controller = _workspace(tester);
final other = controller.panes.firstWhere((pane) => pane.sessionId == 'b');
controller.activate(other.id);
await tester.pump();
expect(controller.activePane?.sessionId, 'b');
await _mount(tester, gateway, route: 'a');
expect(_workspace(tester).activePane?.sessionId, 'a');
await tester.pumpWidget(const SizedBox.shrink());
await tester.pumpAndSettle();
});
}
@@ -4,16 +4,26 @@ import 'package:pipelines_app/features/chat/speech/speech.dart';
/// A scripted [SpeechEngine]: it records calls and a test fires the platform's
/// events. [stop] reports a cancel like every real platform does.
class FakeSpeechEngine extends SpeechEngine {
FakeSpeechEngine({this.supported = true, this.available = const []});
FakeSpeechEngine({
this.supported = true,
this.available = const [],
this.voiceDownloadHint = false,
this.voiceFailure = false,
});
@override
final bool supported;
final List<SpeechVoice> available;
final bool voiceDownloadHint;
final bool voiceFailure;
final calls = <String>[];
final spoken = <String>[];
double? rate;
SpeechVoice? voice;
@override
bool get supportsVoiceDownloadHint => voiceDownloadHint;
@override
Future<void> speak(String text) async {
calls.add('speak');
@@ -36,7 +46,10 @@ class FakeSpeechEngine extends SpeechEngine {
Future<void> setVoice(SpeechVoice? voice) async => this.voice = voice;
@override
Future<List<SpeechVoice>> voices() async => available;
Future<List<SpeechVoice>> voices() async {
if (voiceFailure) throw StateError('voice inventory failed');
return available;
}
/// Reports [word] (its first occurrence at or after [from]) being spoken.
void speakWord(String word, {int from = 0}) {
@@ -165,4 +165,37 @@ void main() {
expect(speech.rate, defaultSpeechRate);
expect(store.saved, (rate: defaultSpeechRate, voice: null));
});
testWidgets('an explicitly selected voice does not require voice inventory', (
tester,
) async {
engine = FakeSpeechEngine(voiceFailure: true);
reader();
const voice = SpeechVoice(name: 'Daniel', locale: 'en-GB');
// The saved selection is passed directly to the engine, even if querying
// the platform voice inventory is unavailable.
await speech.setVoice(voice);
await speech.read('a', ['Hello']);
expect(engine.voice, voice);
expect(engine.spoken, ['Hello']);
});
testWidgets(
'automatic voice selects the most natural device-language voice',
(tester) async {
engine = FakeSpeechEngine(
available: const [
SpeechVoice(name: 'Compact', locale: 'en-US', qualityRank: 1),
SpeechVoice(name: 'Enhanced', locale: 'en-US', qualityRank: 2),
SpeechVoice(name: 'French Natural', locale: 'fr-FR', qualityRank: 3),
],
);
reader();
await speech.read('a', ['Hello']);
expect(engine.voice?.name, 'Enhanced');
expect(speech.voice, isNull);
},
);
}
@@ -0,0 +1,59 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/speech/speech.dart';
void main() {
test('parses Apple quality and identifier without changing identity', () {
final voice = SpeechVoice.fromPlatform({
'name': 'Samantha',
'locale': 'en-US',
'quality': 'premium',
'identifier': 'com.apple.voice.premium.en-US.Samantha',
});
expect(voice.qualityRank, 3);
expect(voice.isNatural, isTrue);
expect(voice, const SpeechVoice(name: 'Samantha', locale: 'en-US'));
});
test('parses Android quality and prefers offline on a quality tie', () {
final online = SpeechVoice.fromPlatform({
'name': 'English online',
'locale': 'en-US',
'quality': 'very high',
'network_required': '1',
});
final offline = SpeechVoice.fromPlatform({
'name': 'English local',
'locale': 'en-US',
'quality': 'very high',
'network_required': '0',
});
expect(bestSpeechVoice([online, offline], 'en'), offline);
});
test('recognises natural web voice names', () {
final voice = SpeechVoice.fromPlatform({
'name': 'Microsoft Aria Online (Natural)',
'locale': 'en-US',
});
expect(voice.qualityRank, 3);
expect(voice.isNatural, isTrue);
});
test('picker ranking buries compact novelty voices', () {
final natural = const SpeechVoice(
name: 'Samantha Enhanced',
locale: 'en-US',
qualityRank: 2,
);
final novelty = const SpeechVoice(
name: 'Zarvox',
locale: 'en-US',
qualityRank: 1,
);
expect(compareSpeechVoices(natural, novelty), lessThan(0));
});
}
@@ -7,7 +7,11 @@ import 'package:pipelines_app/features/settings/settings_voice_picker.dart';
import '../chat/speech/fake_speech_engine.dart';
const _daniel = SpeechVoice(name: 'Daniel', locale: 'en-GB');
const _samantha = SpeechVoice(name: 'Samantha', locale: 'en-US');
const _samantha = SpeechVoice(
name: 'Samantha Enhanced',
locale: 'en-US',
qualityRank: 2,
);
const _thomas = SpeechVoice(name: 'Thomas', locale: 'fr-FR');
const _anna = SpeechVoice(name: 'Anna', locale: 'de-DE');
@@ -21,9 +25,16 @@ late FakeSpeechEngine _engine;
/// A fresh reader over [store], as after an app reload, and its section.
Future<SpeechController> _open(
WidgetTester tester,
MemorySpeechPreferences store,
) async {
_engine = FakeSpeechEngine(available: [_samantha, _thomas, _anna, _daniel]);
MemorySpeechPreferences store, {
List<SpeechVoice>? available,
bool voiceDownloadHint = false,
bool voiceFailure = false,
}) async {
_engine = FakeSpeechEngine(
available: available ?? [_samantha, _thomas, _anna, _daniel],
voiceDownloadHint: voiceDownloadHint,
voiceFailure: voiceFailure,
);
final speech = SpeechController(engine: _engine, store: store);
addTearDown(speech.dispose);
await tester.pumpWidget(
@@ -47,10 +58,11 @@ void main() {
addTearDown(tester.platformDispatcher.clearLocaleTestValue);
final store = MemorySpeechPreferences();
await _open(tester, store);
expect(find.text('System default'), findsOneWidget);
expect(find.text('Automatic (most natural)'), findsOneWidget);
await tester.tap(_voiceRow);
await tester.pumpAndSettle();
expect(find.text('Natural'), findsOneWidget);
// Grouped by language, the device's language first.
final french = tester.getTopLeft(find.text('French')).dy;
final english = tester.getTopLeft(find.text('English')).dy;
@@ -59,7 +71,7 @@ void main() {
expect(english, lessThan(german));
expect(
tester.getTopLeft(find.text('Daniel')).dy,
lessThan(tester.getTopLeft(find.text('Samantha')).dy),
greaterThan(tester.getTopLeft(find.text('Samantha Enhanced')).dy),
);
await tester.tap(find.text('Daniel'));
@@ -108,7 +120,7 @@ void main() {
expect(speech.voice, isNull);
expect(speech.rate, defaultSpeechRate);
expect(store.saved, (rate: defaultSpeechRate, voice: null));
expect(find.text('System default'), findsOneWidget);
expect(find.text('Automatic (most natural)'), findsOneWidget);
expect(find.text('Speaking rate 1.0×'), findsOneWidget);
expect(tester.widget<TextButton>(_reset).onPressed, isNull);
});
@@ -130,7 +142,7 @@ void main() {
// Each voice in the picker has its own sample; it does not choose it.
await tester.tap(_voiceRow);
await tester.pumpAndSettle();
await tester.tap(find.byTooltip('Play sample of Samantha'));
await tester.tap(find.byTooltip('Play sample of Samantha Enhanced'));
await tester.pump();
expect(_engine.voice, _samantha);
expect(_engine.spoken, hasLength(2));
@@ -140,9 +152,72 @@ void main() {
expect(speech.state, SpeechState.idle, reason: 'closing stops the sample');
});
testWidgets(
'shows the Apple download hint only for a non-natural inventory',
(tester) async {
tester.platformDispatcher.localeTestValue = const Locale('en', 'US');
addTearDown(tester.platformDispatcher.clearLocaleTestValue);
final store = MemorySpeechPreferences();
await _open(
tester,
store,
available: const [
SpeechVoice(
name: 'Samantha Compact',
locale: 'en-US',
qualityRank: 1,
),
],
voiceDownloadHint: true,
);
expect(
find.textContaining('download one in System Settings'),
findsOneWidget,
);
final hint = tester.widget<Text>(
find.descendant(
of: find.byKey(const Key('settings-read-aloud-voice-hint')),
matching: find.byType(Text),
),
);
expect(hint.maxLines, 1);
expect(
tester
.getTopLeft(find.byKey(const Key('settings-read-aloud-voice-hint')))
.dy,
greaterThan(tester.getTopLeft(_voiceRow).dy),
);
expect(
tester.getTopLeft(find.text('Speaking rate 1.0×')).dy,
greaterThan(
tester
.getTopLeft(
find.byKey(const Key('settings-read-aloud-voice-hint')),
)
.dy,
),
);
},
);
testWidgets('failed voice inventory is safe and dismissible', (tester) async {
final speech = await _open(
tester,
MemorySpeechPreferences(),
voiceFailure: true,
);
await tester.tap(_voiceRow);
await tester.pumpAndSettle();
expect(find.textContaining('Voices could not be loaded'), findsOneWidget);
expect(find.text('This device offers no other voices.'), findsNothing);
await tester.tap(find.text('Cancel'));
await tester.pumpAndSettle();
expect(speech.state, SpeechState.idle);
});
test('voices group by language, device language first', () {
final groups = groupSpeechVoices([_samantha, _anna, _daniel], 'de');
expect(groups.map((group) => group.language), ['de', 'en']);
expect(groups.last.voices, [_daniel, _samantha]);
expect(groups.last.voices, [_samantha, _daniel]);
});
}