Files
pipelines/app/tool/perf/chat_scroll_fixture.dart
T
alan d02d5ea11d Chat transcript: wheel and trackpad scrolling always reaches the transcript
Root causes found in release web captures (1280x800 and 560x900):
- Follow mode undid small wheel/trackpad ticks at the end: each tick is its
  own scroll, re-judged as following within 32 px and jumped back. A user
  scroll toward older rows now releases the end however small; the jump
  control appears once streamed content moves the end beyond the threshold.
- The end-of-scroll jump ran inside the position's activity switch, so a
  touch or scrollbar drag released near the end recursed without end (stack
  overflow during the gesture). The jump now runs after the notification.
- Horizontally scrolling code blocks and tables claimed diagonal trackpad
  gestures whole. HorizontalScrollView gives mostly vertical gestures to the
  enclosing list; sideways and Shift + wheel still scroll the block.
- The wheel over the floating chat bar, composer and jump control moved
  nothing. VerticalWheelForwarder scrolls the transcript from them unless
  something under the pointer claims the event.

Adds widget tests per content kind and scroll mode, follow/touch/Load older
tests, a capture-kit check (tool/capture/examples/chat-wheel-scroll.json)
with eval/expect steps, wheel dx/repeat, --params and eval: targets, a
transcript scroll probe and fixture options, and fixes the kit ignoring a
script's size. Notes in notes/chat-wheel-scroll.md.
2026-11-02 20:37:36 +00:00

153 lines
4.7 KiB
Dart

// Transcript variety for chat scroll captures over the full-app fixture's
// `?chats=N` sessions (tool/perf/perf_fixture.dart). Every option defaults to
// off, so the bench's short markdown transcripts are unchanged.
//
// `?msgs=60,3` messages per chat, by chat index (the last count repeats);
// `?rich=1` answers carry a wide code line and a wide table, operator
// turns an image, and every fifth turn an agent report and a
// harness notice;
// `?older=1` the first page reports more history; Load older adds 20
// earlier messages;
// `?live=N` 3 s after a chat subscribes, N text deltas stream into a
// new reply, one every 60 ms.
import 'dart:async';
import 'package:pipelines_app/core/api_gateway.dart';
Map<String, String> _params = const {};
void configureChatScrollFixture(Map<String, String> params) => _params = params;
bool get _rich => _params['rich'] == '1';
bool get _older => _params['older'] == '1';
int get _live => int.tryParse(_params['live'] ?? '') ?? 0;
/// The message count for chat [index] (`perf-chat-<index>`).
int chatScrollMessageCount(int index) {
final counts = [
for (final value in (_params['msgs'] ?? '').split(','))
?int.tryParse(value.trim()),
];
if (counts.isEmpty) return 20;
return counts[index < counts.length ? index : counts.length - 1];
}
/// A 96x64 PNG, so an operator turn draws an image thumbnail.
const _png =
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABACAIAAABqVuVZAAAAeklE'
'QVR4nO3QMQ0AIADAMOQgEYnIwgEPBzuaTMDSMdfWpfH9IB4gQIAAAQoHCBAgQIDCAQIECBCg'
'cIAAAQIEKBwgQIAAAQoHCBAgQIDCAQIECBCgcIAAAQIEKBwgQIAAAQoHCBAgQIDCAQIECBCg'
'cIAAAQIEKBwgQG8du9DB8GFqxbUAAAAASUVORK5CYII=';
String _answer(int i) {
final wide = _rich
? '\n```sh\n${List.filled(14, 'go test ./internal/server/... -run Test$i').join(' && ')}\n```\n\n'
'| ${[for (var c = 0; c < 14; c++) 'Column $c'].join(' | ')} |\n'
'| ${List.filled(14, '---').join(' | ')} |\n'
'| ${[for (var c = 0; c < 14; c++) 'value $i.$c'].join(' | ')} |\n\n'
: '';
return '## Answer $i\n\nSome **bold** text with `code`.\n\n'
'```dart\n${List.generate(8, (l) => 'final v$l = $i * $l;').join('\n')}'
'\n```\n$wide\n- one\n- two\n';
}
JsonMap _message(String chat, int i) {
final id = '$chat-m$i';
if (_rich && i % 10 == 5) {
return {
'id': id,
'role': 'user',
'kind': 'agent_report',
'parts': [
{
'type': 'text',
'name': 'reviewer',
'text':
'## Review of change $i\n\nAll checks passed.\n\n${_answer(i)}',
},
],
};
}
if (_rich && i % 10 == 7) {
return {
'id': id,
'role': 'user',
'kind': 'notice',
'parts': [
{'type': 'text', 'text': 'Background task $i finished.'},
],
};
}
if (i.isEven) {
return {
'id': id,
'role': 'user',
'parts': [
if (_rich && i % 4 == 0)
{
'type': 'file',
'mime': 'image/png',
'name': 'shot$i.png',
'uri': _png,
},
{'type': 'text', 'text': 'Question $i'},
],
};
}
return {
'id': id,
'role': 'assistant',
'parts': [
{'type': 'text', 'text': _answer(i)},
],
};
}
/// One history page for chat [index]: the newest messages, or with `?older=1`
/// and a cursor, the 20 messages before them.
JsonMap chatScrollHistory(String sessionId, int index, String cursor) {
final count = chatScrollMessageCount(index);
if (_older && cursor == 'older') {
return {
'messages': [for (var i = -20; i < 0; i++) _message(sessionId, i)],
'next_cursor': '',
'has_more': false,
};
}
return {
'messages': [for (var i = 0; i < count; i++) _message(sessionId, i)],
'next_cursor': _older ? 'older' : '',
'has_more': _older,
};
}
/// Streams the `?live=N` reply into [sessionId] through [emit].
void chatScrollStream(String sessionId, void Function(JsonMap frame) emit) {
final deltas = _live;
if (deltas == 0) return;
JsonMap event(JsonMap body) => {
'type': 'chat_event',
'chat_event': {'session_id': sessionId, ...body},
};
Timer(const Duration(seconds: 3), () {
emit(
event({
'kind': 'step',
'step': {'status': 'running', 'turn_id': 'live', 'intermediate': false},
}),
);
var sent = 0;
Timer.periodic(const Duration(milliseconds: 60), (timer) {
emit(
event({
'message_id': '$sessionId-live',
'kind': 'text',
'part': {'id': '$sessionId-live-text', 'type': 'text'},
'delta': sent % 12 == 11 ? 'word$sent\n\n' : 'word$sent ',
}),
);
if (++sent >= deltas) timer.cancel();
});
});
}