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