Label machine provenance and choose server before chat harness
This commit is contained in:
@@ -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();
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user