feat(app): finish native run Changes wiring and scaled form menus

This commit is contained in:
2026-10-21 20:48:45 +01:00
parent 7b327f012b
commit 77c71eb45e
18 changed files with 1956 additions and 159 deletions
@@ -466,7 +466,9 @@ void main() {
),
);
expect(tester.takeException(), isNull);
expect(find.text('Rendered'), findsOneWidget);
// 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'), findsOneWidget);
});
@@ -1,5 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/changes/changes.dart';
import 'package:pipelines_app/features/changes/widgets/change_style.dart';
@@ -16,6 +17,64 @@ const _raggedPatch =
'-x\n'
' tail\n';
/// Opens the real single-file diff modal from a host, so the test covers the
/// dialog's own width and insets rather than the viewer in isolation.
Widget _diffDialogOpener(FileChange file) => Builder(
builder: (context) => TextButton(
onPressed: () => showFileDiffViewer(context, file),
child: const Text('Open diff'),
),
);
/// Fails when a fixed control label is broken inside a word or clipped by its
/// control. A label may wrap only between whole words, which is how a native
/// menu keeps an accessibility-size label readable.
void _expectWholeLabel(WidgetTester tester, Finder finder, String label) {
final paragraph = tester.renderObject<RenderParagraph>(
find.descendant(of: finder, matching: find.byType(RichText)),
);
final span = paragraph.text as TextSpan;
expect(span.toPlainText(), label);
expect(paragraph.didExceedMaxLines, isFalse);
final boxes = paragraph
.getBoxesForSelection(
TextSelection(baseOffset: 0, extentOffset: label.length),
)
.toList();
expect(boxes, isNotEmpty);
// The laid-out paragraph must be tall enough to paint every line it broke.
expect(
boxes.last.bottom,
lessThanOrEqualTo(paragraph.size.height + 0.5),
reason: '"$label" must not be clipped vertically',
);
final widestLine = boxes
.map((box) => box.right - box.left)
.reduce((a, b) => a > b ? a : b);
final style = span.style ?? const TextStyle();
var widestWord = 0.0;
for (final word in label.split(' ')) {
final painter = TextPainter(
text: TextSpan(text: word, style: style),
textDirection: TextDirection.ltr,
textScaler: paragraph.textScaler,
)..layout();
if (painter.width > widestWord) widestWord = painter.width;
}
// A line narrower than a whole word means the label broke mid-word.
expect(
widestLine,
greaterThanOrEqualTo(widestWord - 0.5),
reason: '"$label" must not break inside a word',
);
// A clipped line would paint wider than the paragraph's laid-out box.
expect(
widestLine,
lessThanOrEqualTo(paragraph.size.width + 0.5),
reason: '"$label" must not be clipped horizontally',
);
}
void main() {
test(
'patch typography preserves the native host style without overrides',
@@ -139,6 +198,49 @@ void main() {
);
});
testWidgets('the Cupertino raw patch is a native selectable field', (
tester,
) async {
await tester.pumpWidget(
cupertinoHost(
SizedBox(
height: 400,
child: FileDiffViewer(
file: FileChange(
path: 'lib/feature.dart',
kind: ChangeKind.modified,
patch: multiHunkPatch,
),
),
),
),
);
await tester.tap(find.text('Raw patch'));
await tester.pumpAndSettle();
// A CupertinoApp has no MaterialLocalizations, so Raw must not use the
// Material SelectionArea; it renders the recorded bytes in a native field.
expect(tester.takeException(), isNull);
expect(find.byType(SelectionArea), findsNothing);
final field = tester.widget<CupertinoTextField>(
find.byKey(const ValueKey('raw-patch-field')),
);
expect(field.readOnly, isTrue);
expect(field.maxLines, isNull);
expect(field.controller?.text, multiHunkPatch);
expect(
find.ancestor(
of: find.byKey(const ValueKey('raw-patch-field')),
matching: find.byWidgetPredicate(
(widget) =>
widget is SingleChildScrollView &&
widget.scrollDirection == Axis.horizontal,
),
),
findsOneWidget,
);
});
testWidgets('a Cupertino row wraps its recorded path instead of clipping it', (
tester,
) async {
@@ -203,4 +305,98 @@ void main() {
expect(rect.right, lessThan(382));
expect(tester.takeException(), isNull);
});
final diffFile = FileChange(
path: 'lib/feature.dart',
kind: ChangeKind.modified,
patch: multiHunkPatch,
);
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
testWidgets('$host diff labels stay whole at 320x720 with 2x text', (
tester,
) async {
tester.view.physicalSize = const Size(320, 720);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final opener = _diffDialogOpener(diffFile);
await tester.pumpWidget(
cupertino
? cupertinoHost(opener, scaler: const TextScaler.linear(2))
: materialHost(opener, scaler: const TextScaler.linear(2)),
);
await tester.tap(find.text('Open diff'));
await tester.pumpAndSettle();
// A segmented control cannot keep both fixed words at this size, so the
// host's native menu carries them instead. "Rendered" used to break
// mid-word and "Raw patch" used to be clipped to "Raw".
expect(find.byType(SegmentedButton<DiffForm>), findsNothing);
expect(
find.byType(CupertinoSlidingSegmentedControl<DiffForm>),
findsNothing,
);
// Copy patch stays a standard action at intrinsic width; it must not
// break its two words either.
_expectWholeLabel(tester, find.text('Copy patch'), 'Copy patch');
await tester.tap(
cupertino
? find.byIcon(CupertinoIcons.ellipsis)
: find.byTooltip('Diff form'),
);
await tester.pumpAndSettle();
final items = cupertino
? find.byType(CupertinoActionSheetAction)
: find.byType(ListTile);
expect(items, findsNWidgets(2));
for (final label in ['Rendered', 'Raw patch']) {
_expectWholeLabel(
tester,
find.descendant(of: items, matching: find.text(label)),
label,
);
}
await tester.tap(
find.descendant(of: items, matching: find.text('Raw patch')),
);
await tester.pumpAndSettle();
if (cupertino) {
expect(find.byKey(const ValueKey('raw-patch-field')), findsOneWidget);
} else {
expect(find.text(multiHunkPatch), findsOneWidget);
}
expect(tester.takeException(), isNull);
});
}
for (final cupertino in [false, true]) {
testWidgets(
'${cupertino ? 'Cupertino' : 'Material'} wide host keeps the native '
'segmented control',
(tester) async {
await tester.pumpWidget(
cupertino
? cupertinoHost(_diffDialogOpener(diffFile))
: materialHost(_diffDialogOpener(diffFile)),
);
await tester.tap(find.text('Open diff'));
await tester.pumpAndSettle();
expect(
cupertino
? find.byType(CupertinoSlidingSegmentedControl<DiffForm>)
: find.byType(SegmentedButton<DiffForm>),
findsOneWidget,
);
expect(find.text('Rendered'), findsOneWidget);
expect(find.text('Raw patch'), findsOneWidget);
expect(tester.takeException(), isNull);
},
);
}
}
@@ -415,6 +415,15 @@ void main() {
);
});
test('showRunChangesSummary is true only for a settled succeeded run', () {
expect(showRunChangesSummary('succeeded'), isTrue);
expect(showRunChangesSummary(' Succeeded '), isTrue);
for (final status in ['failed', 'running', 'waiting', 'canceled', '']) {
expect(showRunChangesSummary(status), isFalse, reason: status);
}
expect(showRunChangesSummary(null), isFalse);
});
test('header covers every empty-capture variant', () {
expect(
runChangesHeader(_run(unavailable: true, files: const [])),
@@ -0,0 +1,177 @@
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';
import 'package:pipelines_app/features/changes/changes.dart';
import 'package:pipelines_app/features/runs/data/runs_repository.dart';
import 'package:pipelines_app/features/runs/ui/run_changes_action.dart';
import 'package:pipelines_app/features/runs/ui/run_detail_view.dart';
import 'package:pipelines_app/features/runs/ui/runs_controller.dart';
import '../../changes/fixtures.dart';
enum _Platform { material, cupertino }
class _FakeGateway implements ApiGateway {
_FakeGateway(this.detail);
final JsonMap detail;
@override
Stream<JsonMap> get frames => const Stream<JsonMap>.empty();
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
if (type != 'get_run') throw UnsupportedError(type);
return Future.value({'run_detail': detail});
}
}
JsonMap _run({
JsonMap? fileChanges,
String status = 'succeeded',
String stepStatus = 'completed',
}) => {
'id': 9,
'title': 'Wiring run',
'name': 'release',
'status': status,
'steps': [
stepFixture(
stage: 'implementer',
sequence: 1,
status: stepStatus,
fileChanges: fileChanges,
),
stepFixture(
stage: 'reviewer',
sequence: 2,
status: stepStatus,
fileChanges: null,
),
],
};
Future<void> _pumpDetail(
WidgetTester tester,
_Platform platform,
RunsController controller,
) async {
tester.view.physicalSize = const Size(500, 1200);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final view = RunDetailView(controller: controller, onBack: () {});
await tester.pumpWidget(
platform == _Platform.material
? MaterialApp(home: Scaffold(body: view))
: CupertinoApp(
// The real host chooses Cupertino on iOS/macOS; state that platform
// without mutating the global debug override, as the Changes tests do.
builder: (context, app) => Theme(
data: ThemeData(platform: TargetPlatform.iOS),
child: app!,
),
home: CupertinoPageScaffold(child: view),
),
);
await tester.pumpAndSettle();
}
void main() {
for (final platform in _Platform.values) {
testWidgets(
'${platform.name}: Changes opens the recorded files, diff and returns',
(tester) async {
final controller = RunsController(
RunsRepository(
_FakeGateway(
_run(
fileChanges: captureFixture(
files: [
fileChangeFixture(
path: 'lib/feature.dart',
patch: multiHunkPatch,
),
],
),
),
),
),
);
addTearDown(controller.dispose);
await controller.select(9);
await _pumpDetail(tester, platform, controller);
await tester.tap(find.byKey(runChangesButtonKey));
await tester.pumpAndSettle();
expect(find.text('Changes'), findsOneWidget);
expect(find.text('lib/feature.dart'), findsOneWidget);
expect(
find.text('1 file changed · +2 -2 · capture incomplete'),
findsOneWidget,
);
// Visit numbers are per stage, so both stages' first visits say Visit 1.
expect(find.text('Visit 1 · completed'), findsNWidgets(2));
await tester.tap(
find.byKey(const ValueKey('change-1-lib/feature.dart')),
);
await tester.pumpAndSettle();
final rendered = tester
.widgetList<RichText>(find.byType(RichText))
.map((rich) => rich.text.toPlainText())
.join('\n');
expect(rendered, contains('+ added line'));
expect(rendered, contains('- removed line'));
if (platform == _Platform.material) {
await tester.tap(find.byTooltip('Close diff'));
} else {
await tester.tap(find.byIcon(CupertinoIcons.xmark));
}
await tester.pumpAndSettle();
expect(find.text('lib/feature.dart'), findsOneWidget);
if (platform == _Platform.material) {
await tester.tap(find.byTooltip('Back'));
} else {
await tester.tap(find.byType(CupertinoNavigationBarBackButton));
}
await tester.pumpAndSettle();
expect(find.text('Wiring run'), findsOneWidget);
expect(find.byKey(runChangesButtonKey), findsOneWidget);
expect(find.text('lib/feature.dart'), findsNothing);
},
);
testWidgets(
'${platform.name}: an unavailable capture keeps its gap wording',
(tester) async {
final diagnostic =
'Workspace snapshot unavailable; changes could not be compared.';
final controller = RunsController(
RunsRepository(
_FakeGateway(
_run(
fileChanges: captureFixture(
status: 'unavailable',
diagnostic: diagnostic,
),
),
),
),
);
addTearDown(controller.dispose);
await controller.select(9);
await _pumpDetail(tester, platform, controller);
await tester.tap(find.byKey(runChangesButtonKey));
await tester.pumpAndSettle();
expect(find.text('Changes · capture unavailable'), findsOneWidget);
expect(find.text(diagnostic), findsWidgets);
expect(find.text(emptyCaptureDetail), findsNothing);
expect(find.text('No changes observed'), findsNothing);
},
);
}
}
@@ -0,0 +1,204 @@
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';
import 'package:pipelines_app/features/runs/data/runs_repository.dart';
import 'package:pipelines_app/features/runs/ui/run_changes_action.dart';
import 'package:pipelines_app/features/runs/ui/run_detail_view.dart';
import 'package:pipelines_app/features/runs/ui/runs_controller.dart';
import '../../changes/fixtures.dart';
enum _Platform { material, cupertino }
class _FakeGateway implements ApiGateway {
_FakeGateway(this.detail);
final JsonMap detail;
@override
Stream<JsonMap> get frames => const Stream<JsonMap>.empty();
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
if (type != 'get_run') throw UnsupportedError(type);
return Future.value({'run_detail': detail});
}
}
JsonMap _run({
required String status,
JsonMap? fileChanges,
String stepStatus = 'completed',
}) => {
'id': 9,
'title': 'Wiring run',
'name': 'release',
'status': status,
'steps': [
stepFixture(
stage: 'implementer',
sequence: 1,
status: stepStatus,
fileChanges: fileChanges,
),
stepFixture(
stage: 'reviewer',
sequence: 2,
status: stepStatus,
fileChanges: null,
),
],
};
Future<void> _pumpDetail(
WidgetTester tester,
_Platform platform,
JsonMap run, {
Brightness brightness = Brightness.light,
}) async {
tester.view.physicalSize = const Size(500, 1200);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final controller = RunsController(RunsRepository(_FakeGateway(run)));
addTearDown(controller.dispose);
await controller.select(9);
final view = RunDetailView(controller: controller, onBack: () {});
await tester.pumpWidget(
platform == _Platform.material
? MaterialApp(
theme: ThemeData(brightness: brightness),
home: Scaffold(body: view),
)
: CupertinoApp(
theme: CupertinoThemeData(brightness: brightness),
builder: (context, app) => Theme(
data: ThemeData(platform: TargetPlatform.iOS),
child: app!,
),
home: CupertinoPageScaffold(child: view),
),
);
await tester.pumpAndSettle();
}
Future<void> _openChanges(
WidgetTester tester,
_Platform platform,
JsonMap run, {
Brightness brightness = Brightness.light,
}) async {
await _pumpDetail(tester, platform, run, brightness: brightness);
await tester.tap(find.byKey(runChangesButtonKey));
await tester.pumpAndSettle();
}
void main() {
test('the Changes action waits for the run to stop executing', () {
for (final status in ['queued', 'running', 'waiting', ' RUNNING ']) {
expect(showRunChangesAction({'status': status}), isFalse, reason: status);
}
for (final status in ['succeeded', 'failed', 'canceled', 'interrupted']) {
expect(showRunChangesAction({'status': status}), isTrue, reason: status);
}
// The server can keep a failed run flagged while one of its steps is still
// active; the snapshot page would go stale, so the flag wins.
expect(
showRunChangesAction({'status': 'failed', 'executing': true}),
isFalse,
);
expect(
showRunChangesAction({'status': 'succeeded', 'executing': false}),
isTrue,
);
});
for (final platform in _Platform.values) {
testWidgets(
'${platform.name}: a failed run keeps visit evidence, not a summary',
(tester) async {
await _openChanges(
tester,
platform,
_run(
status: 'failed',
fileChanges: captureFixture(
files: [fileChangeFixture(path: 'lib/feature.dart')],
),
),
);
// The web client shows the aggregate only for succeeded runs.
expect(find.textContaining('file changed ·'), findsNothing);
expect(
find.textContaining('The summary counts each path once'),
findsNothing,
);
// The visit's own recorded capture stays reachable.
expect(find.text('lib/feature.dart'), findsOneWidget);
expect(find.text('Visit 1 · completed'), findsNWidgets(2));
expect(tester.takeException(), isNull);
},
);
testWidgets(
'${platform.name}: an active run offers no snapshot Changes page',
(tester) async {
await _pumpDetail(
tester,
platform,
_run(status: 'running', stepStatus: 'running'),
);
// The opened page would not follow live captures, so an executing run
// has no action until the live visit pane can show them.
expect(find.byKey(runChangesButtonKey), findsNothing);
expect(find.text('Changes'), findsNothing);
expect(tester.takeException(), isNull);
},
);
testWidgets(
'${platform.name}: the Changes page follows a dark host theme',
(tester) async {
await _openChanges(
tester,
platform,
_run(
status: 'succeeded',
fileChanges: captureFixture(
files: [fileChangeFixture(path: 'lib/feature.dart')],
),
),
brightness: Brightness.dark,
);
final header = tester.widget<Text>(
find.textContaining('1 file changed'),
);
final color = header.style?.color;
expect(color, isNotNull);
expect(
color!.computeLuminance(),
greaterThan(0.5),
reason: 'section text must be light on a dark host: $color',
);
// The diff opens on the app Navigator, above the page's theme, so its
// own header must follow the host brightness too.
await tester.tap(
find.byKey(const ValueKey('change-1-lib/feature.dart')),
);
await tester.pumpAndSettle();
final title = tester.widget<Text>(find.text('Modified'));
final titleColor = title.style?.color;
expect(titleColor, isNotNull);
expect(
titleColor!.computeLuminance(),
greaterThan(0.5),
reason: 'diff header must be light on a dark host: $titleColor',
);
expect(tester.takeException(), isNull);
},
);
}
}