Files
pipelines/app/test/features/settings/server_connections_recovery_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

78 lines
2.6 KiB
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';
SavedServer profile(String id) => SavedServer.validated(
id: id,
name: id,
endpoints: ['wss://$id.test/connect'],
);
void main() {
test('a native host hands the primary role to the next machine', () async {
final store = MemoryServerCatalogStore(
catalog: ServerCatalog(
servers: [profile('mac'), profile('tank')],
selectedId: 'mac',
),
);
final activated = <String?>[];
final connections = ServerConnections(
store: store,
onSelected: (server) async => activated.add(server?.id),
replaceRemovedPrimary: true,
);
addTearDown(connections.dispose);
await connections.load();
expect(await connections.remove('mac'), isTrue);
expect(connections.catalog.active?.id, 'tank');
expect(store.catalog?.selectedId, 'tank');
expect(activated, ['tank']);
// Removing the last machine activates "nothing" so the root can recover.
expect(await connections.remove('tank'), isTrue);
expect(connections.catalog.servers, isEmpty);
expect(activated, ['tank', null]);
});
test('removing a non-primary machine keeps the primary', () async {
final store = MemoryServerCatalogStore(
catalog: ServerCatalog(
servers: [profile('mac'), profile('tank')],
selectedId: 'mac',
),
);
final activated = <String?>[];
final connections = ServerConnections(
store: store,
onSelected: (server) async => activated.add(server?.id),
replaceRemovedPrimary: true,
);
addTearDown(connections.dispose);
await connections.load();
expect(await connections.remove('tank'), isTrue);
expect(connections.catalog.active?.id, 'mac');
expect(activated, isEmpty);
});
test('browsers never switch machines when the primary is removed', () async {
final store = MemoryServerCatalogStore(
catalog: ServerCatalog(
servers: [profile('mac'), profile('tank')],
selectedId: 'mac',
),
);
final activated = <String?>[];
final connections = ServerConnections(
store: store,
onSelected: (server) async => activated.add(server?.id),
);
addTearDown(connections.dispose);
await connections.load();
expect(await connections.remove('mac'), isTrue);
expect(connections.catalog.active, isNull);
expect(connections.catalog.servers.map((s) => s.id), ['tank']);
expect(activated, [null]);
});
}