Merge branches 'worktree-agent-a6019135c1d229f82' and 'worktree-agent-a64fb2f79d15cc2be' into worktree-agent-a717651aa412e3b7c

This commit is contained in:
2026-12-03 00:41:39 +00:00
19 changed files with 1053 additions and 49 deletions
@@ -0,0 +1,148 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.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 'fixtures.dart';
import 'widget_hosts.dart';
String _patch(String path, String line) =>
'--- "a/$path"\n'
'+++ "b/$path"\n'
'@@ -1,1 +1,1 @@\n'
'-old $line\n'
'+new $line\n';
List<JsonMap> _steps() => [
stepFixture(
fileChanges: captureFixture(
files: [
fileChangeFixture(path: 'lib/a.dart', patch: _patch('lib/a.dart', 'A')),
fileChangeFixture(path: 'lib/b.dart', patch: _patch('lib/b.dart', 'B')),
fileChangeFixture(path: 'lib/c.dart', patch: _patch('lib/c.dart', 'C')),
],
),
),
];
Future<void> _pumpAt(
WidgetTester tester,
Size size, {
bool finalOnly = true,
}) async {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(
materialHost(ChangesViewer(steps: _steps(), finalOnly: finalOnly)),
);
await tester.pumpAndSettle();
}
bool _shows(String text) =>
find.textContaining(text, findRichText: true).evaluate().isNotEmpty;
void main() {
testWidgets('a wide pane lists the files beside the first file\'s diff', (
tester,
) async {
await _pumpAt(tester, const Size(1400, 900));
expect(find.byKey(const ValueKey('changes-final-split')), findsOneWidget);
expect(find.byType(FileDiffViewer), findsOneWidget);
expect(
find.byKey(const ValueKey('changes-split-diff-lib/a.dart')),
findsOneWidget,
);
expect(_shows('new A'), isTrue);
expect(_shows('new B'), isFalse);
});
testWidgets('tapping a file shows its diff without leaving the pane', (
tester,
) async {
await _pumpAt(tester, const Size(1400, 900));
await tester.tap(find.bySemanticsLabel(RegExp('^Show diff for lib/c')));
await tester.pumpAndSettle();
expect(find.byType(FileDiffPage), findsNothing);
expect(
find.byKey(const ValueKey('changes-split-diff-lib/c.dart')),
findsOneWidget,
);
expect(_shows('new C'), isTrue);
});
testWidgets('j/k and the arrows move between files once focused', (
tester,
) async {
await _pumpAt(tester, const Size(1400, 900));
await tester.tap(find.bySemanticsLabel(RegExp('^Show diff for lib/a')));
await tester.pumpAndSettle();
Future<void> press(LogicalKeyboardKey key) async {
await tester.sendKeyEvent(key);
await tester.pumpAndSettle();
}
await press(LogicalKeyboardKey.keyJ);
expect(_shows('new B'), isTrue);
await press(LogicalKeyboardKey.arrowDown);
expect(_shows('new C'), isTrue);
// The last file stays selected rather than wrapping.
await press(LogicalKeyboardKey.keyJ);
expect(_shows('new C'), isTrue);
await press(LogicalKeyboardKey.keyK);
expect(_shows('new B'), isTrue);
await press(LogicalKeyboardKey.arrowUp);
expect(_shows('new A'), isTrue);
// Enter opens the selected file on its own page.
await press(LogicalKeyboardKey.enter);
expect(find.byType(FileDiffPage), findsOneWidget);
});
testWidgets('a visit page splits too, under the visit heading', (
tester,
) async {
await _pumpAt(tester, const Size(1400, 900), finalOnly: false);
expect(
find.byKey(const ValueKey('changes-visit-split-implementer-1')),
findsOneWidget,
);
expect(find.textContaining('Visit 1'), findsOneWidget);
expect(_shows('new A'), isTrue);
});
testWidgets('a phone keeps one row per file opening its own page', (
tester,
) async {
await _pumpAt(tester, const Size(560, 1000));
expect(find.byKey(const ValueKey('changes-final-split')), findsNothing);
expect(find.byType(FileDiffViewer), findsNothing);
await tester.tap(find.bySemanticsLabel(RegExp('^Open diff for lib/b')));
await tester.pumpAndSettle();
expect(find.byType(FileDiffPage), findsOneWidget);
});
testWidgets(
'a detail pane beside a list splits from 720 px in a wide window',
(tester) async {
tester.view.physicalSize = const Size(1440, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
Widget pane(double width) => materialHost(
Align(
alignment: Alignment.topRight,
child: SizedBox(
width: width,
child: ChangesViewer(steps: _steps(), finalOnly: true),
),
),
);
await tester.pumpWidget(pane(900));
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('changes-final-split')), findsOneWidget);
await tester.pumpWidget(pane(600));
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('changes-final-split')), findsNothing);
},
);
}
@@ -0,0 +1,88 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:pipelines_app/features/pipelines/screen.dart';
import 'package:pipelines_app/features/pipelines/ui/run_pipeline_wording.dart';
import 'package:pipelines_app/features/pipelines/widgets/pipeline_row_actions.dart';
import 'package:pipelines_app/features/pipelines/pipeline_models.dart';
import 'package:pipelines_app/ui/layout/app_overflow_menu.dart';
import '../fixtures.dart';
import 'run_pipeline_launch_test.dart' show acceptedRun, launchGateway;
Future<void> _pump(WidgetTester tester, Size size, FakeGateway gateway) async {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(MaterialApp(home: PipelinesScreen(gateway: gateway)));
await tester.pumpAndSettle();
}
void main() {
SharedPreferences.setMockInitialValues({});
testWidgets('a wide list row has its own Run button opening the form', (
tester,
) async {
final fixture = PipelineFixture();
final gateway = launchGateway(fixture, onLaunch: (_) => acceptedRun(9));
await _pump(tester, const Size(1440, 900), gateway);
expect(find.byKey(pipelineRowRunKey(1)), findsOneWidget);
await tester.tap(find.byKey(pipelineRowRunKey(1)));
await tester.pumpAndSettle();
// The same New run form as the detail's Run, for the row's pipeline at
// its listed version; opening it starts nothing.
expect(find.byKey(runPipelinePromptKey), findsOneWidget);
expect(gateway.callsOf('get_pipeline').last.fields, {
'pipeline_id': 1,
'version': 2,
});
expect(gateway.callsOf('run_pipeline'), isEmpty);
// The row did not open the pipeline.
expect(find.byKey(const Key('pipeline-detail')), findsNothing);
});
testWidgets('a phone row offers Run… in its menu and no button', (
tester,
) async {
final fixture = PipelineFixture();
final gateway = launchGateway(fixture, onLaunch: (_) => acceptedRun(9));
await _pump(tester, const Size(560, 900), gateway);
expect(find.byKey(pipelineRowRunKey(2)), findsNothing);
await tester.tap(find.byKey(pipelineRowMenuKey(2)));
await tester.pumpAndSettle();
await tester.tap(find.text(pipelineRowRunLabel));
await tester.pumpAndSettle();
expect(find.byKey(runPipelinePromptKey), findsOneWidget);
expect(gateway.callsOf('get_pipeline').last.fields['pipeline_id'], 2);
});
test('an archived pipeline offers no Run, as its detail offers none', () {
final archived = PipelineSummary.fromJson({
...pipelineSummary(id: 4, name: 'Old'),
'archived_at': '2026-10-01T00:00:00Z',
});
void run(BuildContext _) {}
expect(
pipelineRowActions(pipeline: archived, wide: true, onRun: run),
isNull,
);
// Send to chat stays; only Run is withheld.
expect(
pipelineRowActions(
pipeline: archived,
wide: true,
onRun: run,
onOpenInChat: run,
),
isA<AppOverflowMenu<Object?>>(),
);
});
}
@@ -0,0 +1,156 @@
import 'dart:async';
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/actions/retry_wording.dart';
import 'package:pipelines_app/features/runs/actions/title_wording.dart';
import 'package:pipelines_app/features/runs/screen.dart';
import 'package:pipelines_app/features/runs/ui/run_failure_actions.dart';
import 'package:pipelines_app/features/runs/ui/run_more_menu.dart';
import 'run_retry_wiring_support.dart';
Future<void> _mount(
WidgetTester tester,
ApiGateway gateway, {
Future<void> Function(BuildContext, JsonMap)? onOpenInChat,
bool settle = true,
}) async {
tester.view.physicalSize = const Size(1200, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: RunsScreen(
gateway: gateway,
initialRunId: 7,
onOpenInChat: onOpenInChat,
),
),
),
);
if (settle) await tester.pumpAndSettle();
}
/// A gateway that lists run 7 but never answers its detail.
class _SlowDetailGateway implements ApiGateway {
final pending = Completer<JsonMap>();
@override
Stream<JsonMap> get frames => const Stream.empty();
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) =>
switch (type) {
'list_runs' => Future.value({
'runs': [
{'id': 7, 'title': 'Slow run', 'status': 'failed', 'name': 'p'},
],
}),
'get_run' => pending.future,
_ => Future.error(UnsupportedError(type)),
};
}
void main() {
testWidgets('the failure banner offers Retry, Run again… and Open in chat', (
tester,
) async {
final gateway = RetryWiringGateway();
addTearDown(gateway.framesController.close);
gateway.details[7] = {
...retryFailedDetail(),
'pipeline_id': 3,
'version': 2,
'failure_reason': 'The build stage exited with status 2.',
};
final opened = <JsonMap>[];
await _mount(
tester,
gateway,
onOpenInChat: (context, run) async => opened.add(run),
);
expect(find.text('The build stage exited with status 2.'), findsOneWidget);
expect(find.byKey(runFailureRetryKey), findsOneWidget);
expect(find.byKey(runFailureRunAgainKey), findsOneWidget);
expect(find.byKey(runFailureOpenInChatKey), findsOneWidget);
// Retry is the menu's retry prompt; nothing is sent until its confirm.
await tester.tap(find.byKey(runFailureRetryKey));
await tester.pumpAndSettle();
expect(find.text(retryDialogTitle(7)), findsOneWidget);
await tester.tap(find.byKey(retryKeepKey));
await tester.pumpAndSettle();
expect(gateway.retryCalls, isEmpty);
// Open in chat hands the run to the host's send-to-chat flow.
await tester.tap(find.byKey(runFailureOpenInChatKey));
await tester.pumpAndSettle();
expect(opened.single['id'], 7);
// Run again reads the run's pipeline for the pre-filled New run form.
await tester.tap(find.byKey(runFailureRunAgainKey));
await tester.pumpAndSettle();
expect(gateway.calls.map((call) => call.type), contains('get_pipeline'));
});
testWidgets('a failed run without a pipeline offers no Run again', (
tester,
) async {
final gateway = RetryWiringGateway();
addTearDown(gateway.framesController.close);
gateway.details[7] = {...retryFailedDetail(), 'failure_reason': 'Boom.'};
await _mount(tester, gateway);
expect(find.byKey(runFailureRetryKey), findsOneWidget);
expect(find.byKey(runFailureRunAgainKey), findsNothing);
expect(find.byKey(runFailureOpenInChatKey), findsNothing);
});
testWidgets('the more menu shows while the detail loads, items disabled', (
tester,
) async {
final gateway = _SlowDetailGateway();
await _mount(tester, gateway, settle: false);
await tester.pump();
await tester.pump(const Duration(milliseconds: 50));
expect(find.text('Loading run details…'), findsOneWidget);
expect(find.byKey(runMoreMenuKey), findsOneWidget);
await tester.tap(find.byKey(runMoreMenuKey));
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
final rename = tester.widget<PopupMenuItem<Object?>>(
find.ancestor(
of: find.text(runTitleActionLabel),
matching: find.byWidgetPredicate((w) => w is PopupMenuItem),
),
);
expect(rename.enabled, isFalse);
gateway.pending.complete({
'run_detail': {
'id': 7,
'title': 'Slow run',
'status': 'failed',
'name': 'p',
'steps': const <JsonMap>[],
},
});
await tester.tapAt(const Offset(2, 2));
await tester.pumpAndSettle();
await tester.tap(find.byKey(runMoreMenuKey));
await tester.pumpAndSettle();
final loaded = tester.widget<PopupMenuItem<Object?>>(
find.ancestor(
of: find.text(runTitleActionLabel),
matching: find.byWidgetPredicate((w) => w is PopupMenuItem),
),
);
expect(loaded.enabled, isTrue);
});
}