Disable paste targets in hidden retained chat workspaces

This commit is contained in:
2026-11-08 00:17:32 +00:00
parent 8a409e2d0a
commit fa95bf57ff
3 changed files with 103 additions and 1 deletions
+3 -1
View File
@@ -469,7 +469,9 @@ class _ChatScreenState extends State<ChatScreen>
? () => _openNext(selected)
: null,
useNativeBack: _page.open,
pasteTarget: pane == null || pane.id == _workspace.activePaneId,
pasteTarget:
_workspaceVisible &&
(pane == null || pane.id == _workspace.activePaneId),
showBackButton: pane == null
? null
: _page.open || !showsListBesideDetail(context),
+16
View File
@@ -17,3 +17,19 @@ including when quick-switch makes it inactive while bytes decode. Listener
callbacks capture composer identity so decoded files/errors cannot attach to a
replacement composer that reuses the State; changing composer rebinds the listener.
Regressions cover both retained inactive ownership and stale-completion rejection.
Retained-workspace follow-up: after Back from a folded wide workspace,
Offstage keeps composers mounted. Pane ownership alone did not make paste
eligible: `ChatScreen` now additionally requires workspace visibility. Wide
visible conversations remain eligible; hidden retained panes leave both text
and file paste to the current destination.
Full-app regression starts wide, selects a chat, folds, returns to the list,
asserts the mounted hidden composer is ineligible, and sends native Ctrl+V:
zero clipboard reads occur and retapping Chats restores the unchanged draft.
Five application tests passed (`/tmp/memwatch/out.YeXKFV`); six existing native
paste-routing tests passed in the preceding combined runs. Analyzer clean
(`flutter-analyze.Jp8Rwp`). Full-app browser evidence
`/tmp/review/hidden-chat-paste-fixed` verifies hidden text/file events are not
prevented and the original draft remains on retap; both PNGs were inspected.
Script: `/tmp/hidden-chat-paste-capture.json`. No native device or server work.
@@ -2,6 +2,7 @@ import 'dart:convert';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
@@ -9,6 +10,7 @@ import 'package:pipelines_app/application/pipelines_app.dart';
import 'package:pipelines_app/application/server_endpoint.dart';
import 'package:pipelines_app/core/transport/pipelines_client.dart';
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
import 'package:pipelines_app/features/chat/conversation/chat_composer_bar.dart';
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
import 'package:pipelines_app/features/chat/workspace/chat_mobile_peek_divider.dart';
import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_screen.dart';
@@ -505,6 +507,88 @@ void main() {
expect(tester.takeException(), isNull);
},
);
testWidgets(
'a folded workspace rejects paste while retained behind the list',
(tester) async {
SharedPreferences.setMockInitialValues({});
tester.view.physicalSize = const Size(1000, 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(
server: webServer(),
client: client,
cupertino: false,
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.enterText(
find.byKey(const Key('chat-composer-field')),
'original draft',
);
tester.view.physicalSize = const Size(560, 1000);
await tester.pumpAndSettle();
await tester.tap(find.byTooltip('Back').hitTestable());
await tester.pumpAndSettle();
expect(provider.value.uri.path, '/chat');
final retained = tester.widgetList<ChatComposerBar>(
find.byType(ChatComposerBar, skipOffstage: false),
);
expect(retained, hasLength(1));
expect(retained.single.pasteTarget, isFalse);
var clipboardReads = 0;
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(SystemChannels.platform, (call) async {
if (call.method == 'Clipboard.getData') {
clipboardReads++;
return {'text': 'must not enter hidden chat'};
}
return null;
});
addTearDown(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(SystemChannels.platform, null);
});
FocusManager.instance.primaryFocus?.unfocus();
await tester.pump();
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.keyV);
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
await tester.pumpAndSettle();
expect(clipboardReads, 0);
await tester.tap(find.byKey(const ValueKey('shell.destination.chat')));
await tester.pumpAndSettle();
expect(provider.value.uri.path, '/chat/a');
expect(find.text('original draft'), findsOneWidget);
expect(find.textContaining('must not enter hidden chat'), findsNothing);
expect(
tester
.widget<ChatComposerBar>(find.byType(ChatComposerBar))
.pasteTarget,
isTrue,
);
},
);
testWidgets(
'mobile Chats retap stays on list with no history or a removed chat',
(tester) async {