fix(app): offer the session export repair only where the web does

Suppress the export-only repair for a legacy session.html with no recorded
evidence, narrow the identity check to the web's own, and keep the stricter
partial rule for an unverified complete status. Fix the analyzer findings,
add gating/legacy/Cupertino coverage, format, and correct the parity docs.
This commit is contained in:
2026-10-22 10:52:36 +01:00
parent d78712aa77
commit 776afcacea
8 changed files with 265 additions and 41 deletions
@@ -19,6 +19,8 @@ void main() {
expect(find.text('sess-1'), findsOneWidget);
expect(find.text('Open session.html'), findsOneWidget);
// No recorded export evidence, so the web offers no export-only repair.
expect(find.text('Retry export only'), findsNothing);
expect(
find.textContaining('not available in the artifact inventory'),
findsNothing,
@@ -85,6 +87,8 @@ void main() {
findsOneWidget,
);
expect(find.textContaining('Open '), findsNothing);
// No openable document at all is the web's other repair branch.
expect(find.text('Retry export only'), findsOneWidget);
step['session_export'] = <String, dynamic>{
'html': 'session.html',
@@ -1,5 +1,6 @@
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';
@@ -8,8 +9,7 @@ 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);
typedef _RepairHandler = Future<JsonMap> Function(String type, JsonMap fields);
class _RepairGateway implements ApiGateway {
_RepairGateway(this.handler);
@@ -79,42 +79,57 @@ 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',
),
void didUpdateWidget(covariant _SessionHost oldWidget) {
super.didUpdateWidget(oldWidget);
// A test that swaps the recorded run must show the new visit, exactly as
// the detail does when the operator selects another one.
if (!identical(widget.run, oldWidget.run)) _run = widget.run;
}
@override
Widget build(BuildContext context) => RunVisitSession(
run: _run,
step: firstVisitStep(_run),
gateway: widget.gateway,
onRunChanged: (detail) => setState(() => _run = detail),
configuredEndpoint: 'ws://example.test/connect',
);
}
Future<void> pumpSession(
Future<void> _pumpSession(
WidgetTester tester,
_RepairGateway gateway, {
JsonMap? run,
}) => tester.pumpWidget(
MaterialApp(
home: _SessionHost(run: run ?? partialRun(), gateway: gateway),
),
bool cupertino = false,
}) {
final host = _SessionHost(run: run ?? partialRun(), gateway: gateway);
return tester.pumpWidget(
cupertino
? CupertinoApp(
home: CupertinoPageScaffold(child: SafeArea(child: host)),
)
: MaterialApp(home: Scaffold(body: host)),
);
}
TextButton _materialButton(WidgetTester tester) => tester.widget<TextButton>(
find.widgetWithText(TextButton, 'Retry export only'),
);
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);
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,
});
expect(gateway.repairs.single.fields, {'run_id': 77, 'export_sequence': 1});
// Nothing but the one repair request is sent.
expect(gateway.calls.map((call) => call.type), ['repair_session_export']);
// The recorded export state is kept until the server replies.
expect(find.text('partial'), findsOneWidget);
expect(find.text('complete'), findsNothing);
@@ -140,7 +155,7 @@ void main() {
final gateway = _RepairGateway(
(_, _) => Future<JsonMap>.error(StateError('The session is gone.')),
);
await pumpSession(tester, gateway);
await _pumpSession(tester, gateway);
await tester.tap(find.text('Retry export only'));
await tester.pumpAndSettle();
@@ -152,4 +167,105 @@ void main() {
// The option is still available: a refusal is not a success.
expect(find.text('Retry export only'), findsOneWidget);
});
testWidgets('a legacy session.html with no recorded evidence keeps no '
'control', (tester) async {
final gateway = _RepairGateway(
(_, _) => Future<JsonMap>.error(StateError('unexpected')),
);
final run = partialRun();
firstVisitStep(run).remove('session_export');
await _pumpSession(tester, gateway, run: run);
// The document still opens, but there is no evidence to repair.
expect(find.text('Open session.html'), findsOneWidget);
expect(find.text('Retry export only'), findsNothing);
expect(gateway.calls, isEmpty);
});
testWidgets('a verified complete export offers no repair', (tester) async {
final gateway = _RepairGateway(
(_, _) => Future<JsonMap>.error(StateError('unexpected')),
);
await _pumpSession(tester, gateway, run: visitRunFixture());
expect(find.text('complete'), findsOneWidget);
expect(find.text('Retry export only'), findsNothing);
});
testWidgets('the control is disabled while the visit or run is active', (
tester,
) async {
final gateway = _RepairGateway(
(_, _) => Future<JsonMap>.error(StateError('unexpected')),
);
final active = partialRun();
firstVisitStep(active)['agent_active'] = true;
await _pumpSession(tester, gateway, run: active);
expect(find.text('Retry export only'), findsOneWidget);
expect(_materialButton(tester).onPressed, isNull);
final waiting = partialRun();
waiting['status'] = 'waiting';
waiting['export_pending_sequence'] = 2;
await _pumpSession(tester, gateway, run: waiting);
expect(_materialButton(tester).onPressed, isNull);
// The same wait allows the repair when this visit's export is the pending
// one, exactly as the web client's availability check does.
waiting['export_pending_sequence'] = 1;
await _pumpSession(tester, gateway, run: waiting);
expect(_materialButton(tester).onPressed, isNotNull);
});
testWidgets('changing visits clears a pending repair and its reply', (
tester,
) async {
final first = Completer<JsonMap>();
final second = Completer<JsonMap>();
final gateway = _RepairGateway(
(_, fields) =>
fields['export_sequence'] == 1 ? first.future : second.future,
);
await _pumpSession(tester, gateway);
await tester.tap(find.text('Retry export only'));
await tester.pump();
expect(find.text('Exporting…'), findsOneWidget);
final next = partialRun();
firstVisitStep(next)['sequence'] = 2;
await _pumpSession(tester, gateway, run: next);
expect(find.text('Retry export only'), findsOneWidget);
expect(find.text('Exporting…'), findsNothing);
await tester.tap(find.text('Retry export only'));
await tester.pump();
expect(gateway.repairs.map((call) => call.fields['export_sequence']), [
1,
2,
]);
// The first visit's late reply is not folded into the second visit.
first.complete({'run_detail': repairedRun()});
await tester.pump();
expect(find.text('repair'), findsNothing);
expect(find.text('partial'), findsOneWidget);
});
testWidgets('the Cupertino host uses a native Cupertino button', (
tester,
) async {
final gateway = _RepairGateway(
(_, _) => Future<JsonMap>.error(StateError('unexpected')),
);
await _pumpSession(tester, gateway, cupertino: true);
expect(
find.widgetWithText(CupertinoButton, 'Retry export only'),
findsOneWidget,
);
expect(find.widgetWithText(TextButton, 'Retry export only'), findsNothing);
});
}