Merge branch 'main' into worktree-agent-a027d4a4581416c93

# Conflicts:
#	app/lib/features/chat/screen.dart
This commit is contained in:
2026-12-03 22:18:58 +00:00
41 changed files with 1969 additions and 162 deletions
@@ -0,0 +1,147 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.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_list_hidden_controller.dart';
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
import 'package:pipelines_app/shell/adaptive_shell.dart';
import 'package:pipelines_app/shell/destination.dart';
import 'package:pipelines_app/shell/list_pane_divider.dart';
import 'package:pipelines_app/ui/adaptive/segmented_bar_overflow.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'conversation/chat_thread_fixtures.dart';
class _Gateway extends FakeChatGateway {
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
if (type == 'chat_sessions') {
return Future.value({
'chat_sessions': [
{'id': 'a', 'title': 'First chat'},
{'id': 'b', 'title': 'Second chat'},
{'id': 'c', 'title': 'Third chat'},
],
});
}
if (type == 'chat_shells') return Future.value({'chat_shells': []});
return super.call(type, fields);
}
}
final _body = find.byKey(const ValueKey('list-detail-body'));
final _show = find.byKey(const Key('chat-show-list'));
Future<ChatListHiddenController> _open(
WidgetTester tester, {
bool hidden = false,
}) async {
SharedPreferences.setMockInitialValues({});
tester.view.physicalSize = const Size(1280, 800);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final listHidden = ChatListHiddenController(
store: MemoryChatListHiddenStore(hidden),
);
addTearDown(listHidden.dispose);
final gateway = _Gateway()..history = (_) async => chatPage(const []);
addTearDown(gateway.close);
await tester.pumpWidget(
MaterialApp(
home: AdaptiveShell(
destination: AppDestination.chat,
destinationBodies: {
AppDestination.chat: (_) =>
ChatScreen(gateway: gateway, listHidden: listHidden),
},
),
),
);
await tester.pumpAndSettle();
await tester.tap(find.text('First chat'));
await tester.pumpAndSettle();
return listHidden;
}
Future<void> _chord(WidgetTester tester, LogicalKeyboardKey key) async {
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
await tester.sendKeyEvent(key);
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
await tester.pumpAndSettle();
}
double _railRight(WidgetTester tester) =>
tester.getRect(find.byType(NavigationRail)).right;
String? _active(WidgetTester tester) => tester
.widget<ChatWorkspace>(find.byType(ChatWorkspace))
.controller
.activePane
?.sessionId;
void main() {
testWidgets('Ctrl+B hides the list entirely and Show chat list brings it '
'back', (tester) async {
final listHidden = await _open(tester);
final shown = tester.getRect(_body).left;
expect(shown, greaterThan(_railRight(tester) + 100));
expect(_show, findsNothing);
// The list's own bar offers hiding too.
expect(find.byKey(const Key('chat-hide-list')), findsOneWidget);
await _chord(tester, LogicalKeyboardKey.keyB);
expect(listHidden.value, isTrue);
// The open chat takes the whole width beside the rail; no divider is
// left to drag.
expect(tester.getRect(_body).left, closeTo(_railRight(tester), 1));
expect(find.byType(ListPaneDivider), findsNothing);
expect(find.text('Second chat').hitTestable(), findsNothing);
// The chat's top bar starts with the way back.
expect(_show, findsOneWidget);
final bar = tester.getRect(find.byKey(const Key('chat-thread-header')));
expect(tester.getRect(_show).left - bar.left, lessThan(24));
await tester.tap(_show);
await tester.pumpAndSettle();
expect(listHidden.value, isFalse);
expect(tester.getRect(_body).left, closeTo(shown, 1));
expect(_show, findsNothing);
expect(find.text('Second chat').hitTestable(), findsOneWidget);
// Ctrl+B again hides, and again shows.
await _chord(tester, LogicalKeyboardKey.keyB);
expect(listHidden.value, isTrue);
await _chord(tester, LogicalKeyboardKey.keyB);
expect(listHidden.value, isFalse);
expect(tester.takeException(), isNull);
});
testWidgets('the pane menu names the toggle and its shortcut', (
tester,
) async {
final listHidden = await _open(tester);
await tester.tap(find.byKey(segmentedMoreKey).first);
await tester.pumpAndSettle();
await tester.tap(find.text('Hide chat list (Ctrl+B)'));
await tester.pumpAndSettle();
expect(listHidden.value, isTrue);
await tester.tap(find.byKey(segmentedMoreKey).first);
await tester.pumpAndSettle();
expect(find.text('Show chat list (Ctrl+B)'), findsOneWidget);
});
testWidgets('a stored hidden list stays hidden, and Ctrl+Tab still cycles '
'the chats', (tester) async {
await _open(tester, hidden: true);
expect(tester.getRect(_body).left, closeTo(_railRight(tester), 1));
expect(_show, findsOneWidget);
expect(_active(tester), 'a');
await _chord(tester, LogicalKeyboardKey.tab);
expect(_active(tester), 'b');
await _chord(tester, LogicalKeyboardKey.tab);
expect(_active(tester), 'c');
// Still hidden.
expect(tester.getRect(_body).left, closeTo(_railRight(tester), 1));
});
}
@@ -103,7 +103,11 @@ void main() {
await tester.pumpWidget(composerThread(gateway));
await tester.pumpAndSettle();
final send = find.byKey(const Key('chat-composer-primary'));
expect(tester.widget<IconButton>(send).style, isNull);
// Only the fixed size is set: no colours, so the host's filled colours
// apply.
final style = tester.widget<IconButton>(send).style!;
expect(style.backgroundColor, isNull);
expect(style.foregroundColor, isNull);
expect(chatSchemeOf(tester.element(send), null), isNull);
});
@@ -0,0 +1,82 @@
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/workspace/chat_list_hidden_controller.dart';
import 'package:shared_preferences/shared_preferences.dart';
KeyDownEvent _b() => const KeyDownEvent(
physicalKey: PhysicalKeyboardKey.keyB,
logicalKey: LogicalKeyboardKey.keyB,
timeStamp: Duration.zero,
);
void main() {
test('the choice is kept per device and restored', () async {
SharedPreferences.setMockInitialValues({});
final first = ChatListHiddenController();
expect(first.value, isFalse);
first.toggle();
expect(first.value, isTrue);
await Future<void>.delayed(Duration.zero);
expect(
(await SharedPreferences.getInstance()).getBool(
chatListHiddenPreferenceKey,
),
isTrue,
);
final next = ChatListHiddenController();
await next.restore();
expect(next.value, isTrue);
});
test('a choice made while restoring wins', () async {
final store = MemoryChatListHiddenStore(true);
final controller = ChatListHiddenController(store: store);
final restoring = controller.restore();
controller.value = false;
await restoring;
expect(controller.value, isFalse);
});
testWidgets('Ctrl+B elsewhere, Cmd+B on Apple; no other chord', (
tester,
) async {
final keyboard = HardwareKeyboard.instance;
Future<bool> matches(
List<LogicalKeyboardKey> modifiers,
TargetPlatform platform,
) async {
for (final key in modifiers) {
await tester.sendKeyDownEvent(key);
}
final result = chatListToggleShortcut(_b(), keyboard, platform: platform);
for (final key in modifiers.reversed) {
await tester.sendKeyUpEvent(key);
}
return result;
}
const linux = TargetPlatform.linux;
const mac = TargetPlatform.macOS;
expect(await matches([LogicalKeyboardKey.controlLeft], linux), isTrue);
expect(await matches([LogicalKeyboardKey.metaLeft], mac), isTrue);
expect(await matches([LogicalKeyboardKey.controlLeft], mac), isFalse);
expect(await matches([LogicalKeyboardKey.metaLeft], linux), isFalse);
expect(
await matches([
LogicalKeyboardKey.controlLeft,
LogicalKeyboardKey.shiftLeft,
], linux),
isFalse,
);
expect(
await matches([
LogicalKeyboardKey.controlLeft,
LogicalKeyboardKey.altLeft,
], linux),
isFalse,
);
expect(await matches(const [], linux), isFalse);
expect(chatListToggleLabel(true, linux), 'Show chat list (Ctrl+B)');
expect(chatListToggleLabel(false, mac), 'Hide chat list (Cmd+B)');
});
}
@@ -0,0 +1,219 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/settings/design_quick_switch.dart';
import 'package:pipelines_app/features/settings/design_quick_switch_match.dart';
import 'package:pipelines_app/shell/adaptive_shell.dart';
import 'package:pipelines_app/shell/destination.dart';
import 'package:pipelines_app/ui/input/keyboard_owner.dart';
import 'package:pipelines_app/ui/theme/app_design.dart';
import 'package:pipelines_app/ui/theme/app_design_controller.dart';
import 'package:pipelines_app/ui/theme/app_design_tokens.dart';
final _field = find.byKey(const Key('design-quick-switch-field'));
Finder _row(AppDesign design) =>
find.byKey(Key('design-quick-switch-row-${design.id}'));
bool _selected(WidgetTester tester, AppDesign design) =>
tester.widget<ListTile>(_row(design)).selected;
class _App {
_App(this.store) : designs = AppDesignController(store: store);
final MemoryAppDesignStore store;
final AppDesignController designs;
final terminal = FocusNode();
/// The design the app's theme is drawn in, read from the shell's context.
AppDesign shown(WidgetTester tester) =>
AppDesignTokens.of(tester.element(find.byKey(const Key('body')))).design;
}
Future<_App> _pump(WidgetTester tester, {String? stored}) async {
tester.view.physicalSize = const Size(1200, 800);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final app = _App(MemoryAppDesignStore(stored));
addTearDown(app.terminal.dispose);
await app.designs.restore();
final toggle = DesignQuickSwitchToggle(designs: app.designs);
await tester.pumpWidget(
ListenableBuilder(
listenable: app.designs,
builder: (context, _) => MaterialApp(
theme: app.designs.design.light(),
themeAnimationDuration: Duration.zero,
home: AdaptiveShell(
onDesignSwitch: toggle.toggle,
destinationBodies: {
AppDestination.pipelines: (_) => TypingSurface(
child: Focus(
focusNode: app.terminal,
child: const Text('body', key: Key('body')),
),
),
},
),
),
),
);
return app;
}
Future<void> _chord(
WidgetTester tester,
LogicalKeyboardKey modifier,
LogicalKeyboardKey key,
) async {
await tester.sendKeyDownEvent(modifier);
await tester.sendKeyEvent(key);
await tester.sendKeyUpEvent(modifier);
await tester.pumpAndSettle();
}
Future<void> _altL(WidgetTester tester) =>
_chord(tester, LogicalKeyboardKey.altLeft, LogicalKeyboardKey.keyL);
void main() {
test('a query narrows the designs by name, then summary', () {
expect(designQuickSwitchMatches(AppDesign.values, ''), AppDesign.values);
expect(designQuickSwitchMatches(AppDesign.values, 'PAP'), [
AppDesign.paper,
]);
expect(designQuickSwitchMatches(AppDesign.values, 'mono'), [
AppDesign.terminal,
]);
expect(designQuickSwitchMatches(AppDesign.values, 'paper serif'), [
AppDesign.paper,
]);
expect(designQuickSwitchMatches(AppDesign.values, 'zzz'), isEmpty);
});
testWidgets('Alt+L lists every design with its swatch, the current one '
'marked and selected; Alt+L again closes it', (tester) async {
final app = await _pump(tester);
await _altL(tester);
expect(_field, findsOneWidget);
for (final design in AppDesign.values) {
expect(_row(design), findsOneWidget);
expect(
find.descendant(of: _row(design), matching: find.text(design.label)),
findsOneWidget,
);
expect(
find.descendant(
of: _row(design),
matching: find.text(design.description),
),
findsOneWidget,
);
}
expect(find.byType(ListTile), findsNWidgets(AppDesign.values.length));
expect(
find.descendant(
of: _row(AppDesign.terminal),
matching: find.byKey(const Key('design-quick-switch-current')),
),
findsOneWidget,
);
expect(find.byKey(const Key('design-quick-switch-current')), findsOne);
expect(_selected(tester, AppDesign.terminal), isTrue);
await _altL(tester);
expect(_field, findsNothing);
expect(app.shown(tester), AppDesign.terminal);
});
testWidgets('Ctrl+N and Ctrl+P preview live without storing; Esc goes back '
'to the design it opened with', (tester) async {
final app = await _pump(tester);
await _altL(tester);
final order = AppDesign.values;
final start = order.indexOf(AppDesign.terminal);
final next = order[(start + 1) % order.length];
final previous = order[(start - 1) % order.length];
await _chord(
tester,
LogicalKeyboardKey.controlLeft,
LogicalKeyboardKey.keyN,
);
expect(_selected(tester, next), isTrue);
expect(app.shown(tester), next);
expect(app.designs.chosen, AppDesign.terminal);
expect(app.store.id, isNull);
await _chord(
tester,
LogicalKeyboardKey.controlLeft,
LogicalKeyboardKey.keyP,
);
await _chord(
tester,
LogicalKeyboardKey.controlLeft,
LogicalKeyboardKey.keyP,
);
expect(_selected(tester, previous), isTrue);
expect(app.shown(tester), previous);
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pumpAndSettle();
expect(_field, findsNothing);
expect(app.shown(tester), AppDesign.terminal);
expect(app.designs.design, AppDesign.terminal);
expect(app.store.id, isNull);
});
testWidgets('a filter selects the best match and Enter keeps it', (
tester,
) async {
final app = await _pump(tester, stored: AppDesign.standard.id);
await _altL(tester);
expect(_selected(tester, AppDesign.standard), isTrue);
await tester.enterText(_field, 'pap');
await tester.pumpAndSettle();
expect(find.byType(ListTile), findsOneWidget);
expect(_selected(tester, AppDesign.paper), isTrue);
expect(app.shown(tester), AppDesign.paper);
expect(app.store.id, AppDesign.standard.id);
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pumpAndSettle();
expect(_field, findsNothing);
expect(app.shown(tester), AppDesign.paper);
expect(app.designs.chosen, AppDesign.paper);
expect(app.store.id, AppDesign.paper.id);
// Reopened, Paper is now the marked one.
await _altL(tester);
expect(
find.descendant(
of: _row(AppDesign.paper),
matching: find.byKey(const Key('design-quick-switch-current')),
),
findsOneWidget,
);
});
testWidgets('a filter matching nothing shows the design it opened with', (
tester,
) async {
final app = await _pump(tester);
await _altL(tester);
await tester.enterText(_field, 'pap');
await tester.pumpAndSettle();
expect(app.shown(tester), AppDesign.paper);
await tester.enterText(_field, 'zzz');
await tester.pumpAndSettle();
expect(find.byKey(const Key('design-quick-switch-empty')), findsOne);
expect(app.shown(tester), AppDesign.terminal);
});
testWidgets('the terminal keeps Alt+L', (tester) async {
final app = await _pump(tester);
app.terminal.requestFocus();
await tester.pump();
await _altL(tester);
expect(_field, findsNothing);
});
}
@@ -29,7 +29,7 @@ AppDesignTokens _tokens(WidgetTester tester) =>
AppDesignTokens.of(tester.element(find.text(designSectionTitle)));
void main() {
testWidgets('every design is a radio row; Default is chosen at first', (
testWidgets('every design is a radio row; Terminal is chosen at first', (
tester,
) async {
final designs = AppDesignController(store: MemoryAppDesignStore());
@@ -43,40 +43,43 @@ void main() {
final group = tester.widget<RadioGroup<AppDesign>>(
find.byType(RadioGroup<AppDesign>),
);
expect(group.groupValue, AppDesign.standard);
expect(_tokens(tester).terminal, isFalse);
expect(group.groupValue, AppDesign.terminal);
expect(_tokens(tester).terminal, isTrue);
// The Material look is called Classic, so no row reads "Default".
expect(find.text('Classic'), findsOneWidget);
expect(find.text('Default'), findsNothing);
});
testWidgets('choosing Terminal stores it and restyles the page live', (
testWidgets('choosing Classic stores it and restyles the page live', (
tester,
) async {
final store = MemoryAppDesignStore();
final designs = AppDesignController(store: store);
await _pump(tester, designs);
await tester.tap(find.text(AppDesign.terminal.label));
await tester.pumpAndSettle();
expect(store.id, AppDesign.terminal.id);
expect(designs.design, AppDesign.terminal);
expect(_tokens(tester).terminal, isTrue);
expect(find.text(designSaveFailedText), findsNothing);
await tester.tap(find.text(AppDesign.standard.label));
await tester.pumpAndSettle();
expect(store.id, AppDesign.standard.id);
expect(designs.design, AppDesign.standard);
expect(_tokens(tester).terminal, isFalse);
expect(find.text(designSaveFailedText), findsNothing);
await tester.tap(find.text(AppDesign.terminal.label));
await tester.pumpAndSettle();
expect(store.id, AppDesign.terminal.id);
expect(_tokens(tester).terminal, isTrue);
});
testWidgets('a stored choice is restored into the picker', (tester) async {
final designs = AppDesignController(
store: MemoryAppDesignStore(AppDesign.terminal.id),
store: MemoryAppDesignStore(AppDesign.standard.id),
);
await designs.restore();
await _pump(tester, designs);
final group = tester.widget<RadioGroup<AppDesign>>(
find.byType(RadioGroup<AppDesign>),
);
expect(group.groupValue, AppDesign.terminal);
expect(group.groupValue, AppDesign.standard);
});
testWidgets('a failed save says the choice lasts until reload', (
@@ -86,10 +89,10 @@ void main() {
store: MemoryAppDesignStore()..failSaves = true,
);
await _pump(tester, designs);
await tester.tap(find.text(AppDesign.terminal.label));
await tester.tap(find.text(AppDesign.paper.label));
await tester.pumpAndSettle();
expect(find.text(designSaveFailedText), findsOneWidget);
expect(designs.design, AppDesign.terminal);
expect(designs.design, AppDesign.paper);
});
testWidgets('choosing Paper stores it, restyles the page live and is '