Merge branch 'worktree-agent-a717651aa412e3b7c'

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 01:00:02 +00:00
60 changed files with 4265 additions and 222 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);
@@ -0,0 +1,148 @@
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/changes/changes.dart';
import 'fixtures.dart';
import 'widget_hosts.dart';
String _patch(String path, String line) =>
'--- "a/$path"\n'
'+++ "b/$path"\n'
'@@ -1,1 +1,1 @@\n'
'-old $line\n'
'+new $line\n';
List<JsonMap> _steps() => [
stepFixture(
fileChanges: captureFixture(
files: [
fileChangeFixture(path: 'lib/a.dart', patch: _patch('lib/a.dart', 'A')),
fileChangeFixture(path: 'lib/b.dart', patch: _patch('lib/b.dart', 'B')),
fileChangeFixture(path: 'lib/c.dart', patch: _patch('lib/c.dart', 'C')),
],
),
),
];
Future<void> _pumpAt(
WidgetTester tester,
Size size, {
bool finalOnly = true,
}) async {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(
materialHost(ChangesViewer(steps: _steps(), finalOnly: finalOnly)),
);
await tester.pumpAndSettle();
}
bool _shows(String text) =>
find.textContaining(text, findRichText: true).evaluate().isNotEmpty;
void main() {
testWidgets('a wide pane lists the files beside the first file\'s diff', (
tester,
) async {
await _pumpAt(tester, const Size(1400, 900));
expect(find.byKey(const ValueKey('changes-final-split')), findsOneWidget);
expect(find.byType(FileDiffViewer), findsOneWidget);
expect(
find.byKey(const ValueKey('changes-split-diff-lib/a.dart')),
findsOneWidget,
);
expect(_shows('new A'), isTrue);
expect(_shows('new B'), isFalse);
});
testWidgets('tapping a file shows its diff without leaving the pane', (
tester,
) async {
await _pumpAt(tester, const Size(1400, 900));
await tester.tap(find.bySemanticsLabel(RegExp('^Show diff for lib/c')));
await tester.pumpAndSettle();
expect(find.byType(FileDiffPage), findsNothing);
expect(
find.byKey(const ValueKey('changes-split-diff-lib/c.dart')),
findsOneWidget,
);
expect(_shows('new C'), isTrue);
});
testWidgets('j/k and the arrows move between files once focused', (
tester,
) async {
await _pumpAt(tester, const Size(1400, 900));
await tester.tap(find.bySemanticsLabel(RegExp('^Show diff for lib/a')));
await tester.pumpAndSettle();
Future<void> press(LogicalKeyboardKey key) async {
await tester.sendKeyEvent(key);
await tester.pumpAndSettle();
}
await press(LogicalKeyboardKey.keyJ);
expect(_shows('new B'), isTrue);
await press(LogicalKeyboardKey.arrowDown);
expect(_shows('new C'), isTrue);
// The last file stays selected rather than wrapping.
await press(LogicalKeyboardKey.keyJ);
expect(_shows('new C'), isTrue);
await press(LogicalKeyboardKey.keyK);
expect(_shows('new B'), isTrue);
await press(LogicalKeyboardKey.arrowUp);
expect(_shows('new A'), isTrue);
// Enter opens the selected file on its own page.
await press(LogicalKeyboardKey.enter);
expect(find.byType(FileDiffPage), findsOneWidget);
});
testWidgets('a visit page splits too, under the visit heading', (
tester,
) async {
await _pumpAt(tester, const Size(1400, 900), finalOnly: false);
expect(
find.byKey(const ValueKey('changes-visit-split-implementer-1')),
findsOneWidget,
);
expect(find.textContaining('Visit 1'), findsOneWidget);
expect(_shows('new A'), isTrue);
});
testWidgets('a phone keeps one row per file opening its own page', (
tester,
) async {
await _pumpAt(tester, const Size(560, 1000));
expect(find.byKey(const ValueKey('changes-final-split')), findsNothing);
expect(find.byType(FileDiffViewer), findsNothing);
await tester.tap(find.bySemanticsLabel(RegExp('^Open diff for lib/b')));
await tester.pumpAndSettle();
expect(find.byType(FileDiffPage), findsOneWidget);
});
testWidgets(
'a detail pane beside a list splits from 720 px in a wide window',
(tester) async {
tester.view.physicalSize = const Size(1440, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
Widget pane(double width) => materialHost(
Align(
alignment: Alignment.topRight,
child: SizedBox(
width: width,
child: ChangesViewer(steps: _steps(), finalOnly: true),
),
),
);
await tester.pumpWidget(pane(900));
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('changes-final-split')), findsOneWidget);
await tester.pumpWidget(pane(600));
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('changes-final-split')), findsNothing);
},
);
}
@@ -0,0 +1,184 @@
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/conversation/chat_draft_store.dart';
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_find_highlight.dart';
import 'chat_thread_fixtures.dart';
JsonMap _text(String text) => {'type': 'text', 'text': text};
/// Answers scoped searches with [searchHits] for history older than the
/// loaded page.
class _FindGateway extends FakeChatGateway {
final searches = <JsonMap>[];
List<JsonMap> searchHits = const [];
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
if (type == 'search') {
searches.add(Map<String, dynamic>.from(fields['search'] as Map));
return {
'type': 'search_results',
'search_results': {'results': searchHits},
};
}
return super.call(type, fields);
}
}
final _newest = [
for (var i = 0; i < 30; i++)
chatMessage(
'n$i',
i.isEven ? 'user' : 'assistant',
parts: [
_text(i == 2 || i == 27 ? 'Needle at $i, and needle' : 'filler $i'),
],
),
];
final _older = [
chatMessage('o1', 'user', parts: [_text('an old needle')]),
chatMessage('o2', 'assistant', parts: [_text('nothing')]),
];
Future<_FindGateway> _host(WidgetTester tester, {bool older = false}) async {
tester.view.physicalSize = const Size(1000, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final gateway = _FindGateway()
..history = (fields) async {
final query = fields['chat_query'] as Map;
if (query['cursor'] == 'c1') return chatPage(_older);
return chatPage(_newest, cursor: older ? 'c1' : '', hasMore: older);
};
addTearDown(gateway.close);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: ChatThreadView(
gateway: gateway,
sessionId: 's',
onBack: () {},
drafts: MemoryChatDraftStore(),
newOperationId: () => 'op',
),
),
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
await tester.pump();
return gateway;
}
Future<void> _ctrlF(WidgetTester tester) async {
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.keyF);
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
await tester.pump();
await tester.pump();
}
String _count(WidgetTester tester) =>
tester.widget<Text>(find.byKey(const ValueKey('chat-find-count'))).data!;
void main() {
testWidgets('Ctrl+F finds in the chat, steps older with Enter and Esc '
'returns to the composer', (tester) async {
await _host(tester);
await tester.tap(find.byType(EditableText).last);
await tester.pump();
await _ctrlF(tester);
expect(find.byKey(const ValueKey('chat-find-field')), findsOneWidget);
await tester.enterText(
find.byKey(const ValueKey('chat-find-field')),
'needle',
);
await tester.pumpAndSettle();
expect(_count(tester), '1 of 4');
// Each built text with a match registers where it draws.
final scope = tester.widget<ChatFindScope>(find.byType(ChatFindScope));
expect(scope.controller, isNotNull);
expect(scope.targets.texts, isNotEmpty);
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pumpAndSettle();
expect(_count(tester), '2 of 4');
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pumpAndSettle();
expect(_count(tester), '3 of 4');
// The match in message n2 is near the top of history: it is built now.
expect(
find.textContaining('Needle at 2', findRichText: true),
findsWidgets,
);
await tester.sendKeyDownEvent(LogicalKeyboardKey.shiftLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.sendKeyUpEvent(LogicalKeyboardKey.shiftLeft);
await tester.pumpAndSettle();
expect(_count(tester), '2 of 4');
await tester.tap(find.byKey(const ValueKey('chat-find-case')));
await tester.pumpAndSettle();
expect(_count(tester), '1 of 2');
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('chat-find-field')), findsNothing);
});
testWidgets('matches in unloaded history are counted from the server and '
'reached by loading older pages', (tester) async {
final gateway = await _host(tester, older: true);
gateway.searchHits = [
{
'chat': {'message_id': 'o1', 'part': 0, 'offset': 7},
},
];
await tester.tap(find.byType(EditableText).last);
await tester.pump();
await _ctrlF(tester);
await tester.enterText(
find.byKey(const ValueKey('chat-find-field')),
'needle',
);
await tester.pump(const Duration(milliseconds: 300));
await tester.pumpAndSettle();
expect(gateway.searches.single['scope'], 'chat:s');
expect(gateway.searches.single['cursor'], '0|c1');
expect(_count(tester), '1 of 5');
// Step to the oldest: it is only on the server, so the older page loads.
for (var i = 0; i < 4; i++) {
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pumpAndSettle();
}
expect(_count(tester), '5 of 5');
expect(
gateway.calls.where(
(call) =>
call.type == 'chat_messages' &&
(call.fields['chat_query'] as Map)['cursor'] == 'c1',
),
isNotEmpty,
);
expect(
find.textContaining('an old needle', findRichText: true),
findsWidgets,
);
});
testWidgets('Ctrl+F with no focus in the chat opens nothing', (tester) async {
await _host(tester);
expect(find.byKey(const ValueKey('chat-find-field')), findsNothing);
// No focus in the chat at all: the pane's handler never sees the key.
await _ctrlF(tester);
expect(find.byKey(const ValueKey('chat-find-field')), findsNothing);
});
}
@@ -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,78 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/domain/chat_find.dart';
void main() {
final rows = [
{
'kind': 'user',
'key': 'u1',
'message': {
'id': 'u1',
'parts': [
{'type': 'text', 'text': 'Find the Needle'},
{'type': 'text', 'text': 'and another needle'},
],
},
},
{'kind': 'activity', 'key': 'x', 'label': 'needle in activity'},
{
'kind': 'assistant',
'key': 'a1',
'messageIds': ['a1', 'a2'],
'parts': [
{'type': 'reasoning', 'text': 'needle thoughts'},
{'type': 'text', 'text': 'A **needle** here, needle there'},
{'type': 'text', 'text': ' '},
],
},
];
test('units are user turns and answer text parts as rendered', () {
final units = chatFindUnits(rows, ['k0', 'k1', 'k2']);
expect(units.map((u) => u.text), [
'Find the Needle\nand another needle',
'A **needle** here, needle there',
]);
expect(units.map((u) => u.rowKey), ['k0', 'k2']);
expect(units.first.messageIds, ['u1']);
expect(units.last.messageIds, ['a1', 'a2']);
});
test('matches fold case unless asked, in display order', () {
final units = chatFindUnits(rows, ['k0', 'k1', 'k2']);
final folded = chatFindMatches(units, 'needle', caseSensitive: false);
expect(folded.length, 4);
expect(folded.first.start, 'Find the '.length);
expect(folded.map((m) => m.ordinal), [0, 1, 0, 1]);
final exact = chatFindMatches(units, 'Needle', caseSensitive: true);
expect(exact.length, 1);
});
test('regex characters in the query are literal', () {
expect(chatFindRanges('a.b axb (c)', '.', caseSensitive: false), [
(start: 1, end: 2),
]);
expect(chatFindRanges('a.b axb (c)', '(c)', caseSensitive: false), [
(start: 8, end: 11),
]);
});
test('server hits parse from a scoped reply', () {
final hits = ChatFindRemoteHit.fromReply({
'search_results': {
'results': [
{
'chat': {'message_id': 'm9', 'part': 1, 'offset': 4},
},
{
'chat': {'message_id': 'm8'},
},
],
},
});
expect(hits.map((h) => (h.messageId, h.part, h.offset)), [
('m9', 1, 4),
('m8', 0, 0),
]);
});
}
@@ -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,88 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:pipelines_app/features/pipelines/screen.dart';
import 'package:pipelines_app/features/pipelines/ui/run_pipeline_wording.dart';
import 'package:pipelines_app/features/pipelines/widgets/pipeline_row_actions.dart';
import 'package:pipelines_app/features/pipelines/pipeline_models.dart';
import 'package:pipelines_app/ui/layout/app_overflow_menu.dart';
import '../fixtures.dart';
import 'run_pipeline_launch_test.dart' show acceptedRun, launchGateway;
Future<void> _pump(WidgetTester tester, Size size, FakeGateway gateway) async {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(MaterialApp(home: PipelinesScreen(gateway: gateway)));
await tester.pumpAndSettle();
}
void main() {
SharedPreferences.setMockInitialValues({});
testWidgets('a wide list row has its own Run button opening the form', (
tester,
) async {
final fixture = PipelineFixture();
final gateway = launchGateway(fixture, onLaunch: (_) => acceptedRun(9));
await _pump(tester, const Size(1440, 900), gateway);
expect(find.byKey(pipelineRowRunKey(1)), findsOneWidget);
await tester.tap(find.byKey(pipelineRowRunKey(1)));
await tester.pumpAndSettle();
// The same New run form as the detail's Run, for the row's pipeline at
// its listed version; opening it starts nothing.
expect(find.byKey(runPipelinePromptKey), findsOneWidget);
expect(gateway.callsOf('get_pipeline').last.fields, {
'pipeline_id': 1,
'version': 2,
});
expect(gateway.callsOf('run_pipeline'), isEmpty);
// The row did not open the pipeline.
expect(find.byKey(const Key('pipeline-detail')), findsNothing);
});
testWidgets('a phone row offers Run… in its menu and no button', (
tester,
) async {
final fixture = PipelineFixture();
final gateway = launchGateway(fixture, onLaunch: (_) => acceptedRun(9));
await _pump(tester, const Size(560, 900), gateway);
expect(find.byKey(pipelineRowRunKey(2)), findsNothing);
await tester.tap(find.byKey(pipelineRowMenuKey(2)));
await tester.pumpAndSettle();
await tester.tap(find.text(pipelineRowRunLabel));
await tester.pumpAndSettle();
expect(find.byKey(runPipelinePromptKey), findsOneWidget);
expect(gateway.callsOf('get_pipeline').last.fields['pipeline_id'], 2);
});
test('an archived pipeline offers no Run, as its detail offers none', () {
final archived = PipelineSummary.fromJson({
...pipelineSummary(id: 4, name: 'Old'),
'archived_at': '2026-10-01T00:00:00Z',
});
void run(BuildContext _) {}
expect(
pipelineRowActions(pipeline: archived, wide: true, onRun: run),
isNull,
);
// Send to chat stays; only Run is withheld.
expect(
pipelineRowActions(
pipeline: archived,
wide: true,
onRun: run,
onOpenInChat: run,
),
isA<AppOverflowMenu<Object?>>(),
);
});
}
@@ -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,156 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/runs/actions/retry_wording.dart';
import 'package:pipelines_app/features/runs/actions/title_wording.dart';
import 'package:pipelines_app/features/runs/screen.dart';
import 'package:pipelines_app/features/runs/ui/run_failure_actions.dart';
import 'package:pipelines_app/features/runs/ui/run_more_menu.dart';
import 'run_retry_wiring_support.dart';
Future<void> _mount(
WidgetTester tester,
ApiGateway gateway, {
Future<void> Function(BuildContext, JsonMap)? onOpenInChat,
bool settle = true,
}) async {
tester.view.physicalSize = const Size(1200, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: RunsScreen(
gateway: gateway,
initialRunId: 7,
onOpenInChat: onOpenInChat,
),
),
),
);
if (settle) await tester.pumpAndSettle();
}
/// A gateway that lists run 7 but never answers its detail.
class _SlowDetailGateway implements ApiGateway {
final pending = Completer<JsonMap>();
@override
Stream<JsonMap> get frames => const Stream.empty();
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) =>
switch (type) {
'list_runs' => Future.value({
'runs': [
{'id': 7, 'title': 'Slow run', 'status': 'failed', 'name': 'p'},
],
}),
'get_run' => pending.future,
_ => Future.error(UnsupportedError(type)),
};
}
void main() {
testWidgets('the failure banner offers Retry, Run again… and Open in chat', (
tester,
) async {
final gateway = RetryWiringGateway();
addTearDown(gateway.framesController.close);
gateway.details[7] = {
...retryFailedDetail(),
'pipeline_id': 3,
'version': 2,
'failure_reason': 'The build stage exited with status 2.',
};
final opened = <JsonMap>[];
await _mount(
tester,
gateway,
onOpenInChat: (context, run) async => opened.add(run),
);
expect(find.text('The build stage exited with status 2.'), findsOneWidget);
expect(find.byKey(runFailureRetryKey), findsOneWidget);
expect(find.byKey(runFailureRunAgainKey), findsOneWidget);
expect(find.byKey(runFailureOpenInChatKey), findsOneWidget);
// Retry is the menu's retry prompt; nothing is sent until its confirm.
await tester.tap(find.byKey(runFailureRetryKey));
await tester.pumpAndSettle();
expect(find.text(retryDialogTitle(7)), findsOneWidget);
await tester.tap(find.byKey(retryKeepKey));
await tester.pumpAndSettle();
expect(gateway.retryCalls, isEmpty);
// Open in chat hands the run to the host's send-to-chat flow.
await tester.tap(find.byKey(runFailureOpenInChatKey));
await tester.pumpAndSettle();
expect(opened.single['id'], 7);
// Run again reads the run's pipeline for the pre-filled New run form.
await tester.tap(find.byKey(runFailureRunAgainKey));
await tester.pumpAndSettle();
expect(gateway.calls.map((call) => call.type), contains('get_pipeline'));
});
testWidgets('a failed run without a pipeline offers no Run again', (
tester,
) async {
final gateway = RetryWiringGateway();
addTearDown(gateway.framesController.close);
gateway.details[7] = {...retryFailedDetail(), 'failure_reason': 'Boom.'};
await _mount(tester, gateway);
expect(find.byKey(runFailureRetryKey), findsOneWidget);
expect(find.byKey(runFailureRunAgainKey), findsNothing);
expect(find.byKey(runFailureOpenInChatKey), findsNothing);
});
testWidgets('the more menu shows while the detail loads, items disabled', (
tester,
) async {
final gateway = _SlowDetailGateway();
await _mount(tester, gateway, settle: false);
await tester.pump();
await tester.pump(const Duration(milliseconds: 50));
expect(find.text('Loading run details…'), findsOneWidget);
expect(find.byKey(runMoreMenuKey), findsOneWidget);
await tester.tap(find.byKey(runMoreMenuKey));
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
final rename = tester.widget<PopupMenuItem<Object?>>(
find.ancestor(
of: find.text(runTitleActionLabel),
matching: find.byWidgetPredicate((w) => w is PopupMenuItem),
),
);
expect(rename.enabled, isFalse);
gateway.pending.complete({
'run_detail': {
'id': 7,
'title': 'Slow run',
'status': 'failed',
'name': 'p',
'steps': const <JsonMap>[],
},
});
await tester.tapAt(const Offset(2, 2));
await tester.pumpAndSettle();
await tester.tap(find.byKey(runMoreMenuKey));
await tester.pumpAndSettle();
final loaded = tester.widget<PopupMenuItem<Object?>>(
find.ancestor(
of: find.text(runTitleActionLabel),
matching: find.byWidgetPredicate((w) => w is PopupMenuItem),
),
);
expect(loaded.enabled, isTrue);
});
}
@@ -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);
}