fix(app): bound the background-task output pane and row labels
Review 139 found the selected task's output page unbounded, overflowing a phone-height conversation. The bar now keeps half the viewport and scrolls its own body, the output pane is capped at twelve scaled lines, row labels elide instead of overflowing, and a reply without a page reads as unavailable rather than empty.
This commit is contained in:
@@ -76,6 +76,11 @@ JsonMap _running(String id, {String command = 'go test ./...'}) => {
|
||||
|
||||
JsonMap _snapshot(List<JsonMap> shells) => {'chat_shells': shells};
|
||||
|
||||
/// A realistically long recorded page (200 shell lines, more than one screen).
|
||||
List<String> _pageLines() => [
|
||||
for (var index = 0; index < 200; index++) 'line $index',
|
||||
];
|
||||
|
||||
Widget _host(
|
||||
_TasksGateway gateway, {
|
||||
bool cupertino = false,
|
||||
@@ -187,12 +192,10 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('4 running'), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-bg-task-list')), findsOneWidget);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byType(ChatBackgroundTasks),
|
||||
matching: find.byType(SingleChildScrollView),
|
||||
),
|
||||
findsOneWidget,
|
||||
tester.getRect(find.byKey(const Key('chat-bg-task-list'))).height,
|
||||
lessThanOrEqualTo(kMinInteractiveDimension * backgroundTaskVisibleRows),
|
||||
);
|
||||
for (var index = 0; index < 4; index++) {
|
||||
expect(
|
||||
@@ -228,7 +231,7 @@ void main() {
|
||||
'session_id': 's',
|
||||
'shell_id': 'sh1',
|
||||
'cursor': 0,
|
||||
'limit': 64 * 1024,
|
||||
'limit': chatShellOutputLimit,
|
||||
},
|
||||
},
|
||||
]);
|
||||
@@ -263,10 +266,16 @@ void main() {
|
||||
await tester.pumpWidget(_host(gateway));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// A reply with no page at all is unavailable, not "No output yet.".
|
||||
gateway.output = (_) async => const <String, dynamic>{};
|
||||
await _tapTask(tester, 'sh1');
|
||||
expect(find.text('Output unavailable for this task.'), findsOneWidget);
|
||||
|
||||
gateway.output = (_) async => {
|
||||
'chat_shell_output': {'shell': _running('sh1')},
|
||||
};
|
||||
await _tapTask(tester, 'sh1');
|
||||
await _tapTask(tester, 'sh1');
|
||||
expect(find.text('No output yet.'), findsOneWidget);
|
||||
|
||||
gateway.output = (_) async => {
|
||||
@@ -395,6 +404,167 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('a long output page scrolls inside a bounded pane', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(400, 700);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
final lines = [for (var index = 0; index < 200; index++) 'line $index'];
|
||||
final gateway = _TasksGateway();
|
||||
gateway.shells = () async => _snapshot([_running('sh1')]);
|
||||
gateway.output = (_) async => {
|
||||
'chat_shell_output': {
|
||||
'shell': _running('sh1'),
|
||||
'output': '${lines.join('\n')}\n',
|
||||
},
|
||||
};
|
||||
addTearDown(gateway.close);
|
||||
|
||||
await tester.pumpWidget(_thread(gateway));
|
||||
await tester.pumpAndSettle();
|
||||
await _tapTask(tester, 'sh1');
|
||||
|
||||
// A real shell tail is bounded: the transcript and composer stay in the
|
||||
// viewport instead of being pushed out by the whole page.
|
||||
expect(tester.takeException(), isNull);
|
||||
final outputFinder = find.byKey(const Key('chat-bg-task-output'));
|
||||
final output = tester.getRect(outputFinder);
|
||||
expect(output.height, lessThanOrEqualTo(210));
|
||||
final detail = tester.getRect(find.byKey(const Key('chat-bg-task-detail')));
|
||||
final composer = tester.getRect(
|
||||
find.byKey(const ValueKey<String>('chat-composer-s')),
|
||||
);
|
||||
expect(detail.bottom, lessThanOrEqualTo(composer.top));
|
||||
expect(composer.bottom, lessThanOrEqualTo(700));
|
||||
|
||||
// The page scrolls through the host's own text control to its last line.
|
||||
expect(
|
||||
tester.widget<SelectableText>(outputFinder).data,
|
||||
contains('line 199'),
|
||||
);
|
||||
final scrollable = tester.state<ScrollableState>(
|
||||
find.descendant(of: outputFinder, matching: find.byType(Scrollable)),
|
||||
);
|
||||
expect(scrollable.position.maxScrollExtent, greaterThan(0));
|
||||
await tester.drag(outputFinder, const Offset(0, -300));
|
||||
await tester.pumpAndSettle();
|
||||
expect(scrollable.position.pixels, greaterThan(0));
|
||||
});
|
||||
|
||||
testWidgets('three tasks and an open page fit a 320px phone', (tester) async {
|
||||
tester.view.physicalSize = const Size(320, 568);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
final gateway = _TasksGateway();
|
||||
gateway.shells = () async =>
|
||||
_snapshot([_running('sh1'), _running('sh2'), _running('sh3')]);
|
||||
gateway.output = (_) async => {
|
||||
'chat_shell_output': {
|
||||
'shell': _running('sh1'),
|
||||
'output': '${_pageLines().join('\n')}\n',
|
||||
},
|
||||
};
|
||||
addTearDown(gateway.close);
|
||||
|
||||
await tester.pumpWidget(_thread(gateway));
|
||||
await tester.pumpAndSettle();
|
||||
await _tapTask(tester, 'sh1');
|
||||
|
||||
// Three rows plus the whole detail can no longer take the viewport: the bar
|
||||
// keeps its share, scrolls its own body, and the composer stays reachable.
|
||||
expect(tester.takeException(), isNull);
|
||||
final bar = tester.getRect(find.byKey(const Key('chat-background-tasks')));
|
||||
final composer = tester.getRect(
|
||||
find.byKey(const ValueKey<String>('chat-composer-s')),
|
||||
);
|
||||
final transcript = tester.getRect(
|
||||
find.byKey(const ValueKey<String>('chat-thread-s')),
|
||||
);
|
||||
expect(
|
||||
bar.height,
|
||||
lessThanOrEqualTo(568 * backgroundTaskViewportShare + 0.5),
|
||||
);
|
||||
expect(bar.bottom, lessThanOrEqualTo(composer.top));
|
||||
expect(composer.bottom, lessThanOrEqualTo(568));
|
||||
expect(transcript.height, greaterThan(0));
|
||||
expect(
|
||||
find.byKey(const Key('chat-background-tasks-scroll')),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('one open task at 2x text keeps the composer on screen', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(320, 568);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
tester.platformDispatcher.textScaleFactorTestValue = 2;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
|
||||
|
||||
final gateway = _TasksGateway();
|
||||
gateway.shells = () async => _snapshot([_running('sh1')]);
|
||||
gateway.output = (_) async => {
|
||||
'chat_shell_output': {
|
||||
'shell': _running('sh1'),
|
||||
'output': '${_pageLines().join('\n')}\n',
|
||||
},
|
||||
};
|
||||
addTearDown(gateway.close);
|
||||
|
||||
await tester.pumpWidget(_thread(gateway));
|
||||
await tester.pumpAndSettle();
|
||||
await _tapTask(tester, 'sh1');
|
||||
expect(find.byKey(const Key('chat-bg-task-detail')), findsOneWidget);
|
||||
|
||||
// The row labels and the detail are laid out at twice the text size without
|
||||
// overflowing, and the bar's bound still leaves the composer on screen.
|
||||
expect(tester.takeException(), isNull);
|
||||
final bar = tester.getRect(find.byKey(const Key('chat-background-tasks')));
|
||||
final composer = tester.getRect(
|
||||
find.byKey(const ValueKey<String>('chat-composer-s')),
|
||||
);
|
||||
expect(bar.bottom, lessThanOrEqualTo(composer.top));
|
||||
expect(composer.bottom, lessThanOrEqualTo(568));
|
||||
});
|
||||
|
||||
testWidgets('the Cupertino row elides its labels instead of overflowing', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(320, 568);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
tester.platformDispatcher.textScaleFactorTestValue = 2;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
|
||||
|
||||
final gateway = _TasksGateway();
|
||||
gateway.shells = () async => _snapshot([
|
||||
_running('sh1', command: 'go test ./... -run TestSomethingLongEnough'),
|
||||
]);
|
||||
gateway.output = (_) async => {
|
||||
'chat_shell_output': {
|
||||
'shell': _running('sh1'),
|
||||
'output': 'native output',
|
||||
},
|
||||
};
|
||||
addTearDown(gateway.close);
|
||||
|
||||
await tester.pumpWidget(_host(gateway, cupertino: true));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
|
||||
await _tapTask(tester, 'sh1');
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.text('Details'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('the conversation mounts the session task surface', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
@@ -116,11 +116,16 @@ void main() {
|
||||
expect(chatShellOutputLimit, 64 * 1024);
|
||||
});
|
||||
|
||||
test('an unknown reply parses as no page, never invented output', () {
|
||||
test('a reply without the page is unavailable, never invented output', () {
|
||||
final page = ChatShellOutputPage.fromReply(const {});
|
||||
|
||||
expect(page.output, '');
|
||||
expect(page.shell, isNull);
|
||||
expect(page.unavailable, isTrue);
|
||||
expect(
|
||||
ChatShellOutputSnapshot(page: page).state,
|
||||
ChatShellOutputState.unavailable,
|
||||
);
|
||||
expect(
|
||||
const ChatShellOutputSnapshot(page: ChatShellOutputPage()).state,
|
||||
ChatShellOutputState.empty,
|
||||
|
||||
Reference in New Issue
Block a user