Files
pipelines/app/test/features/settings/saved_server_discovery_test.dart
T
alan 079924d19a Recover from zero servers, sign each machine in on its own, offer every route
- Removing the primary machine hands pipelines/runs to the next saved machine
  on native hosts; removing the last machine returns to the connect screen
  instead of stranding the app on "Server endpoint not configured".
- Add server probes the new machine and asks for its own password in the same
  page; Settings rows show Connected / Sign in required / Unreachable with the
  reason and offer Sign in; no other machine's credential is ever reused.
- Unreachable addresses explain why: a TLS failure against an IP points at the
  Tailscale name, a non-Pipelines answer points at the port.
- Discovered machines list every advertised route (LAN, Tailscale IP, Tailscale
  name) as a checklist; chosen routes are saved as one machine.
- tool/connection_probe.dart replays the native login and websocket against
  real addresses for diagnosis.
2026-11-08 23:59:20 +00:00

177 lines
5.6 KiB
Dart

import 'dart:convert';
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/features/settings/server_connections.dart';
import 'package:pipelines_app/features/settings/saved_servers_section.dart';
import 'package:pipelines_app/features/settings/saved_server_row.dart';
import 'package:pipelines_app/features/settings/saved_server_editor.dart';
import 'package:pipelines_app/features/onboarding/discovery/browser_server_discovery.dart';
import 'package:pipelines_app/features/onboarding/onboarding_flow.dart';
import 'package:pipelines_app/core/session/server_session.dart';
BrowserServerDiscovery discovery() => BrowserServerDiscovery(
fetch: () async => jsonEncode({
'discovered_servers': [
{
'name': 'Linux laptop',
'endpoint': 'ws://192.168.1.5:8083/connect',
'auth': 'password',
},
],
}),
);
void main() {
testWidgets(
'browser server rows cannot navigate away by selecting one machine',
(tester) async {
final home = SavedServer.validated(
id: 'home',
name: 'Home',
endpoints: ['wss://home.test/connect'],
);
final other = SavedServer.validated(
id: 'other',
name: 'Other',
endpoints: ['wss://other.test/connect'],
);
final connections = ServerConnections(
store: MemoryServerCatalogStore(
catalog: ServerCatalog(servers: [home, other], selectedId: home.id),
),
onSelected: (_) async =>
fail('Browser must keep all chat connections in this page'),
);
addTearDown(connections.dispose);
await connections.load();
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: SavedServersSection(
connections: connections,
allowPrimarySelection: false,
),
),
),
);
await tester.tap(find.text('Other'));
await tester.pumpAndSettle();
expect(connections.catalog.active!.id, 'home');
await tester.tap(find.byKey(savedServerMenuKey('other')));
await tester.pumpAndSettle();
expect(find.textContaining('Use Other'), findsNothing);
expect(find.text('Edit Other'), findsOneWidget);
expect(find.text('Remove Other'), findsOneWidget);
},
);
testWidgets(
'choosing a discovered machine prefills editable name and address',
(tester) async {
SavedServer? saved;
await tester.pumpWidget(
MaterialApp(
home: Builder(
builder: (context) => Scaffold(
body: TextButton(
onPressed: () => editSavedServer(
context,
discovery: discovery(),
onSave: (value) async {
saved = value;
},
),
child: const Text('Add server'),
),
),
),
),
);
await tester.tap(find.text('Add server'));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('discovery-scan')));
await tester.pumpAndSettle();
await tester.tap(find.text('Linux laptop'));
await tester.pumpAndSettle();
expect(
tester
.widget<TextField>(find.byKey(const Key('server-profile-name')))
.controller!
.text,
'Linux laptop',
);
expect(
tester
.widget<TextField>(
find.byKey(const Key('server-profile-addresses')),
)
.controller!
.text,
'ws://192.168.1.5:8083/connect',
);
expect(saved, isNull);
await tester.enterText(
find.byKey(const Key('server-profile-name')),
'My Linux',
);
await tester.scrollUntilVisible(
find.text('Save server'),
120,
scrollable: find.byType(Scrollable).last,
);
await tester.pumpAndSettle();
await tester.tap(find.text('Save server'));
await tester.pumpAndSettle();
expect(saved!.name, 'My Linux');
expect(saved!.endpoints, ['ws://192.168.1.5:8083/connect']);
},
);
testWidgets('onboarding reviews and persists machine name before sign-in', (
tester,
) async {
var checks = 0;
String? alias;
await tester.pumpWidget(
MaterialApp(
home: OnboardingFlow(
onDone: (_) {},
discovery: discovery(),
check: (_) async {
checks++;
return SessionState.signedOut;
},
saveServerProfile: (url, name) async {
alias = name;
},
),
),
);
await tester.ensureVisible(find.byKey(const Key('discovery-scan')));
await tester.tap(find.byKey(const Key('discovery-scan')));
await tester.pumpAndSettle();
await tester.ensureVisible(find.text('Linux laptop'));
await tester.tap(find.text('Linux laptop'));
await tester.pumpAndSettle();
expect(checks, 0);
expect(
tester
.widget<TextField>(find.byKey(const Key('onboarding-server-name')))
.controller!
.text,
'Linux laptop',
);
await tester.enterText(
find.byKey(const Key('onboarding-server-name')),
'Workstation',
);
await tester.ensureVisible(find.byKey(const Key('onboarding-next')));
await tester.tap(find.byKey(const Key('onboarding-next')));
await tester.pumpAndSettle();
expect(checks, 1);
expect(alias, 'Workstation');
expect(find.byKey(const Key('onboarding-password')), findsOneWidget);
});
}