feat(app): show recorded session export state in visit pane

This commit is contained in:
2026-10-22 03:26:33 +01:00
parent 559d767f39
commit ddd8eacb1f
3 changed files with 482 additions and 57 deletions
@@ -0,0 +1,185 @@
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/ui/run_detail_visit_session.dart';
import 'package:pipelines_app/features/runs/ui/run_detail_visit_session_state.dart';
import 'run_detail_visit_support.dart';
Future<void> pumpSessionExport(WidgetTester tester, JsonMap step) =>
tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: RunVisitSession(
step: step,
configuredEndpoint: 'ws://example.test/connect',
),
),
),
);
JsonMap sessionStep() => firstVisitStep(visitRunFixture());
JsonMap artifact(String name) => <String, dynamic>{
'name': name,
'url': 'https://example.test/artifacts/$name',
'content_type': 'text/html',
'size_bytes': 100,
};
void main() {
testWidgets('a verified export reports complete', (tester) async {
await pumpSessionExport(tester, sessionStep());
expect(find.text('complete'), findsOneWidget);
expect(find.text('partial'), findsNothing);
expect(find.textContaining('full session evidence'), findsNothing);
expect(find.text('Reason'), findsNothing);
});
testWidgets('a partial export keeps the server status and its reason', (
tester,
) async {
final step = sessionStep();
step['session_export'] = <String, dynamic>{
'html': 'session.html',
'status': 'failed',
'messages': 2,
'diagnostic': 'The native read was refused.',
};
await pumpSessionExport(tester, step);
expect(find.text('partial'), findsOneWidget);
expect(
find.textContaining(
'This export is failed; full session evidence is not available.',
),
findsOneWidget,
);
expect(find.text('The native read was refused.'), findsOneWidget);
});
testWidgets('complete status without evidence is not promoted to complete', (
tester,
) async {
final step = sessionStep();
step['session_export'] = <String, dynamic>{
'html': 'session.html',
'status': 'complete',
'messages': 0,
'html_bytes': 0,
'diagnostic': 'Bounded read returned no messages.',
};
await pumpSessionExport(tester, step);
expect(find.text('complete'), findsNothing);
expect(find.text('partial'), findsOneWidget);
expect(find.text('Bounded read returned no messages.'), findsOneWidget);
});
testWidgets('an export with no recorded evidence stays unknown', (
tester,
) async {
final step = sessionStep()..remove('session_export');
await pumpSessionExport(tester, step);
expect(find.text('unknown'), findsOneWidget);
expect(find.text('complete'), findsNothing);
});
testWidgets('a missing export reports missing and the server reason', (
tester,
) async {
final step = sessionStep();
step['session_export'] = <String, dynamic>{
'html': 'session.html',
'status': 'failed',
'diagnostic': 'The export file was not listed.',
};
step['artifacts'] = <dynamic>[artifact('plan.csv')];
await pumpSessionExport(tester, step);
expect(find.text('missing'), findsOneWidget);
expect(
find.textContaining('The export file was not listed.'),
findsOneWidget,
);
expect(find.textContaining('Open '), findsNothing);
});
testWidgets('a skipped visit reports skipped and its recorded sentence', (
tester,
) async {
final step = sessionStep();
step['status'] = 'skipped';
step['outcome'] = 'skipped';
step
..remove('session_id')
..remove('session_export')
..remove('artifacts');
await pumpSessionExport(tester, step);
expect(find.text('skipped'), findsOneWidget);
expect(find.text(visitSessionSkipped), findsOneWidget);
});
testWidgets('recorded repairs and their open labels stay read-only', (
tester,
) async {
final step = sessionStep();
step['session_export'] = <String, dynamic>{
'html': 'session.html',
'status': 'failed',
'messages': 0,
'diagnostic': 'The first export failed.',
};
step['session_export_repairs'] = <dynamic>[
<String, dynamic>{
'html': 'session-repair-1.html',
'status': 'failed',
'messages': 0,
'diagnostic': 'The first repair failed.',
},
<String, dynamic>{
'html': 'session-repair-2.html',
'status': 'complete',
'messages': 3,
'html_bytes': 500,
},
];
step['artifacts'] = <dynamic>[
artifact('plan.csv'),
artifact('session.html'),
artifact('session-repair-1.html'),
artifact('session-repair-2.html'),
];
await pumpSessionExport(tester, step);
expect(find.text('repair'), findsOneWidget);
expect(
find.text('failed · 0 messages. The first repair failed.'),
findsOneWidget,
);
expect(find.text('complete · 3 messages.'), findsOneWidget);
expect(find.text('Open repaired export'), findsOneWidget);
expect(
find.widgetWithText(TextButton, 'Open repaired export'),
findsNothing,
);
expect(find.text('Open session-repair-2.html'), findsOneWidget);
});
testWidgets('an unrecognised export status is kept verbatim', (tester) async {
final step = sessionStep();
step['session_export'] = <String, dynamic>{
'html': 'session.html',
'status': 'quarantined',
'diagnostic': 'The server quarantined this export.',
};
await pumpSessionExport(tester, step);
expect(find.text('quarantined'), findsOneWidget);
expect(find.text('complete'), findsNothing);
expect(find.text('The server quarantined this export.'), findsOneWidget);
});
}