Files
pipelines/app/test/features/onboarding/discovery/browser_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

94 lines
3.3 KiB
Dart

import 'dart:convert';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/onboarding/discovery/browser_server_discovery.dart';
import 'package:pipelines_app/features/onboarding/discovery/discovered_server.dart';
void main() {
test(
'browser parses names, default ports, auth and deduplicates endpoints',
() async {
final scan = BrowserServerDiscovery(
fetch: () async => jsonEncode({
'discovered_servers': [
{
'name': 'Linux',
'endpoint': 'ws://192.168.1.5:8083/connect',
'auth': 'password',
'version': 'v1',
},
{
'name': 'Linux',
'endpoint': 'ws://192.168.1.5:8083/connect',
'auth': 'password',
},
{
'name': 'Mac',
'endpoint': 'wss://mac.local/connect',
'auth': 'none',
},
{'name': 'Bad', 'endpoint': 'ws://password@host/connect'},
{'name': '', 'endpoint': 'ws://host/connect'},
{'name': 'Fragment', 'endpoint': 'ws://host/connect#secret'},
],
}),
);
final values = await scan.scan().single;
expect(values.map((s) => s.name), ['Linux', 'Mac']);
expect(values.first.passwordRequired, isTrue);
expect(values.last.passwordRequired, isFalse);
expect(values.last.port, 443);
},
);
test('unknown and malformed discovery responses report failure', () async {
for (final body in ['not json', '{}', '{"discovered_servers":null}']) {
await expectLater(
BrowserServerDiscovery(fetch: () async => body).scan(),
emitsError(isA<FormatException>()),
);
}
});
test(
'network failure is surfaced instead of pretending no machines exist',
() async {
await expectLater(
BrowserServerDiscovery(
fetch: () async => throw StateError('offline'),
).scan(),
emitsError(isA<StateError>()),
);
},
);
test('advertised routes are listed; older servers yield the LAN only', () async {
final discovery = BrowserServerDiscovery(
fetch: () async => jsonEncode({
'discovered_servers': [
{
'name': 'box',
'endpoint': 'ws://10.0.0.75:8083/connect',
'auth': 'password',
'addresses': [
{'kind': 'lan', 'endpoint': 'ws://10.0.0.75:8083/connect'},
{'kind': 'tailscale', 'endpoint': 'ws://100.85.25.33:8083/connect'},
{'kind': 'public', 'endpoint': 'wss://box.tail1.ts.net:8443/connect'},
{'kind': 'mystery', 'endpoint': 'ws://1.2.3.4:1/connect'},
{'kind': 'public', 'endpoint': 'http://bad.example'},
],
},
{'name': 'old', 'endpoint': 'ws://10.0.0.100:8082/connect', 'auth': 'password'},
],
}),
);
final servers = await discovery.scan().first;
expect(servers, hasLength(2));
expect(servers.first.endpoints.map((u) => u.toString()), [
'ws://10.0.0.75:8083/connect',
'ws://100.85.25.33:8083/connect',
'wss://box.tail1.ts.net:8443/connect',
]);
expect(servers.first.addresses[2].route, DiscoveredRoute.public);
expect(servers.last.addresses, hasLength(1));
expect(servers.last.addresses.single.route, DiscoveredRoute.lan);
});
}