Files
pipelines/app/test/application/pipelines_replies.dart
T
alan 8476cfd740 feat(app): wire the native pipelines browser on the shared session
Register the landed PipelinesScreen at /pipelines through AppSession, with
an honest first-connection gate, a native reconnect banner that retains the
open list and detail, and an in-place refresh on reconnect. Move the shared
connection chrome out of RunsDestination so both destinations use one
implementation and one wording.

Add destination, registration and reconnect coverage plus an isolated
loopback Chrome probe that drives the real runPipelinesApp() composition.
2026-10-21 19:47:08 +01:00

94 lines
2.7 KiB
Dart

import 'dart:convert';
import 'package:flutter_test/flutter_test.dart';
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
import '../features/pipelines/fixtures.dart';
Map<String, dynamic>? pipelineRequest(FakeChannel channel, String type) =>
channel.outgoing
.map((frame) => jsonDecode(frame as String) as Map<String, dynamic>)
.where((frame) => frame['type'] == type)
.firstOrNull;
Future<void> waitForRequest(
WidgetTester tester,
FakeChannel channel,
String type,
) async {
for (
var attempt = 0;
attempt < 60 && pipelineRequest(channel, type) == null;
attempt++
) {
await tester.pump(const Duration(milliseconds: 10));
}
expect(
pipelineRequest(channel, type),
isNotNull,
reason: 'Timed out waiting for $type',
);
}
/// Waits for a later request of [type] than [afterId]. The transport serializes
/// requests, so a destination that mounts later issues its read only after the
/// previous reply arrives.
Future<Map<String, dynamic>> waitForLaterRequest(
WidgetTester tester,
FakeChannel channel,
String type,
String afterId,
) async {
Map<String, dynamic>? later() => channel.outgoing
.map((frame) => jsonDecode(frame as String) as Map<String, dynamic>)
.where((frame) => frame['type'] == type && frame['id'] != afterId)
.firstOrNull;
for (var attempt = 0; attempt < 60 && later() == null; attempt++) {
await tester.pump(const Duration(milliseconds: 10));
}
expect(later(), isNotNull, reason: 'Timed out waiting for later $type');
return later()!;
}
Future<void> replyPipelines(
WidgetTester tester,
FakeChannel channel,
PipelineFixture fixture,
) async {
await waitForRequest(tester, channel, 'list_pipelines');
final pipelines = pipelineRequest(channel, 'list_pipelines')!;
channel.incoming.add(
jsonEncode({
'id': pipelines['id'],
'type': 'pipelines',
'pipelines': fixture.summaries,
}),
);
await tester.pump();
await waitForRequest(tester, channel, 'list_runs');
final runs = pipelineRequest(channel, 'list_runs')!;
channel.incoming.add(
jsonEncode({'id': runs['id'], 'type': 'runs', 'runs': fixture.runs}),
);
await tester.pump();
await tester.pump();
}
Future<void> replyPipelineDetail(
WidgetTester tester,
FakeChannel channel,
PipelineFixture fixture,
) async {
await waitForRequest(tester, channel, 'get_pipeline');
final request = pipelineRequest(channel, 'get_pipeline')!;
final detail = fixture.detailFor(
request['pipeline_id'] as int,
request['version'] as int,
)!;
channel.incoming.add(
jsonEncode({'id': request['id'], 'type': 'pipeline', 'detail': detail}),
);
await tester.pump();
await tester.pump();
}