import 'package:pipelines_app/core/servers/chat/chat_server_pool.dart'; import 'package:pipelines_app/core/servers/machine_access.dart'; import 'package:pipelines_app/core/servers/server_catalog.dart'; import 'package:pipelines_app/core/servers/server_catalog_store.dart'; import 'package:pipelines_app/features/settings/server_connections.dart'; import 'health_probe_fixture.dart'; import 'package:flutter/foundation.dart' show kIsWeb; import 'package:pipelines_app/features/updates/app_updates.dart'; import 'package:pipelines_app/ui/motion/quick_switch_animation.dart'; import 'package:pipelines_app/ui/motion/animation_speed.dart'; // Standalone fixture entry for real-browser Search result-selection evidence. // // Build and probe (from app/): // flutter build web --target tool/search_selection_probe_entry.dart \ // --output build/probe-search-selection // node tool/search_selection_probe.mjs --root build/probe-search-selection \ // --out build/search-selection-probe // // This is the normal application composition (`PipelinesApp`) over the shared // transport, with the socket replaced by an in-process channel that answers // the real `search`, `get_run`, `list_runs`, `list_pipelines`, `get_pipeline` // and `ping` requests with server-shaped fixtures. Nothing here opens a // network connection or touches a live server; the fixtures exist only so the // shell's search → run-detail selection can be rendered and captured. import 'dart:async'; 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/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:pipelines_app/ui/theme/app_font.dart'; import 'package:pipelines_app/ui/theme/app_font_controller.dart'; import 'package:flutter/widgets.dart'; import 'package:web_socket_channel/web_socket_channel.dart'; import 'fixture_host/fixture_host.dart'; import 'perf/chat_search_fixture.dart'; import 'perf/chat_question_fixture.dart'; import 'perf/chat_scroll_fixture.dart'; import 'perf/perf_fixture.dart'; import 'probe_folder_fixture.dart'; import 'probe_files_fixture.dart'; import 'probe_usage_fixture.dart'; /// The run every run-scoped hit names. Its recorded sequences are deliberately /// not its row indexes (plan 5, build 2, plan 1), exactly like the unit /// fixture, so a selection has to resolve the recorded sequence. JsonMap probeRunDetail() => { 'id': 7, 'title': 'Release train run', 'name': 'release-train', 'status': _liveRunStatus ?? 'succeeded', 'created_at': '2026-10-20T08:12:00Z', 'finished_at': '2026-10-20T08:42:00Z', 'workspace': '/srv/probe/release', 'input': {'prompt': 'ship it'}, 'output': {'result': 'ok'}, 'steps': [ { 'stage': 'plan', 'sequence': 5, 'status': 'completed', 'outcome': 'success', 'target': '#success', 'started_at': '2026-10-20T08:30:00Z', 'finished_at': '2026-10-20T08:31:00Z', 'diagnostic': 'release plan accepted', 'file_changes': _probeChanges(['docs/release-plan.md']), }, { 'stage': 'build', 'sequence': 2, 'status': 'completed', 'outcome': 'success', 'target': 'plan', 'started_at': '2026-10-20T08:16:00Z', 'finished_at': '2026-10-20T08:24:00Z', 'artifacts': [ { 'name': 'release-report.txt', 'content_type': 'text/plain', 'size_bytes': 12, 'url': '/artifacts/7/2/release-report.txt', }, if (_htmlArtifact) { 'name': 'release-dashboard.html', 'content_type': 'text/html', 'size_bytes': 4096, 'url': '/artifacts/7/2/release-dashboard.html', }, if (_turnFiles) for (final name in _turnFileNames) { 'name': name, 'content_type': 'text/markdown', 'size_bytes': 640, 'url': '/artifacts/7/2/', 'group': 'debug', }, ], 'file_changes': _probeChanges([ 'lib/release/train.dart', 'lib/release/notes.dart', 'test/release/train_test.dart', ]), }, { 'stage': 'plan', 'sequence': 1, 'status': 'completed', 'outcome': 'success', 'target': 'build', 'started_at': '2026-10-20T08:12:00Z', 'finished_at': '2026-10-20T08:14:00Z', }, ..._fillerSteps(), ], if (perfRunGraph) 'graph': perfRunGraphFixture(), }; /// A complete change capture modifying [paths], so Changes shows visit pages /// and each file opens a paged diff. JsonMap _probeChanges(List paths) => { 'status': 'complete', 'scope': 'Git tracked and nonignored files in the run directory', 'skipped': 0, 'omitted': 0, 'diagnostic': '', 'files': [ for (final path in paths) { 'path': path, 'kind': 'modified', 'patch': '--- "a/$path"\n' '+++ "b/$path"\n' '@@ -1,3 +1,3 @@\n' ' // Release train\n' '-const stage = \'draft\';\n' '+const stage = \'shipped\';\n' ' // end\n', }, ], }; /// Extra rows for scroll-performance captures (`?runs=N`, `?steps=N`). Both /// default to none, so every other capture sees the fixture unchanged. int _fillerRunCount = 0; int _fillerStepCount = 0; /// `?running=1`: run 8 executes, started 3m 50s before the page loaded, so a /// capture shows its duration ticking. Absent by default. DateTime? _runningSince; String? _liveRunStatus; /// `?html=1` adds `release-dashboard.html` to run 7's build visit; the capture /// serves its bytes from the build directory (see notes/artifact-fullscreen.md). bool _htmlArtifact = false; bool _warnings = false; /// `?turn=1` adds the runner-internal turn files the server records for a model /// visit (group `debug`) to run 7's build visit, so the Artifacts tab's hidden /// Debugging files group can be reviewed. bool _turnFiles = false; const List _turnFileNames = [ 'input.md', 'memory.md', 'history.md', 'output.md', 'private/build-log.md', ]; List _fillerSteps() => [ for (var i = 0; i < _fillerStepCount; i++) { 'stage': i.isEven ? 'build' : 'plan', 'sequence': 100 + i, 'status': 'completed', 'outcome': 'success', 'target': i.isEven ? 'plan' : 'build', 'started_at': '2026-10-20T08:32:00Z', 'finished_at': '2026-10-20T08:33:00Z', 'diagnostic': 'filler step $i for scroll captures', }, ]; List _fillerRuns() => [ for (var i = 0; i < _fillerRunCount; i++) { 'id': 1000 + i, 'title': 'Filler run $i for scroll captures', 'name': 'filler-$i', 'status': i % 3 == 0 ? 'failed' : 'succeeded', 'created_at': '2026-10-18T08:12:00Z', 'finished_at': '2026-10-18T08:42:00Z', 'pipeline_id': i.isEven ? 24 : 22, }, ]; List probeRuns() => [ if (_runningSince != null) { 'id': 8, 'title': 'Live deploy run', 'name': 'release-train', 'status': 'running', 'executing': true, 'current_stage': 'deploy', 'completed_steps': 2, 'created_at': _runningSince!.toUtc().toIso8601String(), 'finished_at': '', 'pipeline_id': 24, }, { 'id': 7, 'title': 'Release train run', 'name': 'release-train', 'status': _liveRunStatus ?? 'succeeded', 'created_at': '2026-10-20T08:12:00Z', 'finished_at': '2026-10-20T08:42:00Z', 'pipeline_id': 24, }, { 'id': 6, 'title': 'Nightly docs run', 'name': 'nightly-docs', 'status': 'failed', 'created_at': '2026-10-19T22:00:00Z', 'finished_at': '2026-10-19T22:03:00Z', 'pipeline_id': 22, }, ..._fillerRuns(), ]; /// Pipelines this fixture session archived, with their archive time. final _probeArchived = {}; List probePipelines() => [ for (final pipeline in _probePipelineRows()) { ...pipeline, if (_probeArchived[pipeline['id']] != null) 'archived_at': _probeArchived[pipeline['id']], }, ]; List _probePipelineRows() => [ { 'id': 24, 'name': 'Release train', 'version': 5, 'stages': 2, 'created_at': '2026-09-28T10:12:00', 'updated_at': '2026-10-20T09:18:00', 'scheduled': false, 'schedule_count': 0, 'enabled_schedule_count': 0, }, { 'id': 22, 'name': 'Nightly documentation', 'version': 6, 'stages': 1, 'created_at': '2026-10-02T18:20:00', 'updated_at': '2026-10-18T16:05:00', 'scheduled': true, 'schedule_count': 1, 'enabled_schedule_count': 1, }, ]; const _releaseSource = 'name: Release train\n' 'stages:\n' ' plan:\n' ' type: model\n' ' output: plan\n' ' build:\n' ' type: model\n' ' output: release\n'; JsonMap probePipelineDetail(int id, int requestedVersion) { final summary = probePipelines().firstWhere( (pipeline) => pipeline['id'] == id, orElse: () => probePipelines().first, ); final latest = summary['version'] as int; final version = requestedVersion > 0 ? requestedVersion : latest; return { ...summary, 'version': version, 'latest_version': latest, 'version_created_at': '2026-10-18T16:05:00', 'content_hash': 'sha256:probe-$id-v$version', 'source': _releaseSource, 'versions': [ for (var v = 1; v <= latest; v++) { 'version': v, 'stages': summary['stages'], 'created_at': '2026-10-0${v}T10:00:00', }, ], }; } /// One recorded hit per result kind, each with the text a server would have /// matched (`haystack`). The payloads are server-shaped `search_results` rows: /// the `target` tokens are the ones `internal/protocol/search.go` records. /// /// `release` matches every kind once; `retired` matches only the retired-field /// hit; `missing` matches only an artifact whose recorded visit (sequence 9) /// the run never recorded; `first` matches only the plan visit 1 step hit. const List<({String haystack, JsonMap hit})> probeHits = [ ( haystack: 'Release train pipeline definition', hit: { 'kind': 'pipeline', 'target': 'pipeline:24', 'score': 3, 'recency': '2026-10-20T09:18:00Z', 'pipeline': { 'id': 24, 'name': 'Release train', 'version': 5, 'stages': 2, }, }, ), ( haystack: 'name: Nightly documentation release notes', hit: { 'kind': 'version', 'target': 'pipeline:22:v6', 'score': 2, 'recency': '2026-10-18T16:05:00Z', 'version': { 'pipeline_id': 22, 'version': 6, 'content_hash': '9f2c1ad', 'created_at': '2026-10-18T16:05:00Z', }, }, ), ( haystack: 'Release train run', hit: { 'kind': 'run', 'target': 'run:7', 'score': 2, 'recency': '2026-10-20T08:42:00Z', 'run': { 'id': 7, 'pipeline_name': 'Release train', 'status': 'succeeded', 'workspace': '/srv/probe/release', 'created_at': '2026-10-20T08:12:00Z', 'finished_at': '2026-10-20T08:42:00Z', }, }, ), ( haystack: 'release plan accepted', hit: { 'kind': 'step', 'target': 'run:7:5', 'score': 1, 'recency': '2026-10-20T08:31:00Z', 'step': { 'run_id': 7, 'sequence': 5, 'stage': 'plan', 'visit': 2, 'outcome': 'success', 'target': '#success', 'diagnostic': 'release plan accepted', }, }, ), ( haystack: 'ship the release', hit: { 'kind': 'field', 'target': 'run:7:5:output', 'score': 1, 'matched_field': 'output', 'recency': '2026-10-20T08:31:00Z', 'field': { 'run_id': 7, 'sequence': 5, 'field': 'output', 'snippet': 'ship the release', }, }, ), ( haystack: 'release-report.txt', hit: { 'kind': 'artifact', 'target': '/artifacts/7/2/release-report.txt', 'score': 1, 'recency': '2026-10-20T08:24:00Z', 'artifact': { 'run_id': 7, 'sequence': 2, 'name': 'release-report.txt', 'content_type': 'text/plain', 'size_bytes': 12, 'url': '/artifacts/7/2/release-report.txt', }, }, ), ( haystack: 'retired evidence note', hit: { 'kind': 'field', 'target': 'run:7:5:evidence', 'score': 1, 'matched_field': 'evidence', 'recency': '2026-10-20T08:31:00Z', 'field': { 'run_id': 7, 'sequence': 5, 'field': 'evidence', 'snippet': 'retired evidence note', }, }, ), ( haystack: 'missing.log', hit: { 'kind': 'artifact', 'target': '/artifacts/7/9/missing.log', 'score': 1, 'recency': '2026-10-20T08:40:00Z', 'artifact': { 'run_id': 7, 'sequence': 9, 'name': 'missing.log', 'content_type': 'text/plain', 'size_bytes': 4096, 'url': '/artifacts/7/9/missing.log', }, }, ), ( haystack: 'first plan visit', hit: { 'kind': 'step', 'target': 'run:7:1', 'score': 1, 'recency': '2026-10-20T08:14:00Z', 'step': { 'run_id': 7, 'sequence': 1, 'stage': 'plan', 'visit': 1, 'outcome': 'success', 'target': 'build', }, }, ), ]; /// Answers one decoded request envelope with the server-shaped reply, or null /// for a send-only request the real server does not acknowledge. JsonMap? probeReply(JsonMap request) { final id = request['id']; final type = '${request['type']}'; JsonMap error(String message) => { 'id': id, 'type': 'error', 'error': message, }; final perf = perfChatReply(request); if (perf != null) return perf; switch (type) { case 'list_directory': return probeFilesReply(request); case 'subscribe': case 'unsubscribe': return null; case 'ping': return { 'id': id, 'type': 'pong', 'build': {'version': 'Search selection probe fixture'}, 'time': '2026-10-20T09:00:00Z', }; case 'server_stats': return { 'id': id, 'type': 'server_stats_result', 'server_stats': healthProbeSnapshot(), }; case 'list_runs': return { 'id': id, 'type': 'runs', 'runs': probeRuns().map(withProbeUsage).toList(), 'usage': null, }; case 'get_run': if (request['run_id'] != 7) { return error('Fixture run ${request['run_id']} is unavailable'); } final detail = withProbeUsage(probeRunDetail()); return { 'id': id, 'type': 'run', 'run_detail': { ...detail, if (_warnings) 'warnings': [ 'build visit 1: final result required one repair follow-up.', ], 'steps': [ for (final step in detail['steps'] as List) withProbeStepUsage(step as JsonMap), ], }, }; case 'list_pipelines': return {'id': id, 'type': 'pipelines', 'pipelines': probePipelines()}; case 'validate': return { 'id': id, 'type': 'validated', if (_warnings) 'warnings': ['Review prompt repeats runner instructions.'], }; case 'get_pipeline': final pipelineId = request['pipeline_id']; if (pipelineId is! int || !probePipelines().any((pipeline) => pipeline['id'] == pipelineId)) { return error('Fixture pipeline $pipelineId is unavailable'); } final version = request['version']; return { 'id': id, 'type': 'pipeline', 'detail': probePipelineDetail(pipelineId, version is int ? version : 0), }; case 'archive_pipeline': case 'unarchive_pipeline': // Mirrors the server: an enabled schedule blocks archiving. final pipelineId = request['pipeline_id']; final row = probePipelines().where((p) => p['id'] == pipelineId); if (row.isEmpty) return error('pipeline not found'); final archive = type == 'archive_pipeline'; if (archive && (row.first['enabled_schedule_count'] as int) > 0) { return error( 'pipeline "${row.first['name']}" has enabled schedule(s) ' '"Nightly docs" (#3); pause or repoint them before archiving', ); } if (archive) { _probeArchived[pipelineId as int] = '2026-10-20T09:30:00Z'; } else { _probeArchived.remove(pipelineId); } return { 'id': id, 'type': archive ? 'pipeline_archived' : 'pipeline_unarchived', 'detail': probePipelineDetail(pipelineId as int, 0), }; case 'search': // The app must send exactly the browser's SearchRequest body; anything // else is answered with a visible refusal so the capture cannot pass. final search = request['search']; if (search is! Map || search.length != 3 || search['query'] is! String || search['kind'] is! String || search['limit'] != 0) { return error('Fixture refused a malformed search request: $search'); } final query = (search['query'] as String).trim().toLowerCase(); final kind = search['kind'] as String; if (kind == 'chat') { // The server answers chats as their own request (search_chats.go). return { 'id': id, 'type': 'search_results', 'search_results': { 'query': search['query'], 'kind': kind, 'results': perfChatSearchHits(query), 'truncated': false, 'scanned_steps': 0, 'scanned_bytes': 0, 'cap': 50, 'scan_bound_bytes': 1048576, 'scanned_chats': 3, }, }; } final results = [ for (final entry in probeHits) if ((kind.isEmpty || entry.hit['kind'] == kind) && (query.isEmpty || entry.haystack.toLowerCase().contains(query))) entry.hit, ...perfSearchHits(query, kind), ]; return { 'id': id, 'type': 'search_results', 'search_results': { 'query': search['query'], 'kind': kind, 'results': results, 'truncated': false, 'scanned_steps': 3, 'scanned_bytes': 2048, 'cap': 50, 'scan_bound_bytes': 1048576, }, }; default: return probeFolderReply(request) ?? error('Fixture does not implement $type'); } } /// An in-process websocket channel: every frame the client sends is decoded /// and answered asynchronously with [probeReply], as the server would over the /// wire. `ready` completes at once so the shared client reports connected. /// The capture fixture's stand-in for the chat pool: the Mac is connected, /// the Linux desktop still wants its password, and any machine added during /// the capture asks for `fixture-pass`. class _FixtureAuthenticator extends ChangeNotifier implements MachineAuthenticator { final _verdicts = { 'mac': const MachineAccessResult(MachineAccess.connected), 'linux': const MachineAccessResult(MachineAccess.needsPassword), }; @override MachineAccessResult? status(String id) => _verdicts[id]; @override Future probe(SavedServer server) async { await Future.delayed(const Duration(milliseconds: 400)); return _verdicts[server.id] ??= const MachineAccessResult(MachineAccess.needsPassword); } @override Future authenticate(SavedServer server, String password) async { await Future.delayed(const Duration(milliseconds: 400)); if (password != 'fixture-pass') return 'Wrong password.'; _verdicts[server.id] = const MachineAccessResult(MachineAccess.connected); notifyListeners(); return null; } } class _FixtureChannel implements WebSocketChannel { _FixtureChannel(); final _incoming = StreamController(); Timer? _runCompletion; late final _FixtureSink _sink = _FixtureSink(this); @override Stream get stream => _incoming.stream; @override WebSocketSink get sink => _sink; @override Future get ready => Future.value(); @override String? get protocol => null; @override int? get closeCode => null; @override String? get closeReason => null; void receive(dynamic data) { if (data is! String) return; final decoded = jsonDecode(data); if (decoded is! Map) return; if (_liveRunStatus == 'running' && decoded['type'] == 'list_runs') { _runCompletion ??= Timer(const Duration(seconds: 7), () { _liveRunStatus = 'succeeded'; if (!_incoming.isClosed) { _incoming.add( jsonEncode({ 'type': 'run_event', 'run_event': { 'run_id': 7, 'status': 'succeeded', 'executing': false, 'completed_steps': 3, 'finished_at': '2026-10-20T08:42:00Z', }, }), ); } }); } final reply = probeReply(decoded); final followUps = perfChatFollowUps(decoded); final subscribe = decoded['chat_subscribe']; if (subscribe is Map) { void emit(JsonMap frame) { if (!_incoming.isClosed) _incoming.add(jsonEncode(frame)); } chatScrollStream('${subscribe['session_id'] ?? ''}', emit); chatQuestionStream('${subscribe['session_id'] ?? ''}', emit); } if (reply == null && followUps.isEmpty) return; Future.delayed(const Duration(milliseconds: 120), () { if (_incoming.isClosed) return; if (reply != null) _incoming.add(jsonEncode(reply)); for (final frame in followUps) { _incoming.add(jsonEncode(frame)); } }); } Future close() async { _runCompletion?.cancel(); if (!_incoming.isClosed) await _incoming.close(); } @override dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); } class _FixtureSink implements WebSocketSink { _FixtureSink(this.channel); final _FixtureChannel channel; @override void add(dynamic event) => channel.receive(event); @override void addError(Object error, [StackTrace? stackTrace]) => throw error; @override Future addStream(Stream stream) async { await for (final item in stream) { add(item); } } @override Future close([int? closeCode, String? closeReason]) => channel.close(); @override Future get done => channel._incoming.done; @override dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); } /// Static-server capture flags, so a plain file server (no index.html /// fallback for `/runs/7`) can still open a deep location: /// /// `?route=/runs/7/stage/build%3Fvisit%3D1` opens that app location; /// `?runs=200` / `?steps=60` append filler runs / run-7 steps for scroll /// performance captures; /// `?running=1` adds an executing run 8 whose duration ticks; /// `?html=1` adds an HTML artifact to run 7 (`release-dashboard.html`); /// `?turn=1` adds run 7's debug turn files (input/memory/history/output.md); /// `?q=release` types that query into Search once its field is shown; /// `?platform=cupertino` renders the Cupertino host (`material`, the /// default, renders Material as browsers do); /// `?perf=1` prints frame timings (tool/perf/frame_log.dart); /// `?hits=N`, `?chats=N` and `?graph=1` add bench data /// (tool/perf/perf_fixture.dart); /// `?theme=dark` / `?theme=light` pins the platform brightness the app's /// `ThemeMode.system` follows (omitted: the browser's color scheme). /// /// app/tool/capture/ drives this entry generically; see its README. Future main() async { WidgetsFlutterBinding.ensureInitialized(); await Future.wait([ QuickSwitchAnimationController.instance.restore(), AnimationSpeedController.instance.restore(), ]); final params = fixtureParams(); if (params['liveRun'] == '1') _liveRunStatus = 'running'; 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); if (params['files'] == '1') installFilesFixture(); // `?font=inter` chooses a font as Settings would; otherwise the stored one. final font = params['font']; unawaited( font == null ? AppFontController.instance.restore() : AppFontController.instance.select(AppFont.fromId(font)), ); _fillerRunCount = int.tryParse(params['runs'] ?? '') ?? 0; _fillerStepCount = int.tryParse(params['steps'] ?? '') ?? 0; if (params['running'] == '1') { _runningSince = DateTime.now().subtract( const Duration(minutes: 3, seconds: 50), ); } probeUsage = params['usage'] == '1'; _htmlArtifact = params['html'] == '1'; _warnings = params['warnings'] == '1'; _turnFiles = params['turn'] == '1'; final cupertino = params['platform'] == 'cupertino'; final route = params['route']; final opensRoute = route != null && route.startsWith('/'); if (opensRoute) openFixtureRoute(route, cupertino: cupertino); final query = params['q']; if (query != null && query.isNotEmpty) _typeSearchWhenShown(query); useAppUrlStrategy(); ServerConnections? machines; if (params['machines'] == '1' || params['federated'] == '1') { machines = ServerConnections( store: MemoryServerCatalogStore( catalog: ServerCatalog( servers: [ SavedServer.validated( id: 'mac', name: 'Alan’s Mac', endpoints: ['ws://mac.fixture/connect'], ), SavedServer.validated( id: 'linux', name: 'Linux desktop', endpoints: ['ws://linux.fixture/connect'], ), ], selectedId: 'mac', ), ), onSelected: (_) async {}, ); await machines.load(); // Settings shows each machine's own sign-in state; a new machine asks // for its password (`fixture-pass`) like the real chat pool does. machines.authenticator = _FixtureAuthenticator(); } final pool = params['federated'] == '1' && machines != null ? ChatServerPool( machines, connect: (machine) async { final client = PipelinesClient( channelFactory: (_) => _FixtureChannel(), ); await client.connect(Uri.parse(machine.endpoints.first)); return ChatMachineConnection( gateway: client, endpoint: () => client.endpoint.toString(), connected: () => true, states: client.states, close: client.dispose, retry: () => client.connect(Uri.parse(machine.endpoints.first)), ); }, ) : null; final app = PipelinesApp( serverId: machines?.catalog.active?.id, servers: machines, chatPool: pool, server: fixtureServer(params), webPlatform: params['nativeUpdate'] == null ? kIsWeb : false, androidSupported: params['nativeUpdate'] == null ? null : true, installedVersionReader: () async => 1, androidFeedReader: (base) async => AppUpdate( versionCode: 2, versionName: '0.1.2', apk: base.resolve('Pipelines.zip'), platform: params['nativeUpdate'] ?? 'android', sourceName: 'Home Linux', ), client: PipelinesClient(channelFactory: (_) => _FixtureChannel()), cupertino: cupertino, routeInformationProvider: fixtureRouteProvider(opensRoute ? route : null), ); final brightness = switch (params['theme']) { 'dark' => Brightness.dark, 'light' => Brightness.light, _ => null, }; runFixtureApp( brightness == null ? app : _PinnedBrightness(brightness: brightness, child: app), params, ); } /// Pins the platform brightness below it. The app's own `MediaQuery.fromView` /// takes platform fields from this ambient query, so `ThemeMode.system` (and /// the Cupertino theme's null brightness) resolve to [brightness] while size, /// padding and text scale still follow the real view. class _PinnedBrightness extends StatelessWidget { const _PinnedBrightness({required this.brightness, required this.child}); final Brightness brightness; final Widget child; @override Widget build(BuildContext context) => MediaQuery.fromView( view: View.of(context), child: Builder( builder: (context) => MediaQuery( data: MediaQuery.of(context).copyWith(platformBrightness: brightness), child: child, ), ), ); } /// Types [query] into Search's field once it is shown, through the field's /// own change and submit callbacks, exactly as typing would. void _typeSearchWhenShown(String query) { void attempt(Duration _) { AppSearchField? found; void visit(Element element) { if (found != null) return; final widget = element.widget; if (widget is AppSearchField && widget.fieldKey == searchFieldKey) { found = widget; return; } element.visitChildren(visit); } WidgetsBinding.instance.rootElement?.visitChildren(visit); final field = found; if (field == null) { WidgetsBinding.instance.addPostFrameCallback(attempt); WidgetsBinding.instance.scheduleFrame(); return; } field.controller.text = query; field.onChanged?.call(query); field.onSubmitted?.call(query); } WidgetsFlutterBinding.ensureInitialized(); WidgetsBinding.instance.addPostFrameCallback(attempt); }