Merge commit '50e01934'
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import '../core/servers/server_context.dart';
|
||||
import '../ui/adaptive/platform.dart';
|
||||
import 'dart:async';
|
||||
|
||||
@@ -222,7 +223,11 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
// The comparison includes the query: `?visit=N` is part of the route, while
|
||||
// a dropped or unknown query is canonicalised away.
|
||||
final location = routeLocation(_provider.value.uri);
|
||||
final initial = AppRoute.parse(location);
|
||||
final initial =
|
||||
widget.servers?.newChatServerId == widget.serverId &&
|
||||
widget.serverId != null
|
||||
? AppRoute.chat
|
||||
: AppRoute.parse(location);
|
||||
final nativeDefault =
|
||||
widget.routeInformationProvider == null &&
|
||||
!kIsWeb &&
|
||||
@@ -461,8 +466,13 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) =>
|
||||
MyApp.router(cupertino: _cupertino, routerConfig: _config);
|
||||
Widget build(BuildContext context) => widget.servers == null
|
||||
? MyApp.router(cupertino: _cupertino, routerConfig: _config)
|
||||
: ServerContext(
|
||||
connections: widget.servers!,
|
||||
serverId: widget.serverId,
|
||||
child: MyApp.router(cupertino: _cupertino, routerConfig: _config),
|
||||
);
|
||||
|
||||
/// Open a result through the exact identity the hit records. An unresolvable
|
||||
/// hit navigates nowhere: the screen already presents it read-only rather than
|
||||
|
||||
@@ -78,6 +78,10 @@ class _PipelinesRootState extends State<PipelinesRoot> {
|
||||
if (widget.web) {
|
||||
if (widget.server.uri != null) {
|
||||
_servers.alignBrowserOrigin(widget.server.uri!);
|
||||
final id = _servers.catalog.active?.id;
|
||||
if (id != null && Uri.base.queryParameters['newChat'] == '1') {
|
||||
_servers.restoreNewChatIntent(id);
|
||||
}
|
||||
}
|
||||
setState(() {
|
||||
_booting = false;
|
||||
@@ -110,8 +114,8 @@ class _PipelinesRootState extends State<PipelinesRoot> {
|
||||
}
|
||||
final page = endpoint.replace(
|
||||
scheme: endpoint.scheme == 'wss' ? 'https' : 'http',
|
||||
path: '/',
|
||||
query: null,
|
||||
path: _servers.newChatServerId == server.id ? '/chat' : '/',
|
||||
query: _servers.newChatServerId == server.id ? 'newChat=1' : null,
|
||||
fragment: null,
|
||||
);
|
||||
if (!await launchUrl(page, webOnlyWindowName: '_self')) {
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import '../../features/settings/server_connections.dart';
|
||||
|
||||
/// The machine owning this mounted app. A profile rename rebuilds consumers;
|
||||
/// changing machines creates a new gateway and app instead.
|
||||
class ServerContext extends InheritedNotifier<ServerConnections> {
|
||||
const ServerContext({
|
||||
super.key,
|
||||
required ServerConnections connections,
|
||||
required this.serverId,
|
||||
required super.child,
|
||||
}) : super(notifier: connections);
|
||||
|
||||
final String? serverId;
|
||||
static ServerContext? maybeOf(BuildContext context) =>
|
||||
context.dependOnInheritedWidgetOfExactType<ServerContext>();
|
||||
|
||||
String? get name {
|
||||
for (final server in notifier!.catalog.servers) {
|
||||
if (server.id == serverId) return server.name;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static String metadata(BuildContext context, String detail) =>
|
||||
[?maybeOf(context)?.name, if (detail.isNotEmpty) detail].join(' · ');
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import '../../../core/servers/server_context.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
@@ -80,7 +81,7 @@ class ChatThreadHeader extends StatelessWidget {
|
||||
: null,
|
||||
title: title.isEmpty ? 'Chat' : title,
|
||||
titleLeading: heroIdentity,
|
||||
subtitle: folder,
|
||||
subtitle: ServerContext.metadata(context, folder),
|
||||
subtitleIcon: cupertino
|
||||
? CupertinoIcons.folder
|
||||
: Icons.folder_outlined,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import '../../../../core/servers/server_context.dart';
|
||||
import 'dart:async';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -78,6 +79,7 @@ class ChatCompactSidebar extends StatelessWidget {
|
||||
final title = chatSessionTitle(row);
|
||||
final details = [
|
||||
title,
|
||||
?ServerContext.maybeOf(context)?.name,
|
||||
if (chatSessionSubtitle(row).isNotEmpty) chatSessionSubtitle(row),
|
||||
if (relativeChatSessionTime(row['updated_at']).isNotEmpty)
|
||||
'Updated ${relativeChatSessionTime(row['updated_at'])} ago',
|
||||
@@ -146,6 +148,13 @@ class ChatCompactSidebar extends StatelessWidget {
|
||||
: Icons.menu_open,
|
||||
),
|
||||
const Text('Expand', textAlign: TextAlign.center),
|
||||
if (ServerContext.maybeOf(context)?.name case final name?)
|
||||
Text(
|
||||
name,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
onExpand,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import '../../../../core/servers/server_context.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
@@ -31,7 +32,7 @@ class ChatCreateDialogFrame extends StatelessWidget {
|
||||
final label = submitting ? 'Creating…' : chatCreateConfirmLabel;
|
||||
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
|
||||
return CupertinoAlertDialog(
|
||||
title: const Text(chatCreateTitle),
|
||||
title: Text(ServerContext.metadata(context, chatCreateTitle)),
|
||||
content: content,
|
||||
actions: [
|
||||
CupertinoDialogAction(
|
||||
@@ -48,7 +49,7 @@ class ChatCreateDialogFrame extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
return AlertDialog(
|
||||
title: const Text(chatCreateTitle),
|
||||
title: Text(ServerContext.metadata(context, chatCreateTitle)),
|
||||
content: content,
|
||||
actions: [
|
||||
TextButton(
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../core/servers/server_catalog.dart';
|
||||
import '../../../../core/servers/server_context.dart';
|
||||
import 'chat_adaptive.dart';
|
||||
|
||||
/// Select the machine before reading its harnesses or directory listing.
|
||||
Future<SavedServer?> chooseChatMachine(BuildContext context) async {
|
||||
final scope = ServerContext.maybeOf(context);
|
||||
final servers = scope?.notifier?.catalog.servers ?? const <SavedServer>[];
|
||||
if (servers.isEmpty) return null;
|
||||
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
|
||||
return showCupertinoModalPopup<SavedServer>(
|
||||
context: context,
|
||||
builder: (context) => CupertinoActionSheet(
|
||||
title: const Text('New chat on…'),
|
||||
message: const Text(
|
||||
'Choose a machine. Its configured harnesses appear next.',
|
||||
),
|
||||
actions: [
|
||||
for (final server in servers)
|
||||
CupertinoActionSheetAction(
|
||||
onPressed: () => Navigator.pop(context, server),
|
||||
child: Text(server.name),
|
||||
),
|
||||
],
|
||||
cancelButton: CupertinoActionSheetAction(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return showDialog<SavedServer>(
|
||||
context: context,
|
||||
builder: (context) => SimpleDialog(
|
||||
title: const Text('New chat on…'),
|
||||
children: [
|
||||
for (final server in servers)
|
||||
SimpleDialogOption(
|
||||
onPressed: () => Navigator.pop(context, server),
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.computer),
|
||||
title: Text(server.name),
|
||||
subtitle: Text(Uri.parse(server.endpoints.first).host),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> showChatMachineError(BuildContext context, String message) {
|
||||
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
|
||||
return showCupertinoDialog<void>(
|
||||
context: context,
|
||||
builder: (context) => CupertinoAlertDialog(
|
||||
title: const Text('Machine unavailable'),
|
||||
content: Text(message),
|
||||
actions: [
|
||||
CupertinoDialogAction(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('OK'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
return showDialog<void>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Machine unavailable'),
|
||||
content: Text(message),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('OK'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import '../../../../core/servers/server_context.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'chat_adaptive.dart';
|
||||
@@ -87,7 +88,7 @@ class ChatSessionSubtitle extends StatelessWidget {
|
||||
style: TextStyle(fontWeight: FontWeight.w600),
|
||||
),
|
||||
if (closed && metadata.isNotEmpty) const TextSpan(text: ' · '),
|
||||
TextSpan(text: metadata),
|
||||
TextSpan(text: ServerContext.metadata(context, metadata)),
|
||||
],
|
||||
),
|
||||
style: TextStyle(color: chatMetadataForeground(context)),
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import '../../../../core/servers/server_context.dart';
|
||||
import 'chat_machine_picker.dart';
|
||||
import '../../../../ui/adaptive/segmented_bar.dart';
|
||||
import 'dart:async';
|
||||
|
||||
@@ -176,7 +178,39 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
|
||||
await _controller.close(_sessionId(session));
|
||||
}
|
||||
|
||||
Future<void> _newChat() async {
|
||||
bool _openingRequestedChat = false;
|
||||
|
||||
void _resumeNewChatIntent() {
|
||||
final scope = ServerContext.maybeOf(context);
|
||||
if (_openingRequestedChat ||
|
||||
scope == null ||
|
||||
!scope.notifier!.takeNewChatIntent(scope.serverId)) {
|
||||
return;
|
||||
}
|
||||
_openingRequestedChat = true;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
if (!mounted) return;
|
||||
await _newChat(chooseMachine: false);
|
||||
_openingRequestedChat = false;
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _newChat({bool chooseMachine = true}) async {
|
||||
final scope = ServerContext.maybeOf(context);
|
||||
if (chooseMachine && scope != null) {
|
||||
final selected = await chooseChatMachine(context);
|
||||
if (!mounted || selected == null) return;
|
||||
if (selected.id != scope.serverId) {
|
||||
final switched = await scope.notifier!.requestNewChat(selected.id);
|
||||
if (!switched && mounted) {
|
||||
await showChatMachineError(
|
||||
context,
|
||||
scope.notifier!.error ?? 'The machine could not be selected.',
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
// One id per create intent: a refusal retried in the dialog reuses it.
|
||||
final operationId = 'native-chat-${DateTime.now().microsecondsSinceEpoch}';
|
||||
final session = await showChatCreateDialog(
|
||||
@@ -257,6 +291,7 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
_resumeNewChatIntent();
|
||||
return ListenableBuilder(
|
||||
listenable: _controller,
|
||||
builder: (context, _) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import '../../../core/servers/server_context.dart';
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
@@ -203,7 +204,7 @@ class _PipelineDetailPanelState extends State<PipelineDetailPanel> {
|
||||
);
|
||||
return ShellBar(
|
||||
title: detail.displayName,
|
||||
subtitle: pipelineSubtitle(detail),
|
||||
subtitle: ServerContext.metadata(context, pipelineSubtitle(detail)),
|
||||
actions: _actions(context, detail),
|
||||
child: panel,
|
||||
);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import '../../../core/servers/server_context.dart';
|
||||
import '../../../ui/layout/app_list_avatar.dart';
|
||||
import '../../../ui/layout/app_list_row.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
@@ -242,14 +243,18 @@ class PipelineListPanel extends StatelessWidget {
|
||||
color: runStatusColor(badge.state).resolveFrom(context),
|
||||
semanticLabel: runStateLabel(badge.state),
|
||||
),
|
||||
subtitle: Text(_rowMetadata(pipeline)),
|
||||
subtitle: Text(
|
||||
ServerContext.metadata(context, _rowMetadata(pipeline)),
|
||||
),
|
||||
// A narrow pane keeps the latest state, the useful decision signal;
|
||||
// stage counts, schedules and version live in the detail instead.
|
||||
// Do not turn an in-flight or failed run-history read into a false
|
||||
// no-runs claim: the line stays blank until history is known.
|
||||
compactSubtitle: badge == null
|
||||
? const SizedBox.shrink()
|
||||
: Text(runStateLabel(badge.state)),
|
||||
? Text(ServerContext.metadata(context, ''))
|
||||
: Text(
|
||||
ServerContext.metadata(context, runStateLabel(badge.state)),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import '../../../core/servers/server_context.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
@@ -150,7 +151,7 @@ class _RunDetailViewState extends State<RunDetailView> {
|
||||
if (inShellBar) {
|
||||
return ShellBar(
|
||||
title: title,
|
||||
subtitle: subtitle,
|
||||
subtitle: ServerContext.metadata(context, subtitle),
|
||||
onTitlePressed: openPipeline,
|
||||
expandableTitle: true,
|
||||
titleAction: pipelineAction,
|
||||
@@ -170,7 +171,7 @@ class _RunDetailViewState extends State<RunDetailView> {
|
||||
onPressed: widget.onBack,
|
||||
),
|
||||
title: title,
|
||||
subtitle: subtitle,
|
||||
subtitle: ServerContext.metadata(context, subtitle),
|
||||
onTitlePressed: openPipeline,
|
||||
expandableTitle: true,
|
||||
titleAction: pipelineAction,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import '../../../core/servers/server_context.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
@@ -85,6 +86,7 @@ class RunListRow extends StatelessWidget {
|
||||
String subtitle(DateTime now) {
|
||||
final facts = runRowFacts(run, now);
|
||||
return [
|
||||
?ServerContext.maybeOf(context)?.name,
|
||||
?pipelineLabel,
|
||||
if (scheduled) 'Scheduled',
|
||||
?facts.duration,
|
||||
@@ -99,6 +101,7 @@ class RunListRow extends StatelessWidget {
|
||||
String compactSubtitle(DateTime now) {
|
||||
final facts = runRowFacts(run, now);
|
||||
return [
|
||||
?ServerContext.maybeOf(context)?.name,
|
||||
?pipelineLabel,
|
||||
if (scheduled) 'Scheduled',
|
||||
if (run['executing'] == true && facts.progress != null) facts.progress!,
|
||||
|
||||
@@ -16,6 +16,35 @@ class ServerConnections extends ChangeNotifier {
|
||||
bool _disposed = false;
|
||||
|
||||
ServerCatalog get catalog => _catalog;
|
||||
String? _newChatServerId;
|
||||
String? get newChatServerId => _newChatServerId;
|
||||
|
||||
/// A browser navigation may carry only this non-secret create intent.
|
||||
void restoreNewChatIntent(String id) {
|
||||
if (id == _catalog.active?.id) _newChatServerId = id;
|
||||
}
|
||||
|
||||
bool takeNewChatIntent(String? id) {
|
||||
if (id == null || id != _newChatServerId || id != _catalog.active?.id) {
|
||||
return false;
|
||||
}
|
||||
_newChatServerId = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Keep the intent outside the app that selecting another machine disposes.
|
||||
Future<bool> requestNewChat(String id) async {
|
||||
if (_busy || _disposed) return false;
|
||||
_newChatServerId = id;
|
||||
final selected = await _change(
|
||||
() => _catalog.select(id),
|
||||
activate: true,
|
||||
rollbackSelection: true,
|
||||
);
|
||||
if (!selected) _newChatServerId = null;
|
||||
return selected;
|
||||
}
|
||||
|
||||
bool get busy => _busy;
|
||||
String? get error => _error;
|
||||
|
||||
@@ -63,11 +92,15 @@ class ServerConnections extends ChangeNotifier {
|
||||
(_catalog.active?.id == server.id || _catalog.active == null),
|
||||
);
|
||||
|
||||
Future<bool> select(String id, {bool activate = true}) => _change(
|
||||
() => _catalog.select(id),
|
||||
activate: activate,
|
||||
rollbackSelection: true,
|
||||
);
|
||||
Future<bool> select(String id, {bool activate = true}) {
|
||||
if (_busy || _disposed) return Future.value(false);
|
||||
_newChatServerId = null;
|
||||
return _change(
|
||||
() => _catalog.select(id),
|
||||
activate: activate,
|
||||
rollbackSelection: true,
|
||||
);
|
||||
}
|
||||
|
||||
Future<bool> remove(String id) =>
|
||||
_change(() => _catalog.remove(id), activate: _catalog.active?.id == id);
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
# Machine identity and new chats
|
||||
|
||||
Pipeline/run/chat rows and their detail subtitles show the owning saved machine's
|
||||
name. A rename updates mounted labels without changing gateway identity, stored
|
||||
workspace, credentials or native IDs. Compact chat lists show the machine name
|
||||
under Expand and include it in each chat's tooltip/accessibility description.
|
||||
Profiles and address aliases remain editable in Settings → Servers.
|
||||
|
||||
New chat first presents a native machine picker, then uses that machine's own
|
||||
`chat_backends` and directory catalogue. A cross-machine selection retains a
|
||||
one-shot creation intent outside the disposable app. Root replaces the old
|
||||
socket and credentials normally, routes the new app to Chats and waits for its
|
||||
connection before mounting the create dialog. Sign-in/onboarding can complete
|
||||
first; an offline target stays at its connection gate. Failed profile saves or
|
||||
selection clear the create intent, and ordinary server switching abandons it.
|
||||
A browser navigation carries only `newChat=1` to the target origin, where the
|
||||
normal route canonicalization consumes the query. No credentials cross origins.
|
||||
No chat is created until the final explicit New chat confirmation.
|
||||
|
||||
Lists remain scoped to the selected machine. This change does not aggregate
|
||||
rows or combine native IDs across machines.
|
||||
|
||||
## Validation
|
||||
|
||||
- 51 selected Flutter tests passed, including real Root app/socket replacement,
|
||||
target-only catalogue discovery, exactly-once intent consumption, failed
|
||||
persistence and live alias rename; memory-watchdog peak 1715 MB, 8s.
|
||||
`/tmp/memwatch/out.Q5UKgn`.
|
||||
- `tool/analyze.sh`: clean, 6s.
|
||||
- Fixture web release build passed on Flutter 3.44.6, 26.2s.
|
||||
- Browser Material dark 1280×1000 captures: pipeline list, run list/detail,
|
||||
chat list/detail, machine picker, then the actual harness dialog. Cupertino
|
||||
light 560×1000 captures: chat list, native machine action sheet and harness
|
||||
dialog. Every PNG inspected; no overflow or missing alias observed.
|
||||
`/tmp/review/machine-provenance-material/`,
|
||||
`/tmp/review/machine-provenance-cupertino/`. Compact list dragging was also
|
||||
captured and inspected at `/tmp/review/machine-provenance-compact/`; the
|
||||
machine label remains readable at the 72px compact width.
|
||||
- Native device and second physical server were not used. Tests use owned
|
||||
fixture gateways; real operator chats, server processes and devices untouched.
|
||||
- Source checks precede manager landing/deployment; this note does not claim
|
||||
published artifacts or installation on the Linux machine/phone.
|
||||
@@ -1,3 +1,6 @@
|
||||
import 'package:pipelines_app/application/app.dart';
|
||||
import 'package:pipelines_app/application/app_router.dart';
|
||||
import 'package:pipelines_app/application/app_route.dart';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -162,6 +165,31 @@ void main() {
|
||||
oldClient.connect(Uri.parse(home.endpoints.first)),
|
||||
throwsStateError,
|
||||
);
|
||||
// A create intent must survive the root replacing the app/socket.
|
||||
final createSwitch = selected.servers!.requestNewChat('home');
|
||||
await frames(tester);
|
||||
expect(await createSwitch, isTrue);
|
||||
final creating = tester.widget<PipelinesApp>(find.byType(PipelinesApp));
|
||||
expect(creating.serverId, 'home');
|
||||
final host = tester.widget<MyApp>(find.byType(MyApp));
|
||||
final router = host.routerConfig!.routerDelegate as AppRouterDelegate;
|
||||
expect(router.route.kind, AppRouteKind.chat);
|
||||
// The new socket is connected; harness discovery belongs only to it.
|
||||
expect(find.byKey(const Key('chat-create-confirm')), findsOneWidget);
|
||||
expect(creating.servers!.newChatServerId, isNull);
|
||||
final newRequests = channels.last.outgoing
|
||||
.map((frame) => jsonDecode(frame as String))
|
||||
.toList();
|
||||
expect(
|
||||
newRequests.where((frame) => frame['type'] == 'chat_create'),
|
||||
isEmpty,
|
||||
);
|
||||
expect(
|
||||
channels[1].outgoing
|
||||
.map((frame) => jsonDecode(frame as String))
|
||||
.where((frame) => frame['type'] == 'chat_backends'),
|
||||
isEmpty,
|
||||
);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
},
|
||||
);
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/servers/server_catalog.dart';
|
||||
import 'package:pipelines_app/core/servers/server_catalog_store.dart';
|
||||
import 'package:pipelines_app/core/servers/server_context.dart';
|
||||
import 'package:pipelines_app/features/settings/server_connections.dart';
|
||||
|
||||
SavedServer machine(String id, String name) =>
|
||||
SavedServer.validated(id: id, name: name, endpoints: ['ws://$id.test/ws']);
|
||||
|
||||
void main() {
|
||||
test(
|
||||
'new chat targets selected machine once; failed switches clear intent',
|
||||
() async {
|
||||
final a = machine('a', 'Laptop');
|
||||
final b = machine('b', 'Linux');
|
||||
final store = MemoryServerCatalogStore(
|
||||
catalog: ServerCatalog(servers: [a, b], selectedId: 'a'),
|
||||
);
|
||||
final selected = <String?>[];
|
||||
final connections = ServerConnections(
|
||||
store: store,
|
||||
onSelected: (server) async {
|
||||
selected.add(server?.id);
|
||||
},
|
||||
);
|
||||
await connections.load();
|
||||
expect(await connections.requestNewChat('b'), isTrue);
|
||||
expect(selected, ['b']);
|
||||
expect(connections.takeNewChatIntent('a'), isFalse);
|
||||
expect(connections.takeNewChatIntent('b'), isTrue);
|
||||
expect(connections.takeNewChatIntent('b'), isFalse);
|
||||
store.failSaves = true;
|
||||
expect(await connections.requestNewChat('a'), isFalse);
|
||||
expect(connections.newChatServerId, isNull);
|
||||
expect(connections.catalog.active?.id, 'b');
|
||||
connections.dispose();
|
||||
},
|
||||
);
|
||||
|
||||
test('switching normally abandons a pending create intent', () async {
|
||||
final connections = ServerConnections(
|
||||
store: MemoryServerCatalogStore(
|
||||
catalog: ServerCatalog(
|
||||
servers: [machine('a', 'Laptop'), machine('b', 'Linux')],
|
||||
selectedId: 'a',
|
||||
),
|
||||
),
|
||||
onSelected: (_) async {},
|
||||
);
|
||||
await connections.load();
|
||||
await connections.requestNewChat('b');
|
||||
await connections.select('a');
|
||||
expect(connections.newChatServerId, isNull);
|
||||
connections.dispose();
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'machine metadata follows alias rename without changing identity',
|
||||
(tester) async {
|
||||
final connections = ServerConnections(
|
||||
store: MemoryServerCatalogStore(
|
||||
catalog: ServerCatalog(
|
||||
servers: [machine('a', 'Laptop')],
|
||||
selectedId: 'a',
|
||||
),
|
||||
),
|
||||
onSelected: (_) async {},
|
||||
);
|
||||
await connections.load();
|
||||
await tester.pumpWidget(
|
||||
ServerContext(
|
||||
connections: connections,
|
||||
serverId: 'a',
|
||||
child: MaterialApp(
|
||||
home: Builder(
|
||||
builder: (context) =>
|
||||
Text(ServerContext.metadata(context, 'Chat folder')),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(find.text('Laptop · Chat folder'), findsOneWidget);
|
||||
await connections.save(machine('a', 'My Mac'));
|
||||
await tester.pump();
|
||||
expect(find.text('My Mac · Chat folder'), findsOneWidget);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
connections.dispose();
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/servers/server_catalog.dart';
|
||||
import 'package:pipelines_app/core/servers/server_catalog_store.dart';
|
||||
import 'package:pipelines_app/core/servers/server_context.dart';
|
||||
import 'package:pipelines_app/features/settings/server_connections.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_screen.dart';
|
||||
import 'fake_chat_gateway.dart';
|
||||
import 'chat_test_harness.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'machine choice precedes harness discovery and target resumes once',
|
||||
(tester) async {
|
||||
final old = FakeChatGateway();
|
||||
final target = FakeChatGateway()
|
||||
..backendsHandler = () async => {
|
||||
'chat_backends': ['claude'],
|
||||
};
|
||||
final machines = ServerConnections(
|
||||
store: MemoryServerCatalogStore(
|
||||
catalog: ServerCatalog(
|
||||
servers: [
|
||||
SavedServer.validated(
|
||||
id: 'mac',
|
||||
name: 'My Mac',
|
||||
endpoints: ['ws://mac.test/ws'],
|
||||
),
|
||||
SavedServer.validated(
|
||||
id: 'linux',
|
||||
name: 'Linux',
|
||||
endpoints: ['ws://linux.test/ws'],
|
||||
),
|
||||
],
|
||||
selectedId: 'mac',
|
||||
),
|
||||
),
|
||||
onSelected: (_) async {},
|
||||
);
|
||||
await machines.load();
|
||||
Widget app(String id, FakeChatGateway gateway) => ServerContext(
|
||||
connections: machines,
|
||||
serverId: id,
|
||||
child: MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
home: ChatSessionsScreen(
|
||||
key: ValueKey(id),
|
||||
gateway: gateway,
|
||||
onOpen: (_) {},
|
||||
localStore: MemoryChatSessionLocalStore(),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpWidget(app('mac', old));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('chat-new-chat')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('New chat on…'), findsOneWidget);
|
||||
expect(old.count('chat_backends'), 0);
|
||||
await tester.tap(find.text('Linux'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(machines.catalog.active?.id, 'linux');
|
||||
expect(old.count('chat_backends'), 0);
|
||||
expect(old.count('chat_create'), 0);
|
||||
expect(find.byKey(const Key('chat-create-confirm')), findsNothing);
|
||||
// Equivalent to Root constructing the connected target app after activation.
|
||||
await tester.pumpWidget(app('linux', target));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Linux · Start a chat'), findsOneWidget);
|
||||
expect(target.count('chat_backends'), 1);
|
||||
expect(old.count('chat_backends'), 0);
|
||||
expect(machines.newChatServerId, isNull);
|
||||
await tester.tap(find.text('Cancel'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.pumpWidget(app('linux', target));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('chat-create-confirm')), findsNothing);
|
||||
expect(target.count('chat_backends'), 1);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
machines.dispose();
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
import 'package:pipelines_app/core/servers/server_catalog.dart';
|
||||
import 'package:pipelines_app/core/servers/server_catalog_store.dart';
|
||||
import 'package:pipelines_app/features/settings/server_connections.dart';
|
||||
import 'health_probe_fixture.dart';
|
||||
import 'package:pipelines_app/ui/motion/quick_switch_animation.dart';
|
||||
import 'package:pipelines_app/ui/motion/animation_speed.dart';
|
||||
@@ -791,7 +794,33 @@ Future<void> main() async {
|
||||
final query = params['q'];
|
||||
if (query != null && query.isNotEmpty) _typeSearchWhenShown(query);
|
||||
useAppUrlStrategy();
|
||||
ServerConnections? machines;
|
||||
if (params['machines'] == '1') {
|
||||
machines = ServerConnections(
|
||||
store: MemoryServerCatalogStore(
|
||||
catalog: ServerCatalog(
|
||||
servers: [
|
||||
SavedServer.validated(
|
||||
id: 'mac',
|
||||
name: 'Alan’s Mac',
|
||||
endpoints: ['ws://mac.fixture/connect'],
|
||||
),
|
||||
SavedServer.validated(
|
||||
id: 'linux',
|
||||
name: 'Linux desktop',
|
||||
endpoints: ['ws://linux.fixture/connect'],
|
||||
),
|
||||
],
|
||||
selectedId: 'mac',
|
||||
),
|
||||
),
|
||||
onSelected: (_) async {},
|
||||
);
|
||||
await machines.load();
|
||||
}
|
||||
final app = PipelinesApp(
|
||||
serverId: machines?.catalog.active?.id,
|
||||
servers: machines,
|
||||
server: fixtureServer(params),
|
||||
client: PipelinesClient(channelFactory: (_) => _FixtureChannel()),
|
||||
cupertino: cupertino,
|
||||
|
||||
Reference in New Issue
Block a user