Servers: name a machine after its hostname once it connects
A saved server still named by the app ('My server', 'This server',
'Original legacy server' or its address host/IP) takes the hostname the
machine reports in get_status the first time the app connects; typed
names are kept. New servers (legacy migration, Settings with a blank
name, onboarding) start with the address host. A browser on its page
origin with no saved profile shows the reported hostname too. No server
change: get_status already reports the hostname.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -12,11 +12,22 @@ import 'package:pipelines_app/features/settings/server_connections.dart';
|
||||
|
||||
class _Gateway implements ApiGateway {
|
||||
final events = StreamController<JsonMap>.broadcast();
|
||||
String? hostname;
|
||||
final calls = <String>[];
|
||||
@override
|
||||
Stream<JsonMap> get frames => events.stream;
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async =>
|
||||
type == 'attention_acks' || type == 'ack_attention'
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
||||
calls.add(type);
|
||||
return _reply(type);
|
||||
}
|
||||
|
||||
JsonMap _reply(String type) => type == 'get_status' && hostname != null
|
||||
? {
|
||||
'type': 'status',
|
||||
'status': {'hostname': hostname},
|
||||
}
|
||||
: type == 'attention_acks' || type == 'ack_attention'
|
||||
? {
|
||||
'type': 'attention_acks',
|
||||
'attention_acks': {'chat_seen': {}, 'dismissed': []},
|
||||
@@ -82,6 +93,52 @@ void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
setUp(() => SharedPreferences.setMockInitialValues({}));
|
||||
|
||||
test('a connected machine named by its address takes its hostname', () async {
|
||||
final placeholder = SavedServer.validated(
|
||||
id: 'one',
|
||||
name: 'one.test',
|
||||
endpoints: ['ws://one.test:8083/connect'],
|
||||
);
|
||||
final typed = SavedServer.validated(
|
||||
id: 'two',
|
||||
name: 'Laptop',
|
||||
endpoints: ['ws://two.test:8083/connect'],
|
||||
);
|
||||
final servers = await _servers([placeholder, typed]);
|
||||
final machines = <_Machine>[];
|
||||
final pool = ChatServerPool(
|
||||
servers,
|
||||
web: false,
|
||||
connect: (server) async {
|
||||
final machine = _Machine(server)
|
||||
..gateway.hostname = server.id == 'one' ? 'tank' : 'mac-mini';
|
||||
machines.add(machine);
|
||||
return machine.connection;
|
||||
},
|
||||
);
|
||||
try {
|
||||
await _flush();
|
||||
expect(servers.catalog.servers.map((s) => s.name), ['tank', 'Laptop']);
|
||||
expect(pool.machines.first.adapter!.server.name, 'tank');
|
||||
// Asked once per machine, not on every reconnect.
|
||||
machines.first.states.add(
|
||||
const ConnectionState(ConnectionKind.connected),
|
||||
);
|
||||
await _flush();
|
||||
expect(
|
||||
machines.first.gateway.calls.where((type) => type == 'get_status'),
|
||||
hasLength(1),
|
||||
);
|
||||
} finally {
|
||||
pool.dispose();
|
||||
servers.dispose();
|
||||
await _flush();
|
||||
for (final machine in machines) {
|
||||
await machine.finish();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('an older async detach cannot close a newer connection', () async {
|
||||
final profile = _server('one');
|
||||
final servers = await _servers([profile]);
|
||||
|
||||
Reference in New Issue
Block a user