diff --git a/app/lib/application/app_session.dart b/app/lib/application/app_session.dart index ef205653..39a48df8 100644 --- a/app/lib/application/app_session.dart +++ b/app/lib/application/app_session.dart @@ -18,13 +18,14 @@ enum RunSubscriptionState { pending, live, refused } /// `subscribe` on every connected transition because a new socket has no /// watch, and drops it deliberately with `unsubscribe` when the app stops. class AppSession extends ChangeNotifier { - AppSession({required this.endpoint, PipelinesClient? client}) - : _client = client ?? PipelinesClient() { + AppSession({required Uri? endpoint, PipelinesClient? client}) + : _initialEndpoint = endpoint, + _client = client ?? PipelinesClient() { _states = _client.states.listen(_onState); _frames = _client.frames.listen(_onFrame); } - final Uri? endpoint; + final Uri? _initialEndpoint; final PipelinesClient _client; late final StreamSubscription _states; late final StreamSubscription _frames; @@ -36,6 +37,10 @@ class AppSession extends ChangeNotifier { String? _subscribeRequest; ApiGateway get gateway => _client; + + /// Settings controls the same transport; it must never create another socket. + PipelinesClient get client => _client; + Uri? get endpoint => _client.endpoint ?? _initialEndpoint; ConnectionState get connection => _connection; bool get connected => _connection.kind == ConnectionKind.connected; @@ -62,7 +67,7 @@ class AppSession extends ChangeNotifier { /// Retries now: reopens a disconnected socket, or repeats a refused watch on /// a healthy one. Future retry() async { - if (connected) { + if (_client.state.kind == ConnectionKind.connected) { resubscribe(); return; } diff --git a/app/lib/application/pipelines_app.dart b/app/lib/application/pipelines_app.dart index 99248589..f9c02e35 100644 --- a/app/lib/application/pipelines_app.dart +++ b/app/lib/application/pipelines_app.dart @@ -6,6 +6,7 @@ import 'package:flutter/widgets.dart'; import '../core/transport/pipelines_client.dart'; import '../shell/adaptive_shell.dart'; import '../shell/destination.dart'; +import '../features/settings/settings_screen.dart'; import 'app.dart'; import 'app_route.dart'; import 'app_router.dart'; @@ -106,6 +107,11 @@ class _PipelinesAppState extends State { onRunSelected: (id) => _delegate.goTo(AppRoute.run(id)), onBack: () => _delegate.goTo(AppRoute.runs), ), + AppDestination.settings: (_) => SettingsScreen( + client: _session.client, + initialEndpoint: _session.endpoint, + embedded: true, + ), }, ); diff --git a/app/lib/application/runs_destination.dart b/app/lib/application/runs_destination.dart index 760f439e..ca4e5481 100644 --- a/app/lib/application/runs_destination.dart +++ b/app/lib/application/runs_destination.dart @@ -34,7 +34,8 @@ class RunsDestination extends StatelessWidget { animation: session, builder: (context, _) { final cupertino = usesCupertinoHost(context); - if (server.requiresConfiguration || server.error != null) { + if ((server.requiresConfiguration || server.error != null) && + session.endpoint == null) { return _ConnectionScreen( session: session, server: server, diff --git a/app/lib/core/transport/pipelines_client.dart b/app/lib/core/transport/pipelines_client.dart index dfdeacf0..2560a238 100644 --- a/app/lib/core/transport/pipelines_client.dart +++ b/app/lib/core/transport/pipelines_client.dart @@ -39,6 +39,9 @@ class PipelinesClient implements ApiGateway { Stream get states => _states.stream; ConnectionState get state => _state; + /// Last validated endpoint, including changes made through native Settings. + Uri? get endpoint => _endpoint; + Future connect(Uri uri) async { if (_disposed) throw StateError('Client has been disposed'); final endpoint = ServerUrl.validate(uri.toString()); diff --git a/app/lib/features/settings/settings_controls.dart b/app/lib/features/settings/settings_controls.dart index d82f703d..2c652823 100644 --- a/app/lib/features/settings/settings_controls.dart +++ b/app/lib/features/settings/settings_controls.dart @@ -2,12 +2,9 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'settings_layout.dart'; +import 'settings_theme.dart'; -/// Whether the current platform expects Cupertino controls. The app's theme is -/// the single source of the platform answer, so dark mode and platform overrides -/// stay consistent with the rest of the shell. -bool usesCupertinoControls(BuildContext context) => - Theme.of(context).platform == TargetPlatform.iOS; +export 'settings_theme.dart'; /// A native text field with a label and one supporting line. Both platforms lay /// the label out as wrapping text above the field; Material uses an outlined @@ -40,7 +37,12 @@ class SettingsTextField extends StatelessWidget { // Material floating label is single-line and ellipsizes the workspace label // at narrow widths or large text, dropping required words. final labelWidget = ExcludeSemantics( - child: Text(label, style: theme.textTheme.titleSmall), + child: Text( + label, + style: usesCupertinoControls(context) + ? settingsTextStyle(context) + : theme.textTheme.titleSmall, + ), ); if (!usesCupertinoControls(context)) { return Column( @@ -85,9 +87,6 @@ class SettingsTextField extends StatelessWidget { ], ); } - final supportingColor = hasError - ? theme.colorScheme.error - : theme.colorScheme.onSurfaceVariant; return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -109,7 +108,11 @@ class SettingsTextField extends StatelessWidget { const SizedBox(height: settingsFieldGap), Text( hasError ? error : helper, - style: theme.textTheme.bodySmall?.copyWith(color: supportingColor), + style: settingsTextStyle( + context, + error: hasError, + secondary: !hasError, + ), ), ], ); diff --git a/app/lib/features/settings/settings_screen.dart b/app/lib/features/settings/settings_screen.dart index 425fccda..13891ca4 100644 --- a/app/lib/features/settings/settings_screen.dart +++ b/app/lib/features/settings/settings_screen.dart @@ -26,6 +26,7 @@ class SettingsScreen extends StatefulWidget { this.initialEndpoint, this.store, this.ping, + this.embedded = false, }); final transport.PipelinesClient client; @@ -40,6 +41,9 @@ class SettingsScreen extends StatefulWidget { /// Test seam for the exact ping request. Production uses `client.call('ping')`. final PingCallback? ping; + /// The application shell already owns the native navigation bar and safe area. + final bool embedded; + @override State createState() => _SettingsScreenState(); } @@ -123,6 +127,7 @@ class _SettingsScreenState extends State { ), ), ); + if (widget.embedded) return content; if (usesCupertinoControls(context)) { return CupertinoPageScaffold( navigationBar: const CupertinoNavigationBar(middle: Text('Settings')), @@ -143,6 +148,6 @@ class _SectionTitle extends StatelessWidget { @override Widget build(BuildContext context) { - return Text(title, style: Theme.of(context).textTheme.titleMedium); + return Text(title, style: settingsTextStyle(context, title: true)); } } diff --git a/app/lib/features/settings/settings_sections.dart b/app/lib/features/settings/settings_sections.dart index 270fcb40..4bf9581f 100644 --- a/app/lib/features/settings/settings_sections.dart +++ b/app/lib/features/settings/settings_sections.dart @@ -26,7 +26,6 @@ class SettingsConnectionSection extends StatelessWidget { @override Widget build(BuildContext context) { - final theme = Theme.of(context); return Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ @@ -64,18 +63,14 @@ class SettingsConnectionSection extends StatelessWidget { const SizedBox(height: settingsFieldGap), Text( controller.endpointSaveError, - style: theme.textTheme.bodySmall?.copyWith( - color: theme.colorScheme.error, - ), + style: settingsTextStyle(context, error: true), ), ], if (controller.actionError.isNotEmpty) ...[ const SizedBox(height: settingsFieldGap), Text( controller.actionError, - style: theme.textTheme.bodySmall?.copyWith( - color: theme.colorScheme.error, - ), + style: settingsTextStyle(context, error: true), ), ], const SizedBox(height: settingsTitleGap), @@ -102,13 +97,19 @@ class SettingsStatusCard extends StatelessWidget { final title = lines.isEmpty ? '' : lines.first; final details = lines.length > 1 ? lines.sublist(1) : const []; final titleColor = switch (state.kind) { - transport.ConnectionKind.connected => theme.colorScheme.primary, - transport.ConnectionKind.disconnected => theme.colorScheme.error, - _ => theme.colorScheme.onSurface, + transport.ConnectionKind.connected => + usesCupertinoControls(context) + ? CupertinoTheme.of(context).primaryColor + : theme.colorScheme.primary, + transport.ConnectionKind.disconnected => settingsErrorColor(context), + _ => settingsTextStyle(context).color, }; final titleWidget = Text( title, - style: theme.textTheme.titleMedium?.copyWith(color: titleColor), + style: settingsTextStyle( + context, + title: true, + ).copyWith(color: titleColor), ); return SettingsCard( child: Column( @@ -129,12 +130,7 @@ class SettingsStatusCard extends StatelessWidget { titleWidget, for (final line in details) ...[ const SizedBox(height: settingsFieldGap), - Text( - line, - style: theme.textTheme.bodyMedium?.copyWith( - color: theme.colorScheme.onSurfaceVariant, - ), - ), + Text(line, style: settingsTextStyle(context, secondary: true)), ], ], ), @@ -156,7 +152,6 @@ class SettingsWorkspaceSection extends StatelessWidget { @override Widget build(BuildContext context) { - final theme = Theme.of(context); final saveError = controller.workspaceSaveError; final canSave = canSaveWorkspace(controller.workspaceDraft); return Column( @@ -193,16 +188,11 @@ class SettingsWorkspaceSection extends StatelessWidget { const SizedBox(height: settingsFieldGap), Text( savedWorkspaceLine(controller.savedWorkspace), - style: theme.textTheme.bodyMedium, + style: settingsTextStyle(context), ), if (saveError.isNotEmpty) ...[ const SizedBox(height: settingsFieldGap), - Text( - saveError, - style: theme.textTheme.bodySmall?.copyWith( - color: theme.colorScheme.error, - ), - ), + Text(saveError, style: settingsTextStyle(context, error: true)), ], ], ); diff --git a/app/lib/features/settings/settings_theme.dart b/app/lib/features/settings/settings_theme.dart new file mode 100644 index 00000000..75868479 --- /dev/null +++ b/app/lib/features/settings/settings_theme.dart @@ -0,0 +1,42 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +import '../../ui/adaptive/host.dart'; + +bool usesCupertinoControls(BuildContext context) => + usesCupertinoHost(context) || + Theme.of(context).platform == TargetPlatform.iOS; + +Color settingsErrorColor(BuildContext context) => usesCupertinoControls(context) + ? CupertinoColors.destructiveRed.resolveFrom(context) + : Theme.of(context).colorScheme.error; + +/// Resolve native text roles from the actual host, not Material's fallback +/// light theme when mounted under a dark CupertinoApp. +TextStyle settingsTextStyle( + BuildContext context, { + bool title = false, + bool secondary = false, + bool error = false, +}) { + if (usesCupertinoControls(context)) { + final text = CupertinoTheme.of(context).textTheme; + return (title ? text.navTitleTextStyle : text.textStyle).copyWith( + color: error + ? settingsErrorColor(context) + : (secondary ? CupertinoColors.secondaryLabel : CupertinoColors.label) + .resolveFrom(context), + ); + } + final theme = Theme.of(context); + final base = (title + ? theme.textTheme.titleMedium + : theme.textTheme.bodyMedium)!; + return base.copyWith( + color: error + ? theme.colorScheme.error + : secondary + ? theme.colorScheme.onSurfaceVariant + : base.color, + ); +} diff --git a/app/lib/features/settings/settings_trust_warning.dart b/app/lib/features/settings/settings_trust_warning.dart index d3149b72..9f6fe116 100644 --- a/app/lib/features/settings/settings_trust_warning.dart +++ b/app/lib/features/settings/settings_trust_warning.dart @@ -12,7 +12,6 @@ class SettingsTrustWarning extends StatelessWidget { @override Widget build(BuildContext context) { - final theme = Theme.of(context); final icon = usesCupertinoControls(context) ? CupertinoIcons.exclamationmark_triangle : Icons.warning_amber_rounded; @@ -20,7 +19,7 @@ class SettingsTrustWarning extends StatelessWidget { child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Icon(icon, color: theme.colorScheme.error), + Icon(icon, color: settingsErrorColor(context)), const SizedBox(width: settingsControlGap), Expanded( child: Column( @@ -28,16 +27,12 @@ class SettingsTrustWarning extends StatelessWidget { children: [ Text( trustTitle, - style: theme.textTheme.titleSmall?.copyWith( - color: theme.colorScheme.error, - ), + style: settingsTextStyle(context, title: true, error: true), ), const SizedBox(height: settingsFieldGap), Text( trustBody, - style: theme.textTheme.bodyMedium?.copyWith( - color: theme.colorScheme.onSurfaceVariant, - ), + style: settingsTextStyle(context, secondary: true), ), ], ), diff --git a/app/lib/shell/adaptive_shell.dart b/app/lib/shell/adaptive_shell.dart index 85a5d3e0..1300769c 100644 --- a/app/lib/shell/adaptive_shell.dart +++ b/app/lib/shell/adaptive_shell.dart @@ -26,18 +26,23 @@ class AdaptiveShell extends StatefulWidget { class _AdaptiveShellState extends State { late AppDestination _selected; + final Set _visited = {}; @override void initState() { super.initState(); _selected = widget.destination ?? AppDestination.pipelines; + _visited.add(_selected); } @override void didUpdateWidget(covariant AdaptiveShell oldWidget) { super.didUpdateWidget(oldWidget); final destination = widget.destination; - if (destination != null) _selected = destination; + if (destination != null) { + _selected = destination; + _visited.add(destination); + } } void _select(AppDestination destination) { @@ -46,7 +51,10 @@ class _AdaptiveShellState extends State { callback(destination); return; } - setState(() => _selected = destination); + setState(() { + _selected = destination; + _visited.add(destination); + }); } List _items(T Function(AppDestination) build) => @@ -60,9 +68,10 @@ class _AdaptiveShellState extends State { final item = destinationDetails(destination); return KeyedSubtree( key: ValueKey(destination), - child: - widget.destinationBodies[destination]?.call(context) ?? - Center(child: Text('${item.label} — Not implemented')), + child: _visited.contains(destination) + ? widget.destinationBodies[destination]?.call(context) ?? + Center(child: Text('${item.label} — Not implemented')) + : const SizedBox.shrink(), ); }).toList(); return LayoutBuilder( diff --git a/app/notes/N1-wire.md b/app/notes/N1-wire.md new file mode 100644 index 00000000..03f040cc --- /dev/null +++ b/app/notes/N1-wire.md @@ -0,0 +1,27 @@ +# Settings registered in the normal app + +- `/settings` mounts the landed SettingsScreen with the app-owned client, not a + second socket. Embedded mode leaves the single native bar to the shell. +- Destinations are initialized on first visit and kept mounted thereafter; an + unvisited Settings screen issues no hidden ping or preference read. +- Session Retry uses the transport's current validated endpoint, including one + selected in Settings, rather than reverting to the bootstrap server. A native + missing-endpoint gate can be cleared by a successful Settings configuration. +- Real CupertinoApp dark-host capture exposed Material fallback text colours. + Settings now resolves typography/semantic colours from its actual native host. + The new dark-label regression failed before this correction and passes after. + No fixed font, palette or component dimensions were added. + +## Verification + +- 516 integrated Flutter tests pass; analyzer clean; normal-entry web build pass. +- Widget coverage mounts real Material and dark Cupertino app composition, + asserts one bar, no background Settings ping before visiting, shared socket, + and resolved server build after ping. Endpoint-change Retry has a regression. +- Extended normal-entry Runs CDP fixture answers real ping and drives Settings + in both hosts. Probe passes all existing history/drop/reconnect checks plus + Settings navigation and single-socket checks:20 captures. Both registered + phone screenshots inspected; dark Cupertino labels are readable after fix. +- Evidence in approved temp/settings-wired-browser and corresponding logs. +- Authenticated production-data interaction and Android/iOS remain unverified. + No real server endpoint/workspace preferences were changed by the fixtures. diff --git a/app/test/application/app_session_test.dart b/app/test/application/app_session_test.dart index 709db1b2..28233da0 100644 --- a/app/test/application/app_session_test.dart +++ b/app/test/application/app_session_test.dart @@ -22,6 +22,32 @@ List types(FakeChannel channel) => [ ]; void main() { + test('Retry preserves an endpoint changed through shared Settings', () async { + final endpoints = []; + final client = PipelinesClient( + channelFactory: (uri) { + endpoints.add(uri); + return FakeChannel()..readyCompleter.complete(); + }, + ); + final session = AppSession( + endpoint: Uri.parse('ws://original.test/connect'), + client: client, + ); + addTearDown(session.dispose); + await session.start(); + final changed = Uri.parse('ws://selected.test/connect'); + await session.client.connect(changed); + await session.stop(); + await session.retry(); + expect(endpoints, [ + Uri.parse('ws://original.test/connect'), + changed, + changed, + ]); + expect(session.endpoint, changed); + }); + test( 'start subscribes once, stop unsubscribes, and the app owns the socket', () async { diff --git a/app/test/application/settings_registration_test.dart b/app/test/application/settings_registration_test.dart new file mode 100644 index 00000000..238287ab --- /dev/null +++ b/app/test/application/settings_registration_test.dart @@ -0,0 +1,86 @@ +import 'dart:convert'; + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/application/pipelines_app.dart'; +import 'package:pipelines_app/core/transport/pipelines_client.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +import '../core/transport/pipelines_client_test.dart' show FakeChannel; +import 'pipelines_app_test.dart' show webServer, requestOf; + +void main() { + for (final cupertino in [false, true]) { + testWidgets('Settings shares socket and one native bar ($cupertino)', ( + tester, + ) async { + SharedPreferences.setMockInitialValues({}); + if (cupertino) { + tester.platformDispatcher.platformBrightnessTestValue = Brightness.dark; + addTearDown(tester.platformDispatcher.clearPlatformBrightnessTestValue); + } + final channel = FakeChannel()..readyCompleter.complete(); + var sockets = 0; + final client = PipelinesClient( + channelFactory: (_) { + sockets++; + return channel; + }, + ); + final provider = PlatformRouteInformationProvider( + initialRouteInformation: RouteInformation(uri: Uri.parse('/pipelines')), + ); + addTearDown(provider.dispose); + await tester.pumpWidget( + PipelinesApp( + server: webServer(), + client: client, + cupertino: cupertino, + routeInformationProvider: provider, + ), + ); + await tester.pump(); + expect( + requestOf(channel, 'ping'), + isNull, + reason: 'Unvisited settings must not issue hidden requests', + ); + + await tester.tap(find.text('Settings').last); + await tester.pump(); + await tester.pump(); + expect(provider.value.uri.path, '/settings'); + expect(find.text('Server URL'), findsOneWidget); + if (cupertino) { + final title = tester.widget(find.text('Connection')); + expect( + title.style!.color!.computeLuminance(), + greaterThan(0.5), + reason: 'Cupertino dark host must not inherit light Material text', + ); + } + expect(find.text('Settings — Not implemented'), findsNothing); + expect(sockets, 1); + expect( + cupertino ? find.byType(CupertinoNavigationBar) : find.byType(AppBar), + findsOneWidget, + ); + final ping = requestOf(channel, 'ping')!; + channel.incoming.add( + jsonEncode({ + 'id': ping['id'], + 'type': 'pong', + 'build': {'version': 'settings-fixture'}, + 'time': 'fixture time', + }), + ); + await tester.pump(); + await tester.pump(); + expect(find.textContaining('settings-fixture'), findsOneWidget); + expect(tester.takeException(), isNull); + await tester.pumpWidget(const SizedBox.shrink()); + await tester.pump(); + }); + } +} diff --git a/app/tool/runs_probe.mjs b/app/tool/runs_probe.mjs index 90088254..4d816d2e 100644 --- a/app/tool/runs_probe.mjs +++ b/app/tool/runs_probe.mjs @@ -119,6 +119,8 @@ try { if (!el.children.length && el.innerText) chunks.push(el.innerText); } for (const el of document.querySelectorAll('input, textarea')) { + const label = el.getAttribute('aria-label'); + if (label) chunks.push(label); if (el.value) chunks.push(String(el.value)); } if (document.body?.innerText) chunks.push(document.body.innerText); @@ -369,6 +371,12 @@ try { await assertBody('Fixture live run'); captures.push(await capture('i1-gate-recovered-list-phone')); + await clickText('Settings'); + await assertBody('Server URL'); + await assertBody('Fixture settings build'); + if ((await path()) !== '/settings') throw new Error('Settings did not update route'); + captures.push(await capture('settings-cupertino-registered-phone')); + // Material host: the same deep link and route must render standard Material // controls (the Cupertino host was selected by the macOS browser above). await send( @@ -390,6 +398,16 @@ try { } captures.push(await capture('i1-material-deeplink-run-1-phone')); + const beforeSettings = await (await fetch(`${fixture.url}/fixture/state`)).json(); + await clickText('Settings'); + await assertBody('Server URL'); + await assertBody('Fixture settings build'); + const afterSettings = await (await fetch(`${fixture.url}/fixture/state`)).json(); + if (beforeSettings.subscribed !== afterSettings.subscribed || afterSettings.connections !== 1) { + throw new Error('Settings opened another connection instead of sharing the app socket'); + } + captures.push(await capture('settings-material-registered-phone')); + const fixtureState = await (await fetch(`${fixture.url}/fixture/state`)).json(); if (fixtureState.subscribed < 2) throw new Error(`App never resubscribed: ${JSON.stringify(fixtureState)}`); if (fixtureState.listRuns < 2) throw new Error(`App never reloaded: ${JSON.stringify(fixtureState)}`); diff --git a/app/tool/runs_probe_server.mjs b/app/tool/runs_probe_server.mjs index b3093551..79160044 100644 --- a/app/tool/runs_probe_server.mjs +++ b/app/tool/runs_probe_server.mjs @@ -345,6 +345,14 @@ export async function startFixture({ root }) { return; } if (request.type === 'unsubscribe') return; + if (request.type === 'ping') { + client.send({ + id: request.id, type: 'pong', + build: { version: 'Fixture settings build' }, + time: '2026-10-21T12:00:00Z', + }); + return; + } if (request.type === 'list_runs') { listRuns++; client.send({ id: request.id, type: 'runs', runs: RUNS, usage: null });