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.
This commit is contained in:
2026-11-08 23:59:20 +00:00
parent 929e4cc017
commit 079924d19a
40 changed files with 2524 additions and 259 deletions
+74
View File
@@ -0,0 +1,74 @@
// Probes Pipelines addresses exactly as the native app does, for diagnosing
// a connection that the app reports as unreachable. From app/:
//
// dart run tool/connection_probe.dart wss://box.tail1.ts.net:8443/connect [more...]
//
// With PIPELINES_WEB_AUTH_FILE (or ~/.config/pipelines/web-auth.json) present
// and --sign-in, it also posts that file's password to the first address and
// opens the websocket with the resulting cookie. The password is never printed.
import 'dart:convert';
import 'dart:io';
import 'package:pipelines_app/core/session/server_session_io.dart' as native;
import 'package:pipelines_app/core/session/session_probe.dart';
import 'package:pipelines_app/core/transport/server_url.dart';
Future<void> main(List<String> args) async {
final signIn = args.contains('--sign-in');
final addresses = args.where((a) => !a.startsWith('--')).toList();
if (addresses.isEmpty) {
stderr.writeln('usage: connection_probe.dart [--sign-in] <ws(s)://host:port/connect>...');
exit(2);
}
var failures = 0;
for (final raw in addresses) {
final Uri endpoint;
try {
endpoint = Uri.parse(ServerUrl.validate(raw).wsUrl);
} on FormatException catch (error) {
stdout.writeln('$raw: invalid: ${error.message}');
failures++;
continue;
}
final login = loginUriFor(endpoint)!;
final probe = await native.probeLogin(login, const {});
final result = interpretLoginProbe(login, probe);
stdout.writeln(
'$endpoint: ${result.state.name}'
'${result.reason == null ? '' : ' — ${result.reason}'}'
' (HTTP ${probe.status ?? 'none'}, login page: ${probe.loginPage})',
);
if (result.state == SessionState.unreachable) failures++;
}
if (!signIn) exit(failures == 0 ? 0 : 1);
final endpoint = Uri.parse(ServerUrl.validate(addresses.first).wsUrl);
final login = loginUriFor(endpoint)!;
final file = File(
Platform.environment['PIPELINES_WEB_AUTH_FILE'] ??
'${Platform.environment['HOME']}/.config/pipelines/web-auth.json',
);
final password = (jsonDecode(await file.readAsString()) as Map)['password'] as String;
final signedIn = await native.postLogin(login, password);
if (signedIn.cookie == null) {
stdout.writeln('sign-in: FAILED — ${signedIn.error}');
exit(1);
}
stdout.writeln('sign-in: cookie received');
final kept = interpretLoginProbe(
login,
await native.probeLogin(login, {'Cookie': signedIn.cookie!}),
);
stdout.writeln('kept session: ${kept.state.name}');
try {
final socket = await WebSocket.connect(
endpoint.toString(),
headers: {'Cookie': signedIn.cookie!},
).timeout(const Duration(seconds: 15));
stdout.writeln('websocket: connected (ready state ${socket.readyState})');
await socket.close();
} catch (error) {
stdout.writeln('websocket: FAILED — $error');
exit(1);
}
stdout.writeln('done');
}
@@ -1,4 +1,5 @@
import 'package:pipelines_app/core/servers/chat/chat_server_pool.dart';
import 'package:pipelines_app/core/servers/machine_access.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';
@@ -630,6 +631,36 @@ JsonMap? probeReply(JsonMap request) {
/// An in-process websocket channel: every frame the client sends is decoded
/// and answered asynchronously with [probeReply], as the server would over the
/// wire. `ready` completes at once so the shared client reports connected.
/// The capture fixture's stand-in for the chat pool: the Mac is connected,
/// the Linux desktop still wants its password, and any machine added during
/// the capture asks for `fixture-pass`.
class _FixtureAuthenticator extends ChangeNotifier
implements MachineAuthenticator {
final _verdicts = <String, MachineAccessResult>{
'mac': const MachineAccessResult(MachineAccess.connected),
'linux': const MachineAccessResult(MachineAccess.needsPassword),
};
@override
MachineAccessResult? status(String id) => _verdicts[id];
@override
Future<MachineAccessResult> probe(SavedServer server) async {
await Future<void>.delayed(const Duration(milliseconds: 400));
return _verdicts[server.id] ??=
const MachineAccessResult(MachineAccess.needsPassword);
}
@override
Future<String?> authenticate(SavedServer server, String password) async {
await Future<void>.delayed(const Duration(milliseconds: 400));
if (password != 'fixture-pass') return 'Wrong password.';
_verdicts[server.id] = const MachineAccessResult(MachineAccess.connected);
notifyListeners();
return null;
}
}
class _FixtureChannel implements WebSocketChannel {
_FixtureChannel();
@@ -820,6 +851,9 @@ Future<void> main() async {
onSelected: (_) async {},
);
await machines.load();
// Settings shows each machine's own sign-in state; a new machine asks
// for its password (`fixture-pass`) like the real chat pool does.
machines.authenticator = _FixtureAuthenticator();
}
final pool = params['federated'] == '1' && machines != null
? ChatServerPool(