Files
pipelines/app/tool/connection_probe.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

75 lines
2.8 KiB
Dart

// 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');
}