ca2f7eee32
AppDesign builds each design's light and dark ThemeData with an AppDesignTokens extension (corner radius, flat surfaces, frame colour, ANSI accents, prompt glyph). Settings gains a Design picker stored per device; the theme hosts rebuild live. Terminal is monospace (bundled RobotoMono), near-black or paper, flat 1px frames with 3px corners, and draws the chat transcript as prompt lines, tool dot/result lines and bracketed follow-up lines. Default keeps its exact themes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
155 lines
5.3 KiB
Dart
155 lines
5.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/core/api_gateway.dart';
|
|
import 'package:pipelines_app/features/chat/domain/chat_transcript.dart';
|
|
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_bubble.dart';
|
|
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_view.dart';
|
|
import 'package:pipelines_app/features/chat/ui/transcript/terminal/terminal_activity_rows.dart';
|
|
import 'package:pipelines_app/features/chat/ui/transcript/terminal/terminal_glyphs.dart';
|
|
import 'package:pipelines_app/features/chat/ui/transcript/terminal/terminal_prompt_line.dart';
|
|
import 'package:pipelines_app/ui/theme/app_design.dart';
|
|
|
|
JsonMap _row(JsonMap message) => transcriptRows([message]).single;
|
|
|
|
final JsonMap _operator = _row({
|
|
'id': 'u1',
|
|
'role': 'user',
|
|
'parts': [
|
|
{'type': 'text', 'text': 'Fix the Windows paths.'},
|
|
],
|
|
});
|
|
|
|
JsonMap _tool(String id, String name, String status, {String? output}) => {
|
|
'type': 'tool',
|
|
'id': id,
|
|
'name': name,
|
|
'state': {
|
|
'status': status,
|
|
'input': {'command': 'go test ./...'},
|
|
if (output != null)
|
|
'content': [
|
|
{'type': 'text', 'text': output},
|
|
],
|
|
if (status == 'error') 'error': {'message': 'exit status 1'},
|
|
},
|
|
};
|
|
|
|
final JsonMap _agent = _row({
|
|
'id': 'a1',
|
|
'role': 'assistant',
|
|
'parts': [
|
|
_tool('t1', 'Bash', 'completed', output: 'ok notes 0.2s\nPASS'),
|
|
_tool('t2', 'Bash', 'error'),
|
|
{'type': 'text', 'text': 'Fixed the separators.'},
|
|
],
|
|
});
|
|
|
|
final JsonMap _followup = _row({
|
|
'id': 'f1',
|
|
'role': 'user',
|
|
'origin': 'followup',
|
|
'client': 'Agent follow-up',
|
|
'parts': [
|
|
{'type': 'text', 'text': 'Check whether run 42 finished.'},
|
|
],
|
|
});
|
|
|
|
Widget _host(AppDesign design, List<JsonMap> rows) => MaterialApp(
|
|
theme: design.dark(),
|
|
themeMode: ThemeMode.light,
|
|
home: Scaffold(
|
|
body: ListView(
|
|
children: [for (final row in rows) ChatMessageView(row: row)],
|
|
),
|
|
),
|
|
);
|
|
|
|
double _left(WidgetTester tester, Finder finder) =>
|
|
tester.getTopLeft(finder).dx;
|
|
|
|
void main() {
|
|
testWidgets('Terminal: the operator turn is a prompt line at the start', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(_host(AppDesign.terminal, [_operator, _agent]));
|
|
final line = find.byType(TerminalPromptLine);
|
|
expect(line, findsOneWidget);
|
|
expect(find.descendant(of: line, matching: find.text('>')), findsOneWidget);
|
|
// Same start edge as the answer, not pushed to the trailing side.
|
|
final answer = find.text('Fixed the separators.');
|
|
expect(_left(tester, line), lessThan(_left(tester, answer)));
|
|
expect(_left(tester, line), lessThan(40));
|
|
});
|
|
|
|
testWidgets('Terminal: tool calls are dot lines with result lines', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(_host(AppDesign.terminal, [_agent]));
|
|
final rows = find.byType(TerminalActivityRows);
|
|
expect(rows, findsOneWidget);
|
|
expect(
|
|
find.descendant(of: rows, matching: find.textContaining('Bash')),
|
|
findsNWidgets(2),
|
|
);
|
|
expect(
|
|
find.descendant(
|
|
of: rows,
|
|
matching: find.textContaining('ok notes 0.2s · +1 lines'),
|
|
),
|
|
findsOneWidget,
|
|
);
|
|
expect(
|
|
find.descendant(of: rows, matching: find.textContaining('exit status 1')),
|
|
findsOneWidget,
|
|
);
|
|
final glyphs = tester
|
|
.widgetList<TerminalGlyph>(
|
|
find.descendant(of: rows, matching: find.byType(TerminalGlyph)),
|
|
)
|
|
.toList();
|
|
expect(glyphs.where((g) => g.kind == TerminalGlyphKind.dot), hasLength(2));
|
|
expect(
|
|
glyphs.where((g) => g.kind == TerminalGlyphKind.elbow),
|
|
hasLength(2),
|
|
);
|
|
// The failed call's dot is red, the completed one's is not.
|
|
final dots = glyphs.where((g) => g.kind == TerminalGlyphKind.dot).toList();
|
|
expect(dots.first.color, isNot(dots.last.color));
|
|
// The block still opens the activity details.
|
|
await tester.tap(rows);
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Activity details'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('Terminal: an agent follow-up is a dim bracketed line', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(_host(AppDesign.terminal, [_followup]));
|
|
final header = find.byKey(const Key('chat-automated-prompt-header'));
|
|
expect(header, findsOneWidget);
|
|
final text = tester.widget<Text>(header).textSpan!.toPlainText();
|
|
expect(text, startsWith('[Follow-up from agent'));
|
|
expect(text, endsWith(']'));
|
|
expect(find.text('Check whether run 42 finished.'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('Default: bubbles and the one-line activity are unchanged', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(
|
|
_host(AppDesign.standard, [_operator, _agent, _followup]),
|
|
);
|
|
expect(find.byType(TerminalPromptLine), findsNothing);
|
|
expect(find.byType(TerminalActivityRows), findsNothing);
|
|
expect(find.byType(TerminalGlyph), findsNothing);
|
|
expect(find.byType(ChatUserBubble), findsOneWidget);
|
|
expect(find.text('>'), findsNothing);
|
|
// The operator's bubble sits on the trailing side.
|
|
final bubble = find.byType(ChatUserBubble);
|
|
final answer = find.text('Fixed the separators.');
|
|
expect(_left(tester, bubble), greaterThan(_left(tester, answer)));
|
|
final header = find.byKey(const Key('chat-automated-prompt-header'));
|
|
expect(tester.widget(header), isA<Wrap>());
|
|
});
|
|
}
|