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
@@ -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));
});
}