Files
pipelines/app/test/features/chat/conversation/chat_row_widgets_test.dart
T
alan 2889d59119 App: replace a silent socket instead of hanging; blink the terminal cursor on a timer; keep one markdown cache entry per streamed reply
A socket that outlived a sleep or network change looked open, so every
queued request waited its own 30 s timeout behind the last until the page
was reopened. The client now replaces a socket whose request times out
unheard (or after two timeouts in a row), and probes it with a ping after
a quiet spell or on returning to the foreground.

The terminal's blinking cursor ran a Ticker (a frame every vsync); a 530 ms
timer now flips it. Streamed deltas no longer flood the markdown cache and
evict finished answers.

Adds tool/perf/idle_session_bench.mjs (idle frames, long-session heap,
snapshot census) and notes/perf-hangs-idle.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 20:47:22 +00:00

86 lines
2.8 KiB
Dart

import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/conversation/chat_row_widgets.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_markdown_cache.dart';
void main() {
test('chatJsonEquals compares decoded JSON structurally', () {
expect(
chatJsonEquals(
{
'a': [
1,
'x',
{'b': true},
],
},
{
'a': [
1,
'x',
{'b': true},
],
},
),
isTrue,
);
expect(chatJsonEquals({'a': 1}, {'a': 2}), isFalse);
expect(chatJsonEquals({'a': 1}, {'b': 1}), isFalse);
expect(chatJsonEquals([1, 2], [1, 2, 3]), isFalse);
expect(chatJsonEquals({'a': null}, <String, dynamic>{}), isFalse);
});
test('ChatRowWidgets reuses a widget until its row or inputs change', () {
final rows = ChatRowWidgets();
var builds = 0;
Widget build() {
builds++;
return SizedBox(width: builds.toDouble());
}
final first = rows.widgetFor('k', {'text': 'a'}, [1], build);
expect(rows.widgetFor('k', {'text': 'a'}, [1], build), same(first));
expect(builds, 1);
expect(rows.widgetFor('k', {'text': 'b'}, [1], build), isNot(same(first)));
final second = rows.widgetFor('k', {'text': 'b'}, [2], build);
expect(builds, 3);
rows.prune();
// A row the last build did not ask for is forgotten.
rows.prune();
expect(rows.widgetFor('k', {'text': 'b'}, [2], build), isNot(same(second)));
expect(builds, 4);
});
test('ChatMarkdownCache parses a text once and stays bounded', () {
final cache = ChatMarkdownCache(maxEntries: 2, maxChars: 100);
final blocks = cache.blocksFor('# One');
expect(cache.blocksFor('# One'), same(blocks));
expect(cache.parses, 1);
cache.blocksFor('two');
cache.blocksFor('three');
// The least recently used text was evicted and parses again.
expect(cache.blocksFor('# One'), isNot(same(blocks)));
expect(cache.parses, 4);
// A text larger than the character budget is parsed but never held.
final long = 'x' * 200;
cache.blocksFor(long);
cache.blocksFor(long);
expect(cache.parses, 6);
});
test('ChatMarkdownCache holds one entry for a streamed reply, so finished '
'answers are not evicted by its intermediate texts', () {
final cache = ChatMarkdownCache(maxEntries: 4, maxChars: 5000);
final finished = cache.blocksFor('# Finished answer');
var streamed = '';
for (var delta = 0; delta < 200; delta++) {
streamed += 'word$delta ';
cache.blocksFor(streamed);
}
expect(cache.blocksFor('# Finished answer'), same(finished));
final parses = cache.parses;
cache.blocksFor(streamed);
expect(cache.parses, parses, reason: 'the final text stays cached');
});
}