iPad layout review notes and native fixture host

Run the full-app fixture entry on an iOS simulator: options from a file in
the app's tmp dir or the environment, route via a route provider, a narrow
strip for Split View widths, and a small in-app tap/type driver.
This commit is contained in:
2026-11-03 17:32:58 +00:00
parent 0ac9c5a8a9
commit 9b6809c9a1
43 changed files with 577 additions and 20 deletions
+6
View File
@@ -0,0 +1,6 @@
// The platform half of the full-app fixture entry
// (tool/search_selection_probe_entry.dart): the browser build reads its
// options from the page URL and installs the DevTools probes; a native build
// (an iOS simulator) reads the same options from its launch environment.
export 'fixture_host_native.dart'
if (dart.library.js_interop) 'fixture_host_web.dart';
@@ -0,0 +1,74 @@
import 'dart:io';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:pipelines_app/application/server_endpoint.dart';
import 'fixture_steps.dart';
import 'narrow_view.dart';
/// The fixture options on a native build. `simctl launch` passes the child
/// environment through `SIMCTL_CHILD_FIXTURE_QUERY`, so one installed build
/// opens any route/option set without rebuilding:
///
/// SIMCTL_CHILD_FIXTURE_QUERY='route=/chat/perf-chat-0&chats=3&rich=1' \
/// xcrun simctl launch SIM net.awan.pipelines.next
///
/// Native-only keys: `server=ws://127.0.0.1:PORT/connect` (an artifact
/// file server; the socket itself stays in-process), `orient=landscape|
/// portrait`, `width=N` (logical px, draws the app in a left strip of that
/// width to approximate an iPad Split View pane) and `do=` steps (see
/// fixture_steps.dart). When the launch environment does not reach the app,
/// the same query is read from `fixture_query.txt` in the app's temporary
/// directory (`simctl get_app_container SIM BUNDLE data`/tmp), then from
/// `--dart-define=FIXTURE_QUERY=...`.
Map<String, String> fixtureParams() {
var raw =
Platform.environment['FIXTURE_QUERY'] ??
const String.fromEnvironment('FIXTURE_QUERY');
final file = File('${Directory.systemTemp.path}/fixture_query.txt');
if (raw.isEmpty && file.existsSync()) raw = file.readAsStringSync().trim();
return raw.isEmpty ? const {} : Uri.splitQueryString(raw);
}
/// The DevTools probes are browser-only.
void installHostProbes(Map<String, String> params) {}
/// The route goes through [fixtureRouteProvider] instead.
void openFixtureRoute(String route, {required bool cupertino}) {}
/// An explicit loopback endpoint; nothing connects to it but artifact fetches.
ServerEndpoint fixtureServer(Map<String, String> params) =>
ServerEndpoint.resolve(
base: Uri(),
web: false,
configured: params['server'] ?? 'ws://127.0.0.1:9/connect',
);
/// Opens [route] as the launch location.
RouteInformationProvider? fixtureRouteProvider(String? route) =>
PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(
uri: Uri.parse(route ?? '/pipelines'),
),
);
/// Runs [app] with the native capture options applied.
void runFixtureApp(Widget app, Map<String, String> params) {
final binding = WidgetsFlutterBinding.ensureInitialized();
switch (params['orient']) {
case 'landscape':
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
case 'portrait':
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
}
final width = double.tryParse(params['width'] ?? '');
final view = binding.platformDispatcher.implicitView!;
runWidget(
View(view: width == null ? view : NarrowView(view, width), child: app),
);
runFixtureSteps(params['do'] ?? '');
}
@@ -0,0 +1,38 @@
import 'package:flutter/widgets.dart';
import 'package:pipelines_app/application/server_endpoint.dart';
import 'package:web/web.dart' as web;
import '../perf/backdrop_census.dart';
import '../perf/chat_scroll_probe.dart';
import '../perf/frame_log.dart';
/// The fixture options: the page URL's query.
Map<String, String> fixtureParams() => Uri.base.queryParameters;
/// Installs the DevTools-facing probes the capture kit evaluates.
void installHostProbes(Map<String, String> params) {
installBackdropCensus();
installFrameLog(params);
installChatScrollProbe();
}
/// Moves the browser to [route] before the app reads its location.
void openFixtureRoute(String route, {required bool cupertino}) {
final platform = cupertino ? 'platform=cupertino' : '';
final joiner = route.contains('?') ? '&' : '?';
web.window.history.replaceState(
null,
'',
platform.isEmpty ? route : '$route$joiner$platform',
);
}
/// The browser build's endpoint is its own page origin.
ServerEndpoint fixtureServer(Map<String, String> params) =>
ServerEndpoint.resolve(base: Uri.base, web: true);
/// The browser's location is the route; no provider is needed.
RouteInformationProvider? fixtureRouteProvider(String? route) => null;
/// Runs [app] unchanged.
void runFixtureApp(Widget app, Map<String, String> params) => runApp(app);
+165
View File
@@ -0,0 +1,165 @@
import 'dart:async';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
/// A tiny in-app driver for simulator captures, where `simctl` cannot tap.
///
/// [script] is `;`-separated steps run after the first frame, 700 ms apart:
/// `wait:<ms>`, `tap:<label>` (a Text, Tooltip, Semantics label or field
/// hint; `tap:<label>#<n>` picks the n-th match), `tapxy:<x>,<y>`,
/// `drag:<x>,<y>,<dx>,<dy>`, `type:<text>` (into the focused field; `\n`
/// is a newline), `orient:landscape|portrait` and `labels` (prints the
/// visible labels with their centres to the device log).
void runFixtureSteps(String script) {
final steps = [
for (final step in script.split(';'))
if (step.trim().isNotEmpty) step.trim(),
];
if (steps.isEmpty) return;
WidgetsBinding.instance.waitUntilFirstFrameRasterized.then((_) async {
await Future<void>.delayed(const Duration(milliseconds: 1500));
for (final step in steps) {
final colon = step.indexOf(':');
final verb = colon < 0 ? step : step.substring(0, colon);
final value = colon < 0 ? '' : step.substring(colon + 1);
try {
await _run(verb, value);
} catch (error) {
// ignore: avoid_print
print('FIXTURE_STEP_FAILED $step: $error');
}
await Future<void>.delayed(const Duration(milliseconds: 700));
}
// ignore: avoid_print
print('FIXTURE_STEPS_DONE');
});
}
Future<void> _run(String verb, String value) async {
switch (verb) {
case 'wait':
await Future<void>.delayed(Duration(milliseconds: int.parse(value)));
case 'tap':
final hash = value.lastIndexOf('#');
final index = hash < 0 ? 0 : int.parse(value.substring(hash + 1));
final label = hash < 0 ? value : value.substring(0, hash);
final hits = _find(label);
if (hits.length <= index) throw StateError('no "$label"');
await _tap(hits[index].center);
case 'tapxy':
final parts = value.split(',').map(double.parse).toList();
await _tap(Offset(parts[0], parts[1]));
case 'drag':
final p = value.split(',').map(double.parse).toList();
await _drag(Offset(p[0], p[1]), Offset(p[2], p[3]));
case 'type':
_type(value.replaceAll(r'\n', '\n'));
case 'orient':
await SystemChrome.setPreferredOrientations(
value == 'landscape'
? [DeviceOrientation.landscapeLeft]
: [DeviceOrientation.portraitUp],
);
case 'labels':
for (final hit in _find(null)) {
// ignore: avoid_print
print('FIXTURE_LABEL ${hit.label} @ ${hit.center}');
}
default:
throw StateError('unknown step');
}
}
class _Hit {
_Hit(this.label, this.center);
final String label;
final Offset center;
}
String? _labelOf(Widget widget) => switch (widget) {
Text(:final data?) => data,
Text(:final textSpan?) => textSpan.toPlainText(),
Tooltip(:final message?) => message,
Semantics(:final properties) => properties.label,
Icon(:final semanticLabel?) => semanticLabel,
InputDecorator(:final decoration) =>
decoration.hintText ?? decoration.labelText,
_ => null,
};
/// Visible widgets labelled [label] (every labelled one when null).
List<_Hit> _find(String? label) {
final hits = <_Hit>[];
final size = WidgetsBinding.instance.renderViews.first.size;
void visit(Element element) {
final text = _labelOf(element.widget);
if (text != null && (label == null || text == label)) {
final box = element.findRenderObject();
if (box is RenderBox && box.attached && box.hasSize) {
final center = box.localToGlobal(box.size.center(Offset.zero));
if ((Offset.zero & size).contains(center)) hits.add(_Hit(text, center));
}
}
element.visitChildren(visit);
}
WidgetsBinding.instance.rootElement?.visitChildren(visit);
return hits;
}
var _pointer = 900;
Future<void> _tap(Offset at) async {
final pointer = ++_pointer;
final binding = GestureBinding.instance;
binding.handlePointerEvent(PointerDownEvent(pointer: pointer, position: at));
await Future<void>.delayed(const Duration(milliseconds: 60));
binding.handlePointerEvent(PointerUpEvent(pointer: pointer, position: at));
}
Future<void> _drag(Offset from, Offset by) async {
final pointer = ++_pointer;
final binding = GestureBinding.instance;
binding.handlePointerEvent(
PointerDownEvent(pointer: pointer, position: from),
);
const moves = 16;
for (var i = 1; i <= moves; i++) {
await Future<void>.delayed(const Duration(milliseconds: 16));
binding.handlePointerEvent(
PointerMoveEvent(
pointer: pointer,
position: from + by * (i / moves),
delta: by / moves.toDouble(),
),
);
}
binding.handlePointerEvent(
PointerUpEvent(pointer: pointer, position: from + by),
);
}
void _type(String text) {
EditableTextState? focused;
void visit(Element element) {
if (element is StatefulElement &&
element.state is EditableTextState &&
(element.widget as EditableText).focusNode.hasFocus) {
focused = element.state as EditableTextState;
}
element.visitChildren(visit);
}
WidgetsBinding.instance.rootElement?.visitChildren(visit);
final state = focused;
if (state == null) throw StateError('no focused field');
state.userUpdateTextEditingValue(
TextEditingValue(
text: text,
selection: TextSelection.collapsed(offset: text.length),
),
SelectionChangedCause.keyboard,
);
}
+64
View File
@@ -0,0 +1,64 @@
import 'dart:ui' as ui;
/// The real view, reported [width] logical pixels wide (never wider than the
/// view itself). The app lays out, paints and hit-tests in a strip at the
/// window's left edge, which approximates an iPad Split View pane when the
/// simulator cannot be driven into multitasking. Safe-area padding, insets
/// and the display stay those of the full window.
class NarrowView implements ui.FlutterView {
NarrowView(this._view, this.width);
final ui.FlutterView _view;
final double width;
@override
ui.Size get physicalSize {
final real = _view.physicalSize;
final narrow = width * _view.devicePixelRatio;
return ui.Size(narrow < real.width ? narrow : real.width, real.height);
}
@override
ui.ViewConstraints get physicalConstraints =>
ui.ViewConstraints.tight(physicalSize);
@override
int get viewId => _view.viewId;
@override
ui.PlatformDispatcher get platformDispatcher => _view.platformDispatcher;
@override
ui.Display get display => _view.display;
@override
double get devicePixelRatio => _view.devicePixelRatio;
@override
ui.ViewPadding get viewInsets => _view.viewInsets;
@override
ui.ViewPadding get viewPadding => _view.viewPadding;
@override
ui.ViewPadding get systemGestureInsets => _view.systemGestureInsets;
@override
ui.ViewPadding get padding => _view.padding;
@override
ui.GestureSettings get gestureSettings => _view.gestureSettings;
@override
List<ui.DisplayFeature> get displayFeatures => _view.displayFeatures;
@override
ui.DisplayCornerRadii? get displayCornerRadii => _view.displayCornerRadii;
@override
void render(ui.Scene scene, {ui.Size? size}) => _view.render(scene);
@override
void updateSemantics(ui.SemanticsUpdate update) =>
_view.updateSemantics(update);
}
+17 -20
View File
@@ -17,21 +17,18 @@ import 'dart:convert';
import 'package:pipelines_app/application/app_url_strategy.dart';
import 'package:pipelines_app/application/pipelines_app.dart';
import 'package:pipelines_app/application/server_endpoint.dart';
import 'package:pipelines_app/application/bootstrap.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/core/transport/pipelines_client.dart';
import 'package:pipelines_app/features/search/ui/search_bar_controls.dart'
show searchFieldKey;
import 'package:pipelines_app/ui/input/app_search_field.dart';
import 'package:flutter/widgets.dart';
import 'package:web/web.dart' as web;
import 'package:web_socket_channel/web_socket_channel.dart';
import 'perf/backdrop_census.dart';
import 'fixture_host/fixture_host.dart';
import 'perf/chat_search_fixture.dart';
import 'perf/chat_scroll_fixture.dart';
import 'perf/chat_scroll_probe.dart';
import 'perf/frame_log.dart';
import 'perf/perf_fixture.dart';
import 'probe_folder_fixture.dart';
@@ -597,41 +594,41 @@ class _FixtureSink implements WebSocketSink {
///
/// app/tool/capture/ drives this entry generically; see its README.
void main() {
final params = Uri.base.queryParameters;
installBackdropCensus();
installFrameLog(params);
installChatScrollProbe();
WidgetsFlutterBinding.ensureInitialized();
final params = fixtureParams();
installHostProbes(params);
// `?connect=1` (native only) opens the real launch flow with no saved
// server, so the Connect screen can be reviewed without any server.
if (params['connect'] == '1') {
runPipelinesApp(configured: '');
return;
}
configurePerfFixture(params);
_fillerRunCount = int.tryParse(params['runs'] ?? '') ?? 0;
_fillerStepCount = int.tryParse(params['steps'] ?? '') ?? 0;
final cupertino = params['platform'] == 'cupertino';
final route = params['route'];
if (route != null && route.startsWith('/')) {
final platform = cupertino ? 'platform=cupertino' : '';
final joiner = route.contains('?') ? '&' : '?';
web.window.history.replaceState(
null,
'',
platform.isEmpty ? route : '$route$joiner$platform',
);
}
final opensRoute = route != null && route.startsWith('/');
if (opensRoute) openFixtureRoute(route, cupertino: cupertino);
final query = params['q'];
if (query != null && query.isNotEmpty) _typeSearchWhenShown(query);
useAppUrlStrategy();
final app = PipelinesApp(
server: ServerEndpoint.resolve(base: Uri.base, web: true),
server: fixtureServer(params),
client: PipelinesClient(channelFactory: (_) => _FixtureChannel()),
cupertino: cupertino,
routeInformationProvider: fixtureRouteProvider(opensRoute ? route : null),
);
final brightness = switch (params['theme']) {
'dark' => Brightness.dark,
'light' => Brightness.light,
_ => null,
};
runApp(
runFixtureApp(
brightness == null
? app
: _PinnedBrightness(brightness: brightness, child: app),
params,
);
}