Merge branch 'worktree-agent-a89fcd71b624713a3'

This commit is contained in:
2026-12-03 20:23:25 +00:00
22 changed files with 2132 additions and 50 deletions
@@ -0,0 +1,219 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_column.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';
List<ChatStackEntry> _entries(int count, {int current = 0}) => [
for (var i = 0; i < count; i++)
ChatStackEntry(
paneId: 'pane-$i',
session: {
'id': 's$i',
'title': 'Chat $i',
if (i == 1) 'color': 'teal',
if (i == 2) 'running': true,
if (i == 3) 'awaiting_operator': 1,
},
current: i == current,
),
];
class _Harness {
final opened = <String>[];
final removed = <String>[];
var added = 0;
}
Future<_Harness> _pump(
WidgetTester tester, {
int count = 5,
bool reduced = false,
}) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final harness = _Harness();
await tester.pumpWidget(
MaterialApp(
home: Builder(
builder: (context) => MediaQuery(
data: MediaQuery.of(context).copyWith(disableAnimations: reduced),
child: Scaffold(
body: Stack(
children: [
const Center(child: Text('Transcript')),
Positioned(
right: 16,
bottom: 96,
child: ChatStackFab(
entries: _entries(count),
onOpen: (entry) => harness.opened.add(entry.sessionId),
onAdd: (_) => harness.added++,
onRemove: (entry) => harness.removed.add(entry.sessionId),
),
),
],
),
),
),
),
),
);
return harness;
}
/// The working and waiting badges animate for as long as they show.
Future<void> _settle(WidgetTester tester) async {
for (var i = 0; i < 4; i++) {
await tester.pump(const Duration(milliseconds: 150));
}
}
ChatStackFabState _state(WidgetTester tester) =>
tester.state<ChatStackFabState>(find.byType(ChatStackFab));
void main() {
testWidgets('collapsed: a labelled pile of at most four layers', (
tester,
) async {
final semantics = tester.ensureSemantics();
await _pump(tester, count: 6);
expect(find.bySemanticsLabel(chatStackLabel(6)), findsOneWidget);
expect(find.byType(ChatStackPoseTransition), findsNWidgets(4));
// More chats than layers: the count shows.
expect(find.text('6'), findsOneWidget);
expect(find.byType(ChatStackColumn), findsNothing);
semantics.dispose();
});
testWidgets('tap fans out a column; tap outside folds it back', (
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 tester.pump();
expect(_state(tester).expanded, isTrue);
// Mid-way the column is still rising.
await tester.pump(const Duration(milliseconds: 100));
await _settle(tester);
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.
final first = tester.getCenter(
find.byKey(const ValueKey('chat-stack-button-pane-0')),
);
final second = tester.getCenter(
find.byKey(const ValueKey('chat-stack-button-pane-1')),
);
final add = tester.getCenter(
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(second.dy, lessThan(first.dy));
expect(add.dy, lessThan(second.dy));
// Outside the column.
await tester.tapAt(const Offset(40, 120));
await tester.pump();
expect(_state(tester).expanded, isFalse);
await _settle(tester);
expect(find.byType(ChatStackColumn), findsNothing);
expect(harness.opened, isEmpty);
});
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')));
await _settle(tester);
await tester.tap(find.text('Chat 3'));
await _settle(tester);
expect(harness.opened, ['s3']);
expect(find.byType(ChatStackColumn), findsNothing);
// The chat on screen only folds the column.
await tester.tap(find.byKey(const Key('chat-stack')));
await _settle(tester);
await tester.tap(
find.byKey(const ValueKey('chat-stack-button-pane-0')),
warnIfMissed: false,
);
await _settle(tester);
expect(harness.opened, ['s3']);
});
testWidgets('add opens the picker; long press removes', (tester) async {
final harness = await _pump(tester);
await tester.tap(find.byKey(const Key('chat-stack')));
await _settle(tester);
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);
await tester.tap(find.byKey(const ValueKey('chat-stack-button-add')));
await _settle(tester);
expect(harness.added, 1);
expect(find.byType(ChatStackColumn), findsNothing);
});
testWidgets('Back and Escape fold the column', (tester) async {
await _pump(tester);
await tester.tap(find.byKey(const Key('chat-stack')));
await _settle(tester);
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await _settle(tester);
expect(find.byType(ChatStackColumn), findsNothing);
await tester.tap(find.byKey(const Key('chat-stack')));
await _settle(tester);
final handled = await tester.binding.handlePopRoute();
await _settle(tester);
expect(handled, isTrue);
expect(find.byType(ChatStackColumn), findsNothing);
expect(find.byType(ChatStackFab), findsOneWidget);
});
testWidgets('reduced motion only fades, in place', (tester) async {
await _pump(tester, reduced: true);
final slot = tester.getRect(find.byKey(const Key('chat-stack')));
await tester.tap(find.byKey(const Key('chat-stack')));
await tester.pump();
await tester.pump(const Duration(milliseconds: 40));
// Already at its final place while fading in.
final second = tester.getCenter(
find.byKey(const ValueKey('chat-stack-button-pane-1')),
);
expect(second.dy, lessThan(slot.center.dy - 40));
final fades = tester.widgetList<FadeTransition>(
find.ancestor(
of: find.byKey(const ValueKey('chat-stack-button-pane-1')),
matching: find.byType(FadeTransition),
),
);
expect(
fades.map((fade) => fade.opacity.value),
contains(inExclusiveRange(0, 1)),
);
await _settle(tester);
expect(find.text('Chat 1'), findsOneWidget);
});
testWidgets('the on-screen keyboard hides the stack', (tester) async {
await _pump(tester);
expect(find.byKey(const Key('chat-stack')).hitTestable(), findsOneWidget);
tester.view.viewInsets = const FakeViewPadding(bottom: 300);
await _settle(tester);
expect(find.byKey(const Key('chat-stack')).hitTestable(), findsNothing);
await tester.tap(find.byKey(const Key('chat-stack')), warnIfMissed: false);
await tester.pump();
expect(_state(tester).expanded, isFalse);
tester.view.resetViewInsets();
await _settle(tester);
expect(find.byKey(const Key('chat-stack')).hitTestable(), findsOneWidget);
});
}
@@ -0,0 +1,152 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/screen.dart';
import 'package:pipelines_app/features/chat/stack/chat_stack_entry.dart';
import 'package:pipelines_app/features/chat/stack/mobile_chat_navigation.dart';
import 'package:pipelines_app/features/chat/workspace/chat_peek_header.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';
const _rows = <JsonMap>[
{'id': 'a', 'title': 'Alpha', 'directory': '/w', 'color': 'teal'},
{'id': 'b', 'title': 'Beta', 'directory': '/w'},
{'id': 'c', 'title': 'Gamma', 'directory': '/v'},
];
class _Gateway extends FakeChatGateway {
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
if (type == 'chat_sessions') {
return Future.value({
'chat_sessions': [
for (final row in _rows) {...row},
],
});
}
if (type == 'chat_shells') return Future.value({'chat_shells': []});
return super.call(type, fields);
}
}
Future<void> _pump(WidgetTester tester, Size size) async {
SharedPreferences.setMockInitialValues({});
unawaited(
MobileChatNavigationController.instance.setValue(
MobileChatNavigation.chatStack,
),
);
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final gateway = _Gateway()..history = (_) async => chatPage(const []);
addTearDown(gateway.close);
final route = ValueNotifier<String?>(null);
addTearDown(route.dispose);
await tester.pumpWidget(
MaterialApp(
home: AdaptiveShell(
destination: AppDestination.chat,
destinationBodies: {
AppDestination.chat: (_) => ValueListenableBuilder<String?>(
valueListenable: route,
builder: (context, id, _) => ChatScreen(
gateway: gateway,
initialSessionId: id,
onSessionSelected: (next) => route.value = next,
onBack: () => route.value = null,
),
),
},
),
),
);
await tester.pumpAndSettle();
}
Finder _thread(String id) => find.byKey(ValueKey('chat-thread-$id'));
final _stack = find.byKey(const Key('chat-stack'));
void main() {
final navigation = MobileChatNavigationController.instance;
tearDown(() {
unawaited(navigation.setValue(MobileChatNavigation.quickSwitch));
});
testWidgets('the setting swaps the peek for the stack, live', (tester) async {
await _pump(tester, const Size(390, 844));
await tester.tap(find.byKey(const Key('chat-row-a')));
await tester.pumpAndSettle();
expect(_thread('a'), findsOneWidget);
expect(_stack.hitTestable(), findsOneWidget);
expect(find.bySemanticsLabel(chatStackLabel(1)), findsOneWidget);
// Add chat picks a chat that is not open and opens it.
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(_thread('b').hitTestable(), findsOneWidget);
expect(find.bySemanticsLabel(chatStackLabel(2)), findsOneWidget);
// The stack replaces the peek.
expect(find.byType(ChatPeekHeader), findsNothing);
// A chat in the column opens as its list row would.
await tester.tap(_stack);
await tester.pumpAndSettle();
await tester.tap(find.text('Alpha').last);
await tester.pumpAndSettle();
expect(_thread('a').hitTestable(), findsOneWidget);
expect(_stack.hitTestable(), findsOneWidget);
// Back to Quick switch: the peek returns, the stack leaves.
unawaited(navigation.setValue(MobileChatNavigation.quickSwitch));
await tester.pumpAndSettle();
expect(_stack, findsNothing);
expect(find.byType(ChatPeekHeader), findsOneWidget);
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 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());
});
}
@@ -0,0 +1,64 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/stack/mobile_chat_navigation.dart';
import 'package:pipelines_app/features/settings/settings_chat_navigation_section.dart';
class _Store implements MobileChatNavigationStore {
String? saved;
bool success = true;
@override
Future<String?> load() async => saved;
@override
Future<bool> save(String value) async {
saved = value;
return success;
}
}
void main() {
testWidgets('chooses, saves and restores the phone chat navigation', (
tester,
) async {
final store = _Store();
final controller = MobileChatNavigationController(store: store);
addTearDown(controller.dispose);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: SingleChildScrollView(
child: SettingsChatNavigationSection(controller: controller),
),
),
),
);
expect(find.text(SettingsChatNavigationSection.title), findsOneWidget);
expect(controller.value, MobileChatNavigation.quickSwitch);
expect(
find.text(MobileChatNavigation.quickSwitch.description),
findsOneWidget,
);
await tester.tap(
find.byKey(const ValueKey('settings-chat-navigation-chatStack')),
);
await tester.pumpAndSettle();
expect(controller.value, MobileChatNavigation.chatStack);
expect(store.saved, 'chatStack');
expect(
find.text(MobileChatNavigation.chatStack.description),
findsOneWidget,
);
// A new controller (the next launch) restores the saved choice.
final next = MobileChatNavigationController(store: store);
addTearDown(next.dispose);
await next.restore();
expect(next.value, MobileChatNavigation.chatStack);
store.success = false;
await tester.tap(
find.byKey(const ValueKey('settings-chat-navigation-quickSwitch')),
);
await tester.pumpAndSettle();
expect(find.text('Could not save; applies until reload.'), findsOneWidget);
});
}