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_check_output_view.dart'; import 'package:pipelines_app/features/runs/ui/run_detail_visit_facts.dart'; import 'package:pipelines_app/features/runs/ui/run_detail_visit_sections.dart'; import 'package:pipelines_app/features/runs/ui/run_detail_visit_session_state.dart'; import 'package:pipelines_app/ui/text/monospace.dart'; import 'run_detail_graph_support.dart'; import 'run_detail_visit_support.dart'; /// verify (a delivery check) -> review, with one failed check visit. JsonMap _checkRun({int repairs = 0}) => { 'id': 78, 'title': 'Check run', 'name': 'release', 'pipeline_id': 7, 'version': 4, 'status': 'succeeded', 'graph': { 'stages': [ { 'key': 'verify', 'type': 'check', 'configs': {'delivery': 'true'}, 'edges': {'pass': '#', 'fail': 'verify'}, 'blocks': {'commands': 'go vet ./...\ngo test ./...'}, }, ], }, 'steps': [ { 'stage': 'verify', 'sequence': 1, 'status': 'completed', 'outcome': 'fail', 'target': 'verify', 'started_at': '2026-10-22T00:00:00Z', 'finished_at': '2026-10-22T00:01:00Z', if (repairs > 0) 'control': {'visit': 1, 'outcome_repairs': repairs}, 'output': { 'markdown': '# outcome\n\nfail\n\n# handoff\n\nFix the test.', 'summary': '1 of 2 checks failed: go test ./...', 'delivery': true, 'checks': [ { 'command': 'go vet ./...', 'status': 'passed', 'exit_code': 0, 'duration_ms': 2100, 'output': 'vet ok', 'truncated': false, }, { 'command': 'go test ./...', 'status': 'failed', 'exit_code': 1, 'duration_ms': 51000, 'output': '--- FAIL: TestX', 'truncated': true, }, ], }, }, ], }; void main() { const platform = RunDetailTestPlatform.material; testWidgets('a check visit shows one row per command with its output', ( tester, ) async { await openVisit(tester, platform, run: _checkRun()); expect(find.byKey(const Key('run-check-output')), findsOneWidget); expect(find.byKey(const Key('run-check-delivery')), findsOneWidget); expect(find.text('1 of 2 checks failed: go test ./...'), findsOneWidget); expect(find.text('go vet ./...'), findsOneWidget); expect(find.text('Passed · exit 0 · 2.1s'), findsOneWidget); expect(find.text('Failed · exit 1 · 51s'), findsOneWidget); // The raw checks list is never shown as a `key=value` field dump. expect(find.text('checks'), findsNothing); // Output is collapsed until the row is expanded; then it is selectable // monospace with the truncation note. expect(find.text('--- FAIL: TestX'), findsNothing); final row = find.byKey(const ValueKey('run-check-command-1')); await tester.ensureVisible(row); await tester.tap(find.text('go test ./...')); await tester.pumpAndSettle(); final output = tester.widget( find.widgetWithText(SelectableText, '--- FAIL: TestX'), ); expect(output.style?.fontFamily, appMonospaceFamily); expect(find.text(checkOutputTruncated), findsOneWidget); expect(tester.takeException(), isNull); }); testWidgets('a check visit has no model row and an honest session note', ( tester, ) async { await openVisit(tester, platform, run: _checkRun()); expect(find.text('Provider/model'), findsNothing); expect(find.text('fail'), findsWidgets); await openVisitTab(tester, RunVisitSection.session); expect(find.text(visitSessionCheck), findsOneWidget); expect(find.text(visitSessionNoIdentity), findsNothing); }); testWidgets('a repaired outcome is noted on the visit', (tester) async { await openVisit(tester, platform, run: _checkRun(repairs: 1)); expect(find.byKey(const Key('run-visit-outcome-repaired')), findsOne); expect(find.text('Outcome repaired by follow-up'), findsOneWidget); }); testWidgets('an unrepaired visit shows no repair note', (tester) async { await openVisit(tester, platform, run: _checkRun()); expect(find.byKey(const Key('run-visit-outcome-repaired')), findsNothing); }); test('outcome repairs read from control, absent meaning none', () { expect(detailVisitOutcomeRepairs({}), 0); expect(detailVisitOutcomeRepairs({'control': 'x'}), 0); expect( detailVisitOutcomeRepairs({ 'control': {'visit': 2}, }), 0, ); expect( detailVisitOutcomeRepairs({ 'control': {'outcome_repairs': 2}, }), 2, ); expect(outcomeRepairNote(2), 'Outcome repaired by follow-up (2 times)'); }); }