feat(app): send the recorded session export-only repair
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_visit_session.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_visit_session_state.dart';
|
||||
|
||||
import 'run_detail_graph_support.dart';
|
||||
import 'run_detail_visit_support.dart';
|
||||
|
||||
Future<void> pumpSessionExport(WidgetTester tester, JsonMap step) =>
|
||||
@@ -11,7 +12,10 @@ Future<void> pumpSessionExport(WidgetTester tester, JsonMap step) =>
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: RunVisitSession(
|
||||
run: visitRunFor(step),
|
||||
step: step,
|
||||
gateway: RunDetailFakeGateway(visitRunFor(step)),
|
||||
onRunChanged: (_) {},
|
||||
configuredEndpoint: 'ws://example.test/connect',
|
||||
),
|
||||
),
|
||||
|
||||
@@ -69,7 +69,13 @@ void main() {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: RunVisitSession(step: step, configuredEndpoint: ''),
|
||||
body: RunVisitSession(
|
||||
run: visitRunFor(step),
|
||||
step: step,
|
||||
gateway: RunDetailFakeGateway(visitRunFor(step)),
|
||||
onRunChanged: (_) {},
|
||||
configuredEndpoint: '',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -88,7 +94,13 @@ void main() {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: RunVisitSession(step: step, configuredEndpoint: ''),
|
||||
body: RunVisitSession(
|
||||
run: visitRunFor(step),
|
||||
step: step,
|
||||
gateway: RunDetailFakeGateway(visitRunFor(step)),
|
||||
onRunChanged: (_) {},
|
||||
configuredEndpoint: '',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -108,7 +120,10 @@ void main() {
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: RunVisitSession(
|
||||
run: visitRunFixture(),
|
||||
step: firstVisitStep(visitRunFixture()),
|
||||
gateway: RunDetailFakeGateway(visitRunFixture()),
|
||||
onRunChanged: (_) {},
|
||||
configuredEndpoint: 'ws://example.test/connect',
|
||||
openExternal: (uri) async {
|
||||
opened = uri;
|
||||
@@ -131,7 +146,10 @@ void main() {
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: RunVisitSession(
|
||||
run: visitRunFixture(),
|
||||
step: firstVisitStep(visitRunFixture()),
|
||||
gateway: RunDetailFakeGateway(visitRunFixture()),
|
||||
onRunChanged: (_) {},
|
||||
configuredEndpoint: 'ws://example.test/connect',
|
||||
openExternal: (uri) async => false,
|
||||
),
|
||||
|
||||
@@ -82,6 +82,14 @@ JsonMap visitRunFixture({
|
||||
JsonMap firstVisitStep(JsonMap run) =>
|
||||
(run['steps'] as List).first as Map<String, dynamic>;
|
||||
|
||||
/// The run that owns [step], for direct session-pane pumps outside the detail.
|
||||
JsonMap visitRunFor(JsonMap step, {String status = 'succeeded'}) =>
|
||||
<String, dynamic>{
|
||||
'id': 77,
|
||||
'status': status,
|
||||
'steps': <dynamic>[step],
|
||||
};
|
||||
|
||||
Future<void> openVisit(
|
||||
WidgetTester tester,
|
||||
RunDetailTestPlatform platform, {
|
||||
|
||||
@@ -95,7 +95,13 @@ void main() {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: RunVisitSession(step: step, configuredEndpoint: ''),
|
||||
body: RunVisitSession(
|
||||
run: visitRunFor(step),
|
||||
step: step,
|
||||
gateway: RunDetailFakeGateway(visitRunFor(step)),
|
||||
onRunChanged: (_) {},
|
||||
configuredEndpoint: '',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
import 'dart:async';
|
||||
|
||||
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/actions/session_export_repair_action.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_visit_session.dart';
|
||||
|
||||
import 'run_detail_visit_support.dart';
|
||||
|
||||
typedef _RepairHandler =
|
||||
Future<JsonMap> Function(String type, JsonMap fields);
|
||||
|
||||
class _RepairGateway implements ApiGateway {
|
||||
_RepairGateway(this.handler);
|
||||
|
||||
final _RepairHandler handler;
|
||||
final List<({String type, JsonMap fields})> calls = [];
|
||||
|
||||
@override
|
||||
Stream<JsonMap> get frames => const Stream<JsonMap>.empty();
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
||||
final copy = Map<String, dynamic>.from(fields);
|
||||
calls.add((type: type, fields: copy));
|
||||
return handler(type, copy);
|
||||
}
|
||||
|
||||
Iterable<({String type, JsonMap fields})> get repairs =>
|
||||
calls.where((call) => call.type == 'repair_session_export');
|
||||
}
|
||||
|
||||
/// A recorded visit whose export failed, so the repair option is offered.
|
||||
JsonMap partialRun() {
|
||||
final run = visitRunFixture();
|
||||
final step = firstVisitStep(run);
|
||||
step['session_export'] = <String, dynamic>{
|
||||
'html': 'session.html',
|
||||
'status': 'failed',
|
||||
'messages': 0,
|
||||
'diagnostic': 'The first export failed.',
|
||||
};
|
||||
return run;
|
||||
}
|
||||
|
||||
/// A reply whose recorded repair is verified complete and openable.
|
||||
JsonMap repairedRun() {
|
||||
final run = visitRunFixture();
|
||||
final step = firstVisitStep(run);
|
||||
step['session_export_repairs'] = <dynamic>[
|
||||
<String, dynamic>{
|
||||
'html': 'session-repair-1.html',
|
||||
'status': 'complete',
|
||||
'messages': 3,
|
||||
'html_bytes': 900,
|
||||
},
|
||||
];
|
||||
(step['artifacts'] as List).add(<String, dynamic>{
|
||||
'name': 'session-repair-1.html',
|
||||
'url': 'https://example.test/artifacts/session-repair-1.html',
|
||||
'content_type': 'text/html',
|
||||
'size_bytes': 900,
|
||||
});
|
||||
return run;
|
||||
}
|
||||
|
||||
class _SessionHost extends StatefulWidget {
|
||||
const _SessionHost({required this.run, required this.gateway});
|
||||
|
||||
final JsonMap run;
|
||||
final _RepairGateway gateway;
|
||||
|
||||
@override
|
||||
State<_SessionHost> createState() => _SessionHostState();
|
||||
}
|
||||
|
||||
class _SessionHostState extends State<_SessionHost> {
|
||||
late JsonMap _run = widget.run;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Scaffold(
|
||||
body: RunVisitSession(
|
||||
run: _run,
|
||||
step: firstVisitStep(_run),
|
||||
gateway: widget.gateway,
|
||||
onRunChanged: (detail) => setState(() => _run = detail),
|
||||
configuredEndpoint: 'ws://example.test/connect',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> pumpSession(
|
||||
WidgetTester tester,
|
||||
_RepairGateway gateway, {
|
||||
JsonMap? run,
|
||||
}) => tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: _SessionHost(run: run ?? partialRun(), gateway: gateway),
|
||||
),
|
||||
);
|
||||
|
||||
void main() {
|
||||
testWidgets('sends the recorded run and visit exactly once', (tester) async {
|
||||
final reply = Completer<JsonMap>();
|
||||
final gateway = _RepairGateway((_, _) => reply.future);
|
||||
await pumpSession(tester, gateway);
|
||||
|
||||
expect(find.text('Retry export only'), findsOneWidget);
|
||||
await tester.tap(find.text('Retry export only'));
|
||||
await tester.pump();
|
||||
|
||||
expect(gateway.repairs, hasLength(1));
|
||||
expect(gateway.repairs.single.fields, {
|
||||
'run_id': 77,
|
||||
'export_sequence': 1,
|
||||
});
|
||||
// The recorded export state is kept until the server replies.
|
||||
expect(find.text('partial'), findsOneWidget);
|
||||
expect(find.text('complete'), findsNothing);
|
||||
expect(find.text('Exporting…'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Exporting…'), warnIfMissed: false);
|
||||
await tester.pump();
|
||||
expect(gateway.repairs, hasLength(1));
|
||||
|
||||
reply.complete({'run_detail': repairedRun()});
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// The accepted reply names the verified repair the pane must now show.
|
||||
expect(find.text('repair'), findsOneWidget);
|
||||
expect(find.text('complete · 3 messages.'), findsOneWidget);
|
||||
expect(find.text('Open session-repair-1.html'), findsOneWidget);
|
||||
expect(find.text('Retry export only'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a refusal is shown and the recorded state is unchanged', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = _RepairGateway(
|
||||
(_, _) => Future<JsonMap>.error(StateError('The session is gone.')),
|
||||
);
|
||||
await pumpSession(tester, gateway);
|
||||
|
||||
await tester.tap(find.text('Retry export only'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(sessionExportRepairErrorKey), findsOneWidget);
|
||||
expect(find.text('The session is gone.'), findsOneWidget);
|
||||
expect(find.text('partial'), findsOneWidget);
|
||||
expect(find.text('complete'), findsNothing);
|
||||
// The option is still available: a refusal is not a success.
|
||||
expect(find.text('Retry export only'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user