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
@@ -6,6 +6,7 @@ import 'package:pipelines_app/core/session/server_session.dart';
import 'package:pipelines_app/core/servers/server_catalog.dart';
import 'package:pipelines_app/core/servers/server_catalog_store.dart';
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/transport/connection_state.dart';
import 'package:pipelines_app/features/settings/server_connections.dart';
@@ -279,4 +280,77 @@ void main() {
}
},
);
test('a socket that did not open is classified with the machine\'s own login', () async {
final profile = _server('tank');
final servers = await _servers([profile]);
final probed = <String>[];
var verdict = SessionState.signedOut;
late _Machine machine;
final pool = ChatServerPool(
servers,
web: false,
connect: (server) async {
machine = _Machine(server);
machine.connection = ChatMachineConnection(
gateway: machine.gateway,
endpoint: () => server.endpoints.first,
connected: () => false,
states: machine.states.stream,
close: () async {},
retry: () async {},
);
return machine.connection;
},
probeProfile: ({required id, required endpoints}) async {
probed.add('$id:${endpoints.map((u) => u.host).join(',')}');
return ServerProbeResult(verdict, reason: 'no route');
},
);
try {
await _flush();
expect(probed, ['tank:tank.test']);
expect(pool.status('tank')?.access, MachineAccess.needsPassword);
expect(pool.status('tank')?.detail, 'tank asks for its password.');
verdict = SessionState.unreachable;
await pool.retry('tank');
await _flush();
expect(pool.status('tank')?.access, MachineAccess.unreachable);
expect(pool.status('tank')?.detail, 'no route');
// The editor's own probe uses the same per-machine login, not the pool.
verdict = SessionState.signedIn;
final access = await pool.probe(profile);
expect(access.access, MachineAccess.connected);
expect(probed, hasLength(3));
expect(pool.status('missing'), isNull);
} finally {
pool.dispose();
servers.dispose();
await _flush();
await machine.finish();
}
});
test('a relay that wants a password is not reported as unreachable', () async {
final profile = _server('tank');
final servers = await _servers([profile]);
final pool = ChatServerPool(
servers,
web: true,
connect: (server) async =>
throw const MachineSignInRequired('Sign in to this machine.'),
probeProfile: ({required id, required endpoints}) async =>
fail('browsers never probe the login page directly'),
);
try {
await _flush();
expect(pool.status('tank')?.access, MachineAccess.needsPassword);
expect(pool.status('tank')?.detail, 'Sign in to this machine.');
expect(pool.machines.single.error, 'Sign in to this machine.');
} finally {
pool.dispose();
servers.dispose();
await _flush();
}
});
}
@@ -0,0 +1,104 @@
import 'dart:async';
import 'dart:io';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/servers/server_probe.dart';
import 'package:pipelines_app/core/session/login_probe.dart';
import 'package:pipelines_app/core/session/server_session.dart';
import 'package:pipelines_app/core/session/server_session_io.dart' as io;
void main() {
final login = Uri.parse('https://mac.tail1.ts.net:8443/login');
test('the login page, a redirect and other answers are told apart', () {
expect(
ServerSession.interpret(
login,
const LoginProbe(status: 200, loginPage: true),
).state,
SessionState.signedOut,
);
expect(
ServerSession.interpret(login, const LoginProbe(status: 302)).state,
SessionState.signedIn,
);
final other = ServerSession.interpret(
login,
const LoginProbe(status: 200, loginPage: false),
);
expect(other.state, SessionState.unreachable);
expect(other.reason, contains('not with the Pipelines sign-in page'));
expect(other.reason, contains('mac.tail1.ts.net:8443'));
final missing = ServerSession.interpret(
login,
const LoginProbe(status: 404),
);
expect(missing.state, SessionState.unreachable);
expect(missing.reason, contains('HTTP 404'));
final failed = ServerSession.interpret(
login,
const LoginProbe(failure: 'Could not reach mac.tail1.ts.net:8443: down.'),
);
expect(failed.state, SessionState.unreachable);
expect(failed.reason, 'Could not reach mac.tail1.ts.net:8443: down.');
expect(
LoginProbe.isPipelinesLogin(
'<form method="post" action="/login"><input name="password"></form>',
),
isTrue,
);
expect(LoginProbe.isPipelinesLogin('<h1>Some other app</h1>'), isFalse);
});
test('TLS against a Tailscale IP explains the name requirement', () {
final byIp = io.describeFailure(
Uri.parse('https://100.85.25.33:8443/login'),
const HandshakeException('alert internal error'),
);
expect(byIp, contains('does not cover an IP address'));
expect(byIp, contains('wss://<name>.ts.net:8443/connect'));
final byName = io.describeFailure(
login,
const HandshakeException('certificate verify failed'),
);
expect(byName, contains('HTTPS connection to mac.tail1.ts.net:8443 failed'));
expect(byName, contains('certificate verify failed'));
expect(
io.describeFailure(
login,
const SocketException('refused', osError: OSError('Connection refused', 61)),
),
'Could not reach mac.tail1.ts.net:8443: Connection refused.',
);
expect(
io.describeFailure(login, TimeoutException('slow')),
contains('no answer within 10 seconds'),
);
});
test('probing several addresses reports the first reason when all fail', () async {
final result = await probeServerAddresses(
[Uri.parse('wss://a.test/connect'), Uri.parse('ws://b.test/connect')],
probe: (uri) async => ServerProbeResult(
SessionState.unreachable,
reason: 'no ${uri.host}',
),
isCurrent: () => true,
);
expect(result.state, SessionState.unreachable);
expect(result.endpoint, Uri.parse('wss://a.test/connect'));
expect(result.reason, 'no a.test');
final reached = await probeServerAddresses(
[Uri.parse('wss://a.test/connect'), Uri.parse('ws://b.test/connect')],
probe: (uri) async => uri.host == 'b.test'
? const ServerProbeResult(SessionState.signedOut)
: const ServerProbeResult(SessionState.unreachable, reason: 'x'),
isCurrent: () => true,
);
expect(reached.endpoint, Uri.parse('ws://b.test/connect'));
expect(reached.state, SessionState.signedOut);
expect(reached.reason, isNull);
final plain = probeFromCheck((_) async => SessionState.signedIn);
expect((await plain(login)).state, SessionState.signedIn);
});
}