Merge main (Notebook design) into Glass

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-04 00:12:44 +00:00
304 changed files with 13450 additions and 5590 deletions
@@ -1,5 +1,6 @@
import 'dart:convert';
import 'package:pipelines_app/features/chat/stack/mobile_chat_navigation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/application/app_session.dart';
@@ -29,6 +30,12 @@ Widget host(AppSession session, {String? initialSessionId}) => MaterialApp(
);
void main() {
// These describe the Quick switch layout (the peek of the next chat).
setUp(
() => MobileChatNavigationController.instance.debugUse(
MobileChatNavigation.quickSwitch,
),
);
testWidgets('nothing is requested before the shared socket is ready', (
tester,
) async {
@@ -1,6 +1,7 @@
import 'dart:async';
import 'dart:convert';
import 'package:pipelines_app/features/chat/stack/mobile_chat_navigation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -296,6 +297,12 @@ Future<void> replyChatHistory(
}
void main() {
// These describe the Quick switch layout (the peek of the next chat).
setUp(
() => MobileChatNavigationController.instance.debugUse(
MobileChatNavigation.quickSwitch,
),
);
testWidgets(
'a wide /chat/s1 deep link shows that thread beside the list and route Back returns to /chat',
(tester) async {
@@ -5,6 +5,7 @@ import 'package:pipelines_app/core/servers/chat/chat_identity.dart';
import 'package:pipelines_app/core/servers/chat/chat_server_gateway.dart';
import 'package:pipelines_app/core/servers/chat/federated_chat_gateway.dart';
import 'package:pipelines_app/core/servers/server_catalog.dart';
import 'package:pipelines_app/core/transport/connection_state.dart';
import 'package:pipelines_app/core/transport/server_url.dart';
import 'package:pipelines_app/features/chat/files/files_urls.dart';
@@ -12,6 +13,8 @@ class Machine implements ApiGateway {
final events = StreamController<JsonMap>.broadcast();
final calls = <(String, JsonMap)>[];
bool fail = false;
Object? failure;
JsonMap? sessionsReply;
Completer<JsonMap>? pendingSessions;
@override
Stream<JsonMap> get frames => events.stream;
@@ -19,6 +22,8 @@ class Machine implements ApiGateway {
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
calls.add((type, fields));
if (fail) throw StateError('offline');
if (failure case final failure?) throw failure;
if (type == 'chat_sessions' && sessionsReply != null) return sessionsReply!;
if (type == 'chat_sessions') {
if (pendingSessions != null) return pendingSessions!.future;
return {
@@ -57,6 +62,40 @@ SavedServer server(String id) => SavedServer.validated(
endpoints: ['ws://$id.test/connect'],
);
void main() {
group('a server with no chats or no chat harness', () {
FederatedChatGateway federated(Machine machine) {
final sources = {'a': ChatServerGateway(server('a'), machine)};
return FederatedChatGateway(
() => sources,
() => 'a',
const Stream.empty(),
);
}
test('an omitted empty list reads as no chats, not a failure', () async {
final machine = Machine()..sessionsReply = {'type': 'chat_sessions'};
final reply = await federated(machine).call('chat_sessions');
expect(reply['chat_sessions'], isEmpty);
});
test('the server\'s own refusal is kept when no machine answers', () {
final machine = Machine()
..failure = const ProtocolError(
'chat is not configured on this server',
);
expect(
federated(machine).call('chat_sessions'),
throwsA(
isA<ProtocolError>().having(
(error) => error.message,
'message',
'chat is not configured on this server',
),
),
);
});
});
test(
'colliding native IDs remain distinct, mutations and replies stay on source',
() async {
@@ -0,0 +1,287 @@
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/core/servers/server_scope.dart';
import 'package:pipelines_app/features/chat/chat_runtime.dart';
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
import 'package:pipelines_app/features/chat/screen.dart';
import 'package:pipelines_app/features/chat/stack/mobile_chat_navigation.dart';
import 'package:pipelines_app/features/chat/windows/chat_windows.dart';
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
import 'package:pipelines_app/shell/windows/window_host.dart';
import 'package:pipelines_app/shell/windows/window_kind.dart';
import 'package:pipelines_app/shell/windows/window_manager.dart';
import 'package:pipelines_app/shell/windows/window_store.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'conversation/chat_thread_fixtures.dart';
/// A chat server with an open-chat set whose entries may float.
class _Server extends FakeChatGateway {
_Server(this.open, this.floating);
List<String> open;
Set<String> floating;
int revision = 1;
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
if (type == 'chat_sessions') {
return Future.value({
'chat_sessions': [
for (final id in ['a', 'b', 'c'])
{'id': id, 'title': 'Chat $id', 'directory': '/home/$id'},
],
});
}
if (type == 'chat_shells') return Future.value({'chat_shells': []});
if (type == 'chat_open_workspace') {
final request = fields['chat_open_workspace_request'] as Map?;
var rejected = false;
if (request != null && request['seed'] != true) {
if (request['base_revision'] != revision) {
rejected = true;
} else {
final entries = (request['entries'] as List).cast<Map>();
open = [for (final e in entries) '${e['session_id']}'];
floating = {
for (final e in entries)
if (e['floating'] == true) '${e['session_id']}',
};
revision++;
}
}
return Future.value({
'type': 'chat_open_workspace',
'chat_open_workspace': _body(rejected),
});
}
return super.call(type, fields);
}
JsonMap _body([bool rejected = false]) => {
'revision': revision,
'entries': [
for (final id in open)
{'session_id': id, if (floating.contains(id)) 'floating': true},
],
if (rejected) 'rejected': true,
};
void change(List<String> ids, Set<String> floats) {
open = ids;
floating = floats;
revision++;
emitRaw({
'type': 'chat_open_workspace_changed',
'chat_open_workspace': _body(),
});
}
}
class _Store implements WindowStore {
String? value;
@override
Future<String?> read() async => value;
@override
Future<bool> write(String record) async {
value = record;
return true;
}
}
const _wide = Size(1800, 1000);
const _phone = Size(390, 844);
class _App {
late final _Server server;
late final ChatRuntime runtime;
late final WindowManager manager;
late final ChatWindows windows;
Future<void> start(WidgetTester tester, {Size size = _wide}) async {
SharedPreferences.setMockInitialValues({});
_resize(tester, size);
addTearDown(tester.view.reset);
server = _Server(['a', 'b'], {'b'})..history = (_) async => chatPage([]);
bindServerIdentity(server, 'server-a');
runtime = ChatRuntime(gateway: server, serverKey: 'server-a');
manager = WindowManager(
kinds: WindowKinds(),
store: _Store(),
server: 'server-a',
);
windows = ChatWindows(
manager: manager,
runtime: runtime,
openInChat: (_) {},
)..start();
await manager.restore();
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Stack(
fit: StackFit.expand,
children: [
ChatScreen(
gateway: server,
persistWorkspace: true,
runtime: runtime,
windows: windows,
),
Positioned.fill(child: WindowHost(manager: manager)),
],
),
),
),
);
await tester.pumpAndSettle();
}
Future<void> stop(WidgetTester tester) async {
await tester.pumpWidget(const SizedBox.shrink());
windows.dispose();
runtime.dispose();
manager.dispose();
server.close();
}
List<String> get floatingWindows => [
for (final w in windows.windows) w.contentId,
];
}
void _resize(WidgetTester tester, Size size) {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
}
List<String> _panes(WidgetTester tester) {
final workspace = find.byType(ChatWorkspace, skipOffstage: false);
if (workspace.evaluate().isEmpty) return const [];
return tester
.widget<ChatWorkspace>(workspace)
.controller
.panes
.map((pane) => pane.sessionId)
.toList();
}
Finder _shownThread(String id) => find
.byWidgetPredicate((w) => w is ChatThreadView && w.sessionId == id)
.hitTestable();
void main() {
final navigation = MobileChatNavigationController.instance;
tearDown(() {
unawaited(navigation.setValue(MobileChatNavigation.quickSwitch));
});
testWidgets('a phone tiles a floating chat; a wide layout floats it again', (
tester,
) async {
final app = _App();
await app.start(tester);
expect(app.floatingWindows, ['b']);
_resize(tester, _phone);
await tester.pumpAndSettle();
// No window at phone width: the chat is an open chat like the others,
// and the server still has it floating.
expect(app.floatingWindows, isEmpty);
expect(app.server.floating, {'b'});
// The list opens it full screen.
await tester.tap(find.byKey(const Key('chat-row-b')));
await tester.pumpAndSettle();
expect(_shownThread('b'), findsOneWidget);
expect(_panes(tester), ['a', 'b']);
_resize(tester, _wide);
await tester.pumpAndSettle();
expect(app.floatingWindows, ['b']);
expect(_panes(tester), ['a']);
expect(_shownThread('a'), findsOneWidget);
expect(app.server.floating, {'b'});
expect(app.server.open, ['a', 'b']);
expect(tester.takeException(), isNull);
await app.stop(tester);
});
testWidgets('a floating chat opens from the list on a phone from the start', (
tester,
) async {
final app = _App();
await app.start(tester, size: _phone);
expect(app.floatingWindows, isEmpty);
await tester.tap(find.byKey(const Key('chat-row-b')));
await tester.pumpAndSettle();
expect(_shownThread('b'), findsOneWidget);
expect(_panes(tester), ['a', 'b']);
expect(app.server.floating, {'b'});
await app.stop(tester);
});
testWidgets('quick switch reaches a floating chat on a phone', (
tester,
) async {
final app = _App();
await app.start(tester, size: _phone);
await tester.tap(find.byKey(const Key('chat-row-a')));
await tester.pumpAndSettle();
expect(_shownThread('a'), findsOneWidget);
final controller = tester
.widget<ChatWorkspace>(find.byType(ChatWorkspace))
.controller;
final b = controller.panes.firstWhere((pane) => pane.sessionId == 'b');
await tester.tap(find.byKey(ValueKey('chat-peek-${b.id}')));
await tester.pumpAndSettle();
expect(_shownThread('b'), findsOneWidget);
expect(app.floatingWindows, isEmpty);
await app.stop(tester);
});
testWidgets('the chat stack reaches a floating chat on a phone', (
tester,
) async {
unawaited(navigation.setValue(MobileChatNavigation.chatStack));
final app = _App();
await app.start(tester, size: _phone);
await tester.tap(find.byKey(const Key('chat-row-a')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-stack')));
await tester.pumpAndSettle();
final controller = tester
.widget<ChatWorkspace>(find.byType(ChatWorkspace))
.controller;
final b = controller.panes.firstWhere((pane) => pane.sessionId == 'b');
await tester.tap(find.byKey(ValueKey('chat-stack-button-${b.id}')));
await tester.pumpAndSettle();
expect(_shownThread('b'), findsOneWidget);
await app.stop(tester);
});
testWidgets('a chat another device floats stays tiled on a phone', (
tester,
) async {
final app = _App();
await app.start(tester, size: _phone);
await tester.tap(find.byKey(const Key('chat-row-a')));
await tester.pumpAndSettle();
app.server.change(['a', 'b', 'c'], {'b', 'c'});
await tester.pumpAndSettle();
expect(app.floatingWindows, isEmpty);
expect(_panes(tester), ['a', 'b', 'c']);
// Removing a held chat on the phone drops it from the open chats.
final controller = tester
.widget<ChatWorkspace>(find.byType(ChatWorkspace, skipOffstage: false))
.controller;
controller.close(controller.panes.last.id);
await tester.pumpAndSettle();
expect(app.server.open, ['a', 'b']);
expect(app.server.floating, {'b'});
await app.stop(tester);
});
}
@@ -1,13 +1,23 @@
import 'dart:async';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/stack/mobile_chat_navigation.dart';
/// Functional chat tests settle asynchronous state with reduced motion. Tests
/// covering animation explicitly opt back in and pump known frame durations.
///
/// Tests run as Android, where the Chat stack (the default) also shows on a
/// wide layout. Each test starts on Quick switch, the layout most of them
/// describe; the stack's own tests choose it.
Future<void> testExecutable(FutureOr<void> Function() testMain) async {
TestWidgetsFlutterBinding.ensureInitialized()
.platformDispatcher
.accessibilityFeaturesTestValue = const FakeAccessibilityFeatures(
disableAnimations: true,
);
setUp(
() => MobileChatNavigationController.instance.debugUse(
MobileChatNavigation.quickSwitch,
),
);
await testMain();
}
@@ -0,0 +1,323 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.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/core/servers/server_scope.dart';
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
import 'package:pipelines_app/features/chat/screen.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_column.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_disc.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_drag.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_close_target.dart';
import 'package:pipelines_app/features/chat/stack/mobile_chat_navigation.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:shared_preferences/shared_preferences.dart';
import '../conversation/chat_thread_fixtures.dart';
/// A chat server keeping the open-chat set, as the sync test's does.
class _Server extends FakeChatGateway {
List<String> open = ['a', 'b', 'c'];
int revision = 1;
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
if (type == 'chat_sessions') {
return Future.value({
'chat_sessions': [
for (final id in ['a', 'b', 'c', 'd'])
{'id': id, 'title': 'Chat $id', 'directory': '/w'},
],
});
}
if (type == 'chat_shells') return Future.value({'chat_shells': []});
if (type == 'chat_open_workspace') {
final request = fields['chat_open_workspace_request'] as Map?;
var rejected = false;
if (request != null && request['seed'] != true) {
if (request['base_revision'] != revision) {
rejected = true;
} else {
open = [
for (final e in (request['entries'] as List).cast<Map>())
'${e['session_id']}',
];
revision++;
}
}
return Future.value({
'type': 'chat_open_workspace',
'chat_open_workspace': {
'revision': revision,
'entries': [
for (final id in open) {'session_id': id},
],
if (rejected) 'rejected': true,
},
});
}
return super.call(type, fields);
}
}
Future<_Server> _pump(WidgetTester tester, {bool reduced = false}) async {
SharedPreferences.setMockInitialValues({});
unawaited(
MobileChatNavigationController.instance.setValue(
MobileChatNavigation.chatStack,
),
);
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final server = _Server()..history = (_) async => chatPage(const []);
bindServerIdentity(server, 'server-stack');
addTearDown(server.close);
await tester.pumpWidget(
MaterialApp(
builder: (context, child) => MediaQuery(
data: MediaQuery.of(context).copyWith(disableAnimations: reduced),
child: child!,
),
home: AdaptiveShell(
destination: AppDestination.chat,
destinationBodies: {
AppDestination.chat: (_) =>
ChatScreen(gateway: server, persistWorkspace: true),
},
),
),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-row-a')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-stack')));
await tester.pumpAndSettle();
return server;
}
ChatWorkspaceController _workspace(WidgetTester tester) =>
tester.widget<ChatWorkspace>(find.byType(ChatWorkspace)).controller;
List<String> _order(WidgetTester tester) => [
for (final pane in _workspace(tester).panes) pane.sessionId,
];
/// Chat [id]'s avatar in the open column.
Finder _button(WidgetTester tester, String id) {
final pane = _workspace(
tester,
).panes.firstWhere((pane) => pane.sessionId == id);
return find.byKey(ValueKey('chat-stack-button-${pane.id}'));
}
final _add = find.byKey(const ValueKey('chat-stack-button-add'));
final _target = find.byType(ChatStackCloseTarget);
/// Holds [finder] until it lifts.
Future<TestGesture> _lift(WidgetTester tester, Finder finder) async {
final gesture = await tester.startGesture(tester.getCenter(finder));
await tester.pump(chatStackLiftDelay + const Duration(milliseconds: 20));
return gesture;
}
double _shown(WidgetTester tester) =>
tester.widget<ChatStackCloseTarget>(_target).armed.value;
void main() {
final navigation = MobileChatNavigationController.instance;
tearDown(() {
unawaited(navigation.setValue(MobileChatNavigation.quickSwitch));
});
test('movePane moves a pane and keeps the active one', () {
final controller = ChatWorkspaceController()..open('a');
controller
..splitActive('b', ChatSplitAxis.horizontal)
..splitActive('c', ChatSplitAxis.horizontal);
final active = controller.activePaneId;
final a = controller.panes.first.id;
controller.movePane(a, 2);
expect(controller.panes.map((p) => p.sessionId), ['b', 'c', 'a']);
expect(controller.panes.last.id, a);
expect(controller.activePaneId, active);
controller.dispose();
});
testWidgets('hold and drag reorders, and the order reaches the server', (
tester,
) async {
final server = await _pump(tester);
expect(_order(tester), ['a', 'b', 'c']);
final b = tester.getCenter(_button(tester, 'b'));
final gesture = await _lift(tester, _button(tester, 'a'));
// Lifted: the remove target comes in.
await tester.pumpAndSettle();
expect(_shown(tester), 1);
// Up past the middle of c (its middle would group): b and c slide down.
await gesture.moveBy(const Offset(0, -kChatStackPitch * 2.4));
await tester.pumpAndSettle();
expect(tester.getCenter(_button(tester, 'b')).dy, b.dy + kChatStackPitch);
await gesture.up();
await tester.pumpAndSettle();
expect(_order(tester), ['b', 'c', 'a']);
expect(server.open, ['b', 'c', 'a']);
// Everyone settles in the new slots; the column stays open.
expect(tester.getCenter(_button(tester, 'b')).dy, closeTo(b.dy + 56, .5));
expect(_shown(tester), 0);
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('dropping on the × removes; Undo restores the place', (
tester,
) async {
final server = await _pump(tester);
final gesture = await _lift(tester, _button(tester, 'b'));
await tester.pumpAndSettle();
final from = tester.getCenter(_button(tester, 'b'));
await gesture.moveBy(tester.getCenter(_target) - from);
await tester.pumpAndSettle();
final drag = tester.widget<ChatStackCloseTarget>(_target).hover;
expect(drag.value, 1);
await gesture.up();
await tester.pumpAndSettle();
expect(find.text('Removed Chat b from open chats'), findsOneWidget);
expect(_order(tester), ['a', 'c']);
expect(server.open, ['a', 'c']);
await tester.tap(find.text('Undo'));
await tester.pumpAndSettle();
expect(_order(tester), ['a', 'b', 'c']);
expect(server.open, ['a', 'b', 'c']);
// The chat on screen stays on screen.
expect(_workspace(tester).activePane?.sessionId, 'a');
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('Escape, or a drop away from the column, puts the chat back', (
tester,
) async {
final server = await _pump(tester);
final home = tester.getCenter(_button(tester, 'a'));
var gesture = await _lift(tester, _button(tester, 'a'));
await gesture.moveBy(const Offset(0, -kChatStackPitch * 2));
await tester.pumpAndSettle();
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pumpAndSettle();
await gesture.up();
await tester.pumpAndSettle();
expect(_order(tester), ['a', 'b', 'c']);
expect(tester.getCenter(_button(tester, 'a')), home);
// Escape only cancelled the drag: the column is still open.
expect(find.byType(ChatStackColumn), findsOneWidget);
gesture = await _lift(tester, _button(tester, 'a'));
await gesture.moveBy(const Offset(-200, -kChatStackPitch * 3));
await tester.pumpAndSettle();
await gesture.up();
await tester.pumpAndSettle();
expect(_order(tester), ['a', 'b', 'c']);
expect(server.open, ['a', 'b', 'c']);
expect(tester.getCenter(_button(tester, 'a')), home);
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('a tap still opens a chat; Add chat does not lift', (
tester,
) async {
await _pump(tester);
final add = tester.getCenter(_add);
final gesture = await _lift(tester, _add);
await tester.pumpAndSettle();
expect(_shown(tester), 0);
await gesture.moveBy(const Offset(0, kChatStackPitch * 2));
await tester.pumpAndSettle();
expect(tester.getCenter(_add), add);
await gesture.up();
await tester.pumpAndSettle();
expect(_order(tester), ['a', 'b', 'c']);
// A drag that moved off "+" is no tap: the column is still open.
expect(find.byType(ChatStackColumn), findsOneWidget);
await tester.tap(_button(tester, 'c'));
await tester.pumpAndSettle();
expect(
find
.byWidgetPredicate((w) => w is ChatThreadView && w.sessionId == 'c')
.hitTestable(),
findsOneWidget,
);
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('Move up, Move down and Remove are semantic actions', (
tester,
) async {
final semantics = tester.ensureSemantics();
final server = await _pump(tester);
void act(String id, String label) {
final node = tester.getSemantics(_button(tester, id));
final action = node
.getSemanticsData()
.customSemanticsActionIds!
.map(CustomSemanticsAction.getAction)
.firstWhere((action) => action!.label == label)!;
tester.binding.renderViews.first.owner!.semanticsOwner!.performAction(
node.id,
SemanticsAction.customAction,
CustomSemanticsAction.getIdentifier(action),
);
}
// The bottom chat cannot move down; the top one cannot move up.
final bottom = tester.getSemantics(_button(tester, 'a'));
expect(
bottom.getSemanticsData().customSemanticsActionIds!.map(
(id) => CustomSemanticsAction.getAction(id)!.label,
),
unorderedEquals([
ChatStackColumn.moveUpLabel,
ChatStackColumn.removeLabel,
]),
);
act('a', ChatStackColumn.moveUpLabel);
await tester.pumpAndSettle();
expect(server.open, ['b', 'a', 'c']);
act('c', ChatStackColumn.moveDownLabel);
await tester.pumpAndSettle();
expect(server.open, ['b', 'c', 'a']);
act('b', ChatStackColumn.removeLabel);
await tester.pumpAndSettle();
expect(server.open, ['c', 'a']);
expect(find.text('Removed Chat b from open chats'), findsOneWidget);
semantics.dispose();
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('reduced motion: neighbours swap at once, the × only fades', (
tester,
) async {
await _pump(tester, reduced: true);
final b = tester.getCenter(_button(tester, 'b'));
final gesture = await _lift(tester, _button(tester, 'a'));
expect(_shown(tester), 1);
await gesture.moveBy(const Offset(0, -kChatStackPitch * 1.4));
await tester.pump();
expect(tester.getCenter(_button(tester, 'b')).dy, b.dy + kChatStackPitch);
// No turn or growth: the button only fades.
expect(
find.descendant(of: _target, matching: find.byType(RotationTransition)),
findsNothing,
);
await gesture.up();
await tester.pump();
expect(_order(tester), ['b', 'a', 'c']);
expect(_shown(tester), 0);
await tester.pumpAndSettle();
await tester.pumpWidget(const SizedBox.shrink());
});
}
@@ -1,7 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_close_target.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_column.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_disc.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_entry.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_fab.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_pose.dart';
@@ -103,7 +105,8 @@ void main() {
expect(find.text('Chat 0'), findsOneWidget);
expect(find.text('Chat 4'), findsOneWidget);
expect(find.text(ChatStackColumn.addLabel), findsOneWidget);
// Item 0 sits on the stack; each further item rises one pitch.
// The stack's slot holds the close button; item 0 sits a pitch above
// it and each further item rises one more.
final first = tester.getCenter(
find.byKey(const ValueKey('chat-stack-button-pane-0')),
);
@@ -114,7 +117,11 @@ void main() {
find.byKey(const ValueKey('chat-stack-button-add')),
);
expect(first.dx, closeTo(slot.center.dx, .5));
expect(first.dy, closeTo(slot.center.dy, .5));
expect(first.dy, closeTo(slot.center.dy - kChatStackPitch, .5));
expect(
tester.getCenter(find.bySemanticsLabel(ChatStackCloseTarget.label)),
slot.center,
);
expect(second.dy, lessThan(first.dy));
expect(add.dy, lessThan(second.dy));
// Outside the column.
@@ -126,6 +133,22 @@ void main() {
expect(harness.opened, isEmpty);
});
testWidgets('the close button where the pile was folds the column', (
tester,
) async {
final harness = await _pump(tester);
final slot = tester.getRect(find.byKey(const Key('chat-stack')));
await tester.tap(find.byKey(const Key('chat-stack')));
await _settle(tester);
await tester.tapAt(slot.center);
await tester.pump();
expect(_state(tester).expanded, isFalse);
await _settle(tester);
expect(find.byType(ChatStackColumn), findsNothing);
expect(harness.opened, isEmpty);
expect(harness.added, 0);
});
testWidgets('tapping a chat opens it and folds the column', (tester) async {
final harness = await _pump(tester);
await tester.tap(find.byKey(const Key('chat-stack')));
@@ -145,17 +168,18 @@ void main() {
expect(harness.opened, ['s3']);
});
testWidgets('add opens the picker; long press removes', (tester) async {
testWidgets('add opens the picker; a hold alone removes nothing', (
tester,
) async {
final harness = await _pump(tester);
await tester.tap(find.byKey(const Key('chat-stack')));
await _settle(tester);
// A hold lifts the chat for a drag; let go in place, it settles back.
await tester.longPress(find.text('Chat 2'));
await _settle(tester);
expect(harness.removed, ['s2']);
// Removing folds the column, so a snack bar's Undo is in reach.
expect(find.byType(ChatStackColumn), findsNothing);
await tester.tap(find.byKey(const Key('chat-stack')));
await _settle(tester);
expect(harness.removed, isEmpty);
expect(harness.opened, isEmpty);
expect(find.byType(ChatStackColumn), findsOneWidget);
await tester.tap(find.byKey(const ValueKey('chat-stack-button-add')));
await _settle(tester);
expect(harness.added, 1);
@@ -0,0 +1,371 @@
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/core/servers/server_scope.dart';
import 'package:pipelines_app/features/chat/screen.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_close_target.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_column.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_disc.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_drag.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_group_dialogs.dart';
import 'package:pipelines_app/features/chat/stack/mobile_chat_navigation.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:shared_preferences/shared_preferences.dart';
import '../conversation/chat_thread_fixtures.dart';
/// A chat server keeping the open-chat set with each entry's group.
class _Server extends FakeChatGateway {
List<String> open = ['a', 'b', 'c'];
Map<String, String> groups = {};
int revision = 1;
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
if (type == 'chat_sessions') {
return Future.value({
'chat_sessions': [
for (final id in ['a', 'b', 'c', 'd'])
{'id': id, 'title': 'Chat $id', 'directory': '/w'},
],
});
}
if (type == 'chat_shells') return Future.value({'chat_shells': []});
if (type == 'chat_open_workspace') {
final request = fields['chat_open_workspace_request'] as Map?;
var rejected = false;
if (request != null && request['seed'] != true) {
if (request['base_revision'] != revision) {
rejected = true;
} else {
final entries = (request['entries'] as List).cast<Map>();
open = [for (final e in entries) '${e['session_id']}'];
groups = {
for (final e in entries)
if (e['group'] != null) '${e['session_id']}': '${e['group']}',
};
revision++;
}
}
return Future.value({
'type': 'chat_open_workspace',
'chat_open_workspace': _body(rejected),
});
}
return super.call(type, fields);
}
JsonMap _body([bool rejected = false]) => {
'revision': revision,
'entries': [
for (final id in open)
{'session_id': id, if (groups[id] != null) 'group': groups[id]},
],
if (rejected) 'rejected': true,
};
/// Another device changed the set.
void change(List<String> ids, Map<String, String> byGroup) {
open = ids;
groups = byGroup;
revision++;
emitRaw({
'type': 'chat_open_workspace_changed',
'chat_open_workspace': _body(),
});
}
}
Future<_Server> _pump(WidgetTester tester) async {
SharedPreferences.setMockInitialValues({});
MobileChatNavigationController.instance.debugUse(
MobileChatNavigation.chatStack,
);
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final server = _Server()..history = (_) async => chatPage(const []);
bindServerIdentity(server, 'server-groups');
addTearDown(server.close);
await tester.pumpWidget(
MaterialApp(
home: AdaptiveShell(
destination: AppDestination.chat,
destinationBodies: {
AppDestination.chat: (_) =>
ChatScreen(gateway: server, persistWorkspace: true),
},
),
),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-row-a')));
await tester.pumpAndSettle();
await _expand(tester);
return server;
}
Future<void> _expand(WidgetTester tester) async {
await tester.tap(find.byKey(const Key('chat-stack')));
await tester.pumpAndSettle();
}
ChatWorkspaceController _workspace(WidgetTester tester) =>
tester.widget<ChatWorkspace>(find.byType(ChatWorkspace)).controller;
Finder _chat(WidgetTester tester, String id) {
final pane = _workspace(
tester,
).panes.firstWhere((pane) => pane.sessionId == id);
return find.byKey(ValueKey('chat-stack-button-${pane.id}'));
}
Finder _group(String name) =>
find.byKey(ValueKey('chat-stack-button-group-$name'));
final _header = find.byKey(const ValueKey('chat-stack-button-header'));
/// Holds [item] until it lifts, moves it by [by], lets go.
Future<void> _drag(WidgetTester tester, Finder item, Offset by) async {
final gesture = await tester.startGesture(tester.getCenter(item));
await tester.pump(chatStackLiftDelay + const Duration(milliseconds: 20));
await gesture.moveBy(by);
await tester.pumpAndSettle();
await gesture.up();
await tester.pumpAndSettle();
}
const _up = Offset(0, -kChatStackPitch);
/// Makes group "Work" of b and a (a dropped onto b), naming it.
Future<void> _makeWork(WidgetTester tester) async {
await _drag(tester, _chat(tester, 'a'), _up);
expect(find.text('Name the group'), findsOneWidget);
await tester.enterText(
find.byKey(const Key('chat-stack-group-name')),
'Work',
);
await tester.tap(find.text('Save'));
await tester.pumpAndSettle();
}
void _act(WidgetTester tester, Finder target, String label) {
final node = tester.getSemantics(target);
final action = node
.getSemanticsData()
.customSemanticsActionIds!
.map(CustomSemanticsAction.getAction)
.firstWhere((action) => action!.label == label)!;
tester.binding.renderViews.first.owner!.semanticsOwner!.performAction(
node.id,
SemanticsAction.customAction,
CustomSemanticsAction.getIdentifier(action),
);
}
void main() {
tearDown(
() => MobileChatNavigationController.instance.debugUse(
MobileChatNavigation.quickSwitch,
),
);
testWidgets('a chat dropped onto a chat makes a named group that syncs', (
tester,
) async {
final server = await _pump(tester);
// Mid-drag over b's middle: b grows (the drop target).
final gesture = await tester.startGesture(
tester.getCenter(_chat(tester, 'a')),
);
await tester.pump(chatStackLiftDelay + const Duration(milliseconds: 20));
final b = tester.getSize(_chat(tester, 'b'));
await gesture.moveBy(_up);
await tester.pumpAndSettle();
expect(
tester.getRect(_chat(tester, 'b')).width,
closeTo(b.width * chatStackOntoScale, .5),
);
// The dragged chat shrinks onto it, so the target's ring shows around.
expect(
tester.getRect(_chat(tester, 'a')).width,
closeTo(b.width * chatStackLiftScale * chatStackOverRemoveScale, .5),
);
await gesture.up();
await tester.pumpAndSettle();
await tester.enterText(
find.byKey(const Key('chat-stack-group-name')),
'Work',
);
await tester.tap(find.text('Save'));
await tester.pumpAndSettle();
expect(server.open, ['b', 'a', 'c']);
expect(server.groups, {'b': 'Work', 'a': 'Work'});
expect(_group('Work'), findsOneWidget);
expect(find.text('Work'), findsOneWidget);
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('a group opens in place; header, Back and outside return', (
tester,
) async {
await _pump(tester);
await _makeWork(tester);
await tester.tap(_group('Work'));
await tester.pumpAndSettle();
expect(_chat(tester, 'a').hitTestable(), findsOneWidget);
expect(_chat(tester, 'b').hitTestable(), findsOneWidget);
expect(_header.hitTestable(), findsOneWidget);
// The top level's chat c is behind: no input.
expect(_chat(tester, 'c').hitTestable(), findsNothing);
await tester.tap(_header);
await tester.pumpAndSettle();
expect(_group('Work').hitTestable(), findsOneWidget);
// Outside: out of the group first, then folded.
await tester.tap(_group('Work'));
await tester.pumpAndSettle();
await tester.tapAt(const Offset(40, 120));
await tester.pumpAndSettle();
expect(_group('Work').hitTestable(), findsOneWidget);
await tester.tapAt(const Offset(40, 120));
await tester.pumpAndSettle();
expect(find.byType(ChatStackColumn), findsNothing);
// Back leaves the group, then folds.
await _expand(tester);
await tester.tap(_group('Work'));
await tester.pumpAndSettle();
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(_group('Work').hitTestable(), findsOneWidget);
// A chat in a group opens as any other.
await tester.tap(_group('Work'));
await tester.pumpAndSettle();
await tester.tap(_chat(tester, 'b'));
await tester.pumpAndSettle();
expect(_workspace(tester).activePane?.sessionId, 'b');
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('a chat joins a group; a group takes a chat in', (tester) async {
final server = await _pump(tester);
await _makeWork(tester);
// Top level: Work (b, a) at the bottom, c above it. c down onto it.
await _drag(tester, _chat(tester, 'c'), -_up);
expect(server.groups, {'b': 'Work', 'a': 'Work', 'c': 'Work'});
expect(server.open, ['b', 'a', 'c']);
// Leaving from inside the group: drop on its header.
await tester.tap(_group('Work'));
await tester.pumpAndSettle();
await _drag(tester, _chat(tester, 'c'), _up);
expect(server.groups, {'b': 'Work', 'a': 'Work'});
expect(server.open, ['b', 'a', 'c']);
// Back on the top level: drag the group onto c.
await tester.tap(_header);
await tester.pumpAndSettle();
await _drag(tester, _group('Work'), _up);
expect(server.groups, {'b': 'Work', 'a': 'Work', 'c': 'Work'});
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('the last chat left alone dissolves the group', (tester) async {
final server = await _pump(tester);
await _makeWork(tester);
await tester.tap(_group('Work'));
await tester.pumpAndSettle();
// a is second in the group: one slot up is the header.
await _drag(tester, _chat(tester, 'a'), _up);
expect(server.groups, isEmpty);
// The group is gone: back on the top level.
expect(_header, findsNothing);
expect(_chat(tester, 'a').hitTestable(), findsOneWidget);
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('Rename, Ungroup and Close all; each syncs, Undo restores', (
tester,
) async {
final semantics = tester.ensureSemantics();
final server = await _pump(tester);
await _makeWork(tester);
_act(tester, _group('Work'), ChatStackGroupAction.rename.label);
await tester.pumpAndSettle();
await tester.enterText(
find.byKey(const Key('chat-stack-group-name')),
'Personal',
);
await tester.tap(find.text('Save'));
await tester.pumpAndSettle();
expect(server.groups, {'b': 'Personal', 'a': 'Personal'});
_act(tester, _group('Personal'), ChatStackGroupAction.ungroup.label);
await tester.pumpAndSettle();
expect(server.groups, isEmpty);
expect(find.text('Ungrouped Personal'), findsOneWidget);
await tester.tap(find.text('Undo'));
await tester.pumpAndSettle();
expect(server.groups, {'b': 'Personal', 'a': 'Personal'});
await _expand(tester);
_act(tester, _group('Personal'), ChatStackGroupAction.closeAll.label);
await tester.pumpAndSettle();
expect(server.open, ['c']);
await tester.tap(find.text('Undo'));
await tester.pumpAndSettle();
expect(server.open, ['b', 'a', 'c']);
expect(server.groups, {'b': 'Personal', 'a': 'Personal'});
semantics.dispose();
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('Move to group and Remove from group as semantic actions', (
tester,
) async {
final semantics = tester.ensureSemantics();
final server = await _pump(tester);
await _makeWork(tester);
_act(tester, _chat(tester, 'c'), ChatStackColumn.moveToGroupLabel);
await tester.pumpAndSettle();
await tester.tap(find.text('Work').last);
await tester.pumpAndSettle();
expect(server.groups['c'], 'Work');
await tester.tap(_group('Work'));
await tester.pumpAndSettle();
_act(tester, _chat(tester, 'b'), ChatStackColumn.leaveGroupLabel);
await tester.pumpAndSettle();
expect(server.groups, {'a': 'Work', 'c': 'Work'});
expect(server.open, ['a', 'c', 'b']);
semantics.dispose();
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('a group dropped on the close button is ungrouped', (
tester,
) async {
final server = await _pump(tester);
await _makeWork(tester);
final group = tester.getCenter(_group('Work'));
final close = tester.getCenter(
find.bySemanticsLabel(ChatStackCloseTarget.label),
);
await _drag(tester, _group('Work'), close - group);
expect(server.groups, isEmpty);
expect(server.open, ['b', 'a', 'c']);
expect(find.text('Ungrouped Work'), findsOneWidget);
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('groups from another device appear', (tester) async {
final server = await _pump(tester);
server.change(['a', 'b', 'c'], {'a': 'Home', 'c': 'Home'});
await tester.pumpAndSettle();
expect(_group('Home'), findsOneWidget);
expect(find.text('Home'), findsOneWidget);
// The group's pill counts its chats.
expect(find.text('2'), findsWidgets);
await tester.pumpWidget(const SizedBox.shrink());
});
}
@@ -0,0 +1,168 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_drop_target.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_entry.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_group_ops.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_groups.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_node.dart';
import 'package:pipelines_app/features/chat/workspace/chat_open_workspace_gateway.dart';
ChatStackEntry _entry(String id, [String? group]) =>
ChatStackEntry(paneId: 'p$id', session: {'id': id}, group: group);
void main() {
group('ChatStackGroups', () {
test('assigns, merges on rename, dissolves a group of one', () {
final groups = ChatStackGroups();
var changes = 0;
groups.addListener(() => changes++);
// One chat is no group.
groups.assign(['a'], 'Work');
expect(groups.assignments, isEmpty);
expect(changes, 0);
groups.assign(['a', 'b'], 'Work');
groups.assign(['c', 'd'], 'Home');
expect(groups.membersOf('Work'), ['a', 'b']);
expect(groups.nextName(), 'Group 1');
groups.rename('Home', 'Work');
expect(groups.membersOf('Work'), ['a', 'b', 'c', 'd']);
groups.unassign(['a', 'b', 'c']);
expect(groups.assignments, isEmpty);
groups.assign(['a', 'b', 'c'], 'Group 1');
expect(groups.nextName(), 'Group 2');
groups.retain({'a', 'x'});
expect(groups.assignments, isEmpty);
expect(changes, greaterThan(0));
groups.dispose();
});
test('names are trimmed, bounded and never empty', () {
expect(chatStackGroupName(' Work \n'), 'Work');
expect(chatStackGroupName(' '), isNull);
expect(chatStackGroupName('a\tb'), 'a b');
expect(chatStackGroupName('x' * 100)!.length, chatStackGroupNameLimit);
});
});
group('nodes and drops', () {
final entries = [
_entry('a'),
_entry('b', 'Work'),
_entry('c'),
_entry('d', 'Work'),
];
final nodes = chatStackNodes(entries);
test('a group stands where its first chat is', () {
expect(nodes.map((node) => node.key), [
'chat:pa',
'group:Work',
'chat:pc',
]);
expect(chatStackOrder(nodes), ['a', 'b', 'd', 'c']);
// A lone member shows as a chat.
expect(
chatStackNodes([_entry('x', 'Solo')]).single,
isA<ChatStackChatNode>(),
);
});
test('dropping onto a chat or a group joins as expected', () {
final made = chatStackJoined(nodes, 2, 0, () => 'Group 1');
expect(made.created, isTrue);
expect(made.join, ['a', 'c']);
expect(made.order, ['a', 'c', 'b', 'd']);
final joined = chatStackJoined(nodes, 0, 1, () => 'unused');
expect((joined.group, joined.created), ('Work', false));
expect(joined.join, ['a']);
expect(joined.order, ['b', 'd', 'a', 'c']);
final took = chatStackJoined(nodes, 1, 2, () => 'unused');
expect(took.join, ['c']);
expect(took.order, ['a', 'b', 'd', 'c']);
expect(chatStackLeft(nodes, 'Work', 'b'), ['a', 'd', 'b', 'c']);
expect(chatStackRegrouped(nodes, 'Work', ['d', 'b']), [
'a',
'd',
'b',
'c',
]);
expect(chatStackMoved(nodes, 0, 2), ['b', 'd', 'c', 'a']);
});
test('the middle of an item groups, its edges reorder, stably', () {
bool all(int _) => true;
// From slot 0, one slot up: the middle of item 1.
expect(
chatStackDropTarget(
position: 1,
from: 0,
count: 3,
slot: 0,
canDropOnto: all,
),
(slot: 0, onto: 1),
);
// Past its middle: the gap moves above it...
expect(
chatStackDropTarget(
position: 1.4,
from: 0,
count: 3,
slot: 0,
canDropOnto: all,
),
(slot: 1, onto: null),
);
// ...and holds there while item 1 slides below it.
expect(
chatStackDropTarget(
position: 1.3,
from: 0,
count: 3,
slot: 1,
canDropOnto: all,
),
(slot: 1, onto: null),
);
// Below its middle the gap stays below it.
expect(
chatStackDropTarget(
position: .7,
from: 0,
count: 3,
slot: 0,
canDropOnto: all,
),
(slot: 0, onto: null),
);
// Without grouping the middle reorders too; the gap never passes
// lastSlot.
expect(
chatStackDropTarget(
position: 2.3,
from: 0,
count: 3,
slot: 1,
lastSlot: 1,
),
(slot: 1, onto: null),
);
});
});
test('an entry carries its group over the wire', () {
final entry = ChatOpenWorkspaceEntry.fromJson({
'session_id': 'a',
'group': ' Work ',
})!;
expect(entry.group, 'Work');
expect(entry.toJson(), {'session_id': 'a', 'group': 'Work'});
expect(ChatOpenWorkspaceEntry.fromJson({'session_id': 'b'})!.group, isNull);
const snapshot = ChatOpenWorkspaceSnapshot(1, [
ChatOpenWorkspaceEntry('a'),
]);
expect(
snapshot.sameEntries([const ChatOpenWorkspaceEntry('a', group: 'W')]),
isFalse,
);
});
}
@@ -34,6 +34,15 @@ class _Gateway extends FakeChatGateway {
}
}
class _Store implements MobileChatNavigationStore {
_Store(this.value);
final String? value;
@override
Future<String?> load() async => value;
@override
Future<bool> save(String value) async => true;
}
Future<void> _pump(WidgetTester tester, Size size) async {
SharedPreferences.setMockInitialValues({});
unawaited(
@@ -114,39 +123,53 @@ void main() {
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('long press removes a chat, Undo restores it', (tester) async {
await _pump(tester, const Size(390, 844));
await tester.tap(find.byKey(const Key('chat-row-a')));
await tester.pumpAndSettle();
await tester.tap(_stack);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const ValueKey('chat-stack-button-add')));
await tester.pumpAndSettle();
await tester.tap(find.text('Gamma').last);
await tester.pumpAndSettle();
expect(find.bySemanticsLabel(chatStackLabel(2)), findsOneWidget);
await tester.tap(_stack);
await tester.pumpAndSettle();
await tester.longPress(find.text('Alpha').last);
await tester.pumpAndSettle();
expect(find.text('Removed Alpha from open chats'), findsOneWidget);
expect(find.bySemanticsLabel(chatStackLabel(1)), findsOneWidget);
await tester.tap(find.text('Undo'));
await tester.pumpAndSettle();
// Gamma stays on screen; Alpha is back in the stack.
expect(_thread('c').hitTestable(), findsOneWidget);
expect(find.bySemanticsLabel(chatStackLabel(2)), findsOneWidget);
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets(
'a wide desktop window keeps its panes and shows no stack',
variant: TargetPlatformVariant.desktop(),
(tester) async {
await _pump(tester, const Size(1280, 800));
await tester.tap(find.byKey(const Key('chat-row-a')));
await tester.pumpAndSettle();
expect(_thread('a'), findsOneWidget);
expect(_stack, findsNothing);
await tester.pumpWidget(const SizedBox.shrink());
},
);
testWidgets('a wide window keeps its panes and shows no stack', (
tester,
) async {
await _pump(tester, const Size(1280, 800));
await tester.tap(find.byKey(const Key('chat-row-a')));
await tester.pumpAndSettle();
expect(_thread('a'), findsOneWidget);
expect(_stack, findsNothing);
await tester.pumpWidget(const SizedBox.shrink());
testWidgets(
'a wide phone or tablet layout (an unfolded foldable) keeps the stack',
variant: TargetPlatformVariant({
TargetPlatform.android,
TargetPlatform.iOS,
}),
(tester) async {
await _pump(tester, const Size(1280, 800));
await tester.tap(find.byKey(const Key('chat-row-a')));
await tester.pumpAndSettle();
expect(_thread('a'), findsOneWidget);
// The list stays beside the chat, the stack floats over the pane.
expect(find.byKey(const Key('chat-row-b')), findsOneWidget);
expect(_stack.hitTestable(), findsOneWidget);
await tester.tap(_stack);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const ValueKey('chat-stack-button-add')));
await tester.pumpAndSettle();
await tester.tap(find.text('Beta').last);
await tester.pumpAndSettle();
expect(find.bySemanticsLabel(chatStackLabel(2)), findsOneWidget);
await tester.pumpWidget(const SizedBox.shrink());
},
);
test('Chat stack is the default without a stored choice', () async {
final controller = MobileChatNavigationController(store: _Store(null));
expect(controller.value, MobileChatNavigation.chatStack);
await controller.restore();
expect(controller.value, MobileChatNavigation.chatStack);
final chosen = MobileChatNavigationController(store: _Store('quickSwitch'));
await chosen.restore();
expect(chosen.value, MobileChatNavigation.quickSwitch);
controller.dispose();
chosen.dispose();
});
}
@@ -17,7 +17,7 @@ void main() {
expect(find.byType(Scaffold), findsWidgets);
const message = 'No chats yet. Use New chat to start one.';
const message = 'No chats yet';
expect(find.text(message), findsOneWidget);
expectNormalTextStyle(tester, message);
});
@@ -39,7 +39,7 @@ void main() {
'for this operator';
expect(find.text(message), findsOneWidget);
expectNormalTextStyle(tester, message);
expect(find.text('No chats yet. Use New chat to start one.'), findsNothing);
expect(find.text('No chats yet'), findsNothing);
expect(
find.ancestor(
of: find.text('Retry'),
@@ -3,6 +3,8 @@ 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/core/transport/connection_state.dart';
import 'package:pipelines_app/features/chat/ui/sessions/chat_harness_setup_state.dart';
import 'chat_test_harness.dart';
import 'fake_chat_gateway.dart';
@@ -91,13 +93,29 @@ void main() {
) async {
final gateway = FakeChatGateway();
await pumpMaterialChat(tester, gateway);
expect(
find.text('No chats yet. Use New chat to start one.'),
findsOneWidget,
);
expect(find.text('No chats yet'), findsOneWidget);
expect(find.text('Start a chat'), findsOneWidget);
expect(find.textContaining('No chats match'), findsNothing);
});
testWidgets('a server without a chat harness shows the setup step', (
tester,
) async {
usePhoneSurface(tester);
final gateway = FakeChatGateway()
..sessionsHandler = () => Future.error(
const ProtocolError('chat is not configured on this server'),
);
await pumpMaterialChat(tester, gateway);
expect(find.byKey(chatHarnessSetupKey), findsOneWidget);
expect(find.text('pipelines harness setup claude'), findsOneWidget);
// Not a failure: no error notice, no raw server text.
expect(find.textContaining('not configured'), findsNothing);
expect(find.text('No chats yet'), findsNothing);
expect(find.text('Refresh'), findsWidgets);
});
testWidgets('load failure wraps the reason and hides the empty message', (
tester,
) async {
@@ -114,7 +132,7 @@ void main() {
'Bad state: server unavailable while listing chat sessions '
'for this operator';
expect(find.text(message), findsOneWidget);
expect(find.text('No chats yet. Use New chat to start one.'), findsNothing);
expect(find.text('No chats yet'), findsNothing);
final messageBox = tester.renderObject<RenderBox>(find.text(message));
expect(
messageBox.size.height,
@@ -0,0 +1,283 @@
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/chat/domain/chat_cell_numbers.dart';
import 'package:pipelines_app/features/chat/domain/chat_transcript.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_markdown_view.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_bubble.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_view.dart';
import 'package:pipelines_app/features/chat/ui/transcript/notebook/notebook_input_cell.dart';
import 'package:pipelines_app/features/chat/ui/transcript/notebook/notebook_tool_cell.dart';
import 'package:pipelines_app/features/chat/ui/transcript/notebook/notebook_tool_cells.dart';
import 'package:pipelines_app/features/chat/ui/transcript/paper/paper_quote.dart';
import 'package:pipelines_app/features/chat/ui/transcript/terminal/terminal_activity_rows.dart';
import 'package:pipelines_app/features/chat/ui/transcript/terminal/terminal_prompt_line.dart';
import 'package:pipelines_app/ui/theme/app_design.dart';
JsonMap _row(JsonMap message) => transcriptRows([message]).single;
final JsonMap _operator = _row({
'id': 'u1',
'role': 'user',
'parts': [
{'type': 'text', 'text': 'Fix the Windows paths.'},
],
});
JsonMap _tool(String id, String name, String status, {String output = ''}) => {
'type': 'tool',
'id': id,
'name': name,
'time': {'created': 1000, 'completed': 2200},
'state': {
'status': status,
'input': {'command': 'go test ./...'},
if (output.isNotEmpty)
'content': [
{'type': 'text', 'text': output},
],
if (status == 'error') 'error': {'message': 'exit status 1'},
},
};
const String _longOutput = 'ok pkg/a\nok pkg/b\nok pkg/c\nok pkg/d\nPASS';
JsonMap _agent({bool streaming = false}) => {
..._row({
'id': 'a1',
'role': 'assistant',
'parts': [
_tool('t1', 'Bash', 'completed', output: _longOutput),
_tool('t2', 'Read', 'error'),
{'type': 'text', 'text': 'Fixed the separators.'},
],
}),
if (streaming) 'streaming': true,
};
final JsonMap _followup = _row({
'id': 'f1',
'role': 'user',
'origin': 'followup',
'client': 'Agent follow-up',
'parts': [
{'type': 'text', 'text': 'Check whether run 42 finished.'},
],
});
Widget _host(
AppDesign design,
List<(JsonMap, int?)> rows, {
double width = 900,
}) => MaterialApp(
theme: design.light(),
home: Scaffold(
body: Center(
child: SizedBox(
width: width,
child: ListView(
children: [
for (final (row, cell) in rows)
ChatMessageView(
row: row,
cell: cell,
textBuilder: chatMarkdownText,
),
],
),
),
),
),
);
Finder _label(String text) => find.byWidgetPredicate(
(widget) =>
widget is Text &&
widget.key == const Key('chat-notebook-gutter-label') &&
widget.data == text,
);
void main() {
test('cells number each operator turn and pair its answers', () {
final rows = <JsonMap>[
{'kind': 'assistant', 'key': 'early'},
{'kind': 'user', 'key': 'u1'},
{'kind': 'assistant', 'key': 'a1'},
{'kind': 'system_notice', 'key': 'n1'},
{'kind': 'assistant', 'key': 'a1b'},
{'kind': 'user', 'key': 'f1'},
{'kind': 'assistant', 'key': 'chat-pending-response'},
];
expect(chatCellNumbers(rows), {
'u1': 1,
'a1': 1,
'a1b': 1,
'f1': 2,
'chat-pending-response': 2,
});
// Derived from the turn order alone: the same history numbers the same.
expect(chatCellNumbers(rows), chatCellNumbers([...rows]));
});
testWidgets('Notebook: In and Out cells with right-aligned gutter labels', (
tester,
) async {
await tester.pumpWidget(
_host(AppDesign.notebook, [(_operator, 3), (_agent(), 3)]),
);
expect(find.byType(NotebookInputCell), findsOneWidget);
expect(find.byType(TerminalPromptLine), findsNothing);
expect(find.byType(PaperQuote), findsNothing);
final inLabel = _label('In [3]:');
final outLabel = _label('Out [3]:');
expect(inLabel, findsOneWidget);
expect(outLabel, findsOneWidget);
// One gutter: both labels end in the same column, left of the cells.
expect(
tester.getTopRight(inLabel).dx,
closeTo(tester.getTopRight(outLabel).dx, 0.5),
);
final cell = find.byType(NotebookInputCell);
expect(
tester.getTopRight(inLabel).dx,
lessThan(tester.getTopLeft(cell).dx),
);
// The prompt's and the answer's text share one column.
expect(
tester.getTopLeft(find.text('Fix the Windows paths.')).dx,
closeTo(tester.getTopLeft(find.text('Fixed the separators.')).dx, 0.5),
);
// The label sits on the prompt's first line.
final labelBox = tester.getRect(inLabel);
final textBox = tester.getRect(find.text('Fix the Windows paths.'));
expect(labelBox.bottom, closeTo(textBox.bottom, 3));
});
testWidgets('Notebook: a prompt not yet run reads In [ ]:', (tester) async {
await tester.pumpWidget(_host(AppDesign.notebook, [(_operator, null)]));
expect(_label('In [ ]:'), findsOneWidget);
});
testWidgets('Notebook: tool calls are collapsed sub-cells that expand in '
'place', (tester) async {
await tester.pumpWidget(_host(AppDesign.notebook, [(_agent(), 1)]));
expect(find.byType(NotebookToolCells), findsOneWidget);
expect(find.byType(TerminalActivityRows), findsNothing);
final cells = find.byType(NotebookToolCell);
expect(cells, findsNWidgets(2));
// Collapsed: the first lines of the output, "+N lines", the duration and
// the status on the right.
expect(find.byKey(const Key('chat-notebook-tool-preview')), findsWidgets);
expect(find.text('+4 lines'), findsOneWidget);
expect(find.text('1.2s'), findsNWidgets(2));
expect(find.byKey(const Key('chat-notebook-tool-output')), findsNothing);
expect(find.textContaining('PASS'), findsNothing);
await tester.tap(find.byKey(const Key('chat-notebook-tool-header')).first);
await tester.pump();
expect(find.byKey(const Key('chat-notebook-tool-output')), findsOneWidget);
expect(find.textContaining('PASS'), findsOneWidget);
expect(find.text('+4 lines'), findsNothing);
await tester.tap(find.byKey(const Key('chat-notebook-tool-header')).first);
await tester.pump();
expect(find.byKey(const Key('chat-notebook-tool-output')), findsNothing);
// The status line still opens the activity details.
await tester.tap(find.byKey(const Key('chat-turn-activity')));
await tester.pumpAndSettle();
expect(find.text('Activity details'), findsOneWidget);
});
testWidgets('Notebook: a long turn folds its earlier calls', (tester) async {
final row = _row({
'id': 'a9',
'role': 'assistant',
'parts': [
for (var i = 0; i < notebookToolMaxCalls + 3; i++)
_tool('t$i', 'Read', 'completed', output: 'line $i'),
],
});
await tester.pumpWidget(_host(AppDesign.notebook, [(row, 1)]));
expect(find.byType(NotebookToolCell), findsNWidgets(notebookToolMaxCalls));
await tester.tap(find.byKey(const Key('chat-notebook-tool-earlier')));
await tester.pump();
expect(
find.byType(NotebookToolCell),
findsNWidgets(notebookToolMaxCalls + 3),
);
});
testWidgets('Notebook: a running turn shows Jupyter\'s [*] busy marker', (
tester,
) async {
await tester.pumpWidget(
_host(AppDesign.notebook, [(_agent(streaming: true), 2)]),
);
expect(_label('Out [2]:'), findsOneWidget);
final busy = find.byKey(const Key('chat-notebook-busy'));
expect(busy, findsOneWidget);
expect(tester.widget<Text>(busy).data, '[*]');
expect(
tester.getTopLeft(busy).dy,
greaterThan(tester.getTopLeft(_label('Out [2]:')).dy),
);
await tester.pumpWidget(_host(AppDesign.notebook, [(_agent(), 2)]));
expect(find.byKey(const Key('chat-notebook-busy')), findsNothing);
});
testWidgets('Notebook: a follow-up is an In cell with a scheduled tag', (
tester,
) async {
await tester.pumpWidget(_host(AppDesign.notebook, [(_followup, 4)]));
expect(_label('In [4]:'), findsOneWidget);
expect(find.byType(NotebookScheduledCell), findsOneWidget);
final tag = find.byKey(const Key('chat-notebook-scheduled-tag'));
expect(
find.descendant(of: tag, matching: find.text('scheduled')),
findsOneWidget,
);
expect(find.text('Follow-up from agent'), findsOneWidget);
expect(find.text('Check whether run 42 finished.'), findsOneWidget);
});
testWidgets('Notebook: at phone width the gutter collapses to an inline '
'label above the cell', (tester) async {
await tester.pumpWidget(
_host(AppDesign.notebook, [(_operator, 1), (_agent(), 1)], width: 380),
);
final label = _label('In [1]:');
final cell = find.byType(NotebookInputCell);
expect(
tester.getBottomLeft(label).dy,
lessThanOrEqualTo(tester.getTopLeft(cell).dy),
);
expect(tester.getTopLeft(label).dx, closeTo(tester.getTopLeft(cell).dx, 4));
});
for (final design in [
AppDesign.standard,
AppDesign.terminal,
AppDesign.paper,
]) {
testWidgets('${design.label} is unchanged: no cells, even with a number', (
tester,
) async {
await tester.pumpWidget(
_host(design, [
(_operator, 1),
(_agent(streaming: true), 1),
(_followup, 2),
]),
);
expect(find.byKey(const Key('chat-notebook-gutter-label')), findsNothing);
expect(find.byType(NotebookInputCell), findsNothing);
expect(find.byType(NotebookToolCells), findsNothing);
expect(find.byType(NotebookScheduledCell), findsNothing);
expect(find.byKey(const Key('chat-notebook-busy')), findsNothing);
if (design == AppDesign.standard) {
expect(find.byType(ChatUserBubble), findsOneWidget);
}
});
}
}
@@ -0,0 +1,84 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/graph/domain/stage_run_facts.dart';
import 'package:pipelines_app/features/graph/domain/stage_summary.dart';
void main() {
test('a model stage with no tools block runs the default tools', () {
final summary = stageSummaryFor({
'stages': [
{'key': 'a', 'prompt': 'Do it', 'edges': {}},
],
}, 'a')!;
expect(summary.kind, StageKind.model);
expect(summary.tools, defaultStageTools);
expect(summary.toolsDefault, isTrue);
expect(summary.prompt, 'Do it');
});
test('a delivery check reads as the delivery gate with its commands', () {
final summary = stageSummaryFor({
'stages': [
{
'key': 'land',
'type': 'check',
'configs': {'delivery': 'true', 'command_timeout': '10m'},
'blocks': {'commands': 'make test\n\nmake lint'},
'edges': {'pass': '#success'},
},
],
}, 'land')!;
expect(summary.typeLabel, 'Delivery gate');
expect(summary.commands, ['make test', 'make lint']);
expect(summary.tools, isEmpty);
expect(summary.prompt, isNull);
expect(summary.meta, ['10m timeout']);
expect(summary.routes.single, (outcome: 'pass', target: 'Success'));
});
test('an undeclared stage has no summary; a terminal lists routes in', () {
final graph = {
'stages': [
{
'key': 'a',
'edges': {'success': '#success'},
},
],
};
expect(stageSummaryFor(graph, 'missing'), isNull);
final end = stageSummaryFor(graph, '#success')!;
expect(end.kind, StageKind.terminal);
expect(end.routes.single, (outcome: 'success', target: 'a'));
});
test('short model names drop the vendor and date', () {
expect(
shortModelName('anthropic/claude-opus-4-1-20250805'),
'claude-opus-4-1',
);
expect(shortModelName('gpt-5'), 'gpt-5');
});
test('an unvisited stage has no run facts', () {
final facts = stageRunFacts({'steps': []}, 'a');
expect(facts.visits, 0);
expect(facts.status, isNull);
});
test('a failure reason is read only from a failed latest visit', () {
final facts = stageRunFacts({
'steps': [
{'sequence': 1, 'stage': 'a', 'status': 'failed', 'diagnostic': 'boom'},
{
'sequence': 2,
'stage': 'a',
'status': 'completed',
'diagnostic': 'old',
},
],
}, 'a');
expect(facts.visits, 2);
expect(facts.status, 'completed');
expect(facts.failure, isNull);
});
}
@@ -96,8 +96,13 @@ void main() {
// A tap in the larger canvas follows the same transform and updates the
// presentation's own selection.
// The tap opens the stage's popover; its "Open definition" reports it.
await tester.tap(_inExpanded(_node('plan')));
await tester.pump();
expect(picked, isEmpty);
expect(find.byKey(const Key('graph-stage-popover')), findsOneWidget);
await tester.tap(find.byKey(const Key('stage-popover-open-definition')));
await tester.pump();
expect(picked, ['plan']);
expect(
tester.widget<GraphStageNode>(_inExpanded(_node('plan'))).selected,
@@ -98,6 +98,14 @@ Future<void> _tapNode(WidgetTester tester, String key) async {
await tester.pump();
}
/// Taps a node, then its popover's "Open definition", which reports the key.
Future<void> _openDefinition(WidgetTester tester, String key) async {
await _tapNode(tester, key);
expect(find.byKey(const Key('graph-stage-popover')), findsOneWidget);
await tester.tap(find.byKey(const Key('stage-popover-open-definition')));
await tester.pump();
}
void _expectNoOverlaps(WidgetTester tester) {
final rects = <Rect>[
for (final element in find.byType(GraphStageNode).evaluate())
@@ -148,11 +156,10 @@ void main() {
expect(tester.widget<GraphStageNode>(_node('build')).selected, isTrue);
expect(tester.widget<GraphStageNode>(_node('plan')).selected, isFalse);
await tester.tap(_node('plan'));
await tester.pump();
await _openDefinition(tester, 'plan');
expect(picked, ['plan']);
await _tapNode(tester, '#success');
await _openDefinition(tester, '#success');
expect(picked, ['plan', '#success']);
});
@@ -189,7 +196,10 @@ void main() {
);
await tester.tapAt(build.center);
await tester.pump();
expect(picked, ['build']);
expect(
tester.widget<Text>(find.byKey(const Key('stage-popover-title'))).data,
'build',
);
});
testWidgets('nodes use measured native sizes and never overlap', (
@@ -0,0 +1,369 @@
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/graph/widgets/definition_graph_view.dart';
import 'package:pipelines_app/features/graph/widgets/graph_stage_node.dart';
import 'package:pipelines_app/features/graph/widgets/run_graph_view.dart';
import 'package:pipelines_app/features/graph/widgets/stage_popover_position.dart';
/// One stage of every type, with the fields the popover shows.
JsonMap _graph() => <String, dynamic>{
'stages': <dynamic>[
<String, dynamic>{
'key': 'implement',
'type': 'model',
'prompt': 'Implement the feature.\n\nKeep the change small.',
'configs': <String, dynamic>{
'harness': 'claude',
'model': 'anthropic/claude-sonnet-4-5-20250929',
'reasoning_effort': 'high',
'timeout': '30m',
'retries': '2',
'budget_usd': '5',
},
'blocks': <String, dynamic>{
'tools': 'read\nglob\nedit\nshell\nmcp:pipelines',
'permissions': '{"edit": ["app/**"], "shell": ["flutter test"]}',
},
'limits': <String, dynamic>{
'max_visits': 3,
'on': ['fail'],
'on_exhausted': 'decide',
},
'edges': <String, dynamic>{'success': 'verify', 'error': '#failure'},
},
<String, dynamic>{
'key': 'verify',
'type': 'check',
'blocks': <String, dynamic>{'commands': 'flutter analyze\nflutter test'},
'edges': <String, dynamic>{
'pass': 'triage',
'fail': 'implement',
'error': '#failure',
},
},
<String, dynamic>{
'key': 'triage',
'type': 'findings',
'configs': <String, dynamic>{'severity': 'critical', 'origin': 'any'},
'edges': <String, dynamic>{'open': 'approve', 'clear': '#success'},
},
<String, dynamic>{
'key': 'approve',
'type': 'human',
'prompt': 'Check the screenshots before landing.',
'edges': <String, dynamic>{'accept': '#success', 'reject': 'implement'},
},
],
};
JsonMap _run() => <String, dynamic>{
'id': 7,
'pipeline_id': 3,
'name': 'feature',
'version': 4,
'steps': <dynamic>[
<String, dynamic>{
'sequence': 1,
'stage': 'implement',
'status': 'completed',
'outcome': 'success',
'target': 'verify',
'started_at': '2026-10-21T10:00:00Z',
'finished_at': '2026-10-21T10:01:00Z',
},
<String, dynamic>{
'sequence': 2,
'stage': 'verify',
'status': 'failed',
'outcome': 'fail',
'target': 'implement',
'diagnostic': 'flutter test: 2 failures',
},
<String, dynamic>{
'sequence': 3,
'stage': 'implement',
'status': 'completed',
'outcome': 'success',
'target': 'verify',
'started_at': '2026-10-21T10:02:00Z',
'finished_at': '2026-10-21T10:04:05Z',
'output': '# Fixed the two failing tests\nmore detail',
'verdict': <String, dynamic>{'option': 'success', 'reason': 'All green'},
},
],
'current_stage': '',
'executing': false,
};
Widget _host(Widget child, {Size size = const Size(1000, 760)}) => MaterialApp(
home: Scaffold(
body: Align(
alignment: Alignment.topLeft,
child: SizedBox(width: size.width, height: size.height, child: child),
),
),
);
Future<void> _settle(WidgetTester tester) async {
await tester.pump();
await tester.pump();
await tester.pump();
}
Finder _node(String key) => find.byWidgetPredicate(
(widget) => widget is GraphStageNode && widget.node.key == key,
);
final Finder _popover = find.byKey(const Key('graph-stage-popover'));
String _title(WidgetTester tester) =>
tester.widget<Text>(find.byKey(const Key('stage-popover-title'))).data!;
Future<void> _view(
WidgetTester tester, {
ValueChanged<String>? onSelected,
Size size = const Size(1000, 760),
}) async {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(
_host(
DefinitionGraphView(graph: _graph(), onSelected: onSelected ?? (_) {}),
size: size,
),
);
await _settle(tester);
}
void main() {
testWidgets('a model stage shows its type, configs, tools and prompt', (
tester,
) async {
await _view(tester);
expect(_popover, findsNothing);
await tester.tap(_node('implement'));
await tester.pump();
expect(_popover, findsOneWidget);
expect(_title(tester), 'implement');
expect(find.text('Model'), findsOneWidget);
for (final chip in [
'claude',
'claude-sonnet-4-5',
'high effort',
'30m timeout',
'2 retries',
r'$5 budget',
'mcp:pipelines',
'max 3 visits',
'on fail',
'when exhausted: decide',
]) {
expect(find.text(chip), findsOneWidget, reason: chip);
}
for (final route in ['success to verify', 'error to Failure']) {
expect(find.bySemanticsLabel(route), findsOneWidget, reason: route);
}
expect(find.textContaining('Implement the feature.'), findsOneWidget);
// The permission allow-lists stay behind a collapsed line.
expect(
find.byKey(const Key('stage-popover-permission-lines')),
findsNothing,
);
await tester.tap(find.byKey(const Key('stage-popover-permissions')));
await tester.pump();
expect(
tester
.widget<Text>(find.byKey(const Key('stage-popover-permission-lines')))
.data,
'edit: app/**\nshell: flutter test',
);
// The node is the open selection while its popover shows.
expect(tester.widget<GraphStageNode>(_node('implement')).selected, isTrue);
});
testWidgets('a check stage lists its commands instead of a prompt', (
tester,
) async {
await _view(tester);
await tester.tap(_node('verify'));
await tester.pump();
expect(find.text('Check'), findsWidgets);
expect(find.byKey(const Key('stage-popover-commands')), findsOneWidget);
expect(find.byKey(const Key('stage-popover-prompt')), findsNothing);
final commands = tester.widget<SelectableText>(
find.byKey(const Key('stage-popover-commands')),
);
expect(commands.textSpan!.toPlainText(), contains('flutter analyze'));
expect(find.bySemanticsLabel('fail to implement'), findsOneWidget);
});
testWidgets('a findings gate shows severity and origin', (tester) async {
await _view(tester);
await tester.tap(_node('triage'));
await tester.pump();
expect(find.text('Findings gate'), findsOneWidget);
expect(find.text('min severity critical'), findsOneWidget);
expect(find.text('origin any'), findsOneWidget);
});
testWidgets('a human stage shows the operator instructions', (tester) async {
await _view(tester);
await tester.tap(_node('approve'));
await tester.pump();
expect(find.text('Human'), findsOneWidget);
expect(find.text('Operator instructions'), findsOneWidget);
expect(
find.textContaining('Check the screenshots before landing.'),
findsOneWidget,
);
});
testWidgets('the card sits inside the viewport with its nub on the node', (
tester,
) async {
await _view(tester);
await tester.tap(_node('verify'));
await tester.pump();
final card = tester.getRect(find.byKey(const Key('stage-popover-body')));
final viewport = tester.getRect(find.byType(InteractiveViewer));
expect(viewport.inflate(1).contains(card.topLeft), isTrue);
expect(viewport.inflate(1).contains(card.bottomRight), isTrue);
final position = tester.renderObject<RenderStagePopoverPosition>(_popover);
expect(position.side, isNot(StagePopoverSide.over));
});
testWidgets('an outside tap, Escape and the same node close it', (
tester,
) async {
await _view(tester);
await tester.tap(_node('implement'));
await tester.pump();
expect(_popover, findsOneWidget);
// Tapping inside the card keeps it open.
await tester.tap(find.byKey(const Key('stage-popover-title')));
await tester.pump();
expect(_popover, findsOneWidget);
// An outside tap on the empty canvas closes it.
final viewport = tester.getRect(find.byType(InteractiveViewer));
await tester.tapAt(viewport.bottomRight - const Offset(10, 10));
await tester.pump();
expect(_popover, findsNothing);
// A drag pans the graph but keeps the card on its node.
await tester.tap(_node('implement'));
await tester.pump();
await tester.dragFrom(
viewport.bottomRight - const Offset(40, 40),
const Offset(-60, -20),
);
await tester.pump();
expect(_popover, findsOneWidget);
// Escape closes it.
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pump();
expect(_popover, findsNothing);
// Tapping the same node again toggles it shut.
await tester.tap(_node('implement'));
await tester.pump();
expect(_popover, findsOneWidget);
await tester.tap(_node('implement'));
await tester.pump();
expect(_popover, findsNothing);
// Another node replaces it.
await tester.tap(_node('triage'));
await tester.pump();
expect(_title(tester), 'triage');
await tester.tap(_node('implement'));
await tester.pump();
expect(_title(tester), 'implement');
});
testWidgets('Open definition reports the stage and closes the card', (
tester,
) async {
final opened = <String>[];
await _view(tester, onSelected: opened.add);
await tester.tap(_node('approve'));
await tester.pump();
await tester.tap(find.byKey(const Key('stage-popover-open-definition')));
await tester.pump();
expect(opened, ['approve']);
expect(_popover, findsNothing);
});
testWidgets('a focused node opens with Enter', (tester) async {
await _view(tester);
// The node's own focus: the nearest focus above its label.
final label = find
.descendant(of: _node('triage'), matching: find.byType(Text))
.first;
Focus.of(tester.element(label)).requestFocus();
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pump();
expect(_popover, findsOneWidget);
expect(_title(tester), 'triage');
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pump();
expect(_popover, findsNothing);
});
testWidgets('a phone-width graph opens the stage in a bottom sheet', (
tester,
) async {
await _view(tester, size: const Size(390, 760));
await tester.tap(_node('implement'));
await tester.pumpAndSettle();
expect(_popover, findsNothing);
expect(find.byKey(const Key('graph-stage-sheet')), findsOneWidget);
expect(_title(tester), 'implement');
expect(find.text('claude-sonnet-4-5'), findsOneWidget);
});
testWidgets('the run variant shows status, visits, verdict and failure', (
tester,
) async {
tester.view.physicalSize = const Size(1000, 760);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final visits = <String>[];
await tester.pumpWidget(
_host(
RunGraphView(graph: _graph(), run: _run(), onStageSelected: visits.add),
),
);
await _settle(tester);
await tester.tap(_node('implement'));
await tester.pump();
expect(find.text('completed'), findsWidgets);
expect(find.text('×2'), findsOneWidget);
expect(find.text('2m 5s'), findsOneWidget);
expect(find.text('success: All green'), findsOneWidget);
expect(find.text('Fixed the two failing tests'), findsOneWidget);
await tester.tap(find.byKey(const Key('stage-popover-open-visit')));
await tester.pump();
expect(visits, ['implement']);
await tester.tap(_node('verify'));
await tester.pump();
expect(find.text('×1'), findsOneWidget);
expect(find.text('flutter test: 2 failures'), findsOneWidget);
// Open definition pushes the pinned stage definition page.
await tester.tap(find.byKey(const Key('stage-popover-open-definition')));
await tester.pumpAndSettle();
expect(find.text('verify definition'), findsOneWidget);
});
}
@@ -260,7 +260,7 @@ void main() {
});
testWidgets(
'a visited stage reports its key and an unvisited node does not',
'a visited stage opens its visit from the popover; an unvisited one has none',
(tester) async {
final picked = <String>[];
await tester.pumpWidget(
@@ -278,28 +278,26 @@ void main() {
final visited = tester.getSemantics(_node('plan')).getSemanticsData();
expect(visited.flagsCollection.isButton, isTrue);
expect(visited.hasAction(SemanticsAction.tap), isTrue);
// An unvisited stage still opens its declaration, with no status.
final unvisited = tester.getSemantics(_node('build')).getSemanticsData();
expect(unvisited.flagsCollection.isButton, isFalse);
expect(unvisited.hasAction(SemanticsAction.tap), isFalse);
expect(unvisited.flagsCollection.isButton, isTrue);
expect(unvisited.label, 'build');
await tester.tap(_node('plan'));
await tester.pump();
expect(picked, isEmpty);
await tester.tap(find.byKey(const Key('stage-popover-open-visit')));
await tester.pump();
expect(picked, ['plan']);
// `build` was never recorded in this run: it is a plain label, not a
// button, and tapping it reports nothing (never a fabricated visit).
await tester.tap(_node('build'), warnIfMissed: false);
// `build` was never recorded in this run: its popover offers no visit,
// so nothing is ever fabricated.
await tester.tap(_node('build'));
await tester.pump();
expect(find.byKey(const Key('graph-stage-popover')), findsOneWidget);
expect(find.byKey(const Key('stage-popover-open-visit')), findsNothing);
expect(find.byKey(const Key('stage-popover-status')), findsNothing);
expect(picked, ['plan']);
expect(
find.ancestor(
of: _node('build'),
matching: find.byWidgetPredicate(
(widget) => widget is IgnorePointer && widget.ignoring,
),
),
findsOneWidget,
);
handle.dispose();
},
);
@@ -132,7 +132,7 @@ void main() {
const [],
const PipelineFilters(),
)?.message,
'No pipelines yet.',
'No pipelines yet',
);
expect(pipelineListEmptyState(all, all, const PipelineFilters()), isNull);
});
@@ -30,6 +30,10 @@ Future<void> _tapNode(WidgetTester tester, Finder node) async {
await tester.pumpAndSettle();
}
await tester.tap(node);
await tester.pump(); // A tap opens the stage's popover (or sheet); "Open definition" opens the
// pinned definition page, as a tap did before the popover.
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('stage-popover-open-definition')));
await tester.pump();
}
@@ -25,6 +25,10 @@ Future<void> _tapNode(WidgetTester tester, String key) async {
await tester.pumpAndSettle();
}
await tester.tap(_node(key));
await tester.pump(); // A tap opens the stage's popover (or sheet); "Open definition" opens the
// pinned definition page, as a tap did before the popover.
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('stage-popover-open-definition')));
await tester.pump();
}
@@ -1,6 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/pipelines/screen.dart';
import 'package:pipelines_app/features/pipelines/widgets/pipeline_list_panel.dart';
import 'fixtures.dart';
import 'test_helpers.dart';
@@ -20,11 +23,8 @@ void main() {
(tester) async {
await pumpWide(tester, emptyServerGateway());
expect(find.text('No pipelines yet.'), findsOneWidget);
expect(
find.text('Create one from a template in Templates.'),
findsOneWidget,
);
expect(find.text('No pipelines yet'), findsOneWidget);
expect(find.textContaining('Start from a template'), findsOneWidget);
expect(find.text('Loading pipelines…'), findsNothing);
expect(find.byKey(const Key('pipeline-list')), findsNothing);
expect(find.textContaining('not defined'), findsNothing);
@@ -33,6 +33,28 @@ void main() {
},
);
testWidgets('the empty state opens Templates as its next step', (
tester,
) async {
tester.view.physicalSize = const Size(1100, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
var opened = 0;
await tester.pumpWidget(
MaterialApp(
home: PipelinesScreen(
gateway: emptyServerGateway(),
onOpenTemplates: () => opened++,
),
),
);
await tester.pumpAndSettle();
expect(find.byKey(pipelinesEmptyKey), findsOneWidget);
await tester.tap(find.text('Browse templates'));
expect(opened, 1);
});
testWidgets(
'a failed list stays an error and never reads as an empty server',
(tester) async {
@@ -42,7 +64,7 @@ void main() {
);
expect(find.textContaining('server offline'), findsOneWidget);
expect(find.text('No pipelines yet.'), findsNothing);
expect(find.text('No pipelines yet'), findsNothing);
expect(find.text('Loading pipelines…'), findsNothing);
expect(tester.takeException(), isNull);
},
@@ -104,11 +104,8 @@ void main() {
MaterialApp(home: PipelinesScreen(gateway: emptyGateway)),
);
await tester.pumpAndSettle();
expect(find.text('No pipelines yet.'), findsOneWidget);
expect(
find.text('Create one from a template in Templates.'),
findsOneWidget,
);
expect(find.text('No pipelines yet'), findsOneWidget);
expect(find.textContaining('Start from a template'), findsOneWidget);
});
testWidgets('a detail refusal keeps the selection and offers retry', (
@@ -182,7 +182,7 @@ void main() {
) async {
await pumpDeepLink(tester, RunDetailTestPlatform.material);
await openRunDetailTab(tester, RunDetailTab.graph);
await tapGraphNode(tester, 'plan');
await openGraphVisit(tester, 'plan');
await tester.pumpAndSettle();
// The web client's graph click takes the last visit in sequence order, not
@@ -156,3 +156,11 @@ Future<void> tapGraphNode(WidgetTester tester, String key) async {
await tester.pump();
await tester.pump();
}
/// Opens [key]'s stage popover (or sheet), then its "Open visit".
Future<void> openGraphVisit(WidgetTester tester, String key) async {
await tapGraphNode(tester, key);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('stage-popover-open-visit')));
await tester.pump();
}
@@ -46,7 +46,7 @@ void main() {
) async {
await pumpRunDetail(tester, platform);
await openRunDetailTab(tester, RunDetailTab.graph);
await tapGraphNode(tester, 'plan');
await openGraphVisit(tester, 'plan');
await tester.pumpAndSettle();
// The Graph reports the stage; the exact recorded visit opens as its
@@ -76,9 +76,11 @@ void main() {
) async {
await pumpRunDetail(tester, platform);
await openRunDetailTab(tester, RunDetailTab.graph);
// `audit` was never recorded: its node is not a control and a click must
// leave the detail on the Graph tab.
// `audit` was never recorded: its popover shows the declaration but
// offers no visit, and the detail stays on the Graph tab.
await tapGraphNode(tester, 'audit');
await tester.pumpAndSettle();
expect(find.byKey(const Key('stage-popover-open-visit')), findsNothing);
expect(find.byType(RunGraphView), findsOneWidget);
expect(
find.byKey(const Key('run-detail-tab-body-timeline')),
@@ -96,7 +98,7 @@ void main() {
scale: 2,
);
await openRunDetailTab(tester, RunDetailTab.graph);
await tapGraphNode(tester, 'plan');
await openGraphVisit(tester, 'plan');
await tester.pumpAndSettle();
// Leaving the visit page lands on Timeline. At 320/2x the strip
@@ -146,4 +146,34 @@ void main() {
);
expect(find.text('Why it failed'), findsNothing);
});
testWidgets('a run that found no agent harness names the setup step', (
tester,
) async {
const reason =
'environment problem: model stage research: HARNESS TRANSPORT: '
'harness unreachable: cannot run the selected OpenCode CLI: exec: '
'"opencode": executable file not found in \$PATH';
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: RunFailureBanner(
run: _run('failed', {'failure_reason': reason}),
),
),
),
);
expect(find.byKey(runFailureHarnessHintKey), findsOneWidget);
expect(find.textContaining('pipelines harness setup'), findsOneWidget);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: RunFailureBanner(
run: _run('failed', {'diagnostic': 'exit status 2'}),
),
),
),
);
expect(find.byKey(runFailureHarnessHintKey), findsNothing);
});
}
@@ -9,6 +9,7 @@ import 'package:pipelines_app/features/runs/ui/runs_controller.dart';
import 'package:pipelines_app/features/runs/ui/runs_filters.dart';
import 'package:pipelines_app/ui/status/run_status_icon.dart';
import 'package:pipelines_app/features/runs/ui/runs_list.dart';
import 'package:pipelines_app/ui/status/error_notice.dart';
class _Gateway implements ApiGateway {
final framesController = StreamController<JsonMap>.broadcast();
@@ -162,8 +163,10 @@ void main() {
gateway.reply = {'runs': []};
await controller.load();
await tester.pumpAndSettle();
expect(find.text('No runs yet.'), findsOneWidget);
expect(find.textContaining('Start one from Pipelines'), findsOneWidget);
expect(find.text('No runs yet'), findsOneWidget);
expect(find.textContaining('A run is a pipeline'), findsOneWidget);
// No New run seam in this fixture: the state offers no dead button.
expect(find.text('Start your first run'), findsNothing);
expect(find.text('No runs found.'), findsNothing);
expect(find.textContaining('offline'), findsNothing);
expect(tester.takeException(), isNull);
@@ -173,7 +176,7 @@ void main() {
controller.setStatus('failed');
await tester.pumpAndSettle();
expect(find.text('No runs found.'), findsOneWidget);
expect(find.text('No runs yet.'), findsNothing);
expect(find.text('No runs yet'), findsNothing);
expect(
find.text('Try changing or clearing the filters.'),
findsOneWidget,
@@ -183,6 +186,32 @@ void main() {
variant: TargetPlatformVariant.only(TargetPlatform.android),
);
testWidgets('an empty server offers the first run as the next step', (
tester,
) async {
gateway.failure = null;
gateway.gate = null;
gateway.reply = {'runs': []};
await controller.load();
var started = 0;
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: RunsList(
controller: controller,
onSelected: (_) {},
onNewRun: () => started++,
),
),
),
);
await tester.pumpAndSettle();
expect(find.byKey(runsEmptyKey), findsOneWidget);
expect(find.byType(ErrorNotice), findsNothing);
await tester.tap(find.text('Start your first run'));
expect(started, 1);
});
testWidgets(
'an empty server with a search query reads as no match, not no runs',
(tester) async {
@@ -200,7 +229,7 @@ void main() {
);
await tester.pumpAndSettle();
expect(find.text('No runs found.'), findsOneWidget);
expect(find.text('No runs yet.'), findsNothing);
expect(find.text('No runs yet'), findsNothing);
expect(
find.text('Try changing or clearing the filters.'),
findsOneWidget,
@@ -88,7 +88,7 @@ void main() {
(type, fields) async => {'type': 'schedules'},
);
await pumpSchedules(tester, gateway: empty);
expect(find.text('No schedules yet.'), findsOneWidget);
expect(find.text('No schedules yet'), findsOneWidget);
expect(find.byKey(scheduleRetryKey), findsNothing);
final unsupported = FakeSchedulesGateway(
@@ -100,7 +100,7 @@ void main() {
findsOneWidget,
);
expect(find.byKey(scheduleRetryKey), findsOneWidget);
expect(find.text('No schedules yet.'), findsNothing);
expect(find.text('No schedules yet'), findsNothing);
final failed = FakeSchedulesGateway(
(type, fields) async => throw StateError('socket closed'),
@@ -32,19 +32,20 @@ void main() {
),
);
expect(find.text(SettingsChatNavigationSection.title), findsOneWidget);
expect(controller.value, MobileChatNavigation.quickSwitch);
// Without a stored choice: the Chat stack.
expect(controller.value, MobileChatNavigation.chatStack);
expect(
find.text(MobileChatNavigation.quickSwitch.description),
find.text(MobileChatNavigation.chatStack.description),
findsOneWidget,
);
await tester.tap(
find.byKey(const ValueKey('settings-chat-navigation-chatStack')),
find.byKey(const ValueKey('settings-chat-navigation-quickSwitch')),
);
await tester.pumpAndSettle();
expect(controller.value, MobileChatNavigation.chatStack);
expect(store.saved, 'chatStack');
expect(controller.value, MobileChatNavigation.quickSwitch);
expect(store.saved, 'quickSwitch');
expect(
find.text(MobileChatNavigation.chatStack.description),
find.text(MobileChatNavigation.quickSwitch.description),
findsOneWidget,
);
@@ -52,11 +53,11 @@ void main() {
final next = MobileChatNavigationController(store: store);
addTearDown(next.dispose);
await next.restore();
expect(next.value, MobileChatNavigation.chatStack);
expect(next.value, MobileChatNavigation.quickSwitch);
store.success = false;
await tester.tap(
find.byKey(const ValueKey('settings-chat-navigation-quickSwitch')),
find.byKey(const ValueKey('settings-chat-navigation-chatStack')),
);
await tester.pumpAndSettle();
expect(find.text('Could not save; applies until reload.'), findsOneWidget);
@@ -27,7 +27,7 @@ bool _switchValue(WidgetTester tester) {
}
void main() {
testWidgets('shows the switch, status and ntfy note', (tester) async {
testWidgets('shows the switch, status and delivery note', (tester) async {
final service = FakeNotificationService();
await tester.pumpWidget(_host(service));
await tester.pumpAndSettle();
@@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/core/transport/connection_state.dart';
import 'package:pipelines_app/features/settings/settings_ntfy_section.dart';
import 'package:pipelines_app/features/settings/settings_notification_settings_section.dart';
/// A scripted gateway: records every request and answers from [respond].
class _Gateway implements ApiGateway {
@@ -32,24 +32,31 @@ JsonMap _reply(bool run, bool needs, bool reply) => {
},
};
Widget _host(ApiGateway gateway) {
Widget _host(ApiGateway gateway, {bool connected = true}) {
final body = SingleChildScrollView(
child: SettingsNtfySection(gateway: gateway, connected: true),
child: SettingsNotificationSettingsSection(
gateway: gateway,
connected: connected,
),
);
return MaterialApp(home: Scaffold(body: body));
}
bool _checked(WidgetTester tester, String key) {
final tile = find.byKey(ntfySettingKey(key));
return tester.widget<CheckboxListTile>(tile).value!;
}
Finder _tile(String key) => find.byKey(notificationSettingKey(key));
bool _checked(WidgetTester tester, String key) =>
tester.widget<CheckboxListTile>(_tile(key)).value!;
void main() {
testWidgets('loads the stored values', (tester) async {
testWidgets('shows the three shared switches with stored values', (
tester,
) async {
final gateway = _Gateway((_, _) => _reply(true, false, true));
await tester.pumpWidget(_host(gateway));
await tester.pumpAndSettle();
expect(gateway.calls.single.$1, 'notification_settings');
expect(find.text(notificationEventsTitle), findsOneWidget);
expect(find.text(notificationEventsSubtitle), findsOneWidget);
expect(find.text('Notify when any run ends'), findsOneWidget);
expect(
find.text('Otherwise only runs started with Notify me'),
@@ -57,14 +64,13 @@ void main() {
);
expect(find.text('Chat needs your answer or approval'), findsOneWidget);
expect(find.text('Chat reply finished'), findsOneWidget);
expect(find.text(ntfySectionSubtitle), findsOneWidget);
expect(find.byType(CheckboxListTile), findsNWidgets(3));
expect(_checked(tester, 'run_finished'), isTrue);
expect(_checked(tester, 'chat_needs_you'), isFalse);
expect(_checked(tester, 'chat_reply_finished'), isTrue);
});
testWidgets('shows the server default: only marked runs', (tester) async {
// The server's defaults: run ends notify only for "Notify me" runs.
final gateway = _Gateway((_, _) => _reply(false, true, false));
await tester.pumpWidget(_host(gateway));
await tester.pumpAndSettle();
@@ -73,24 +79,53 @@ void main() {
expect(_checked(tester, 'chat_reply_finished'), isFalse);
});
testWidgets('toggling writes only that setting', (tester) async {
final gateway = _Gateway((type, fields) {
if (type == 'set_notification_settings') {
return _reply(true, true, true);
}
return _reply(true, true, false);
for (final key in ['run_finished', 'chat_needs_you', 'chat_reply_finished']) {
testWidgets('toggling $key writes only that setting', (tester) async {
final gateway = _Gateway((type, fields) {
if (type == 'set_notification_settings') {
return _reply(true, true, true);
}
return _reply(false, false, false);
});
await tester.pumpWidget(_host(gateway));
await tester.pumpAndSettle();
await tester.tap(_tile(key));
await tester.pumpAndSettle();
expect(gateway.calls, hasLength(2));
expect(gateway.calls.last.$1, 'set_notification_settings');
expect(gateway.calls.last.$2, {
'notification_settings': {key: true},
});
expect(_checked(tester, key), isTrue);
expect(find.byKey(notificationSettingsErrorKey), findsNothing);
});
}
testWidgets('a legacy ntfy_enabled key in the reply is ignored', (
tester,
) async {
JsonMap legacy() => {
'type': 'notification_settings',
'notification_settings': {
...(_reply(true, true, false)['notification_settings'] as Map),
'ntfy_enabled': true,
},
};
final gateway = _Gateway((_, _) => legacy());
await tester.pumpWidget(_host(gateway));
await tester.pumpAndSettle();
await tester.tap(find.byKey(ntfySettingKey('chat_reply_finished')));
expect(find.byType(CheckboxListTile), findsNWidgets(3));
expect(_tile('ntfy_enabled'), findsNothing);
expect(find.textContaining('ntfy'), findsNothing);
expect(find.byKey(notificationSettingsErrorKey), findsNothing);
// A write after such a reply still sends only the toggled key.
await tester.tap(_tile('chat_reply_finished'));
await tester.pumpAndSettle();
expect(gateway.calls, hasLength(2));
expect(gateway.calls.last.$1, 'set_notification_settings');
expect(gateway.calls.last.$2, {
'notification_settings': {'chat_reply_finished': true},
});
expect(_checked(tester, 'chat_reply_finished'), isTrue);
expect(find.byKey(ntfyErrorKey), findsNothing);
expect(find.byType(CheckboxListTile), findsNWidgets(3));
});
testWidgets('failure reverts and shows the refusal', (tester) async {
@@ -101,53 +136,50 @@ void main() {
});
await tester.pumpWidget(_host(gateway));
await tester.pumpAndSettle();
await tester.tap(find.byKey(ntfySettingKey('run_finished')));
await tester.tap(_tile('run_finished'));
await tester.pump();
// The change shows at once and the group is disabled while it saves.
expect(_checked(tester, 'run_finished'), isFalse);
await tester.tap(find.byKey(ntfySettingKey('chat_needs_you')));
await tester.tap(_tile('chat_needs_you'));
await tester.pump();
expect(gateway.calls, hasLength(2));
pending.completeError(const ProtocolError('settings are read-only'));
await tester.pumpAndSettle();
expect(_checked(tester, 'run_finished'), isTrue);
expect(_checked(tester, 'chat_needs_you'), isTrue);
expect(
find.text('Could not save: settings are read-only'),
findsOneWidget,
);
expect(find.text('Could not save: settings are read-only'), findsOneWidget);
});
testWidgets('disabled while loading and offline', (tester) async {
testWidgets('disabled while loading', (tester) async {
final pending = Completer<JsonMap>();
final gateway = _Gateway((_, _) => pending.future);
await tester.pumpWidget(_host(gateway));
await tester.pump();
expect(find.text('Loading…'), findsOneWidget);
await tester.tap(find.byKey(ntfySettingKey('run_finished')));
await tester.tap(_tile('run_finished'));
await tester.pump();
expect(gateway.calls, hasLength(1));
expect(
tester
.widget<CheckboxListTile>(find.byKey(ntfySettingKey('run_finished')))
.onChanged,
tester.widget<CheckboxListTile>(_tile('run_finished')).onChanged,
isNull,
);
pending.complete(_reply(true, true, false));
await tester.pumpAndSettle();
expect(find.text('Loading…'), findsNothing);
});
final offline = _Gateway((_, _) => _reply(true, true, false));
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: SettingsNtfySection(gateway: offline, connected: false),
),
),
);
testWidgets('offline: no request, the offline text, switches disabled', (
tester,
) async {
final gateway = _Gateway((_, _) => _reply(true, true, false));
await tester.pumpWidget(_host(gateway, connected: false));
await tester.pumpAndSettle();
expect(offline.calls, isEmpty);
expect(find.text(ntfyOfflineText), findsOneWidget);
expect(gateway.calls, isEmpty);
expect(find.text(notificationEventsOfflineText), findsOneWidget);
expect(
tester.widget<CheckboxListTile>(_tile('chat_needs_you')).onChanged,
isNull,
);
});
testWidgets('a load failure is shown with a retry', (tester) async {
@@ -165,47 +197,7 @@ void main() {
fail = false;
await tester.tap(find.text('Retry'));
await tester.pumpAndSettle();
expect(find.byKey(ntfyErrorKey), findsNothing);
expect(
tester
.widget<CheckboxListTile>(find.byKey(ntfySettingKey('run_finished')))
.value,
isFalse,
);
});
group('ntfy_enabled', () {
JsonMap withNtfy(bool ntfy) => {
'type': 'notification_settings',
'notification_settings': {
...(_reply(true, true, false)['notification_settings'] as Map),
'ntfy_enabled': ntfy,
},
};
testWidgets('hidden when the server does not send it', (tester) async {
final gateway = _Gateway((_, _) => _reply(true, true, false));
await tester.pumpWidget(_host(gateway));
await tester.pumpAndSettle();
expect(find.byKey(ntfySettingKey('ntfy_enabled')), findsNothing);
expect(find.text(ntfySectionSubtitle), findsOneWidget);
});
testWidgets('shows and writes it', (tester) async {
final gateway = _Gateway(
(type, _) => withNtfy(type == 'set_notification_settings'),
);
await tester.pumpWidget(_host(gateway));
await tester.pumpAndSettle();
expect(find.text('Also send to ntfy'), findsOneWidget);
expect(find.text(ntfySectionAppSubtitle), findsOneWidget);
expect(_checked(tester, 'ntfy_enabled'), isFalse);
await tester.tap(find.byKey(ntfySettingKey('ntfy_enabled')));
await tester.pumpAndSettle();
expect(gateway.calls.last.$2, {
'notification_settings': {'ntfy_enabled': true},
});
expect(_checked(tester, 'ntfy_enabled'), isTrue);
});
expect(find.byKey(notificationSettingsErrorKey), findsNothing);
expect(_checked(tester, 'run_finished'), isFalse);
});
}
@@ -164,8 +164,8 @@ void main() {
'ping',
'notification_settings',
]);
await openSettingsSection(tester, 'Phone notifications');
_answerNtfySettings(factory.last);
await openSettingsSection(tester, 'Notification events');
_answerNotificationSettings(factory.last);
await tester.pump();
await tester.pump();
expect(factory.last.decodedOutgoing, hasLength(2));
@@ -203,8 +203,8 @@ void main() {
expect(find.text(serverDetailsPending), findsNothing);
expect(find.text('Server build unavailable'), findsOneWidget);
expect(find.text('Server time unavailable'), findsOneWidget);
await openSettingsSection(tester, 'Phone notifications');
_answerNtfySettings(factory.last);
await openSettingsSection(tester, 'Notification events');
_answerNotificationSettings(factory.last);
await tester.pump();
});
@@ -521,8 +521,8 @@ Future<void> _pump(
await openSettingsSection(tester, 'Connection');
}
/// Answers the Settings screen's queued ntfy-settings load on [channel].
void _answerNtfySettings(FakeChannel channel) {
/// Answers the Settings screen's queued notification-settings load on [channel].
void _answerNotificationSettings(FakeChannel channel) {
final request = channel.decodedOutgoing.last;
expect(request['type'], 'notification_settings');
channel.reply(<String, dynamic>{
@@ -48,7 +48,7 @@ void main() {
..._filler(6),
SettingsSection(
id: 'server',
title: 'Phone notifications',
title: 'Notification events',
lazy: true,
builder: (_) => ServerSettingsView<int>(
load: load,
@@ -60,11 +60,11 @@ void main() {
// The local sections are built and the server section is only a skeleton:
// no request runs until the list reaches it.
expect(find.text('filler body'), findsWidgets);
expect(find.text('Phone notifications'), findsOneWidget);
expect(find.text('Notification events'), findsOneWidget);
expect(fetches, 0);
expect(tester.takeException(), isNull);
await tester.ensureVisible(find.text('Phone notifications'));
await tester.ensureVisible(find.text('Notification events'));
await tester.pump();
await tester.pump();
expect(fetches, 1);
@@ -131,8 +131,8 @@ void main() {
..._filler(6),
SettingsSection(
id: 'server',
title: 'Phone notifications',
keywords: 'ntfy push',
title: 'Notification events',
keywords: 'push devices',
lazy: true,
builder: (_) => ServerSettingsView<int>(
load: load,
@@ -144,7 +144,7 @@ void main() {
await tester.enterText(
find.byKey(const ValueKey('settings.search')),
'ntfy',
'devices',
);
await tester.pump();
await tester.pump();
@@ -3,6 +3,7 @@ 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/core/transport/connection_state.dart';
import 'package:pipelines_app/features/templates/screen.dart';
import 'package:pipelines_app/features/templates/ui/template_detail.dart';
import 'package:pipelines_app/features/templates/ui/template_gallery.dart'
@@ -122,6 +123,29 @@ void main() {
expect(find.text('Release workflow'), findsOneWidget);
});
testWidgets('a gallery opened before the connection reads again on connect', (
tester,
) async {
var connected = false;
final gateway = GalleryGateway((type, fields) async {
if (!connected) throw const NotConnectedError();
if (type == 'list_templates') return templatesReply(galleryTemplates);
throw StateError('unexpected $type');
});
Widget screen(int token) => MaterialApp(
home: TemplatesScreen(gateway: gateway, reloadToken: token),
);
await tester.pumpWidget(screen(0));
await tester.pumpAndSettle();
expect(find.byKey(templatesErrorKey), findsOneWidget);
connected = true;
await tester.pumpWidget(screen(1));
await tester.pumpAndSettle();
expect(find.byKey(templatesErrorKey), findsNothing);
expect(find.text('Release workflow'), findsOneWidget);
});
testWidgets('refresh re-reads the catalogue and keeps the selection', (
tester,
) async {
@@ -108,6 +108,37 @@ Future<void> _finishWalkthrough(WidgetTester tester) async {
}
void main() {
testWidgets(
'first launch waits briefly for the connection before welcoming',
(tester) async {
final store = MemoryWalkthroughStore();
final link = ValueNotifier<bool>(false);
await tester.pumpWidget(_host(store: store, link: link));
await tester.pump();
expect(find.text(_welcome), findsNothing);
// The app connects a moment later: the welcome is the connected one,
// with no connect directions.
link.value = true;
await tester.pumpAndSettle();
expect(find.text(_welcome), findsOneWidget);
expect(find.textContaining('start by connecting'), findsNothing);
},
);
testWidgets(
'first launch without a connection still offers the connect page',
(tester) async {
final store = MemoryWalkthroughStore();
final link = ValueNotifier<bool>(false);
await tester.pumpWidget(_host(store: store, link: link));
await tester.pump(const Duration(seconds: 3));
await tester.pumpAndSettle();
expect(find.text(_welcome), findsOneWidget);
expect(find.textContaining('start by connecting'), findsOneWidget);
},
);
testWidgets('first launch shows the walkthrough once per device', (
tester,
) async {
+17
View File
@@ -35,6 +35,23 @@ void main() {
errorAdviceKind(TimeoutException('request timed out after 30000ms')),
ErrorAdviceKind.timeout,
);
expect(
errorAdviceKind(
const ProtocolError('chat is not configured on this server'),
),
ErrorAdviceKind.noHarness,
);
expect(
errorAdviceKind(
'HARNESS TRANSPORT: harness unreachable: cannot run the selected '
'OpenCode CLI',
),
ErrorAdviceKind.noHarness,
);
expect(
errorAdviceSentence(ErrorAdviceKind.noHarness),
contains('pipelines harness setup'),
);
expect(errorAdviceKind('pipeline 4 has no stage review'), isNull);
final advice = errorAdvice(StateError('Connection closed'));
expect(advice?.detail, 'Connection closed');
@@ -106,6 +106,7 @@ void main() {
AppDesign.standard,
AppDesign.terminal,
AppDesign.paper,
AppDesign.notebook,
// Glass blends with the comfortable designs and snaps to Compact.
AppDesign.glass,
AppDesign.compact,
+128
View File
@@ -0,0 +1,128 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.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/notebook/notebook_cell_frame.dart';
import 'package:pipelines_app/ui/theme/app_design.dart';
import 'package:pipelines_app/ui/theme/app_design_tokens.dart';
import '../../features/chat/conversation/chat_composer_bar_fixtures.dart';
ThemeData _theme(Brightness brightness, {String? font}) =>
brightness == Brightness.dark
? AppDesign.notebook.dark(fontFamily: font)
: AppDesign.notebook.light(fontFamily: font);
Widget _thread(ComposerBarGateway gateway, AppDesign design) => MaterialApp(
theme: design.light(),
home: Scaffold(
body: ChatThreadView(
gateway: gateway,
sessionId: 's',
session: const {'id': 's', 'directory': '/Users/ada/repos/tank'},
syncToken: 0,
onBack: () {},
drafts: MemoryChatDraftStore(),
),
),
);
void main() {
test('Notebook is listed with a stable id, a label and one line', () {
expect(AppDesign.fromId('notebook'), AppDesign.notebook);
expect(AppDesign.notebook.label, 'Notebook');
expect(AppDesign.notebook.description, isNot(contains('\n')));
expect(AppDesign.notebook.usesInterfaceFont, isTrue);
});
test('Notebook tokens: cells transcript, cell composer, washed row, '
'4-6px corners, hairlines, flat', () {
for (final brightness in Brightness.values) {
final theme = _theme(brightness);
final tokens = theme.extension<AppDesignTokens>()!;
expect(tokens.design, AppDesign.notebook);
expect(tokens.transcript, TranscriptStyle.cells);
expect(tokens.terminal, isFalse);
expect(tokens.composer, ComposerStyle.cell);
expect(tokens.selectedRow, SelectedRowStyle.washed);
expect(tokens.radius, inInclusiveRange(4, 6));
expect(tokens.flat, isTrue);
expect(tokens.frame, theme.colorScheme.outlineVariant);
expect(tokens.ansi, isNotNull);
// Reading text keeps the interface sans.
expect(tokens.reading.family, isNull);
}
});
test('Notebook pages: white by day, neutral charcoal by night, cells a '
'step off the page', () {
final light = _theme(Brightness.light);
expect(light.scaffoldBackgroundColor, const Color(0xFFFFFFFF));
final dark = _theme(Brightness.dark);
expect(
dark.scaffoldBackgroundColor.computeLuminance(),
inExclusiveRange(0.005, 0.03),
);
for (final theme in [light, dark]) {
final scheme = theme.colorScheme;
expect(scheme.surfaceContainerLow, isNot(scheme.surface));
expect(scheme.onSurface, isNot(scheme.onSurfaceVariant));
}
});
test('Notebook keeps the interface font and caches its themes', () {
expect(
_theme(Brightness.light, font: 'Inter').textTheme.bodyLarge?.fontFamily,
'Inter',
);
expect(identical(_theme(Brightness.dark), _theme(Brightness.dark)), isTrue);
expect(
AppDesign.notebook.build(Brightness.light),
_theme(Brightness.light),
);
});
testWidgets('Notebook: the composer is an In [ ]: input cell whose frame '
'takes the accent on focus', (tester) async {
final gateway = ComposerBarGateway();
addTearDown(gateway.close);
await tester.pumpWidget(_thread(gateway, AppDesign.notebook));
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-composer-pill')), findsNothing);
expect(find.byKey(const Key('chat-composer-underline')), findsNothing);
final cell = find.byKey(const Key('chat-composer-cell'));
expect(cell, findsOneWidget);
expect(
find.descendant(of: cell, matching: find.text('In [ ]:')),
findsOneWidget,
);
for (final key in [
'chat-composer-attach',
'chat-composer-field',
'chat-composer-primary',
]) {
expect(
find.descendant(of: cell, matching: find.byKey(Key(key))),
findsOneWidget,
);
}
final scheme = Theme.of(tester.element(cell)).colorScheme;
Color frame() {
final paint = tester.widget<CustomPaint>(
find
.descendant(
of: find.byKey(const Key('chat-composer-cell-frame')),
matching: find.byType(CustomPaint),
)
.first,
);
return (paint.painter! as NotebookCellPainter).border;
}
expect(frame(), scheme.outlineVariant);
await tester.tap(find.byKey(const Key('chat-composer-field')));
await tester.pumpAndSettle();
expect(frame(), scheme.primary);
});
}