Label machine provenance and choose server before chat harness

This commit is contained in:
2026-11-08 16:46:23 +00:00
parent 3fbfb85ace
commit 4c57c50a0f
18 changed files with 466 additions and 21 deletions
@@ -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();
},
);
}