Merge main (Paper design) into the design perf budget

Paper's theme joins the cached builder; AppDesignTokens and ReadingType
compare every new token by value, and Paper's tab indicator and switch
outline resolver are kept per colour so a rebuilt Paper theme equals
the last.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 19:45:24 +00:00
61 changed files with 2376 additions and 118 deletions
@@ -0,0 +1,68 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/conversation/chat_draft_store.dart';
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
import 'package:pipelines_app/ui/theme/app_design.dart';
import 'chat_composer_bar_fixtures.dart';
Widget _thread(ComposerBarGateway gateway, AppDesign design) => MaterialApp(
theme: design.light(),
home: Scaffold(
body: ChatThreadView(
gateway: gateway,
sessionId: 's',
session: const {'id': 's', 'directory': '/Users/ada/repos/tank'},
syncToken: 0,
onBack: () {},
drafts: MemoryChatDraftStore(),
),
),
);
void main() {
testWidgets('Paper: the composer is an underlined writing area, not a '
'pill, and its rule takes the accent on focus', (tester) async {
final gateway = ComposerBarGateway();
addTearDown(gateway.close);
await tester.pumpWidget(_thread(gateway, AppDesign.paper));
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-composer-pill')), findsNothing);
final area = find.byKey(const Key('chat-composer-underline'));
expect(area, findsOneWidget);
for (final key in [
'chat-composer-attach',
'chat-composer-field',
'chat-composer-primary',
]) {
expect(
find.descendant(of: area, matching: find.byKey(Key(key))),
findsOneWidget,
);
}
final scheme = Theme.of(tester.element(area)).colorScheme;
Color? rule() =>
(tester
.widget<AnimatedContainer>(
find.byKey(const Key('chat-composer-rule')),
)
.decoration
as BoxDecoration?)
?.color;
expect(rule(), scheme.outline);
await tester.tap(find.byKey(const Key('chat-composer-field')));
await tester.pumpAndSettle();
expect(rule(), scheme.primary);
});
testWidgets('Default keeps the pill', (tester) async {
final gateway = ComposerBarGateway();
addTearDown(gateway.close);
await tester.pumpWidget(_thread(gateway, AppDesign.standard));
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-composer-pill')), findsOneWidget);
expect(find.byKey(const Key('chat-composer-underline')), findsNothing);
});
}
@@ -0,0 +1,203 @@
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_markdown_view.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/paper/paper_activity_note.dart';
import 'package:pipelines_app/features/chat/ui/transcript/paper/paper_editorial_note.dart';
import 'package:pipelines_app/features/chat/ui/transcript/paper/paper_quote.dart';
import 'package:pipelines_app/features/chat/ui/transcript/terminal/terminal_activity_rows.dart';
import 'package:pipelines_app/features/chat/ui/transcript/terminal/terminal_prompt_line.dart';
import 'package:pipelines_app/ui/text/monospace.dart';
import 'package:pipelines_app/ui/theme/app_design.dart';
import 'package:pipelines_app/ui/theme/paper_fonts.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) => {
'type': 'tool',
'id': id,
'name': name,
'state': {
'status': status,
'input': {'command': 'go test ./...'},
if (status == 'error') 'error': {'message': 'exit status 1'},
},
};
final JsonMap _agent = _row({
'id': 'a1',
'role': 'assistant',
'parts': [
_tool('t1', 'Bash', 'completed'),
_tool('t2', 'Read', 'completed'),
_tool('t3', 'Bash', 'completed'),
{
'type': 'text',
'text':
'## Cause\n\nFixed the separators.\n\n'
'- one\n- two\n\n```go\nreturn filepath.Join(a, b)\n```',
},
],
});
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.light(),
home: Scaffold(
body: ListView(
children: [
for (final row in rows)
ChatMessageView(row: row, textBuilder: chatMarkdownText),
],
),
),
);
double _left(WidgetTester tester, Finder finder) =>
tester.getTopLeft(finder).dx;
/// The style the text containing [text] is laid out in: the root of the
/// first [RichText] that draws it.
TextStyle _style(WidgetTester tester, String text) {
final rich = tester
.widgetList<RichText>(find.byType(RichText))
.firstWhere((rich) => rich.text.toPlainText().contains(text));
return rich.text.style ?? const TextStyle();
}
void main() {
testWidgets('Paper: the operator turn is an indented block quote with a '
'small-caps label and a rule, not a bubble', (tester) async {
await tester.pumpWidget(_host(AppDesign.paper, [_operator, _agent]));
final quote = find.byType(PaperQuote);
expect(quote, findsOneWidget);
expect(find.byType(TerminalPromptLine), findsNothing);
final label = find.byKey(const Key('chat-paper-quote-label'));
expect(tester.widget<Text>(label).data, 'YOU');
expect(tester.widget<Text>(label).style?.fontStyle, FontStyle.italic);
// Indented past the answer's text edge, not on the trailing side.
final words = find.text('Fix the Windows paths.');
final answer = find.text('Fixed the separators.');
expect(_left(tester, words), greaterThan(_left(tester, answer)));
expect(_left(tester, words) - _left(tester, answer), lessThan(40));
// The rule runs down the quote's leading edge.
final rule = tester.widget<DecoratedBox>(
find.descendant(of: quote, matching: find.byType(DecoratedBox)).first,
);
final side =
((rule.decoration as BoxDecoration).border! as BorderDirectional).start;
expect(side.width, paperQuoteRule);
});
testWidgets('Paper: answers are serif prose, code keeps the monospace', (
tester,
) async {
await tester.pumpWidget(_host(AppDesign.paper, [_agent]));
final prose = _style(tester, 'Fixed the separators.');
expect(prose.fontFamily, paperSerifFamily);
expect(prose.height, closeTo(1.55, 0.01));
final heading = _style(tester, 'Cause');
expect(heading.fontFamily, paperSerifFamily);
expect(heading.fontWeight, FontWeight.w600);
expect(heading.fontSize, greaterThan(prose.fontSize!));
final code = _style(tester, 'return filepath.Join(a, b)');
expect(code.fontFamily, appMonospaceFamily);
expect(code.fontSize, lessThan(prose.fontSize!));
expect(find.text('•'), findsNWidgets(2));
});
testWidgets('Paper: tool activity is a muted marginal note naming the '
'tools, and it still opens the details', (tester) async {
await tester.pumpWidget(_host(AppDesign.paper, [_agent]));
expect(find.byType(TerminalActivityRows), findsNothing);
final note = find.byType(PaperActivityNote);
expect(note, findsOneWidget);
expect(
find.descendant(
of: note,
matching: find.textContaining('Used 3 tools — Bash, Read'),
),
findsOneWidget,
);
final text = tester.widget<Text>(
find.descendant(of: note, matching: find.byType(Text)),
);
expect(text.style?.fontStyle, FontStyle.italic);
await tester.tap(note);
await tester.pumpAndSettle();
expect(find.text('Activity details'), findsOneWidget);
});
testWidgets('Paper: a follow-up is a small italic editorial note', (
tester,
) async {
await tester.pumpWidget(_host(AppDesign.paper, [_followup]));
expect(find.byType(PaperEditorialNote), findsOneWidget);
final header = find.byKey(const Key('chat-automated-prompt-header'));
final text = tester.widget<Text>(header).textSpan!.toPlainText();
expect(text, startsWith('FOLLOW-UP FROM AGENT'));
// The body is selectable text in the note's ambient style.
final body = DefaultTextStyle.of(
tester.element(find.text('Check whether run 42 finished.')),
).style;
expect(body.fontStyle, FontStyle.italic);
// No card: the note has no Material fill.
final note = tester.widget<Material>(
find.byKey(const Key('chat-automated-prompt')),
);
expect(note.type, MaterialType.transparency);
});
testWidgets('Default is unchanged: a trailing bubble, no Paper pieces', (
tester,
) async {
await tester.pumpWidget(
_host(AppDesign.standard, [_operator, _agent, _followup]),
);
expect(find.byType(PaperQuote), findsNothing);
expect(find.byType(PaperActivityNote), findsNothing);
expect(find.byType(PaperEditorialNote), findsNothing);
expect(find.byType(ChatUserBubble), findsOneWidget);
final bubble = find.byType(ChatUserBubble);
final answer = find.text('Fixed the separators.');
expect(_left(tester, bubble), greaterThan(_left(tester, answer)));
expect(
_style(tester, 'Fixed the separators.').fontFamily,
isNot(paperSerifFamily),
);
});
testWidgets('Terminal is unchanged: prompt line and tool rows', (
tester,
) async {
await tester.pumpWidget(_host(AppDesign.terminal, [_operator, _agent]));
expect(find.byType(TerminalPromptLine), findsOneWidget);
expect(find.byType(TerminalActivityRows), findsOneWidget);
expect(find.byType(PaperQuote), findsNothing);
expect(find.byType(PaperActivityNote), findsNothing);
expect(
_style(tester, 'Fixed the separators.').fontFamily,
appMonospaceFamily,
);
});
}
@@ -91,4 +91,27 @@ void main() {
expect(find.text(designSaveFailedText), findsOneWidget);
expect(designs.design, AppDesign.terminal);
});
testWidgets('choosing Paper stores it, restyles the page live and is '
'restored on the next launch', (tester) async {
final store = MemoryAppDesignStore();
final designs = AppDesignController(store: store);
await _pump(tester, designs);
// Every row shows its design's swatch.
expect(
find.byType(DesignSwatchPreview),
findsNWidgets(AppDesign.values.length),
);
expect(find.text(AppDesign.paper.description), findsOneWidget);
await tester.tap(find.text(AppDesign.paper.label));
await tester.pumpAndSettle();
expect(store.id, 'paper');
expect(designs.design, AppDesign.paper);
expect(_tokens(tester).transcript, TranscriptStyle.manuscript);
final next = AppDesignController(store: MemoryAppDesignStore(store.id));
await next.restore();
expect(next.design, AppDesign.paper);
});
}
+60
View File
@@ -6,6 +6,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/layout/app_list_avatar.dart';
import 'package:pipelines_app/ui/layout/app_list_row.dart';
import 'package:pipelines_app/ui/layout/app_overflow_menu.dart';
import 'package:pipelines_app/ui/theme/app_design.dart';
const _longTitle = 'A row title long enough that it must ellipsise somewhere';
const _longLine = 'a muted line of facts that is far too long for one line';
@@ -257,4 +258,63 @@ void main() {
expect(_paint(tester, 'B').fontSize, 18);
expect(_paint(tester, 'B').fontWeight, FontWeight.w700);
});
// Each design marks the open row its own way (AppDesignTokens.selectedRow);
// every way keeps the leading bar in the accent.
for (final (design, framed, tonal) in [
(AppDesign.standard, false, true),
(AppDesign.terminal, true, false),
(AppDesign.paper, false, false),
]) {
testWidgets('${design.label}: the open row is clearly marked', (
tester,
) async {
_size(tester, 560);
await tester.pumpWidget(
MaterialApp(
theme: design.light(),
home: Scaffold(body: ListView(children: [_row(selected: true)])),
),
);
final row = find.byKey(const Key('row'));
final context = tester.element(row);
final scheme = Theme.of(context).colorScheme;
final fill = tester
.widget<Material>(
find.descendant(
of: row,
matching: find.byKey(appListRowSurfaceKey),
),
)
.color!;
if (tonal) {
expect(fill, AppListRow.selectedColor(context));
} else {
// The accent washed over the page, visibly apart from it.
expect(fill, isNot(Theme.of(context).scaffoldBackgroundColor));
expect(fill.a, 1);
final page = Theme.of(context).scaffoldBackgroundColor;
expect(
(fill.computeLuminance() - page.computeLuminance()).abs(),
greaterThan(0.04),
);
}
final border =
(tester
.widget<DecoratedBox>(
find.descendant(
of: row,
matching: find.byKey(appListRowSelectionKey),
),
)
.decoration
as BoxDecoration)
.border!
as BorderDirectional;
expect(border.start.color, scheme.primary);
expect(border.start.width, kAppListRowBarWidth);
expect(border.top == BorderSide.none, !framed);
expect(border.end == BorderSide.none, !framed);
});
}
}
+177
View File
@@ -0,0 +1,177 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/text/monospace.dart';
import 'package:pipelines_app/ui/theme/app_design.dart';
import 'package:pipelines_app/ui/theme/app_design_tokens.dart';
import 'package:pipelines_app/ui/theme/app_theme.dart';
import 'package:pipelines_app/ui/theme/paper_fonts.dart';
ThemeData _theme(AppDesign design, Brightness brightness, {String? font}) =>
brightness == Brightness.dark
? design.dark(fontFamily: font)
: design.light(fontFamily: font);
void main() {
test('Paper is listed with a stable id, a label and one line', () {
expect(AppDesign.values, contains(AppDesign.paper));
expect(AppDesign.fromId('paper'), AppDesign.paper);
expect(AppDesign.paper.label, 'Paper');
expect(AppDesign.paper.description, isNot(contains('\n')));
expect(AppDesign.paper.usesInterfaceFont, isTrue);
expect(AppDesign.terminal.usesInterfaceFont, isFalse);
});
test('Paper tokens: manuscript transcript, underline composer, washed '
'row, serif reading at ~70ch, soft corners, hairlines', () {
for (final brightness in Brightness.values) {
final theme = _theme(AppDesign.paper, brightness);
final tokens = theme.extension<AppDesignTokens>()!;
expect(tokens.design, AppDesign.paper);
expect(tokens.transcript, TranscriptStyle.manuscript);
expect(tokens.terminal, isFalse);
expect(tokens.composer, ComposerStyle.underline);
expect(tokens.selectedRow, SelectedRowStyle.washed);
expect(tokens.reading.family, paperSerifFamily);
expect(tokens.reading.height, closeTo(1.5, 0.1));
expect(tokens.reading.measure, 70);
expect(tokens.radius, inInclusiveRange(8, 10));
expect(tokens.flat, isTrue);
expect(tokens.frame, theme.colorScheme.outlineVariant);
expect(tokens.panel, theme.colorScheme.surface);
expect(tokens.chatColorSaturation, lessThan(1));
expect(tokens.ansi, isNotNull);
}
});
test('Paper pages: warm off-white by day, sepia charcoal by night', () {
final light = _theme(AppDesign.paper, Brightness.light);
final page = light.scaffoldBackgroundColor;
expect(page.computeLuminance(), greaterThan(0.8));
expect(page, isNot(const Color(0xFFFFFFFF)));
expect(page.r, greaterThan(page.b), reason: 'a warm page');
final dark = _theme(AppDesign.paper, Brightness.dark);
final night = dark.scaffoldBackgroundColor;
expect(night.computeLuminance(), inExclusiveRange(0.008, 0.05));
expect(night.r, greaterThan(night.b), reason: 'sepia, not neutral');
for (final theme in [light, dark]) {
// Ink, a muted secondary ink and one accent.
final scheme = theme.colorScheme;
expect(scheme.onSurface, isNot(scheme.onSurfaceVariant));
expect(scheme.primary.b, greaterThan(scheme.primary.r));
}
});
test('Paper sets titles in the serif and keeps chrome in the interface '
'font', () {
for (final brightness in Brightness.values) {
final text = _theme(AppDesign.paper, brightness, font: 'Inter').textTheme;
for (final title in [
text.headlineSmall,
text.titleLarge,
text.displaySmall,
]) {
expect(title?.fontFamily, paperSerifFamily);
}
for (final chrome in [
text.labelLarge,
text.labelSmall,
text.titleMedium,
text.bodyMedium,
text.bodySmall,
]) {
expect(chrome?.fontFamily, 'Inter');
}
}
// The reading style sets the serif over the body role and keeps the
// interface face as its fallback.
final paper = _theme(AppDesign.paper, Brightness.light, font: 'Inter');
final tokens = paper.extension<AppDesignTokens>()!;
const body = TextStyle(fontFamily: 'Inter', fontSize: 16);
final reading = tokens.reading.apply(body)!;
expect(reading.fontFamily, paperSerifFamily);
expect(reading.fontFamilyFallback, contains('Inter'));
expect(reading.height, tokens.reading.height);
expect(reading.fontSize, greaterThan(16));
});
test('Paper floats only menus and dialogs, by a whisper, in its corners', () {
final theme = _theme(AppDesign.paper, Brightness.light);
final radius = theme.extension<AppDesignTokens>()!.radius!;
expect(theme.cardTheme.elevation, 0);
expect(theme.appBarTheme.scrolledUnderElevation, 0);
expect(theme.floatingActionButtonTheme.elevation, 0);
expect(theme.dialogTheme.elevation, inInclusiveRange(1, 4));
expect(theme.popupMenuTheme.elevation, inInclusiveRange(1, 4));
expect(theme.dialogTheme.shadowColor!.a, lessThan(0.5));
for (final shape in [
theme.cardTheme.shape,
theme.dialogTheme.shape,
theme.popupMenuTheme.shape,
theme.chipTheme.shape,
theme.snackBarTheme.shape,
]) {
expect(
(shape! as RoundedRectangleBorder).borderRadius,
BorderRadius.circular(radius),
);
}
// Controls the Default leaves to Material are Paper's own.
expect(theme.sliderTheme.trackHeight, 2);
expect(theme.sliderTheme.thumbShape, isA<RoundSliderThumbShape>());
expect(theme.badgeTheme.backgroundColor, theme.colorScheme.primary);
expect(theme.checkboxTheme.shape, isA<RoundedRectangleBorder>());
expect(theme.switchTheme.trackOutlineWidth, isNotNull);
expect(theme.tabBarTheme.indicator, isA<UnderlineTabIndicator>());
expect(theme.inputDecorationTheme.border, isA<UnderlineInputBorder>());
expect(theme.searchBarTheme.elevation?.resolve({}), 0);
});
test('the Default design is unchanged: no tokens, every style defaulted', () {
expect(AppDesign.standard.light(), appLightTheme());
expect(AppDesign.standard.dark(), appDarkTheme());
const tokens = AppDesignTokens.standard;
expect(tokens.transcript, TranscriptStyle.bubbles);
expect(tokens.composer, ComposerStyle.pill);
expect(tokens.selectedRow, SelectedRowStyle.tonal);
expect(tokens.reading.family, isNull);
expect(tokens.reading.measure, isNull);
expect(tokens.chatColorSaturation, 1);
expect(tokens.panel, isNull);
final style = const TextStyle(fontSize: 16, fontFamily: 'Inter');
expect(tokens.reading.apply(style), same(style));
});
test('Terminal is unchanged: prompt transcript, framed row, pill, its own '
'monospace and no reading type', () {
for (final brightness in Brightness.values) {
final theme = _theme(AppDesign.terminal, brightness, font: 'Inter');
final tokens = theme.extension<AppDesignTokens>()!;
expect(tokens.transcript, TranscriptStyle.prompt);
expect(tokens.terminal, isTrue);
expect(tokens.selectedRow, SelectedRowStyle.framed);
expect(tokens.composer, ComposerStyle.pill);
expect(tokens.reading.family, isNull);
expect(tokens.panel, isNull);
expect(tokens.chatColorSaturation, 1);
expect(tokens.radius, 3);
expect(theme.textTheme.bodyLarge?.fontFamily, appMonospaceFamily);
// A flat panel keeps Terminal's own low surface.
expect(
tokens.panelFill(theme.colorScheme, Colors.red),
theme.colorScheme.surfaceContainerLow,
);
}
});
test('each design swatch matches its theme', () {
for (final design in AppDesign.values) {
for (final brightness in Brightness.values) {
final theme = _theme(design, brightness);
final swatch = design.swatch(brightness);
expect(swatch.page, theme.scaffoldBackgroundColor, reason: '$design');
expect(swatch.ink, theme.colorScheme.onSurface, reason: '$design');
expect(swatch.accent, theme.colorScheme.primary, reason: '$design');
}
}
});
}