Chat quick switcher MRU, Closed section and markers; Alt+N, Alt+J and run tab keys

Ctrl+K lists open chats most recently used first (tracked on open and pane
focus, persisted per server) and preselects the previous chat, so Ctrl+K,
Enter returns to it. Rows mark needs you / working / unread; a query also
lists matching closed chats under Closed, and choosing one reopens it.
Alt+N (Option+N) starts a new chat and Alt+J (Option+J) opens the next chat
waiting for you, unread or failed, cycling; the terminal keeps both. In run
detail, bare 1-4 switch tabs when not typing. Cheatsheet entries added.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 00:49:36 +00:00
parent accb9970b6
commit 12c7642e35
25 changed files with 1223 additions and 46 deletions
@@ -13,7 +13,11 @@ import 'chat_registration_test.dart'
final _field = find.byKey(const Key('chat-quick-switch-field'));
Future<void> _replySessions(WidgetTester tester, FakeChannel channel) async {
Future<void> _replySessions(
WidgetTester tester,
FakeChannel channel, {
bool awaiting = false,
}) async {
final request = await waitForRequest(tester, channel, 'chat_sessions');
channel.incoming.add(
jsonEncode({
@@ -22,7 +26,12 @@ Future<void> _replySessions(WidgetTester tester, FakeChannel channel) async {
'chat_sessions': [
{'id': 's1', 'title': 'Wire chat', 'directory': '/workspace/demo'},
{'id': 's2', 'title': 'Second chat', 'directory': '/workspace/other'},
{'id': 's3', 'title': 'Third chat', 'directory': '/workspace/demo'},
{
'id': 's3',
'title': 'Third chat',
'directory': '/workspace/demo',
if (awaiting) 'activity': {'awaiting_operator': 1, 'seq': 1},
},
],
}),
);
@@ -31,8 +40,9 @@ Future<void> _replySessions(WidgetTester tester, FakeChannel channel) async {
Future<FakeChannel> _mountOnChat(
WidgetTester tester,
PlatformRouteInformationProvider provider,
) async {
PlatformRouteInformationProvider provider, {
bool awaiting = false,
}) async {
tester.view.physicalSize = const Size(1200, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
@@ -48,10 +58,15 @@ Future<FakeChannel> _mountOnChat(
),
);
await tester.pump();
await _replySessions(tester, channel);
await _replySessions(tester, channel, awaiting: awaiting);
await replySubscribe(tester, channel);
await replyHistory(tester, channel);
await tester.pumpAndSettle();
// A chat waiting for the operator pulses its badge, so it never settles.
if (awaiting) {
await tester.pump(const Duration(seconds: 1));
} else {
await tester.pumpAndSettle();
}
expect(find.byType(ChatThreadView), findsOneWidget);
return channel;
}
@@ -149,6 +164,81 @@ void main() {
await _teardown(tester);
});
testWidgets('the shortcut then Enter returns to the previous chat', (
tester,
) async {
final provider = _provider();
final channel = await _mountOnChat(tester, provider);
await _chord(tester, LogicalKeyboardKey.controlLeft);
await tester.enterText(_field, 'second');
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pump();
await replySubscribe(tester, channel, index: 1);
await replyHistory(tester, channel, index: 1);
await tester.pumpAndSettle();
expect(provider.value.uri.path, '/chat/s2');
await _chord(tester, LogicalKeyboardKey.controlLeft);
// Most recent first: the open chat, then the one before it, selected.
final rows = tester
.widgetList<ListTile>(
find.byWidgetPredicate(
(w) =>
w is ListTile && '${w.key}'.contains('chat-quick-switch-row'),
),
)
.toList();
expect(
rows.map((tile) => '${tile.key}'.split('row-').last.split("'").first),
['s2', 's1', 's3'],
);
expect(rows[1].selected, isTrue);
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pumpAndSettle();
expect(provider.value.uri.path, '/chat/s1');
await _teardown(tester);
});
testWidgets('Alt+J opens the next chat waiting for you', (tester) async {
final provider = _provider();
final channel = await _mountOnChat(tester, provider, awaiting: true);
await tester.sendKeyDownEvent(LogicalKeyboardKey.altLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.keyJ);
await tester.sendKeyUpEvent(LogicalKeyboardKey.altLeft);
await tester.pump();
await tester.pump();
await replySubscribe(tester, channel, index: 1);
await replyHistory(tester, channel, index: 1);
await tester.pump(const Duration(seconds: 1));
expect(provider.value.uri.path, '/chat/s3');
// Only the open chat needs you now: nothing else to go to.
await tester.sendKeyDownEvent(LogicalKeyboardKey.altLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.keyJ);
await tester.sendKeyUpEvent(LogicalKeyboardKey.altLeft);
await tester.pump();
await tester.pump();
expect(provider.value.uri.path, '/chat/s3');
expect(find.text('No other chat needs you.'), findsOneWidget);
await _teardown(tester);
});
testWidgets('Alt+N from Runs opens New chat', (tester) async {
await _mountOnChat(tester, _provider());
await tester.tap(find.byKey(const ValueKey('shell.destination.runs')));
await tester.pump(const Duration(milliseconds: 600));
FocusManager.instance.primaryFocus?.unfocus();
await tester.pump();
await tester.sendKeyDownEvent(LogicalKeyboardKey.altLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.keyN);
await tester.sendKeyUpEvent(LogicalKeyboardKey.altLeft);
await tester.pump();
await tester.pump(const Duration(milliseconds: 600));
expect(find.byType(Dialog), findsOneWidget);
await _teardown(tester);
});
testWidgets('elsewhere the shortcut still jumps to Chat', (tester) async {
final provider = _provider();
await _mountOnChat(tester, provider);
@@ -31,6 +31,8 @@ class _Switcher {
Future<_Switcher> _open(
WidgetTester tester, {
Size size = const Size(900, 800),
List<String> recent = const [],
String? currentId,
}) async {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
@@ -54,6 +56,8 @@ Future<_Switcher> _open(
onPressed: () => switcher.route = showChatQuickSwitch(
context,
sessions: controller,
recent: () => recent,
currentId: currentId,
onSelected: (row) => switcher.chosen.add('${row['id']}'),
),
child: const Text('Open'),
@@ -162,8 +166,20 @@ void main() {
'build',
);
await tester.pump();
// The closed chat titled "Closed build" is not offered.
expect(_shown(tester), ['one']);
// The closed chat titled "Closed build" follows under Closed.
expect(_shown(tester), ['one', 'gone']);
expect(
find.byKey(const Key('chat-quick-switch-closed-header')),
findsOneWidget,
);
expect(
tester.getTopLeft(find.text('Closed')).dy,
lessThan(
tester
.getTopLeft(find.byKey(const Key('chat-quick-switch-row-gone')))
.dy,
),
);
await tester.enterText(
find.byKey(const Key('chat-quick-switch-field')),
'zzz',
@@ -213,6 +229,38 @@ void main() {
await tester.pump();
});
testWidgets(
'no query: most recent first, the previous chat selected; Enter goes back',
(tester) async {
final switcher = await _open(
tester,
recent: ['three', 'two'],
currentId: 'three',
);
expect(_shown(tester), ['three', 'two', 'one']);
expect(_selected(tester), 'two');
await _key(tester, LogicalKeyboardKey.enter);
await tester.pumpAndSettle();
expect(switcher.chosen, ['two']);
},
);
testWidgets('rows mark working, needs you and unread chats', (tester) async {
await _open(tester);
final two = find.byKey(const Key('chat-quick-switch-row-two'));
expect(
find.descendant(
of: two,
matching: find.byKey(const Key('chat-quick-switch-marker-working')),
),
findsOneWidget,
);
expect(
find.byKey(const Key('chat-quick-switch-marker-needsYou')),
findsNothing,
);
});
testWidgets('a phone shows it as a full-width bottom sheet', (tester) async {
await _open(tester, size: const Size(400, 800));
expect(find.byType(Dialog), findsNothing);
@@ -0,0 +1,44 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/data/chat_recency.dart';
import 'package:shared_preferences/shared_preferences.dart';
void main() {
test('touch moves a chat to the front and persists the order', () async {
final store = MemoryChatRecencyStore(['b', 'a']);
final recency = ChatRecency(store: store);
await recency.load();
expect(recency.ids, ['b', 'a']);
recency.touch('a');
recency.touch('c');
expect(recency.ids, ['c', 'a', 'b']);
await Future<void>.delayed(Duration.zero);
expect(store.ids, ['c', 'a', 'b']);
});
test('a chat touched before the read stays in front', () async {
final recency = ChatRecency(store: MemoryChatRecencyStore(['b', 'a']));
recency.touch('a');
await recency.load();
expect(recency.ids, ['a', 'b']);
});
test('keeps at most the limit', () async {
final recency = ChatRecency(limit: 2);
for (final id in ['a', 'b', 'c']) {
recency.touch(id);
}
expect(recency.ids, ['c', 'b']);
});
test('shared preferences keep the order per server', () async {
SharedPreferences.setMockInitialValues({});
const one = SharedPreferencesChatRecencyStore(serverScope: 'one');
const two = SharedPreferencesChatRecencyStore(serverScope: 'two');
await one.write(['x', 'y']);
expect(await one.read(), ['x', 'y']);
expect(await two.read(), isEmpty);
final reloaded = ChatRecency(store: one);
await reloaded.load();
expect(reloaded.ids, ['x', 'y']);
});
}
@@ -0,0 +1,113 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/domain/chat_attention_cycle.dart';
import 'package:pipelines_app/features/chat/domain/chat_quick_switch_order.dart';
List<String> ids(List<JsonMap> rows) => [
for (final row in rows) '${row['id']}',
];
void main() {
final rows = <JsonMap>[
{'id': 'a', 'title': 'A'},
{'id': 'b', 'title': 'B'},
{'id': 'c', 'title': 'C'},
{'id': 'd', 'title': 'D'},
];
test('recently used chats lead, the rest keep their order', () {
expect(ids(chatQuickSwitchByRecency(rows, ['c', 'x', 'a'])), [
'c',
'a',
'b',
'd',
]);
expect(ids(chatQuickSwitchByRecency(rows, const [])), ['a', 'b', 'c', 'd']);
});
test('no query selects the chat used before the current one', () {
final shown = chatQuickSwitchByRecency(rows, ['c', 'a']);
expect(
chatQuickSwitchInitialSelection(shown, currentId: 'c', emptyQuery: true),
1,
);
// Not showing a chat: the most recent one.
expect(
chatQuickSwitchInitialSelection(shown, currentId: null, emptyQuery: true),
0,
);
// A query selects the best match, even the current chat.
expect(
chatQuickSwitchInitialSelection(shown, currentId: 'c', emptyQuery: false),
0,
);
expect(
chatQuickSwitchInitialSelection(
[rows.first],
currentId: 'a',
emptyQuery: true,
),
0,
);
});
test('closed chats, most recently closed first', () {
expect(
ids(
chatQuickSwitchClosed([
...rows,
{'id': 'old', 'closed_at': 1},
{'id': 'new', 'closed_at': 9},
{'id': 'flag', 'closed': true},
]),
),
['new', 'old', 'flag'],
);
});
test('markers: needs you, working, unread', () {
expect(
chatQuickSwitchMarkers({
'awaiting_operator': 2,
'running': true,
}, unread: true),
[
ChatQuickSwitchMarker.needsYou,
ChatQuickSwitchMarker.working,
ChatQuickSwitchMarker.unread,
],
);
expect(chatQuickSwitchMarkers({'id': 'a'}, unread: false), isEmpty);
});
group('next chat needing attention', () {
final sessions = <JsonMap>[
{'id': 'a', 'title': 'A', 'directory': '/x'},
{'id': 'b', 'title': 'B', 'directory': '/x', 'awaiting_operator': 1},
{'id': 'c', 'title': 'C', 'directory': '/x'},
{'id': 'd', 'title': 'D', 'directory': '/x'},
{'id': 'e', 'title': 'E', 'closed_at': 3, 'awaiting_operator': 1},
];
const unread = {'d'};
const failed = {'a'};
bool needs(JsonMap row) => chatNeedsAttention(
row,
unread: unread.contains(row['id']),
failed: failed.contains(row['id']),
);
test('cycles in list order, wrapping, skipping closed chats', () {
expect(chatNextNeedingAttention(sessions, 'a', needs)?['id'], 'b');
expect(chatNextNeedingAttention(sessions, 'b', needs)?['id'], 'd');
expect(chatNextNeedingAttention(sessions, 'd', needs)?['id'], 'a');
expect(chatNextNeedingAttention(sessions, 'c', needs)?['id'], 'd');
expect(chatNextNeedingAttention(sessions, null, needs)?['id'], 'a');
});
test('null when only the current chat needs the operator', () {
bool onlyB(JsonMap row) => row['id'] == 'b';
expect(chatNextNeedingAttention(sessions, 'b', onlyB), isNull);
expect(chatNextNeedingAttention(sessions, 'a', onlyB)?['id'], 'b');
});
});
}
@@ -0,0 +1,72 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
import 'run_detail_graph_support.dart';
int _current(WidgetTester tester) => tester
.widget<FloatingDestinationBar>(
find.descendant(
of: find.byKey(const Key('run-detail-tabs')),
matching: find.byType(FloatingDestinationBar),
),
)
.currentIndex;
void main() {
testWidgets('bare 1-4 switch the run detail tabs', (tester) async {
await pumpRunDetail(tester, RunDetailTestPlatform.material);
expect(_current(tester), 0);
await tester.sendKeyEvent(LogicalKeyboardKey.digit2);
await tester.pump();
expect(_current(tester), 1);
await tester.sendKeyEvent(LogicalKeyboardKey.numpad1);
await tester.pump();
expect(_current(tester), 0);
});
testWidgets('a modifier or a focused text field keeps the digit', (
tester,
) async {
await pumpRunDetail(tester, RunDetailTestPlatform.material);
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.digit2);
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
await tester.pump();
expect(_current(tester), 0);
// A text field over the detail (in an overlay of the same route) types.
final field = TextEditingController();
addTearDown(field.dispose);
final overlay = OverlayEntry(
builder: (_) => Material(
child: TextField(key: const Key('probe-field'), controller: field),
),
);
Overlay.of(
tester.element(find.byKey(const Key('run-detail-tabs'))),
).insert(overlay);
await tester.pump();
await tester.tap(find.byKey(const Key('probe-field')));
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.digit2);
await tester.pump();
expect(_current(tester), 0);
overlay.remove();
});
testWidgets('a dialog over the run keeps the digits', (tester) async {
await pumpRunDetail(tester, RunDetailTestPlatform.material);
showDialog<void>(
context: tester.element(find.byKey(const Key('run-detail-tabs'))),
builder: (_) => const AlertDialog(content: Text('Over')),
);
await tester.pumpAndSettle();
await tester.sendKeyEvent(LogicalKeyboardKey.digit2);
await tester.pump();
Navigator.of(tester.element(find.text('Over'))).pop();
await tester.pumpAndSettle();
expect(_current(tester), 0);
});
}
@@ -0,0 +1,119 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/adaptive_shell.dart';
import 'package:pipelines_app/shell/destination.dart';
import 'package:pipelines_app/shell/shell_chat_actions_shortcut.dart';
import 'package:pipelines_app/ui/input/keyboard_owner.dart';
KeyDownEvent _down(PhysicalKeyboardKey physical, LogicalKeyboardKey logical) =>
KeyDownEvent(
physicalKey: physical,
logicalKey: logical,
timeStamp: Duration.zero,
);
final _n = _down(PhysicalKeyboardKey.keyN, LogicalKeyboardKey.keyN);
final _j = _down(PhysicalKeyboardKey.keyJ, LogicalKeyboardKey.keyJ);
Future<void> _alt(WidgetTester tester, LogicalKeyboardKey key) async {
await tester.sendKeyDownEvent(LogicalKeyboardKey.altLeft);
await tester.sendKeyEvent(key);
await tester.sendKeyUpEvent(LogicalKeyboardKey.altLeft);
await tester.pump();
}
void main() {
test('Alt+N is New chat and Alt+J the next chat needing you, alone', () {
ShellChatAction? chord(Set<LogicalKeyboardKey> held, KeyEvent event) =>
shellChatActionShortcut(event, _FakeKeyboard(held));
const alt = LogicalKeyboardKey.altLeft;
expect(chord({alt}, _n), ShellChatAction.newChat);
expect(chord({alt}, _j), ShellChatAction.nextAttention);
expect(chord({}, _n), isNull);
expect(chord({alt, LogicalKeyboardKey.shiftLeft}, _n), isNull);
expect(chord({alt, LogicalKeyboardKey.controlLeft}, _j), isNull);
expect(chord({alt, LogicalKeyboardKey.metaLeft}, _j), isNull);
expect(chord({LogicalKeyboardKey.controlLeft}, _n), isNull);
// Option+N is a dead key (˜) on a Mac: matched by position.
final dead = _down(
PhysicalKeyboardKey.keyN,
const LogicalKeyboardKey(0x02dc),
);
expect(chord({alt}, dead), ShellChatAction.newChat);
expect(
shellChatActionLabel(ShellChatAction.newChat, TargetPlatform.macOS),
'Option+N',
);
expect(
shellChatActionLabel(ShellChatAction.nextAttention, TargetPlatform.linux),
'Alt+J',
);
});
testWidgets('the chords show Chat and report the action; the terminal '
'keeps them', (tester) async {
final terminal = FocusNode();
addTearDown(terminal.dispose);
final actions = <ShellChatAction>[];
await tester.pumpWidget(
MaterialApp(
home: AdaptiveShell(
onChatAction: actions.add,
destinationBodies: {
AppDestination.pipelines: (_) => TypingSurface(
child: Focus(focusNode: terminal, child: const Text('terminal')),
),
AppDestination.chat: (_) => const Text('chat body'),
},
),
),
);
terminal.requestFocus();
await tester.pump();
await _alt(tester, LogicalKeyboardKey.keyN);
expect(actions, isEmpty);
expect(find.text('chat body'), findsNothing);
terminal.unfocus();
await tester.pump();
await _alt(tester, LogicalKeyboardKey.keyJ);
expect(actions, [ShellChatAction.nextAttention]);
expect(find.text('chat body'), isOnstage);
await _alt(tester, LogicalKeyboardKey.keyN);
expect(actions, [ShellChatAction.nextAttention, ShellChatAction.newChat]);
});
testWidgets('a dialog keeps the chords', (tester) async {
final actions = <ShellChatAction>[];
await tester.pumpWidget(
MaterialApp(
home: AdaptiveShell(
onChatAction: actions.add,
destinationBodies: {
AppDestination.pipelines: (context) => TextButton(
onPressed: () => showDialog<void>(
context: context,
builder: (_) =>
const AlertDialog(content: TextField(autofocus: true)),
),
child: const Text('dialog'),
),
AppDestination.chat: (_) => const Text('chat body'),
},
),
),
);
await tester.tap(find.text('dialog'));
await tester.pumpAndSettle();
await _alt(tester, LogicalKeyboardKey.keyN);
expect(actions, isEmpty);
});
}
class _FakeKeyboard extends HardwareKeyboard {
_FakeKeyboard(this.pressed);
final Set<LogicalKeyboardKey> pressed;
@override
bool isLogicalKeyPressed(LogicalKeyboardKey key) => pressed.contains(key);
}