Files
pipelines/app/tool/perf/chat_scroll_fixture.dart
T
alan 55ef6558e0 Hug the turn activity row's hover on desktop
On macOS, Linux, Windows and desktop browsers the "Thought · tool calls ·
background tasks" row is as wide as its label, so its hover and click area
no longer span the transcript. Phones keep the full-width touch row. The
check uses the device platform because web themes are pinned to Android.
The scroll fixture gains ?turnactivity=1 for captures.
2026-11-09 20:46:22 +00:00

207 lines
6.8 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;
// `?tasks=N` the history ends with N consecutive background-task notices
// in the server's wording (every third one failed);
// `?links=1` answers and operator turns carry a markdown link, an
// autolink, a bare URL and URLs inside code (never linkified).
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';
/// `?turnactivity=1`: replies carry thinking and a tool call, so the turn
/// activity row ("Thought … · 1 tool call") is shown.
bool get _activity => _params['turnactivity'] == '1';
bool get _links => _params['links'] == '1';
bool get _older => _params['older'] == '1';
int get _live => int.tryParse(_params['live'] ?? '') ?? 0;
int get _tasks => int.tryParse(_params['tasks'] ?? '') ?? 0;
/// Background task [i]'s notice, as the server records a Claude Code task
/// notification.
JsonMap _taskNotice(String chat, int i) {
final failed = i % 3 == 2;
final summary = i.isEven
? 'Background command "Build step $i" '
'${failed ? 'failed (exit code 1)' : 'completed (exit code 0)'}'
: 'Agent "Review part $i" ${failed ? 'failed' : 'finished'}';
return {
'id': '$chat-task-$i',
'role': 'assistant',
'kind': 'notice',
'parts': [
{
'type': 'text',
'text': 'Background task ${failed ? 'failed' : 'finished'}: $summary',
},
],
};
}
/// 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${_links ? _answerLinks : ''}';
}
const _answerLinks =
'\nRead [the release notes](https://example.com/releases/v2) or '
'<https://example.com/auto>; the bare https://example.com/bare/path. '
'and www.example.org work too. Not `https://example.com/inline`:\n\n'
'```sh\ncurl https://example.com/fenced\n```\n';
const _questionLinks =
' See https://example.com/question?id=1, [md](https://example.com/md) '
'and `https://example.com/code`.';
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${_links ? _questionLinks : ''}'},
],
};
}
return {
'id': id,
'role': 'assistant',
'parts': [
if (_activity) ...[
{'type': 'reasoning', 'text': 'Checking the files for step $i.'},
{
'type': 'tool',
'id': 'tool-$i',
'name': 'read',
'state': 'completed',
'input': {'path': 'lib/main.dart'},
},
],
{'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),
for (var i = 0; i < _tasks; i++) _taskNotice(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();
});
});
}