Answer open-chat sync requests in chat re-tap tests

This commit is contained in:
2026-11-12 03:52:29 +00:00
parent 69ac844322
commit 24618964ce
2 changed files with 117 additions and 110 deletions
+39 -64
View File
@@ -2,32 +2,53 @@
## Change
- `lib/shell/adaptive_shell.dart`: new `onDestinationReselected` hook on
`AdaptiveShell`. Every tab control calls `_tapDestination`; a tap on the
destination already shown goes to the hook (when given), any other tap selects
as before.
- `lib/application/pipelines_app.dart`: the Chat re-tap decision (`chatRouteForRetap`
with the retained workspace route) moved from `_selectDestination` into
`AdaptiveShell`. Every tab control calls `_tapDestination`: the phone
`ShellNavigationBar`, the wide `FloatingDestinationBar` and the
`ShellNavigationRail`. A tap on the destination already shown goes to the
hook (when given); any other tap selects as before.
- `lib/application/pipelines_app.dart`: the Chat re-tap decision
(`chatRouteForRetap` with the retained workspace route) lives in
`_reselectDestination`, passed as `onDestinationReselected`. Other tabs keep
`_selectDestination`'s behaviour.
- Tests: `test/shell/destination_reselect_test.dart` (new, 3 cases) and
`test/application/chat_registration_test.dart` (one new phone case: list ->
re-tap Chat -> active chat shows).
`test/application/chat_registration_test.dart` (new phone case plus the
composer-focus case; both answer main's `chat_open_workspace` sync through the
new `answerOpenWorkspace` helper).
## Merge with main
- Main had moved: the phone bottom bar (`ShellNavigationBar`, from
`phone-bottom-tab-bar`) replaced the floating bar on phones and called
`_select` directly, which conflicted with this branch's `_tapDestination`.
- Resolved by taking main's `adaptive_shell.dart` and re-applying the hook at
the three tap sites. Against main the shell differs only by the hook.
- Merge of `main` is staged but not committed (left for land to conclude).
## Focused results (app/, memwatch)
- Baseline before edits: `chat_registration_test`, `app_route_test`,
`destination_shortcuts_test` -> 21 passed, 0 failed.
- After edits, 11 files: `destination_reselect_test`, `chat_registration_test`,
`app_route_test`, `tab_location_navigation_test`, `pipelines_app_test`,
`tab_history_back_test`, `floating_tab_bar_test`, `chat_control_tab_test`,
- Run on the merged worktree, 13 files named in the stage's list:
`destination_reselect_test`, `chat_registration_test`, `app_route_test`,
`tab_location_navigation_test`, `pipelines_app_test`, `tab_history_back_test`,
`floating_tab_bar_test`, `navigation_rail_test`, `chat_control_tab_test`,
`terminal_chat_tab_test`, `chat_wide_back_test`, `chat_scroll_back_test`
-> 55 passed, 0 failed (one earlier run failed on my own test's second
phone re-tap, which is unreachable; that step was removed, not the expectation).
-> 60 passed, 8 failed.
- The 8 failures are the same 8 tests that fail on untouched `main` (checked in
a detached main worktree): `tab_location_navigation_test` (4) and
`chat_registration_test` (4: "mobile Chats retap reopens the retained
multi-pane workspace after tabs", "a folded workspace rejects paste while
retained behind the list", "mobile Chats retap stays on list with no history
or a removed chat", "Chats retap restores a boot deep link after folding and
Back"). Cause on main: the chat-open flow now sends `chat_open_workspace`
before `chat_subscribe`, and those tests do not answer it. Not changed here.
- The new tests pass: "phone Chat re-tap from the list opens the active chat",
"mobile Chats retap from the list focuses the reopened chat composer".
- `destination_reselect_test` passes (3 cases).
- `tool/analyze.sh` -> clean.
- `dart format` on the four touched files -> clean after formatting the test file.
## States covered by tests
- Phone: list (chat detail Back'd) -> re-tap Chat -> `/chat/a` with the thread.
- No open chats / removed chat: stays on the list (existing case in
`chat_registration_test`, still passing).
- Phone: re-tap Chat from the list focuses the reopened chat's composer.
- No open chats / removed chat: stays on the list (existing case, pre-existing
failure on main, see above).
- Shell: re-tap calls the hook and not selection; other tab selects; with no
hook a re-tap is a plain selection.
@@ -35,51 +56,5 @@
- Not browser- or device-verified (no capture here, per stage rules).
- On a phone the open chat page covers the tab bar, so the "already showing"
re-tap is not reachable there; it is not tested.
- A future NavigationRail or phone bottom bar must call `_tapDestination` (the
shell's tab entry) to get the same re-select behaviour.
## Review fix: composer focus on re-tap from the list
- `lib/application/pipelines_app.dart` (`_reselectDestination`): when the Chat
re-tap reopens the retained chat from the list, its composer now takes focus
(`_focusOpenChatComposer`, the same request Ctrl+K makes), after `goTo`, as
`_openChat` does. A re-tap while a chat is already showing requests nothing.
- Test: `test/application/chat_registration_test.dart`, new case
"mobile Chats retap from the list focuses the reopened chat composer"
(phone size, list after Back -> re-tap Chat -> `chat-composer-a` EditableText
has focus). The focus request is not platform-specific; a wide layout has no
Back control that hides the workspace, so the case is run at phone size.
- Mutation check: with the focus call disabled the new case fails (6 passed,
1 failed); restored, the file passes.
## Focused results after the fix (app/, memwatch)
- `test/application/chat_registration_test.dart test/shell/destination_reselect_test.dart`
-> 10 passed, 0 failed (verdict named only these two paths).
- `tool/analyze.sh` -> clean.
- Not run: the other nine files from the earlier run; not rerun this visit.
## Land-gate fix: rail re-tap reaches the re-select hook
- Cause: on a wide window (`showsNavigationRail`, width >=
`kNavigationRailMinWindowWidth`) the rail's `onSelected` was wired to `_select`,
so a re-tap of the shown Chat rail item never called `onDestinationReselected`.
The floating bar already used `_tapDestination`.
- Fix: `lib/shell/adaptive_shell.dart` passes `_tapDestination` to
`ShellNavigationRail`. Settings on the rail goes through the same entry; it has
no hook branch of its own, and `_reselectDestination` sends non-Chat tabs to
`_selectDestination`, so Settings behaves as before.
- Test: `test/shell/destination_reselect_test.dart` gains a phone-width case
(400x800, floating bar) so both nav widgets are covered. The existing 800px cases
exercise the rail.
## Focused results (app/, memwatch, this visit)
- `test/shell/destination_reselect_test.dart test/application/chat_registration_test.dart`
-> 11 passed, 0 failed (verdict named only these two paths).
- Affected users of `AdaptiveShell` / the rail, run as one list of 17 files
(rail, floating bar, tab history, shortcuts, menu, pipelines_app_test, chat
wide/scroll back, chat open shortcut, chat control tab, terminal chat tab,
chat next chat, plus the two above) -> 69 passed, 0 failed.
- `test/application/tab_location_navigation_test.dart` -> 2 passed, 4 failed
("Settings is retained...", "a delayed read merges...", "an explicit root URL...",
"Settings does not clear..."). The same 4 fail with the rail line reverted to
`_select`, and on untouched main (9999e091, temporary detached worktree, since
removed). Pre-existing; not caused by this change, not fixed here.
- `tool/analyze.sh` -> clean.
- The rail and phone bottom bar are covered by the shared `_tapDestination`
entry, but no test drives a rail or bottom-bar tap through the hook yet.
@@ -222,6 +222,40 @@ Future<void> replyChatSessions(
await tester.pump();
}
/// Answers the `chat_open_workspace` requests the app sends around opening a
/// chat (main's open-chat sync), so the chat can subscribe. A read gets an
/// empty set; a write is stored at the next revision with its own entries.
/// Each request is answered once.
Future<void> answerOpenWorkspace(
WidgetTester tester,
FakeChannel channel,
) async {
final answered = <Object?>{};
for (var attempt = 0; attempt < 20; attempt++) {
for (final raw in channel.outgoing.toList()) {
final message = jsonDecode(raw as String) as Map<String, dynamic>;
if (message['type'] != 'chat_open_workspace' ||
!answered.add(message['id'])) {
continue;
}
final write = message['chat_open_workspace_request'] as Map?;
channel.incoming.add(
jsonEncode({
'id': message['id'],
'type': 'chat_open_workspace',
'chat_open_workspace': write == null
? {'revision': 0, 'entries': const []}
: {
'revision': (write['base_revision'] as num) + 1,
'entries': write['entries'],
},
}),
);
}
await tester.pump(const Duration(milliseconds: 5));
}
}
Future<void> replyChatHistory(
WidgetTester tester,
FakeChannel channel, {
@@ -677,10 +711,12 @@ void main() {
);
await tester.pump();
await replyChatSessions(tester, channel, ['a']);
await answerOpenWorkspace(tester, channel);
await tester.pumpAndSettle();
final chatTab = find.byKey(const ValueKey('shell.destination.chat'));
await tester.tap(find.text('Chat a').first);
await tester.pump();
await answerOpenWorkspace(tester, channel);
await replyChatHistory(
tester,
channel,
@@ -824,51 +860,47 @@ void main() {
expect(tester.takeException(), isNull);
});
testWidgets(
'phone Chat re-tap from the list opens the active chat',
(tester) async {
SharedPreferences.setMockInitialValues({});
tester.view.physicalSize = const Size(560, 1000);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final channel = FakeChannel()..readyCompleter.complete();
final client = PipelinesClient(channelFactory: (_) => channel);
final provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(uri: Uri.parse('/chat')),
);
addTearDown(provider.dispose);
addTearDown(client.dispose);
await tester.pumpWidget(
PipelinesApp(
androidSupported: false,
server: webServer(),
client: client,
routeInformationProvider: provider,
),
);
await tester.pump();
await replyChatSessions(tester, channel, ['a']);
await tester.pumpAndSettle();
await tester.tap(find.text('Chat a').first);
await tester.pump();
await replyChatHistory(
tester,
channel,
subscribeIndex: 0,
historyIndex: 0,
);
await tester.pumpAndSettle();
await tester.tap(find.byTooltip('Back').hitTestable());
await tester.pumpAndSettle();
expect(provider.value.uri.path, '/chat');
expect(find.byType(ChatThreadView), findsNothing);
testWidgets('phone Chat re-tap from the list opens the active chat', (
tester,
) async {
SharedPreferences.setMockInitialValues({});
tester.view.physicalSize = const Size(560, 1000);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final channel = FakeChannel()..readyCompleter.complete();
final client = PipelinesClient(channelFactory: (_) => channel);
final provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(uri: Uri.parse('/chat')),
);
addTearDown(provider.dispose);
addTearDown(client.dispose);
await tester.pumpWidget(
PipelinesApp(
androidSupported: false,
server: webServer(),
client: client,
routeInformationProvider: provider,
),
);
await tester.pump();
await replyChatSessions(tester, channel, ['a']);
await answerOpenWorkspace(tester, channel);
await tester.pumpAndSettle();
await tester.tap(find.text('Chat a').first);
await tester.pump();
await answerOpenWorkspace(tester, channel);
await replyChatHistory(tester, channel, subscribeIndex: 0, historyIndex: 0);
await tester.pumpAndSettle();
await tester.tap(find.byTooltip('Back').hitTestable());
await tester.pumpAndSettle();
expect(provider.value.uri.path, '/chat');
expect(find.byType(ChatThreadView), findsNothing);
final chatTab = find.byKey(const ValueKey('shell.destination.chat'));
await tester.tap(chatTab);
await tester.pumpAndSettle();
expect(provider.value.uri.path, '/chat/a');
expect(find.byType(ChatThreadView), findsOneWidget);
expect(tester.takeException(), isNull);
},
);
final chatTab = find.byKey(const ValueKey('shell.destination.chat'));
await tester.tap(chatTab);
await tester.pumpAndSettle();
expect(provider.value.uri.path, '/chat/a');
expect(find.byType(ChatThreadView), findsOneWidget);
expect(tester.takeException(), isNull);
});
}