Files
pipelines/app/test/features/changes/changes_viewer_test.dart
T
alan fde086cc4a feat(app): glass viewer bars, graph controls and immersive image viewer
Review findings F12, F13, F25 and F1 for viewers: the artifact viewer's
actions/pager and the Changes pager float as glass pills over content,
file facts move to the top bar, graph overlay controls are one glass pill
(duplicate fullscreen glyph removed), the image viewer is immersive, and
diff/artifact/graph views let content pass behind the bar. Implemented by
pipeline run #204 (Terra); its Review stopped after three rejections, the
last being an empty glass bar for a single unresolved artifact, which the
manager fixed here with a regression test.
2026-10-31 04:26:22 +00:00

511 lines
16 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
import 'package:pipelines_app/features/changes/changes.dart';
import 'package:pipelines_app/features/changes/widgets/visit_pager.dart';
import 'fixtures.dart';
import 'widget_hosts.dart';
void main() {
testWidgets(
'a missing capture is an evidence gap, not an observed no-change',
(tester) async {
await tester.pumpWidget(
materialHost(ChangesViewer(steps: [stepFixture(fileChanges: null)])),
);
expect(find.text('Changes · not recorded for this run'), findsOneWidget);
expect(find.text('Capture unavailable'), findsOneWidget);
expect(find.text(missingCaptureDetail), findsOneWidget);
expect(find.text(emptyCaptureDetail), findsNothing);
expect(find.text('No changes observed'), findsNothing);
},
);
testWidgets('a running step with no capture is pending, not unavailable', (
tester,
) async {
await tester.pumpWidget(
materialHost(
ChangesViewer(
steps: [stepFixture(status: 'running', fileChanges: null)],
),
),
);
expect(find.text('Changes · capture pending'), findsOneWidget);
expect(find.text('Capture pending'), findsOneWidget);
expect(find.text(pendingCaptureDetail), findsOneWidget);
expect(find.text('Capture unavailable'), findsNothing);
});
testWidgets('a differently cased running status agrees with the header', (
tester,
) async {
await tester.pumpWidget(
materialHost(
ChangesViewer(
steps: [stepFixture(status: 'Running', fileChanges: null)],
),
),
);
expect(find.text('Changes · capture pending'), findsOneWidget);
expect(find.text('Capture pending'), findsOneWidget);
expect(find.text('Capture unavailable'), findsNothing);
});
testWidgets('an empty complete capture says the workspace was unchanged', (
tester,
) async {
await tester.pumpWidget(
materialHost(
ChangesViewer(steps: [stepFixture(fileChanges: captureFixture())]),
),
);
expect(find.text('Changes · no changes observed'), findsOneWidget);
expect(find.text('No changes observed'), findsOneWidget);
expect(find.text(emptyCaptureDetail), findsOneWidget);
expect(find.text(missingCaptureDetail), findsNothing);
});
testWidgets('an unavailable capture never claims there were no changes', (
tester,
) async {
await tester.pumpWidget(
materialHost(
ChangesViewer(
steps: [
stepFixture(
fileChanges: captureFixture(
status: 'unavailable',
diagnostic:
'Workspace snapshot unavailable; changes could not be '
'compared.',
),
),
],
),
),
);
expect(find.text('Changes · capture unavailable'), findsOneWidget);
expect(find.textContaining('Workspace snapshot unavailable'), findsWidgets);
expect(find.text(emptyCaptureDetail), findsNothing);
});
testWidgets('stage/visit pages keep partial status, counters and scope', (
tester,
) async {
final diagnostic = 'Excluded protected files.';
await tester.pumpWidget(
materialHost(
ChangesViewer(
steps: [
stepFixture(
stage: 'implementer',
fileChanges: captureFixture(
status: 'partial',
skipped: 1,
omitted: 2,
diagnostic: diagnostic,
files: [
fileChangeFixture(path: 'lib/a.dart', patch: multiHunkPatch),
],
),
),
stepFixture(
stage: 'reviewer',
sequence: 2,
status: 'failed',
fileChanges: null,
),
],
),
),
);
// The run-wide aggregate still counts the file this visit recorded.
expect(find.textContaining('1 file changed'), findsOneWidget);
expect(find.text('implementer'), findsOneWidget);
expect(find.text('Visit 1 · completed'), findsOneWidget);
expect(
find.text(
'partial (1 files), 1 skipped, 2 omitted · Excluded protected files.',
),
findsOneWidget,
);
expect(
find.text('Scope: Git tracked and nonignored files in the run directory'),
findsOneWidget,
);
// The second visit is its own page, not a second section.
expect(find.text('reviewer'), findsNothing);
expect(find.text(missingCaptureDetail), findsNothing);
expect(
find.ancestor(
of: find.byKey(ChangesVisitPager.nextKey),
matching: find.byType(GlassPill),
),
findsOneWidget,
);
await tester.tap(find.byKey(ChangesVisitPager.nextKey));
await tester.pump();
expect(find.text('implementer'), findsNothing);
expect(find.text('reviewer'), findsOneWidget);
// The reviewer's first visit is Visit 1, not the run-wide step ordinal 2.
expect(find.text('Visit 1 · failed'), findsOneWidget);
expect(find.text('Visit 2 · failed'), findsNothing);
expect(find.text(missingCaptureDetail), findsOneWidget);
});
testWidgets(
'repeated stages number their own visits and honour control.visit',
(tester) async {
await tester.pumpWidget(
materialHost(
ChangesViewer(
steps: [
stepFixture(
stage: 'implementer',
sequence: 1,
fileChanges: captureFixture(),
),
stepFixture(
stage: 'reviewer',
sequence: 2,
fileChanges: captureFixture(),
),
stepFixture(
stage: 'implementer',
sequence: 3,
fileChanges: captureFixture(),
),
stepFixture(
stage: 'reviewer',
sequence: 4,
visit: 6,
fileChanges: captureFixture(),
),
],
),
),
);
// Pages are in run order; each stage numbers its own visits, so the
// run-wide step ordinals (1-4) must not leak into the label.
expect(find.text('Visit 1 · completed'), findsOneWidget);
expect(find.text('Visit 2 · completed'), findsNothing);
expect(find.text('Visit 6 · completed'), findsNothing);
await tester.tap(find.byKey(ChangesVisitPager.nextKey));
await tester.pump();
// The reviewer's first recorded visit is Visit 1 too.
expect(find.text('reviewer'), findsOneWidget);
expect(find.text('Visit 1 · completed'), findsOneWidget);
await tester.tap(find.byKey(ChangesVisitPager.nextKey));
await tester.pump();
expect(find.text('implementer'), findsOneWidget);
expect(find.text('Visit 2 · completed'), findsOneWidget);
await tester.tap(find.byKey(ChangesVisitPager.nextKey));
await tester.pump();
// The resumed reviewer visit records control.visit 6.
expect(find.text('reviewer'), findsOneWidget);
expect(find.text('Visit 6 · completed'), findsOneWidget);
expect(find.text('Visit 3 · completed'), findsNothing);
expect(find.text('Visit 4 · completed'), findsNothing);
},
);
testWidgets(
'opening a file shows the rendered patch and copies exact bytes',
(tester) async {
final calls = <MethodCall>[];
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(SystemChannels.platform, (call) async {
if (call.method == 'Clipboard.setData') calls.add(call);
return null;
});
addTearDown(
() => TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(SystemChannels.platform, null),
);
await tester.pumpWidget(
materialHost(
ChangesViewer(
steps: [
stepFixture(
fileChanges: captureFixture(
files: [
fileChangeFixture(
path: 'lib/feature.dart',
patch: multiHunkPatch,
),
],
),
),
],
),
),
);
await tester.tap(find.byKey(const ValueKey('change-1-lib/feature.dart')));
await tester.pumpAndSettle();
// A file opens on its own page, not a dialog.
expect(find.byType(FileDiffPage), findsOneWidget);
expect(find.byType(Dialog), findsNothing);
expect(find.text('Rendered'), findsOneWidget);
expect(find.text('Raw patch'), findsOneWidget);
final rendered = tester
.widgetList<RichText>(find.byType(RichText))
.map((rich) => rich.text.toPlainText())
.join('\n');
expect(rendered, contains('+ new line'));
expect(rendered, contains('- old line'));
expect(rendered, contains('@@ -20,3 +21,2 @@'));
await tester.tap(find.text('Raw patch'));
await tester.pumpAndSettle();
final raw = tester.widget<Text>(find.text(multiHunkPatch));
expect(raw.data, multiHunkPatch);
expect(raw.softWrap, isFalse);
await tester.tap(find.text('Copy patch'));
await tester.pump();
expect(calls, hasLength(1));
expect(calls.single.arguments, {'text': multiHunkPatch});
expect(find.text('Copied'), findsOneWidget);
await tester.pageBack();
await tester.pumpAndSettle();
expect(find.byType(Dialog), findsNothing);
},
);
testWidgets('binary, truncated and mode-only entries explain the missing diff', (
tester,
) async {
await tester.pumpWidget(
materialHost(
SingleChildScrollView(
child: Column(
children: [
SizedBox(
height: 300,
child: FileDiffViewer(
file: FileChange(
path: 'assets/logo.bin',
kind: ChangeKind.modified,
binary: true,
),
),
),
SizedBox(
height: 300,
child: FileDiffViewer(
file: FileChange(
path: 'logs/build.log',
kind: ChangeKind.modified,
patch: '@@ -1 +1 @@\n-a\n+b',
truncated: true,
),
),
),
SizedBox(
height: 300,
child: FileDiffViewer(
file: FileChange(
path: 'scripts/run.sh',
kind: ChangeKind.modified,
beforeMode: '0644',
afterMode: '0755',
),
),
),
],
),
),
),
);
expect(find.text(binaryDiffMessage), findsOneWidget);
expect(find.text(truncatedPatchNote), findsOneWidget);
expect(
find.text(
"Only the file's mode changed (0644→0755); the server recorded no text "
'diff.',
),
findsOneWidget,
);
final copyButtons = <TextButton>[];
for (var index = 0; index < 3; index++) {
final button = find
.ancestor(
of: find.text('Copy patch').at(index),
matching: find.byWidgetPredicate((widget) => widget is TextButton),
)
.first;
copyButtons.add(tester.widget<TextButton>(button));
}
// Binary and mode-only have nothing to copy; the truncated patch still can.
expect(
copyButtons.where((button) => button.onPressed == null),
hasLength(2),
);
expect(
copyButtons.where((button) => button.onPressed != null),
hasLength(1),
);
});
testWidgets('Cupertino uses native list tiles and segmented control', (
tester,
) async {
await tester.pumpWidget(
cupertinoHost(
ChangesViewer(
steps: [
stepFixture(
fileChanges: captureFixture(
files: [
fileChangeFixture(
path: 'lib/feature.dart',
patch: multiHunkPatch,
),
],
),
),
],
),
),
);
expect(find.byType(CupertinoListTile), findsOneWidget);
// No filter field: the changes list shows every recorded file.
expect(find.byType(CupertinoSearchTextField), findsNothing);
expect(find.byType(TextField), findsNothing);
await tester.tap(find.byKey(const ValueKey('change-1-lib/feature.dart')));
await tester.pumpAndSettle();
expect(
find.byType(CupertinoSlidingSegmentedControl<DiffForm>),
findsOneWidget,
);
expect(find.text('Rendered'), findsOneWidget);
expect(find.text('Raw patch'), findsOneWidget);
await tester.pageBack();
await tester.pumpAndSettle();
expect(
find.byType(CupertinoSlidingSegmentedControl<DiffForm>),
findsNothing,
);
});
testWidgets('narrow viewport and large text keep every control reachable', (
tester,
) async {
tester.view.physicalSize = const Size(320, 720);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(
materialHost(
ChangesViewer(
steps: [
stepFixture(
fileChanges: captureFixture(
files: [
fileChangeFixture(
path: 'lib/a_rather_long_feature_file_name.dart',
patch: multiHunkPatch,
),
fileChangeFixture(path: 'assets/logo.bin', binary: true),
],
),
),
],
),
scaler: const TextScaler.linear(2),
),
);
expect(tester.takeException(), isNull);
expect(
find.text('lib/a_rather_long_feature_file_name.dart'),
findsOneWidget,
);
// The viewer itself at the same narrow width and 2x text: every action
// stays on screen and the patch body scrolls instead of overflowing.
await tester.pumpWidget(
materialHost(
FileDiffViewer(
file: FileChange(
path: 'lib/a_rather_long_feature_file_name.dart',
kind: ChangeKind.modified,
patch: multiHunkPatch,
),
),
scaler: const TextScaler.linear(2),
),
);
expect(tester.takeException(), isNull);
// The host is too narrow for a two-segment control at 2x, so the same form
// selection is offered through the native menu instead.
expect(find.byTooltip('Diff form'), findsOneWidget);
expect(find.text('Copy patch'), findsOneWidget);
expect(find.byTooltip('Close diff'), findsNothing);
});
testWidgets('without the settled-run gate there is no run-wide summary', (
tester,
) async {
// A failed or running run: the web shows no aggregate, only each visit's
// own capture.
await tester.pumpWidget(
materialHost(
ChangesViewer(
steps: [stepFixture(fileChanges: null)],
showSummary: false,
),
),
);
expect(find.text('Changes · not recorded for this run'), findsNothing);
expect(find.text('Capture unavailable'), findsOneWidget);
});
testWidgets('does not show an empty floating bar without multiple visits', (
tester,
) async {
await tester.pumpWidget(
materialHost(
ChangesViewer(
finalOnly: true,
steps: [
stepFixture(
fileChanges: captureFixture(
files: [fileChangeFixture(path: 'lib/feature.dart')],
),
),
],
),
),
);
expect(find.byType(GlassPill), findsNothing);
expect(find.byType(ChangesVisitPager), findsNothing);
await tester.pumpWidget(
materialHost(
ChangesViewer(steps: [stepFixture(fileChanges: captureFixture())]),
),
);
expect(find.byType(GlassPill), findsNothing);
expect(find.byType(ChangesVisitPager), findsNothing);
await tester.pumpWidget(materialHost(const ChangesViewer(steps: [])));
expect(find.byType(GlassPill), findsNothing);
expect(find.byType(ChangesVisitPager), findsNothing);
});
}