merge(app): finish retained Runs integration after deadline

This commit is contained in:
2026-10-21 17:26:41 +01:00
40 changed files with 5025 additions and 50 deletions
+52
View File
@@ -0,0 +1,52 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/application/app_route.dart';
void main() {
test('parses each destination and a run detail', () {
expect(AppRoute.parse('/pipelines'), AppRoute.pipelines);
expect(AppRoute.parse('/runs'), AppRoute.runs);
expect(AppRoute.parse('/runs/12'), AppRoute.run(12));
expect(AppRoute.parse('/chat'), AppRoute.chat);
expect(AppRoute.parse('/settings'), AppRoute.settings);
});
test('normalises slashes and accepts a full URL, query and fragment', () {
expect(AppRoute.parse('/runs/'), AppRoute.runs);
expect(AppRoute.parse('/pipelines///'), AppRoute.pipelines);
expect(
AppRoute.parse('http://127.0.0.1:8096/runs/7?action=decide#top'),
AppRoute.run(7),
);
expect(AppRoute.parse('/runs/7/'), AppRoute.run(7));
});
test('a malformed or unknown location is the default Pipelines route', () {
for (final path in [
'',
'/',
'/runs/abc',
'/runs/0',
'/runs/-1',
'/runs/1/extra',
'/pipelines/2',
'/chat/session',
'/unknown',
'/runs/%E0%A4%A',
]) {
expect(AppRoute.parse(path), AppRoute.pipelines, reason: path);
}
});
test('serialises every route back to a parsable path', () {
for (final route in [
AppRoute.pipelines,
AppRoute.runs,
AppRoute.run(3),
AppRoute.chat,
AppRoute.settings,
]) {
expect(AppRoute.parse(route.path), route);
}
expect(AppRoute.run(3).path, '/runs/3');
});
}
+148
View File
@@ -0,0 +1,148 @@
import 'dart:convert';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/application/app_session.dart';
import 'package:pipelines_app/core/transport/pipelines_client.dart';
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
Future<void> flush() => Future<void>.delayed(Duration.zero);
Future<void> waitFor(bool Function() condition, String reason) async {
for (var attempt = 0; attempt < 200; attempt++) {
if (condition()) return;
await Future<void>.delayed(const Duration(milliseconds: 5));
}
fail('Timed out: $reason');
}
List<String> types(FakeChannel channel) => [
for (final frame in channel.outgoing)
(jsonDecode(frame as String) as Map<String, dynamic>)['type'] as String,
];
void main() {
test(
'start subscribes once, stop unsubscribes, and the app owns the socket',
() async {
final channel = FakeChannel()..readyCompleter.complete();
final client = PipelinesClient(channelFactory: (_) => channel);
final session = AppSession(
endpoint: Uri.parse('ws://example.test/connect'),
client: client,
);
await session.start();
await flush();
expect(session.connected, isTrue);
expect(types(channel), ['subscribe']);
final frame = jsonDecode(channel.outgoing.single as String) as Map;
expect(frame['workspace'], '');
await session.stop();
await flush();
expect(types(channel), ['subscribe', 'unsubscribe']);
expect(session.connected, isFalse);
session.dispose();
},
);
test('reconnect subscribes the new socket again', () async {
final first = FakeChannel()..readyCompleter.complete();
final second = FakeChannel()..readyCompleter.complete();
var sockets = 0;
final client = PipelinesClient(
channelFactory: (_) => sockets++ == 0 ? first : second,
backoffBase: const Duration(milliseconds: 5),
);
final session = AppSession(
endpoint: Uri.parse('ws://example.test/connect'),
client: client,
);
addTearDown(session.dispose);
await session.start();
await flush();
expect(types(first), ['subscribe']);
expect(session.connectionEpoch, 1);
first.incoming.addError(StateError('network drop'));
await waitFor(
() => sockets == 2 && session.connected && second.outgoing.isNotEmpty,
'reconnected socket did not subscribe',
);
expect(types(second), ['subscribe']);
expect(session.connectionEpoch, 2);
});
test('a subscribe ack marks the watch live, a refusal reports it', () async {
final channel = FakeChannel()..readyCompleter.complete();
final client = PipelinesClient(channelFactory: (_) => channel);
final session = AppSession(
endpoint: Uri.parse('ws://example.test/connect'),
client: client,
);
addTearDown(session.dispose);
await session.start();
await flush();
final subscribe =
jsonDecode(channel.outgoing.single as String) as Map<String, dynamic>;
expect(session.subscription, RunSubscriptionState.pending);
channel.incoming.add(
jsonEncode({'id': subscribe['id'], 'type': 'subscribe'}),
);
await flush();
expect(session.subscription, RunSubscriptionState.live);
expect(session.subscriptionError, isEmpty);
session.resubscribe();
await flush();
final repeated =
jsonDecode(channel.outgoing.last as String) as Map<String, dynamic>;
expect(repeated['type'], 'subscribe');
channel.incoming.add(
jsonEncode({
'id': repeated['id'],
'type': 'error',
'error': 'too many run subscriptions on this connection',
}),
);
await flush();
expect(session.subscription, RunSubscriptionState.refused);
expect(session.subscriptionError, contains('too many run subscriptions'));
});
test('dispose drops the watch and releases the client', () async {
final channel = FakeChannel()..readyCompleter.complete();
final client = PipelinesClient(channelFactory: (_) => channel);
final session = AppSession(
endpoint: Uri.parse('ws://example.test/connect'),
client: client,
);
await session.start();
await flush();
session.dispose();
await flush();
expect(types(channel), ['subscribe', 'unsubscribe']);
await expectLater(
client.connect(Uri.parse('ws://example.test/connect')),
throwsStateError,
);
});
test('a missing endpoint is not replaced by a guessed connection', () async {
final channel = FakeChannel();
final client = PipelinesClient(channelFactory: (_) => channel);
final session = AppSession(endpoint: null, client: client);
addTearDown(session.dispose);
await session.start();
await flush();
expect(channel.outgoing, isEmpty);
expect(session.connected, isFalse);
});
}
@@ -0,0 +1,177 @@
import 'dart:convert';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/application/pipelines_app.dart';
import 'package:pipelines_app/application/server_endpoint.dart';
import 'package:pipelines_app/core/transport/pipelines_client.dart';
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
ServerEndpoint webServer() => ServerEndpoint.resolve(
base: Uri.parse('http://127.0.0.1:8096/'),
web: true,
);
Map<String, dynamic>? requestOf(FakeChannel channel, String type) => channel
.outgoing
.map((frame) => jsonDecode(frame as String) as Map<String, dynamic>)
.where((frame) => frame['type'] == type)
.firstOrNull;
Future<void> pumpApp(
WidgetTester tester, {
required FakeChannel channel,
required PipelinesClient client,
required PlatformRouteInformationProvider provider,
}) async {
await tester.pumpWidget(
PipelinesApp(
server: webServer(),
client: client,
cupertino: false,
routeInformationProvider: provider,
),
);
await tester.pump();
}
Future<void> replyList(
WidgetTester tester,
FakeChannel channel, {
required List<Map<String, dynamic>> runs,
}) async {
for (
var attempt = 0;
attempt < 40 && requestOf(channel, 'list_runs') == null;
attempt++
) {
await tester.pump(const Duration(milliseconds: 5));
}
final request = requestOf(channel, 'list_runs')!;
channel.incoming.add(
jsonEncode({'id': request['id'], 'type': 'runs', 'runs': runs}),
);
await tester.pump();
await tester.pump();
}
Future<void> replyDetail(
WidgetTester tester,
FakeChannel channel,
num id,
) async {
for (
var attempt = 0;
attempt < 40 && requestOf(channel, 'get_run') == null;
attempt++
) {
await tester.pump(const Duration(milliseconds: 5));
}
final request = requestOf(channel, 'get_run')!;
expect(request['run_id'], id);
channel.incoming.add(
jsonEncode({
'id': request['id'],
'type': 'run',
'run_detail': {'id': id, 'title': 'Run $id', 'status': 'running'},
}),
);
await tester.pump();
await tester.pump();
}
void main() {
testWidgets('a /runs/1 boot link opens that run and Back returns to /runs', (
tester,
) async {
final channel = FakeChannel()..readyCompleter.complete();
final client = PipelinesClient(channelFactory: (_) => channel);
final provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(uri: Uri.parse('/runs/1')),
);
addTearDown(provider.dispose);
await pumpApp(tester, channel: channel, client: client, provider: provider);
await replyList(
tester,
channel,
runs: [
{'id': 1, 'name': 'Deep-linked run', 'status': 'running'},
],
);
await replyDetail(tester, channel, 1);
expect(find.text('Run 1'), findsWidgets);
expect(find.text('Back to list'), findsOneWidget);
expect(provider.value.uri.path, '/runs/1');
expect(find.text('Pipelines — Not implemented'), findsNothing);
await tester.tap(find.text('Back to list'));
await tester.pump();
expect(provider.value.uri.path, '/runs');
expect(find.text('Deep-linked run'), findsWidgets);
});
testWidgets('tabs and run selection update the route; browser Back pops it', (
tester,
) async {
final channel = FakeChannel()..readyCompleter.complete();
final client = PipelinesClient(channelFactory: (_) => channel);
final provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(uri: Uri.parse('/pipelines')),
);
addTearDown(provider.dispose);
await pumpApp(tester, channel: channel, client: client, provider: provider);
expect(provider.value.uri.path, '/pipelines');
await tester.tap(find.text('Runs').last);
await tester.pump();
expect(provider.value.uri.path, '/runs');
await replyList(
tester,
channel,
runs: [
{'id': 2, 'name': 'Beta run', 'status': 'failed'},
],
);
await tester.tap(find.text('Beta run'));
await tester.pump();
expect(provider.value.uri.path, '/runs/2');
await replyDetail(tester, channel, 2);
expect(find.text('Back to list'), findsOneWidget);
// The engine's browser Back arrives as new route information.
await provider.didPushRouteInformation(
RouteInformation(uri: Uri.parse('/runs')),
);
await tester.pump();
expect(find.text('Beta run'), findsWidgets);
expect(find.text('Back to list'), findsNothing);
// Forward re-opens the same run.
await provider.didPushRouteInformation(
RouteInformation(uri: Uri.parse('/runs/2')),
);
await tester.pump();
await replyDetail(tester, channel, 2);
expect(find.text('Back to list'), findsOneWidget);
});
testWidgets('a malformed boot path is corrected to /pipelines', (
tester,
) async {
final channel = FakeChannel()..readyCompleter.complete();
final client = PipelinesClient(channelFactory: (_) => channel);
final provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(uri: Uri.parse('/runs/abc')),
);
addTearDown(provider.dispose);
await pumpApp(tester, channel: channel, client: client, provider: provider);
expect(provider.value.uri.path, '/pipelines');
expect(find.text('Pipelines — Not implemented'), findsOneWidget);
});
}
@@ -0,0 +1,302 @@
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/app_session.dart';
import 'package:pipelines_app/application/runs_destination.dart';
import 'package:pipelines_app/application/server_endpoint.dart';
import 'package:pipelines_app/core/transport/pipelines_client.dart';
import 'package:pipelines_app/features/runs/screen.dart';
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
ServerEndpoint webServer() => ServerEndpoint.resolve(
base: Uri.parse('http://127.0.0.1:8096/'),
web: true,
);
Widget materialApp(
AppSession session,
ServerEndpoint server, {
int? initialRunId,
ValueChanged<int>? onRunSelected,
VoidCallback? onBack,
}) => MaterialApp(
home: Scaffold(
body: RunsDestination(
session: session,
server: server,
initialRunId: initialRunId,
onRunSelected: onRunSelected,
onBack: onBack,
),
),
);
Map<String, dynamic>? listRequest(FakeChannel channel) => channel.outgoing
.map((frame) => jsonDecode(frame as String) as Map<String, dynamic>)
.where((frame) => frame['type'] == 'list_runs')
.firstOrNull;
Iterable<Map<String, dynamic>> detailRequests(FakeChannel channel, int id) =>
channel.outgoing
.map((frame) => jsonDecode(frame as String) as Map<String, dynamic>)
.where((frame) => frame['type'] == 'get_run' && frame['run_id'] == id);
void main() {
testWidgets('gate explains missing native configuration without connecting', (
tester,
) async {
final channel = FakeChannel();
final client = PipelinesClient(channelFactory: (_) => channel);
final server = ServerEndpoint.resolve(
base: Uri.parse('http://127.0.0.1:8096/'),
web: false,
);
final session = AppSession(endpoint: server.uri, client: client);
addTearDown(session.dispose);
await tester.pumpWidget(materialApp(session, server));
expect(find.text('Server endpoint not configured'), findsOneWidget);
expect(find.textContaining('PIPELINES_SERVER_URL'), findsOneWidget);
expect(find.byType(RunsScreen), findsNothing);
expect(channel.outgoing, isEmpty);
});
testWidgets('gate shows connecting, then mounts the normal runs screen', (
tester,
) async {
final channel = FakeChannel();
final client = PipelinesClient(channelFactory: (_) => channel);
final server = webServer();
final session = AppSession(endpoint: server.uri, client: client);
addTearDown(session.dispose);
final starting = session.start();
await tester.pumpWidget(materialApp(session, server));
await tester.pump();
expect(find.text('Connecting to Pipelines…'), findsOneWidget);
expect(find.byType(CircularProgressIndicator), findsOneWidget);
expect(find.byType(RunsScreen), findsNothing);
channel.readyCompleter.complete();
await starting;
await tester.pump();
await tester.pump();
expect(find.byType(RunsScreen), findsOneWidget);
final list = listRequest(channel)!;
channel.incoming.add(
jsonEncode({
'id': list['id'],
'type': 'runs',
'runs': [
{'id': 5, 'name': 'Live fixture run', 'status': 'succeeded'},
],
}),
);
await tester.pump();
expect(find.text('Live fixture run'), findsOneWidget);
});
testWidgets('a refused socket shows a friendly reason, never the exception', (
tester,
) async {
final channel = FakeChannel();
final client = PipelinesClient(
channelFactory: (_) => channel,
backoffBase: const Duration(hours: 1),
backoffMax: const Duration(hours: 1),
);
final server = webServer();
final session = AppSession(endpoint: server.uri, client: client);
addTearDown(session.dispose);
final starting = session.start();
channel.readyCompleter.completeError(
StateError('WebSocketChannelException: Failed to connect'),
);
await starting;
await tester.pumpWidget(materialApp(session, server));
await tester.pump();
expect(find.text('Pipelines server unavailable'), findsOneWidget);
expect(find.textContaining('Retrying automatically'), findsOneWidget);
expect(find.textContaining('WebSocketChannelException'), findsNothing);
expect(find.widgetWithText(FilledButton, 'Retry'), findsOneWidget);
expect(find.byType(RunsScreen), findsNothing);
// The client keeps retrying by design; end the retry loop explicitly so
// the test does not leave a wall-clock timer behind.
session.dispose();
});
testWidgets(
'a drop keeps the list and reports reconnecting, not unavailable',
(tester) async {
final first = FakeChannel()..readyCompleter.complete();
final second = FakeChannel()..readyCompleter.complete();
var sockets = 0;
final client = PipelinesClient(
channelFactory: (_) => sockets++ == 0 ? first : second,
backoffBase: const Duration(milliseconds: 200),
);
final server = webServer();
final session = AppSession(endpoint: server.uri, client: client);
addTearDown(session.dispose);
await session.start();
await tester.pumpWidget(materialApp(session, server));
await tester.pump();
await tester.pump();
first.incoming.add(
jsonEncode({
'id': listRequest(first)!['id'],
'type': 'runs',
'runs': [
{'id': 1, 'name': 'Before reconnect', 'status': 'running'},
],
}),
);
await tester.pump();
expect(find.text('Before reconnect'), findsOneWidget);
first.incoming.addError(StateError('network drop'));
await tester.pump();
expect(find.byType(RunsScreen), findsOneWidget);
expect(find.text('Reconnecting to Pipelines…'), findsOneWidget);
expect(find.text('Pipelines server unavailable'), findsNothing);
expect(find.text('Before reconnect'), findsOneWidget);
for (
var attempt = 0;
attempt < 40 && listRequest(second) == null;
attempt++
) {
await tester.pump(const Duration(milliseconds: 50));
}
expect(listRequest(second), isNotNull);
expect(find.text('Reconnecting to Pipelines…'), findsNothing);
second.incoming.add(
jsonEncode({
'id': listRequest(second)!['id'],
'type': 'runs',
'runs': [
{'id': 2, 'name': 'After reconnect', 'status': 'succeeded'},
],
}),
);
await tester.pump();
expect(find.text('After reconnect'), findsOneWidget);
expect(find.text('Before reconnect'), findsNothing);
},
);
testWidgets(
'reconnect keeps the open detail instead of resetting to the list',
(tester) async {
final first = FakeChannel()..readyCompleter.complete();
final second = FakeChannel()..readyCompleter.complete();
var sockets = 0;
final client = PipelinesClient(
channelFactory: (_) => sockets++ == 0 ? first : second,
backoffBase: const Duration(milliseconds: 10),
);
final server = webServer();
final session = AppSession(endpoint: server.uri, client: client);
addTearDown(session.dispose);
await session.start();
await tester.pumpWidget(materialApp(session, server, initialRunId: 1));
await tester.pump();
await tester.pump();
first.incoming.add(
jsonEncode({
'id': listRequest(first)!['id'],
'type': 'runs',
'runs': [
{'id': 1, 'name': 'Open run', 'status': 'running'},
],
}),
);
await tester.pump();
final firstDetail = detailRequests(first, 1).single;
first.incoming.add(
jsonEncode({
'id': firstDetail['id'],
'type': 'run',
'run_detail': {'id': 1, 'title': 'Open run', 'status': 'running'},
}),
);
await tester.pump();
expect(find.text('Open run'), findsOneWidget);
expect(find.text('Back to list'), findsOneWidget);
first.incoming.addError(StateError('network drop'));
await tester.pump();
expect(find.byType(RunsScreen), findsOneWidget);
expect(find.text('Open run'), findsOneWidget);
expect(find.text('Reconnecting to Pipelines…'), findsOneWidget);
for (
var attempt = 0;
attempt < 60 && listRequest(second) == null;
attempt++
) {
await tester.pump(const Duration(milliseconds: 10));
}
expect(listRequest(second), isNotNull);
second.incoming.add(
jsonEncode({
'id': listRequest(second)!['id'],
'type': 'runs',
'runs': [
{'id': 1, 'name': 'Open run', 'status': 'running'},
],
}),
);
for (
var attempt = 0;
attempt < 20 && detailRequests(second, 1).isEmpty;
attempt++
) {
await tester.pump(const Duration(milliseconds: 10));
}
final refreshed = detailRequests(second, 1).single;
expect(find.text('Open run'), findsOneWidget);
second.incoming.add(
jsonEncode({
'id': refreshed['id'],
'type': 'run',
'run_detail': {'id': 1, 'title': 'Open run', 'status': 'succeeded'},
}),
);
await tester.pump();
expect(find.text('Open run'), findsOneWidget);
expect(find.text('Back to list'), findsOneWidget);
},
);
testWidgets('gate uses Cupertino progress without a Material ancestor', (
tester,
) async {
final channel = FakeChannel();
final client = PipelinesClient(channelFactory: (_) => channel);
final server = webServer();
final session = AppSession(endpoint: server.uri, client: client);
addTearDown(session.dispose);
session.start();
await tester.pumpWidget(
CupertinoApp(
home: CupertinoPageScaffold(
child: RunsDestination(session: session, server: server),
),
),
);
await tester.pump();
expect(find.text('Connecting to Pipelines…'), findsOneWidget);
expect(find.byType(CupertinoActivityIndicator), findsOneWidget);
expect(find.byType(CircularProgressIndicator), findsNothing);
expect(find.byType(Material), findsNothing);
});
}
@@ -0,0 +1,61 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/application/server_endpoint.dart';
void main() {
test('web infers its own origin over ws at /connect', () {
final server = ServerEndpoint.resolve(
base: Uri.parse('http://127.0.0.1:8096/runs?filter=active'),
web: true,
);
expect(server.uri, Uri.parse('ws://127.0.0.1:8096/connect'));
expect(server.error, isNull);
expect(server.requiresConfiguration, isFalse);
});
test('secure web origin uses wss and the default port', () {
final server = ServerEndpoint.resolve(
base: Uri.parse('https://pipelines.example.test/runs'),
web: true,
);
expect(server.uri, Uri.parse('wss://pipelines.example.test/connect'));
});
test('web never guesses an endpoint when the page is not HTTP(S)', () {
final server = ServerEndpoint.resolve(
base: Uri.parse('file:///tmp/index.html'),
web: true,
);
expect(server.uri, isNull);
expect(server.error, contains('page URL'));
});
test('native requires an explicit endpoint instead of a baked host', () {
final server = ServerEndpoint.resolve(
base: Uri.parse('http://127.0.0.1:8096/'),
web: false,
);
expect(server.uri, isNull);
expect(server.requiresConfiguration, isTrue);
expect(server.error, isNull);
});
test('native validates and normalizes the configured endpoint', () {
final server = ServerEndpoint.resolve(
base: Uri.parse('http://127.0.0.1:8096/'),
web: false,
configured: ' ws://192.168.1.20:8081 ',
);
expect(server.uri, Uri.parse('ws://192.168.1.20:8081/connect'));
expect(server.requiresConfiguration, isFalse);
});
test('invalid native configuration reports the reason, never a fallback', () {
final server = ServerEndpoint.resolve(
base: Uri.parse('http://127.0.0.1:8096/'),
web: false,
configured: 'https://pipelines.example.test',
);
expect(server.uri, isNull);
expect(server.error, contains('Unsupported scheme'));
});
}
@@ -0,0 +1,264 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/runs/data/runs_repository.dart';
import 'package:pipelines_app/features/runs/ui/run_detail_view.dart';
import 'package:pipelines_app/features/runs/ui/runs_controller.dart';
enum AppPlatform { material, cupertino }
class FakeGateway implements ApiGateway {
FakeGateway(this.detail);
JsonMap detail;
Object? failure;
Completer<JsonMap>? hold;
@override
Stream<JsonMap> get frames => const Stream<JsonMap>.empty();
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
if (type != 'get_run') throw UnsupportedError(type);
if (hold != null) return hold!.future;
if (failure != null) return Future.error(failure!);
return Future.value({'run_detail': detail});
}
}
const prompt = ' keep\n\nspacing ';
JsonMap runFixture({JsonMap? usage, int steps = 2}) {
final run = <String, dynamic>{
'id': 7,
'title': 'Nightly build',
'name': 'release',
'status': 'succeeded',
'input': {
'prompt': prompt,
'nested': {
'alpha': 1,
'items': [1, 2],
},
},
'output': {
'result': {'ok': true},
},
'steps': [
for (var i = 0; i < steps; i++)
{
'stage': i == 0 ? 'build' : 'test',
'sequence': i + 3,
'status': 'completed',
'outcome': 'success',
'target': '#success',
},
],
};
if (usage != null) run['usage'] = usage;
return run;
}
JsonMap usageFixture({int known = 1}) => {
'stages': 1,
'tokens_total': 0,
'tokens_known_stages': known,
'tokens_in': 0,
'tokens_out': 0,
'split_known': true,
'cost_known_stages': known,
};
Future<void> pumpDetail(
WidgetTester tester,
AppPlatform platform,
RunsController controller, {
VoidCallback? onBack,
bool settle = true,
}) async {
tester.view.physicalSize = const Size(390, 1600);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final view = RunDetailView(controller: controller, onBack: onBack ?? () {});
final page = MediaQuery(
data: MediaQueryData.fromView(
tester.view,
).copyWith(textScaler: const TextScaler.linear(2)),
child: view,
);
await tester.pumpWidget(
platform == AppPlatform.material
? MaterialApp(home: Scaffold(body: page))
: CupertinoApp(
home: CupertinoPageScaffold(child: SafeArea(child: page)),
),
);
if (settle) {
await tester.pumpAndSettle();
} else {
await tester.pump();
}
}
void mockClipboard(
WidgetTester tester,
List<String> copied, {
bool Function()? denied,
}) {
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
SystemChannels.platform,
(call) async {
if (call.method != 'Clipboard.setData') return null;
if (denied?.call() ?? false) {
throw PlatformException(code: 'clipboard-denied');
}
copied.add((call.arguments as Map)['text'] as String);
return null;
},
);
addTearDown(
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
SystemChannels.platform,
null,
),
);
}
void main() {
late FakeGateway gateway;
late RunsController controller;
setUp(() {
gateway = FakeGateway(runFixture());
controller = RunsController(RunsRepository(gateway));
});
tearDown(() => controller.dispose());
for (final platform in AppPlatform.values) {
testWidgets('${platform.name} detail at 390 with 2x text', (tester) async {
gateway.detail = runFixture(steps: 12);
await controller.select(1);
await pumpDetail(tester, platform, controller);
expect(tester.takeException(), isNull);
expect(find.text('Nightly build'), findsOneWidget);
expect(find.textContaining('Original prompt'), findsOneWidget);
if (platform == AppPlatform.material) {
expect(find.byType(Chip), findsOneWidget);
expect(find.byType(ExpansionTile), findsNWidgets(2));
} else {
expect(find.byType(Material), findsNothing);
expect(find.byType(Chip), findsNothing);
expect(find.byType(CupertinoExpansionTile), findsNWidgets(2));
}
await tester.tap(find.text('Input'));
await tester.pumpAndSettle();
expect(find.textContaining('"alpha": 1'), findsOneWidget);
await tester.scrollUntilVisible(
find.text('Output'),
200,
scrollable: find.byType(Scrollable).first,
);
await tester.tap(find.text('Output'));
await tester.pumpAndSettle();
expect(find.textContaining('"ok": true'), findsOneWidget);
await tester.scrollUntilVisible(
find.textContaining('build · visit 3'),
200,
scrollable: find.byType(Scrollable).first,
);
expect(find.textContaining('build · visit 3'), findsOneWidget);
expect(find.textContaining('test · visit 4'), findsOneWidget);
if (platform == AppPlatform.material) {
final scrollable = tester.state<ScrollableState>(
find.byType(Scrollable).first,
);
final before = scrollable.position.pixels;
expect(before, greaterThan(0));
gateway.detail = runFixture(steps: 13);
await controller.select(1);
await tester.pumpAndSettle();
expect(scrollable.position.pixels, closeTo(before, 0.1));
}
});
testWidgets('${platform.name} loading and error stay honest', (
tester,
) async {
gateway.hold = Completer<JsonMap>();
final pending = controller.select(1);
await pumpDetail(tester, platform, controller, settle: false);
expect(find.text('Loading run details…'), findsOneWidget);
expect(
find.byType(
platform == AppPlatform.material
? CircularProgressIndicator
: CupertinoActivityIndicator,
),
findsOneWidget,
);
gateway.hold!.complete({'run_detail': runFixture()});
await pending;
await tester.pumpAndSettle();
expect(find.text('Nightly build'), findsOneWidget);
controller.dispose();
gateway = FakeGateway(runFixture())
..failure = StateError('server unavailable');
controller = RunsController(RunsRepository(gateway));
await controller.select(1);
var backs = 0;
await pumpDetail(tester, platform, controller, onBack: () => backs++);
expect(find.textContaining('server unavailable'), findsOneWidget);
await tester.tap(find.text('Back to list'));
expect(backs, 1);
});
testWidgets('${platform.name} copies the exact prompt and reports denial', (
tester,
) async {
final copied = <String>[];
var denied = false;
mockClipboard(tester, copied, denied: () => denied);
final copy = platform == AppPlatform.material
? find.byTooltip('Copy prompt')
: find.text('Copy prompt');
await controller.select(1);
await pumpDetail(tester, platform, controller);
await tester.tap(copy);
await tester.pumpAndSettle();
expect(copied.single, prompt);
expect(find.text('Prompt copied to clipboard.'), findsOneWidget);
if (platform == AppPlatform.material) {
await tester.pump(const Duration(seconds: 5));
await tester.pumpAndSettle();
}
denied = true;
await tester.tap(copy);
await tester.pumpAndSettle();
expect(find.text('Could not copy prompt to clipboard.'), findsOneWidget);
});
}
testWidgets('reported zero and missing usage stay distinct', (tester) async {
gateway.detail = runFixture(usage: usageFixture());
await controller.select(1);
await pumpDetail(tester, AppPlatform.material, controller);
await tester.tap(find.text('Metrics'));
await tester.pumpAndSettle();
expect(find.text('Unavailable'), findsNothing);
expect(find.text('0'), findsNWidgets(3));
expect(find.text('\$0.000000'), findsOneWidget);
gateway.detail = runFixture(usage: usageFixture(known: 0));
await controller.select(1);
await tester.pumpAndSettle();
expect(find.text('Unavailable'), findsNWidgets(4));
expect(find.text('0'), findsNothing);
});
}
@@ -0,0 +1,344 @@
import 'dart:async';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/runs/data/runs_repository.dart';
import 'package:pipelines_app/features/runs/ui/runs_controller.dart';
class FakeGateway implements ApiGateway {
final framesController = StreamController<JsonMap>.broadcast();
final lists = <Completer<JsonMap>>[];
final details = <num, List<Completer<JsonMap>>>{};
int listCalls = 0;
@override
Stream<JsonMap> get frames => framesController.stream;
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
if (type == 'list_runs') {
listCalls++;
final request = Completer<JsonMap>();
lists.add(request);
return request.future;
}
final id = fields['run_id'] as num;
final request = Completer<JsonMap>();
details.putIfAbsent(id, () => []).add(request);
return request.future;
}
void listReply(int index, List<JsonMap> runs) =>
lists[index].complete({'runs': runs});
void detailReply(num id, int index, JsonMap value) =>
details[id]![index].complete({'run_detail': value});
}
void main() {
late FakeGateway gateway;
late RunsController controller;
var disposed = false;
setUp(() {
gateway = FakeGateway();
controller = RunsController(RunsRepository(gateway));
disposed = false;
});
tearDown(() {
if (!disposed) controller.dispose();
gateway.framesController.close();
});
test('late selection response cannot replace latest selection', () async {
final first = controller.select(1);
final second = controller.select(2);
gateway.detailReply(2, 0, {'id': 2});
await second;
gateway.detailReply(1, 0, {'id': 1});
await first;
expect(controller.detail?['id'], 2);
});
test('pending load and selection futures are safe after dispose', () async {
final load = controller.load();
final select = controller.select(1);
controller.dispose();
disposed = true;
gateway.listReply(0, []);
gateway.detailReply(1, 0, {'id': 1});
await Future.wait([load, select]);
});
test('Back cancels scheduled detail refresh', () async {
final select = controller.select(1);
gateway.detailReply(1, 0, {'id': 1, 'status': 'running'});
await select;
controller.listen(gateway.frames);
gateway.framesController.add({
'type': 'run_event',
'run_id': 1,
'status': 'succeeded',
});
controller.back();
await Future<void>.delayed(const Duration(milliseconds: 220));
expect(gateway.details[1], hasLength(1));
expect(controller.detail, isNull);
});
test('unrelated run event does not refresh selected detail', () async {
final select = controller.select(1);
gateway.detailReply(1, 0, {'id': 1, 'status': 'running'});
await select;
controller.listen(gateway.frames);
gateway.framesController.add({
'type': 'run_event',
'run_id': 2,
'status': 'succeeded',
});
await Future<void>.delayed(const Duration(milliseconds: 220));
expect(gateway.details[1], hasLength(1));
});
test('identity-less event reloads list', () async {
controller.listen(gateway.frames);
gateway.framesController.add({'type': 'run_event', 'status': 'running'});
await Future<void>.delayed(Duration.zero);
expect(gateway.listCalls, 1);
gateway.listReply(0, [
{'id': 3},
]);
await Future<void>.delayed(Duration.zero);
expect(controller.runs.single['id'], 3);
expect(controller.loading, isFalse);
});
test(
'full refresh is coalesced and keeps current detail until reply',
() async {
final select = controller.select(1);
gateway.detailReply(1, 0, {'id': 1, 'status': 'running'});
await select;
controller.listen(gateway.frames);
gateway.framesController.add({
'type': 'run_event',
'run_id': 1,
'status': 'succeeded',
});
await Future<void>.delayed(const Duration(milliseconds: 180));
expect(controller.detail?['id'], 1);
expect(gateway.details[1], hasLength(2));
gateway.detailReply(1, 1, {'id': 1, 'status': 'succeeded'});
await Future<void>.delayed(Duration.zero);
expect(controller.detail?['status'], 'succeeded');
},
);
test('load with initial id clears list and detail loading', () async {
final load = controller.load(7);
expect(controller.loading, isTrue);
gateway.listReply(0, [
{'id': 7},
{'id': 8},
]);
await Future<void>.delayed(Duration.zero);
expect(gateway.details[7], hasLength(1));
expect(controller.loading, isFalse);
expect(controller.detailLoading, isTrue);
gateway.detailReply(7, 0, {'id': 7});
await load;
expect(controller.loading, isFalse);
expect(controller.detailLoading, isFalse);
expect(controller.detail?['id'], 7);
expect(controller.selectedRunId, 7);
});
test('newer list load wins when replies complete out of order', () async {
final first = controller.load();
final second = controller.load();
gateway.listReply(1, [
{'id': 2},
]);
await second;
gateway.listReply(0, [
{'id': 1},
]);
await first;
expect(controller.runs.single['id'], 2);
expect(controller.loading, isFalse);
});
test('list resync leaves the selected detail request valid', () async {
final select = controller.select(1);
gateway.detailReply(1, 0, {'id': 1, 'status': 'running'});
await select;
controller.listen(gateway.frames);
gateway.framesController.add({'type': 'run_event', 'status': 'running'});
await Future<void>.delayed(Duration.zero);
expect(gateway.listCalls, 1);
gateway.listReply(0, [
{'id': 1, 'status': 'running'},
]);
await Future<void>.delayed(Duration.zero);
expect(controller.detail?['id'], 1);
expect(controller.selectedRunId, 1);
expect(gateway.details[1], hasLength(1));
});
test('manual list load keeps an in-flight detail refresh valid', () async {
final select = controller.select(1);
gateway.detailReply(1, 0, {'id': 1, 'status': 'running'});
await select;
controller.listen(gateway.frames);
gateway.framesController.add({
'type': 'run_event',
'run_id': 1,
'status': 'succeeded',
});
await Future<void>.delayed(const Duration(milliseconds: 180));
expect(gateway.details[1], hasLength(2));
final load = controller.load();
gateway.listReply(1, [
{'id': 1},
]);
await load;
gateway.detailReply(1, 1, {'id': 1, 'status': 'succeeded'});
await Future<void>.delayed(Duration.zero);
expect(controller.detail?['status'], 'succeeded');
expect(controller.detailLoading, isFalse);
gateway.listReply(0, [
{'id': 1},
]);
});
test('event during a superseded resync still runs one followup', () async {
controller.listen(gateway.frames);
gateway.framesController.add({
'type': 'run_event',
'run_id': 9,
'status': 'running',
});
await Future<void>.delayed(Duration.zero);
expect(gateway.listCalls, 1);
final load = controller.load();
expect(gateway.listCalls, 2);
gateway.listReply(1, [
{'id': 1},
]);
await load;
gateway.framesController.add({
'type': 'run_event',
'run_id': 10,
'status': 'running',
});
await Future<void>.delayed(Duration.zero);
expect(gateway.listCalls, 2);
gateway.listReply(0, [
{'id': 1},
]);
await Future<void>.delayed(Duration.zero);
expect(gateway.listCalls, 3);
gateway.listReply(2, [
{'id': 1},
{'id': 2},
]);
await Future<void>.delayed(Duration.zero);
expect(controller.runs, hasLength(2));
expect(controller.loading, isFalse);
});
test('unknown run events coalesce into one followup resync', () async {
controller.listen(gateway.frames);
gateway.framesController.add({
'type': 'run_event',
'run_id': 9,
'status': 'running',
});
await Future<void>.delayed(Duration.zero);
expect(gateway.listCalls, 1);
expect(controller.loading, isTrue);
gateway.framesController.add({
'type': 'run_event',
'run_id': 10,
'status': 'running',
});
await Future<void>.delayed(Duration.zero);
expect(gateway.listCalls, 1);
gateway.listReply(0, [
{'id': 3},
]);
await Future<void>.delayed(Duration.zero);
expect(gateway.listCalls, 2);
expect(controller.loading, isTrue);
gateway.listReply(1, [
{'id': 3},
{'id': 4},
]);
await Future<void>.delayed(Duration.zero);
expect(gateway.listCalls, 2);
expect(controller.loading, isFalse);
expect(controller.runs, hasLength(2));
});
test(
'selected refresh coalesces and Back ignores the pending reply',
() async {
final select = controller.select(1);
gateway.detailReply(1, 0, {'id': 1, 'status': 'running'});
await select;
controller.listen(gateway.frames);
gateway.framesController.add({
'type': 'run_event',
'run_id': 1,
'status': 'succeeded',
});
await Future<void>.delayed(const Duration(milliseconds: 180));
expect(gateway.details[1], hasLength(2));
gateway.framesController.add({
'type': 'run_event',
'run_id': 1,
'status': 'failed',
});
await Future<void>.delayed(Duration.zero);
expect(gateway.details[1], hasLength(2));
gateway.detailReply(1, 1, {'id': 1, 'status': 'succeeded'});
await Future<void>.delayed(Duration.zero);
expect(gateway.details[1], hasLength(3));
controller.back();
gateway.detailReply(1, 2, {'id': 1, 'status': 'failed'});
await Future<void>.delayed(Duration.zero);
expect(controller.detail, isNull);
expect(controller.detailLoading, isFalse);
expect(controller.error, isNull);
},
);
test('choosing another run does not display the previous detail', () async {
final first = controller.select(1);
gateway.detailReply(1, 0, {'id': 1});
await first;
final second = controller.select(2);
expect(controller.detail, isNull);
expect(controller.selectedRunId, 2);
expect(controller.detailLoading, isTrue);
gateway.detailReply(2, 0, {'id': 2});
await second;
expect(controller.detail?['id'], 2);
expect(controller.detailLoading, isFalse);
});
test('pending detail refresh is safe after dispose', () async {
final select = controller.select(1);
gateway.detailReply(1, 0, {'id': 1, 'status': 'running'});
await select;
controller.listen(gateway.frames);
gateway.framesController.add({
'type': 'run_event',
'run_id': 1,
'status': 'succeeded',
});
await Future<void>.delayed(const Duration(milliseconds: 180));
expect(gateway.details[1], hasLength(2));
controller.dispose();
disposed = true;
gateway.detailReply(1, 1, {'id': 1, 'status': 'succeeded'});
await Future<void>.delayed(Duration.zero);
expect(controller.detail?['id'], 1);
});
}
@@ -0,0 +1,180 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
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/runs/data/runs_repository.dart';
import 'package:pipelines_app/features/runs/ui/runs_controller.dart';
import 'package:pipelines_app/features/runs/ui/runs_list.dart';
class _Gateway implements ApiGateway {
final framesController = StreamController<JsonMap>.broadcast();
JsonMap? reply;
Object? failure;
Completer<void>? gate;
@override
Stream<JsonMap> get frames => framesController.stream;
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
await gate?.future;
if (failure != null) throw failure!;
return reply ?? {'runs': []};
}
}
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
late _Gateway gateway;
late RunsController controller;
setUp(() {
gateway = _Gateway();
controller = RunsController(RunsRepository(gateway));
});
tearDown(() async {
controller.dispose();
await gateway.framesController.close();
});
Future<void> mount(
WidgetTester tester, {
required bool cupertino,
ValueChanged<num>? onSelected,
}) async {
gateway.reply = {
'runs': [
{'id': 1, 'name': 'Alpha', 'status': 'running', 'scheduled': true},
{'id': 2, 'name': 'Beta', 'status': 'failed', 'scheduled': false},
],
};
await controller.load();
final list = AnimatedBuilder(
animation: controller,
builder: (context, _) =>
RunsList(controller: controller, onSelected: onSelected ?? (_) {}),
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: list))
: MaterialApp(home: Scaffold(body: list)),
);
}
testWidgets(
'uses native search and filters runs in CupertinoApp',
(tester) async {
num? selectedRun;
await mount(
tester,
cupertino: true,
onSelected: (id) => selectedRun = id,
);
expect(find.byType(CupertinoSearchTextField), findsOneWidget);
expect(find.text('Alpha'), findsOneWidget);
await tester.enterText(find.byType(CupertinoSearchTextField), 'Beta');
await tester.pumpAndSettle();
expect(find.text('Beta'), findsNWidgets(2));
expect(find.text('Alpha'), findsNothing);
await tester.tap(find.byType(CupertinoListTile));
expect(selectedRun, 2);
await tester.enterText(find.byType(CupertinoSearchTextField), 'missing');
await tester.pumpAndSettle();
expect(find.text('No runs found.'), findsOneWidget);
await tester.enterText(find.byType(CupertinoSearchTextField), '');
await tester.pumpAndSettle();
await tester.tap(find.textContaining('Schedule:'));
await tester.pumpAndSettle();
expect(find.text('Scheduled'), findsWidgets);
await tester.tap(find.text('Scheduled').last);
await tester.pumpAndSettle();
expect(controller.scheduled, 'scheduled');
},
variant: TargetPlatformVariant.only(TargetPlatform.iOS),
);
testWidgets(
'retains Material controls and handles large text on narrow layout',
(tester) async {
tester.view.devicePixelRatio = 2;
tester.view.physicalSize = const Size(780, 1560);
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
MaterialApp(
builder: (context, child) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: const TextScaler.linear(2)),
child: child!,
),
home: Scaffold(
body: AnimatedBuilder(
animation: controller,
builder: (_, _) =>
RunsList(controller: controller, onSelected: (_) {}),
),
),
),
);
gateway.reply = {
'runs': [
{'id': 1, 'name': 'Alpha', 'status': 'running', 'scheduled': true},
{'id': 2, 'name': 'Beta', 'status': 'failed', 'scheduled': false},
],
};
await controller.load();
await tester.pumpAndSettle();
expect(find.byType(TextField), findsOneWidget);
final layoutError = tester.takeException();
expect(
layoutError,
isNull,
reason: layoutError is FlutterError
? layoutError.toStringDeep()
: '$layoutError',
);
},
variant: TargetPlatformVariant.only(TargetPlatform.android),
);
testWidgets(
'shows loading, error and server-empty states distinctly',
(tester) async {
gateway.failure = StateError('offline');
gateway.gate = Completer<void>();
final loading = controller.load();
await tester.pumpWidget(
CupertinoApp(
home: CupertinoPageScaffold(
child: AnimatedBuilder(
animation: controller,
builder: (_, child) =>
RunsList(controller: controller, onSelected: (_) {}),
),
),
),
);
await tester.pump();
expect(find.byType(CupertinoActivityIndicator), findsOneWidget);
gateway.gate!.complete();
await loading;
await tester.pumpAndSettle();
expect(find.textContaining('offline'), findsOneWidget);
expect(tester.takeException(), isNull);
gateway.failure = null;
gateway.gate = null;
gateway.reply = {'runs': []};
await controller.load();
await tester.pumpAndSettle();
expect(find.text('No runs found.'), findsOneWidget);
expect(find.textContaining('offline'), findsNothing);
expect(tester.takeException(), isNull);
},
variant: TargetPlatformVariant.only(TargetPlatform.iOS),
);
}
@@ -0,0 +1,247 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
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/runs/screen.dart';
class _Gateway implements ApiGateway {
final framesController = StreamController<JsonMap>.broadcast();
final listRequests = <Completer<JsonMap>>[];
final detailRequests = <num, List<Completer<JsonMap>>>{};
@override
Stream<JsonMap> get frames => framesController.stream;
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
final request = Completer<JsonMap>();
if (type == 'list_runs') {
listRequests.add(request);
} else if (type == 'get_run') {
final id = fields['run_id'] as num;
detailRequests.putIfAbsent(id, () => []).add(request);
} else {
request.completeError(UnsupportedError(type));
}
return request.future;
}
void replyList(int index, List<JsonMap> runs) =>
listRequests[index].complete({'runs': runs});
void replyDetail(num id, int index, JsonMap detail) =>
detailRequests[id]![index].complete({'run_detail': detail});
void failDetail(num id, int index, Object error) =>
detailRequests[id]![index].completeError(error);
}
const _runs = [
{'id': 1, 'title': 'Alpha run', 'name': 'alpha', 'status': 'running'},
{'id': 2, 'title': 'Beta run', 'name': 'beta', 'status': 'failed'},
];
Widget _materialScreen(
_Gateway gateway, {
int? initialRunId,
int syncToken = 0,
ValueChanged<int>? onRunSelected,
VoidCallback? onBack,
}) => MaterialApp(
home: Scaffold(
body: RunsScreen(
gateway: gateway,
initialRunId: initialRunId,
syncToken: syncToken,
onRunSelected: onRunSelected,
onBack: onBack,
),
),
);
Future<void> _mountList(WidgetTester tester, _Gateway gateway) async {
await tester.pump();
gateway.replyList(0, _runs);
await tester.pump();
await tester.pump();
}
void main() {
late _Gateway gateway;
setUp(() => gateway = _Gateway());
tearDown(() => gateway.framesController.close());
testWidgets('initial run opens a pending detail with Back available', (
tester,
) async {
await tester.pumpWidget(_materialScreen(gateway, initialRunId: 1));
await _mountList(tester, gateway);
expect(gateway.detailRequests[1], hasLength(1));
expect(find.text('Loading run details…'), findsOneWidget);
expect(find.text('Back to list'), findsOneWidget);
expect(find.text('Alpha run'), findsNothing);
await tester.tap(find.text('Back to list'));
await tester.pump();
expect(find.text('Alpha run'), findsOneWidget);
expect(find.text('Beta run'), findsOneWidget);
// A reply that lands after Back must not reopen the previous detail.
gateway.replyDetail(1, 0, {'id': 1, 'title': 'Alpha run'});
await tester.pump();
expect(find.text('Alpha run'), findsOneWidget);
expect(find.text('Loading run details…'), findsNothing);
});
testWidgets('initial run renders its detail after the reply', (tester) async {
await tester.pumpWidget(_materialScreen(gateway, initialRunId: 1));
await _mountList(tester, gateway);
gateway.replyDetail(1, 0, {
'id': 1,
'title': 'Alpha run',
'status': 'succeeded',
'input': {'prompt': 'initial prompt'},
});
await tester.pump();
expect(find.text('Alpha run'), findsOneWidget);
expect(find.text('initial prompt'), findsOneWidget);
expect(find.text('Loading run details…'), findsNothing);
});
testWidgets('detail failure keeps Back and returns to the list', (
tester,
) async {
await tester.pumpWidget(_materialScreen(gateway, initialRunId: 2));
await _mountList(tester, gateway);
gateway.failDetail(2, 0, StateError('server unavailable'));
await tester.pump();
expect(find.textContaining('server unavailable'), findsOneWidget);
expect(find.text('Back to list'), findsOneWidget);
await tester.tap(find.text('Back to list'));
await tester.pump();
expect(find.text('Alpha run'), findsOneWidget);
expect(find.textContaining('server unavailable'), findsNothing);
});
testWidgets('selecting a list row is driven by the controller selection', (
tester,
) async {
await tester.pumpWidget(_materialScreen(gateway));
await _mountList(tester, gateway);
await tester.tap(find.text('Beta run'));
await tester.pump();
expect(gateway.detailRequests[2], hasLength(1));
gateway.replyDetail(2, 0, {'id': 2, 'title': 'Beta run'});
await tester.pump();
expect(find.text('Beta run'), findsOneWidget);
expect(find.text('Back to list'), findsOneWidget);
});
testWidgets('selection and Back report route changes to the host', (
tester,
) async {
int? selected;
var backs = 0;
await tester.pumpWidget(
_materialScreen(
gateway,
onRunSelected: (id) => selected = id,
onBack: () => backs++,
),
);
await _mountList(tester, gateway);
await tester.tap(find.text('Beta run'));
await tester.pump();
expect(selected, 2);
gateway.replyDetail(2, 0, {'id': 2, 'title': 'Beta run'});
await tester.pump();
await tester.tap(find.text('Back to list'));
await tester.pump();
expect(backs, 1);
expect(find.text('Alpha run'), findsOneWidget);
});
testWidgets('a route change opens and closes the named run', (tester) async {
await tester.pumpWidget(_materialScreen(gateway, initialRunId: 2));
await _mountList(tester, gateway);
expect(gateway.detailRequests[2], hasLength(1));
gateway.replyDetail(2, 0, {'id': 2, 'title': 'Beta run'});
await tester.pump();
expect(find.text('Beta run'), findsOneWidget);
await tester.pumpWidget(_materialScreen(gateway, initialRunId: 1));
await tester.pump();
expect(gateway.detailRequests[1], hasLength(1));
gateway.replyDetail(1, 0, {'id': 1, 'title': 'Alpha run'});
await tester.pump();
expect(find.text('Alpha run'), findsOneWidget);
await tester.pumpWidget(_materialScreen(gateway));
await tester.pump();
expect(find.text('Alpha run'), findsOneWidget);
expect(find.text('Beta run'), findsOneWidget);
expect(find.text('Back to list'), findsNothing);
});
testWidgets('a reconnect token refreshes the open detail in place', (
tester,
) async {
await tester.pumpWidget(_materialScreen(gateway, initialRunId: 2));
await _mountList(tester, gateway);
gateway.replyDetail(2, 0, {'id': 2, 'title': 'Beta run'});
await tester.pump();
expect(find.text('Beta run'), findsOneWidget);
await tester.pumpWidget(
_materialScreen(gateway, initialRunId: 2, syncToken: 1),
);
await tester.pump();
expect(gateway.listRequests, hasLength(2));
gateway.replyList(1, _runs);
await tester.pump();
await tester.pump();
expect(gateway.detailRequests[2], hasLength(2));
gateway.replyDetail(2, 1, {
'id': 2,
'title': 'Beta run',
'status': 'succeeded',
});
await tester.pump();
expect(find.text('Beta run'), findsOneWidget);
expect(find.text('Back to list'), findsOneWidget);
});
testWidgets(
'Cupertino host keeps exactly one navigation bar while pending',
(tester) async {
await tester.pumpWidget(
CupertinoApp(
home: CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(middle: Text('Runs')),
child: SafeArea(
child: RunsScreen(gateway: gateway, initialRunId: 1),
),
),
),
);
await _mountList(tester, gateway);
expect(find.byType(CupertinoPageScaffold), findsOneWidget);
expect(find.byType(CupertinoNavigationBar), findsOneWidget);
expect(find.text('Loading run details…'), findsOneWidget);
expect(find.byType(CupertinoActivityIndicator), findsOneWidget);
expect(find.text('Back to list'), findsOneWidget);
},
variant: TargetPlatformVariant.only(TargetPlatform.iOS),
);
}