Merge main into the Compact design branch

This commit is contained in:
2026-12-03 22:00:25 +00:00
34 changed files with 1162 additions and 118 deletions
@@ -129,7 +129,9 @@ void main() {
);
expect(swatch.lines, greaterThan(2));
expect(find.text(AppDesign.compact.description), findsOneWidget);
final before = tester.getSize(find.byKey(settingsDesignKey(AppDesign.paper)));
final before = tester.getSize(
find.byKey(settingsDesignKey(AppDesign.paper)),
);
await tester.tap(find.text(AppDesign.compact.label));
await tester.pumpAndSettle();
@@ -139,7 +141,9 @@ void main() {
expect(tokens.density.dense, isTrue);
expect(tokens.transcript, TranscriptStyle.bubbles);
// The rows themselves tighten at once.
final after = tester.getSize(find.byKey(settingsDesignKey(AppDesign.paper)));
final after = tester.getSize(
find.byKey(settingsDesignKey(AppDesign.paper)),
);
expect(after.height, lessThan(before.height));
final next = AppDesignController(store: MemoryAppDesignStore(store.id));
+302
View File
@@ -0,0 +1,302 @@
// Per-design cost budget: every registered AppDesign must cost what Default
// costs (tool/perf/README.md). Each scenario prints `BENCH design ...` lines
// and fails when a design rebuilds, animates or composites more than Default:
// - building a design's themes is cached: the same objects for the same
// (design, brightness, font), and equal values when rebuilt;
// - a host rebuild for an unrelated reason (a detached window's title, a
// font notification) rebuilds no theme dependent and starts no theme
// animation;
// - scrolling a long transcript rebuilds and composites no more than
// Default (saveLayer-style layers: opacity, backdrop filter, clips);
// - switching designs back and forth leaves no listener behind.
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/application/app.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_view.dart';
import 'package:pipelines_app/shell/destination.dart';
import 'package:pipelines_app/ui/theme/app_design.dart';
import 'package:pipelines_app/ui/theme/app_design_controller.dart';
import 'package:pipelines_app/ui/theme/app_font_controller.dart';
import 'package:pipelines_app/ui/theme/app_font_store.dart';
/// Exposes whether anything still listens.
class _Designs extends AppDesignController {
_Designs() : super(store: MemoryAppDesignStore());
bool get listened => hasListeners;
}
JsonMap _tool(String id, String status) => {
'type': 'tool',
'id': id,
'name': 'Bash',
'state': {
'status': status,
'input': {'command': 'go test ./internal/notes/...'},
'content': [
{'type': 'text', 'text': 'ok notes 0.2s\nPASS'},
],
if (status == 'error') 'error': {'message': 'exit status 1'},
},
};
/// A long CLI-agent transcript: operator turns, tool calls and markdown.
final List<JsonMap> _rows = transcriptRows([
for (var i = 0; i < 60; i++) ...[
{
'id': 'u$i',
'role': 'user',
'parts': [
{'type': 'text', 'text': 'Step $i: fix the Windows paths in notes.'},
],
},
{
'id': 'a$i',
'role': 'assistant',
'parts': [
_tool('t$i-1', 'completed'),
_tool('t$i-2', i % 4 == 0 ? 'error' : 'completed'),
{
'type': 'text',
'text':
'Fixed **step $i**: `filepath.Join` now.\n\n'
'- one\n- two\n\n```go\nreturn filepath.Join(root, name)\n```',
},
],
},
],
]);
class _ThemeProbe extends StatelessWidget {
const _ThemeProbe();
static int builds = 0;
@override
Widget build(BuildContext context) {
Theme.of(context);
builds++;
return const SizedBox();
}
}
class _Rebuilds {
int count = 0;
void install() => debugOnRebuildDirtyWidget = (_, _) => count++;
void uninstall() => debugOnRebuildDirtyWidget = null;
}
/// Layers that cost a saveLayer or a clip on every raster.
Map<String, int> _layers(WidgetTester tester) {
final counts = <String, int>{};
void visit(Layer layer) {
final kind = switch (layer) {
OpacityLayer() => 'opacity',
BackdropFilterLayer() => 'backdrop',
ImageFilterLayer() => 'imageFilter',
ColorFilterLayer() => 'colorFilter',
ShaderMaskLayer() => 'shaderMask',
ClipPathLayer() => 'clipPath',
ClipRRectLayer() => 'clipRRect',
ClipRectLayer() => 'clipRect',
_ => null,
};
if (kind != null) counts.update(kind, (n) => n + 1, ifAbsent: () => 1);
if (layer is ContainerLayer) {
for (
var child = layer.firstChild;
child != null;
child = child.nextSibling
) {
visit(child);
}
}
}
visit(tester.binding.renderViews.first.debugLayer!);
return counts;
}
int _sum(Map<String, int> m, [bool Function(String)? where]) => m.entries
.where((e) => where == null || where(e.key))
.fold(0, (a, e) => a + e.value);
void main() {
final results = <AppDesign, Map<String, num>>{};
Future<void> sizeView(WidgetTester tester) async {
tester.view.physicalSize = const Size(900, 1000);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
}
for (final design in AppDesign.values) {
group(design.id, () {
final row = results[design] = <String, num>{};
test('themes are cached and value-equal', () {
for (final family in [null, 'Inter']) {
expect(
design.light(fontFamily: family),
same(design.light(fontFamily: family)),
);
expect(
design.dark(fontFamily: family),
same(design.dark(fontFamily: family)),
);
}
// Rebuilt from scratch, a design's theme still equals the cached one,
// so a host with its own copy never restarts a theme animation.
expect(design.build(Brightness.dark), design.dark());
final watch = Stopwatch()..start();
for (var i = 0; i < 20; i++) {
design.build(Brightness.light);
design.build(Brightness.dark);
}
row['themeBuildUs'] = watch.elapsedMicroseconds ~/ 40;
row['cachedLookupUs'] = () {
final cached = Stopwatch()..start();
for (var i = 0; i < 1000; i++) {
design.light();
design.dark();
}
return cached.elapsedMicroseconds / 2000;
}();
});
testWidgets('an unrelated host rebuild touches no theme dependent', (
tester,
) async {
await sizeView(tester);
final designs = _Designs();
await designs.select(design);
final fonts = AppFontController(
store: MemoryAppFontStore(),
loader: (family, assets) async {},
);
final tick = ValueNotifier(0);
// A const probe: only a theme change can make it rebuild.
final bodies = <AppDestination, WidgetBuilder>{
AppDestination.settings: (_) => const _ThemeProbe(),
};
await tester.pumpWidget(
ValueListenableBuilder<int>(
valueListenable: tick,
builder: (_, _, _) => MyApp(
fonts: fonts,
designs: designs,
destination: AppDestination.settings,
destinationBodies: bodies,
),
),
);
await tester.pumpAndSettle();
_ThemeProbe.builds = 0;
var frames = 0;
for (var i = 0; i < 10; i++) {
tick.value++;
frames += await tester.pumpAndSettle();
}
final themed = _ThemeProbe.builds;
row['unrelatedThemeRebuilds'] = themed;
row['unrelatedFrames'] = frames;
expect(themed, 0, reason: 'theme dependents rebuilt');
// One frame per rebuild; a theme animation would add ~12 each.
expect(frames, lessThanOrEqualTo(10));
// Switching designs back and forth leaves nothing behind.
var switchFrames = 0;
for (var i = 0; i < 10; i++) {
for (final other in AppDesign.values) {
await designs.select(other);
switchFrames += await tester.pumpAndSettle();
}
await designs.select(design);
switchFrames += await tester.pumpAndSettle();
}
row['switchFramesPerSwitch'] =
switchFrames / (10 * (AppDesign.values.length + 1));
await tester.pumpWidget(const SizedBox());
expect(designs.listened, isFalse, reason: 'a host kept listening');
tick.dispose();
});
testWidgets('scrolling a long transcript', (tester) async {
await sizeView(tester);
final controller = ScrollController();
addTearDown(controller.dispose);
await tester.pumpWidget(
MaterialApp(
theme: design.light(),
darkTheme: design.dark(),
themeMode: ThemeMode.dark,
home: Scaffold(
body: ListView.builder(
controller: controller,
itemCount: _rows.length,
itemBuilder: (_, i) => ChatMessageView(row: _rows[i]),
),
),
),
);
await tester.pumpAndSettle();
final rebuilds = _Rebuilds()..install();
final layers = <String, int>{};
var frames = 0;
final watch = Stopwatch()..start();
for (var i = 0; i < 60; i++) {
controller.jumpTo(controller.offset + 120);
await tester.pump();
frames++;
_layers(tester).forEach(
(k, v) => layers.update(k, (n) => n + v, ifAbsent: () => v),
);
}
row['scrollFrameUs'] = watch.elapsedMicroseconds ~/ frames;
rebuilds.uninstall();
row['scrollRebuildsPerFrame'] = rebuilds.count / frames;
// A denser design shows more rows in the same 120px, so it builds
// more per frame for the same per-row cost: the budget is per row
// scrolled past (rows over the transcript's whole extent).
final position = controller.position;
final extent = position.maxScrollExtent + position.viewportDimension;
final rowsScrolled = frames * 120 * _rows.length / extent;
row['scrollRebuildsPerRow'] = rebuilds.count / rowsScrolled;
row['scrollLayersPerFrame'] = _sum(layers) / frames;
row['scrollSaveLayersPerFrame'] =
_sum(layers, (k) => !k.startsWith('clip')) / frames;
// ignore: avoid_print
print('BENCH ${design.id} layers $layers');
});
});
}
tearDownAll(() {
for (final MapEntry(key: design, value: row) in results.entries) {
// ignore: avoid_print
print('BENCH ${design.id.padRight(10)} $row');
}
final base = results[AppDesign.standard]!;
for (final MapEntry(key: design, value: row) in results.entries) {
if (design == AppDesign.standard) continue;
// Counts are deterministic: a design may not exceed Default's by more
// than a quarter (its own rows are allowed to differ a little).
for (final key in [
'scrollRebuildsPerRow',
'scrollLayersPerFrame',
'scrollSaveLayersPerFrame',
'switchFramesPerSwitch',
]) {
final limit = base[key]! * 1.25 + 1;
if (row[key]! > limit) {
fail(
'${design.id}: $key ${row[key]} over budget $limit '
'(Default ${base[key]})',
);
}
}
}
});
}
+31 -6
View File
@@ -2,6 +2,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/theme/app_design.dart';
import 'package:pipelines_app/ui/theme/app_design_controller.dart';
import 'package:pipelines_app/ui/theme/app_design_tokens.dart';
import 'package:pipelines_app/ui/theme/app_theme.dart';
@@ -128,10 +129,7 @@ void main() {
expect(_radiusOf(theme.floatingActionButtonTheme.shape), six);
expect(_radiusOf(theme.listTileTheme.shape), six);
expect(_radiusOf(theme.navigationRailTheme.indicatorShape), six);
expect(
_radiusOf(theme.menuTheme.style?.shape?.resolve(const {})),
six,
);
expect(_radiusOf(theme.menuTheme.style?.shape?.resolve(const {})), six);
expect(
_radiusOf(theme.filledButtonTheme.style?.shape?.resolve(const {})),
six,
@@ -162,13 +160,40 @@ void main() {
(TargetPlatform.iOS, false),
]) {
debugDefaultTargetPlatformOverride = platform;
final theme = AppDesign.compact.light();
// Built afresh: the cached theme is the device's, built once.
final theme = AppDesign.compact.build(Brightness.light);
expect(
theme.materialTapTargetSize,
pointer ? MaterialTapTargetSize.shrinkWrap : MaterialTapTargetSize.padded,
pointer
? MaterialTapTargetSize.shrinkWrap
: MaterialTapTargetSize.padded,
);
expect(DesignDensity.compact.minTouchRow, pointer ? 0 : 40);
}
debugDefaultTargetPlatformOverride = null;
});
test(
'a switch into or out of Compact snaps; others keep the blend',
() async {
final designs = AppDesignController(store: MemoryAppDesignStore());
expect(AppDesign.compact.dense, isTrue);
for (final design in [
AppDesign.standard,
AppDesign.terminal,
AppDesign.paper,
]) {
expect(design.dense, isFalse);
}
expect(designs.themeAnimationDuration, kThemeAnimationDuration);
await designs.select(AppDesign.terminal);
expect(designs.themeAnimationDuration, kThemeAnimationDuration);
await designs.select(AppDesign.compact);
expect(designs.themeAnimationDuration, Duration.zero);
await designs.select(AppDesign.paper);
expect(designs.themeAnimationDuration, Duration.zero);
await designs.select(AppDesign.standard);
expect(designs.themeAnimationDuration, kThemeAnimationDuration);
},
);
}
@@ -8,11 +8,14 @@ import 'package:pipelines_app/shell/windows/window_frame.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/theme/app_design.dart';
import 'package:pipelines_app/ui/theme/app_design_tokens.dart';
/// Compact as drawn: thin rows, a narrow icon-only rail, 32px icon buttons
/// (40px targets on touch), tight bubbles, a slim window title bar, and no
/// clipping at a large text scale.
void main() {
tearDown(() => debugDefaultTargetPlatformOverride = null);
Future<void> pump(
WidgetTester tester,
Widget child, {
@@ -26,7 +29,8 @@ void main() {
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
MaterialApp(
theme: design.light(),
// Built afresh, so the platform this test sets is the theme's.
theme: design.build(Brightness.light),
home: MediaQuery(
data: MediaQueryData(
size: Size(width, 900),
@@ -189,7 +193,10 @@ void main() {
matching: find.byType(Padding),
),
);
expect(padding.padding, const EdgeInsets.symmetric(horizontal: 12, vertical: 8));
expect(
padding.padding,
const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
);
final gap = chatParagraphGap(tester.element(find.text('Ship it')), 14);
expect(gap, closeTo(14 * 0.6, 0.01));
});
+121
View File
@@ -0,0 +1,121 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/domain/chat_transcript.dart';
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_view.dart';
import 'package:pipelines_app/ui/theme/app_design.dart';
final _rows = transcriptRows([
for (var i = 0; i < 6; i++) ...[
{
'id': 'u$i',
'role': 'user',
'parts': [
{'type': 'text', 'text': 'Step $i'},
],
},
{
'id': 'a$i',
'role': 'assistant',
'parts': [
{
'type': 'tool',
'id': 't$i',
'name': 'Bash',
'state': {
'status': 'completed',
'input': {'command': 'go test'},
},
},
{'type': 'text', 'text': 'Fixed `x`.\n\n- one\n\n```go\nreturn 1\n```'},
],
},
],
]);
/// A live design switch to and from Compact animates the theme without an
/// error in any frame. A component theme that set a text-theme style failed
/// to lerp against Default's unset one, and in the browser the broken
/// frames stopped the app drawing.
void main() {
testWidgets('switching to and from Compact lerps every frame cleanly', (
tester,
) async {
debugDefaultTargetPlatformOverride = TargetPlatform.linux;
final design = ValueNotifier(AppDesign.compact);
await tester.pumpWidget(
ValueListenableBuilder<AppDesign>(
valueListenable: design,
builder: (_, d, _) => MaterialApp(
theme: d.dark(),
darkTheme: d.dark(),
home: Scaffold(
floatingActionButton: FloatingActionButton.extended(
onPressed: () {},
icon: const Icon(Icons.add),
label: const Text('New run'),
),
body: Row(
children: [
NavigationRail(
destinations: const [
NavigationRailDestination(
icon: Icon(Icons.add),
label: Text('a'),
),
NavigationRailDestination(
icon: Icon(Icons.add),
label: Text('b'),
),
],
selectedIndex: 0,
),
Expanded(
child: ListView(
children: [
IconButton(onPressed: () {}, icon: const Icon(Icons.add)),
IconButton.filled(
onPressed: () {},
icon: const Icon(Icons.add),
),
Checkbox(value: true, onChanged: (_) {}),
Switch(value: true, onChanged: (_) {}),
const ListTile(title: Text('t'), subtitle: Text('s')),
const TextField(),
Chip(label: const Text('c'), onDeleted: () {}),
SegmentedButton<int>(
segments: const [
ButtonSegment(value: 1, label: Text('one')),
ButtonSegment(value: 2, label: Text('two')),
],
selected: const {1},
),
for (final row in _rows) ChatMessageView(row: row),
],
),
),
],
),
),
),
),
);
await tester.pumpAndSettle();
for (var round = 0; round < 3; round++) {
for (final other in [
AppDesign.standard,
AppDesign.terminal,
AppDesign.paper,
AppDesign.compact,
]) {
design.value = other;
for (var f = 0; f < 20; f++) {
await tester.pump(const Duration(milliseconds: 16));
final e = tester.takeException();
if (e != null) fail('to ${other.id} frame $f: $e');
}
}
}
debugDefaultTargetPlatformOverride = null;
});
}