From 79e5183469de1daaeea2b78a72a253aeab732be6 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Sat, 21 Nov 2026 08:40:42 +0000 Subject: [PATCH] Open machine-scoped chats from Search With several machines connected a chat id is chat@; routes rejected the @, so a search hit fell back to /chat and closed the chat. Accept a valid machine-scoped id in chat routes. Co-Authored-By: Claude Opus 5.5 --- app/lib/application/app_route.dart | 26 +++++++++++++++++++----- app/test/application/app_route_test.dart | 12 +++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/app/lib/application/app_route.dart b/app/lib/application/app_route.dart index 730f7f51..3f10e90f 100644 --- a/app/lib/application/app_route.dart +++ b/app/lib/application/app_route.dart @@ -1,3 +1,5 @@ +import '../core/servers/chat/chat_identity.dart'; + part 'app_route_codec.dart'; /// The destinations the app has a URL for. @@ -140,11 +142,25 @@ class AppRoute { /// A chat session id is nonempty, bounded and URL-safe, matching the web /// parser. Anything else is malformed rather than a stale session the - /// destination has to guess about. - static bool isChatSessionId(String value) => - value.isNotEmpty && - value.length <= 200 && - RegExp(r'^[A-Za-z0-9_-]+$').hasMatch(value); + /// destination has to guess about. With several machines connected, a + /// chat's id is its machine-scoped `chat@` form + /// ([federatedChatId]); it is valid when it decodes to a machine and a + /// valid native id. + static bool isChatSessionId(String value) { + if (value.startsWith('chat@')) { + if (value.length > 1024 || !_urlSafe.hasMatch(value.substring(5))) { + return false; + } + final federated = parseFederatedChatId(value); + return federated != null && _isNativeChatId(federated.native); + } + return _isNativeChatId(value); + } + + static final _urlSafe = RegExp(r'^[A-Za-z0-9_-]+$'); + + static bool _isNativeChatId(String value) => + value.isNotEmpty && value.length <= 200 && _urlSafe.hasMatch(value); @override bool operator ==(Object other) => diff --git a/app/test/application/app_route_test.dart b/app/test/application/app_route_test.dart index 50cd0005..8d776900 100644 --- a/app/test/application/app_route_test.dart +++ b/app/test/application/app_route_test.dart @@ -1,5 +1,6 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/application/app_route.dart'; +import 'package:pipelines_app/core/servers/chat/chat_identity.dart'; void main() { test('parses each destination, detail and stage pane', () { @@ -170,6 +171,9 @@ void main() { '/chat/a/b', '/chat/%2F', '/chat/${'x' * 201}', + '/chat/chat@', + '/chat/chat@not-base64', + '/chat/${federatedChatId('mac', 'bad id')}', '/unknown', '/runs/%E0%A4%A', ]) { @@ -194,6 +198,7 @@ void main() { AppRoute.run.stage(3, 'build', visit: 4), AppRoute.chat, AppRoute.chatSession('probe_open-1'), + AppRoute.chatSession(federatedChatId('mac', 'ses_abc-1')), AppRoute.search, AppRoute.settings, AppRoute.templates, @@ -207,6 +212,13 @@ void main() { expect(AppRoute.run(3).path, '/runs/3'); expect(AppRoute.chatSession('probe_open-1').path, '/chat/probe_open-1'); expect(AppRoute.chatSession('bad id').path, '/chat'); + // A machine-scoped id (several machines connected) keeps its session. + final scoped = federatedChatId('mac', 'ses_abc-1'); + expect(AppRoute.chatSession(scoped).chatSessionId, scoped); + expect( + AppRoute.parse(AppRoute.chatSession(scoped).path).chatSessionId, + scoped, + ); expect(AppRoute.templates.path, '/templates'); });