Open machine-scoped chats from Search

With several machines connected a chat id is chat@<base64url>; 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 <noreply@anthropic.com>
This commit is contained in:
2026-11-21 08:40:42 +00:00
parent 93e9042a8b
commit 79e5183469
2 changed files with 33 additions and 5 deletions
+21 -5
View File
@@ -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@<base64url>` 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) =>
+12
View File
@@ -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');
});