Merge: archive and unarchive pipelines

# Conflicts:
#	internal/cli/commands.go
#	internal/pipeline/store.go
This commit is contained in:
2026-11-04 23:39:02 +00:00
30 changed files with 1206 additions and 78 deletions
@@ -25,6 +25,7 @@ class PipelineSummary {
this.recordedStages,
this.flowStages,
this.shape,
this.archivedAt,
});
factory PipelineSummary.fromJson(PipelineJson json) {
@@ -47,6 +48,7 @@ class PipelineSummary {
scheduleCount: scheduleCount,
enabledScheduleCount: _optionalInt(json['enabled_schedule_count']),
shape: _jsonObject(json['shape']),
archivedAt: _optionalString(json['archived_at']),
);
}
@@ -77,6 +79,12 @@ class PipelineSummary {
/// empty flow.
final PipelineJson? shape;
/// When the pipeline was archived, or null while it is active. An archived
/// pipeline keeps its versions, runs and name but cannot start runs.
final String? archivedAt;
bool get archived => archivedAt != null;
/// The list row's stage count from recorded values only: the summary's own
/// count, else the recorded flow's count, else its plain [stages] field.
/// Zero only when none was recorded, which is the web row's own fallback.
@@ -146,6 +154,7 @@ class PipelineDetail extends PipelineSummary {
super.recordedStages,
super.flowStages,
super.shape,
super.archivedAt,
required this.latestVersion,
required this.versionCreatedAt,
required this.contentHash,
@@ -170,6 +179,7 @@ class PipelineDetail extends PipelineSummary {
recordedStages: summary.recordedStages,
flowStages: summary.flowStages,
shape: summary.shape,
archivedAt: summary.archivedAt,
latestVersion: _int(json['latest_version']),
versionCreatedAt: _string(json['version_created_at']),
contentHash: _string(json['content_hash']),
@@ -270,6 +280,9 @@ int? _optionalInt(Object? value) {
String _string(Object? value) => value is String ? value : '';
String? _optionalString(Object? value) =>
value is String && value.isNotEmpty ? value : null;
/// The stage count recorded by a list row's optional flow summary (`shape`),
/// or null when that flow was not recorded with a stage list.
int? _flowStageCount(Object? value) {
@@ -11,16 +11,19 @@ class PipelineRequestException implements Exception {
String toString() => message;
}
/// Read-only pipeline requests. Request shapes mirror `web/src/repository.js`
/// exactly; no mutation of server state is offered here.
/// Pipeline requests. Reads mirror `web/src/repository.js`; the one mutation
/// is archiving, which keeps every version and run.
class PipelinesRepository {
PipelinesRepository(this._gateway);
final ApiGateway _gateway;
/// `list_pipelines` -> the whole `pipelines` array.
/// `list_pipelines` -> the whole `pipelines` array, archived ones included
/// (each marked by `archived_at`) so the list can offer an Archived view.
Future<List<PipelineSummary>> listPipelines() async {
final envelope = await _gateway.call('list_pipelines');
final envelope = await _gateway.call('list_pipelines', {
'include_archived': true,
});
_throwIfError(envelope, 'The server returned no pipeline list.');
final type = envelope['type'];
if (type != null && type != 'pipelines') {
@@ -69,6 +72,28 @@ class PipelinesRepository {
return PipelineDetail.fromJson(Map<String, dynamic>.from(detail));
}
/// `archive_pipeline` / `unarchive_pipeline`, guarded by the latest
/// version the operator saw. Replies with the updated detail.
Future<PipelineDetail> setArchived(
int id, {
required bool archived,
required int expectedVersion,
}) async {
final type = archived ? 'archive_pipeline' : 'unarchive_pipeline';
final envelope = await _gateway.call(type, {
'pipeline_id': id,
if (expectedVersion > 0) 'expected_version': expectedVersion,
});
const fallback = 'The server did not confirm the change.';
_throwIfError(envelope, fallback);
final expected = archived ? 'pipeline_archived' : 'pipeline_unarchived';
final detail = envelope['detail'];
if (envelope['type'] != expected || detail is! Map) {
throw const PipelineRequestException(fallback);
}
return PipelineDetail.fromJson(Map<String, dynamic>.from(detail));
}
/// `list_runs` is read only here for the pipeline list's last-run join.
Future<List<PipelineRun>> listRuns() async {
final envelope = await _gateway.call('list_runs');
@@ -27,7 +27,9 @@ class PipelinesController extends ChangeNotifier {
final Set<String> _loadedPendingRuns = {};
final Map<String, int> _pendingRunGenerations = {};
List<PipelineSummary> _pipelines = const <PipelineSummary>[];
/// Every row the server listed, archived ones included.
List<PipelineSummary> _allPipelines = const <PipelineSummary>[];
bool _showArchived = false;
List<PipelineRun> _runs = const <PipelineRun>[];
PipelineFilters _filters = emptyPipelineFilters;
PipelineSort _sort = PipelineSort.serverOrder;
@@ -60,7 +62,13 @@ class PipelinesController extends ChangeNotifier {
final Map<String, RunPipelineIntent> _pendingRuns =
<String, RunPipelineIntent>{};
List<PipelineSummary> get pipelines => _pipelines;
/// The rows of the current view: active pipelines, or with [showArchived]
/// only the archived ones. Archived pipelines never mix into the main list.
List<PipelineSummary> get pipelines => List.unmodifiable(
_allPipelines.where((pipeline) => pipeline.archived == _showArchived),
);
bool get showArchived => _showArchived;
PipelineFilters get filters => _filters;
PipelineSort get sort => _sort;
bool get listLoading => _listLoading;
@@ -86,12 +94,13 @@ class PipelinesController extends ChangeNotifier {
/// The rows after sorting and filtering, using the same pure rules as web.
List<PipelineSummary> get visiblePipelines {
final runs = latestRuns;
final sorted = sortPipelines(_pipelines, _sort, runs);
final sorted = sortPipelines(pipelines, _sort, runs);
return filterPipelines(sorted, _filters, runs, _runsLoaded);
}
PipelineEmptyState? get emptyState =>
pipelineListEmptyState(_pipelines, visiblePipelines, _filters);
PipelineEmptyState? get emptyState => _showArchived && pipelines.isEmpty
? const PipelineEmptyState('No archived pipelines.')
: pipelineListEmptyState(pipelines, visiblePipelines, _filters);
/// Reloads the list and runs and re-reads the current detail. The selection
/// (pipeline id and requested version) is deliberately preserved.
@@ -110,7 +119,7 @@ class PipelinesController extends ChangeNotifier {
try {
final rows = await _repository.listPipelines();
if (!_current(_listSequence, token)) return;
_pipelines = rows;
_allPipelines = rows;
_pipelinesLoaded = true;
_listError = null;
} catch (error) {
@@ -213,6 +222,35 @@ class PipelinesController extends ChangeNotifier {
_notify();
}
/// Switches between the active list and the Archived view.
void setShowArchived(bool value) {
if (_showArchived == value) return;
_showArchived = value;
_notify();
}
/// Archives or unarchives [detail] and refreshes the list. Returns the
/// server's refusal (an enabled schedule, a newer version) verbatim, or
/// null on success.
Future<String?> setArchived(PipelineDetail detail, bool archived) async {
try {
final updated = await _repository.setArchived(
detail.id,
archived: archived,
expectedVersion: detail.latestVersion,
);
if (_disposed) return null;
if (_selectedId == detail.id && _selectedVersion == 0) {
_detail = updated;
}
_notify();
} catch (error) {
return pipelineErrorMessage(error);
}
await load();
return null;
}
void setSort(PipelineSort sort) {
_sort = sort;
_notify();
@@ -0,0 +1,179 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../ui/adaptive/segmented_bar_overflow.dart';
import '../../../ui/layout/app_overflow_menu.dart';
import '../pipeline_models.dart';
import '../pipelines_controller.dart';
import 'pipeline_controls.dart';
import 'pipeline_detail_styles.dart';
/// The confirmation body: archiving hides, it never deletes.
String archiveConfirmation(String name) =>
'$name leaves the pipeline list and can no longer start runs. Its '
'versions, runs, artifacts and search history are kept, and you can '
'unarchive it from the Archived list at any time.';
/// The open pipeline's own actions menu in its bar: Archive or Unarchive.
/// A narrow bar moves it into the bar's More menu as one entry.
Widget pipelineActionsMenu(
BuildContext context,
PipelinesController controller,
PipelineDetail detail,
) {
final archived = detail.archived;
final label = archived ? 'Unarchive' : 'Archive…';
void run(BuildContext context) =>
archiveOrUnarchive(context, controller, detail);
return SegmentedOverflowAction(
overflowEntry: SegmentedOverflowEntry(
label: archived ? 'Unarchive pipeline' : 'Archive pipeline…',
icon: useCupertinoControls(context)
? CupertinoIcons.archivebox
: Icons.archive_outlined,
onPressed: () => run(context),
),
child: AppOverflowMenu<bool>(
key: const Key('pipeline-actions-menu'),
label: 'Pipeline actions',
sheetTitle: detail.displayName,
cupertino: useCupertinoControls(context),
actions: [
AppMenuAction(
key: Key(archived ? 'pipeline-unarchive' : 'pipeline-archive'),
value: true,
label: label,
),
],
onSelected: (context, _) => run(context),
),
);
}
/// Archives (after confirmation) or unarchives [detail], reporting a server
/// refusal such as an enabled schedule in a dialog.
Future<void> archiveOrUnarchive(
BuildContext context,
PipelinesController controller,
PipelineDetail detail,
) async {
final archiving = !detail.archived;
if (archiving && !await _confirmArchive(context, detail.displayName)) return;
final error = await controller.setArchived(detail, archiving);
if (error == null || !context.mounted) return;
await _showRefusal(
context,
archiving ? 'Could not archive' : 'Could not unarchive',
error,
);
}
/// The notice an archived pipeline's detail leads with.
class PipelineArchivedNotice extends StatelessWidget {
const PipelineArchivedNotice({
super.key,
required this.controller,
required this.detail,
});
final PipelinesController controller;
final PipelineDetail detail;
@override
Widget build(BuildContext context) {
return Padding(
key: const Key('pipeline-archived-notice'),
padding: const EdgeInsets.fromLTRB(16, 8, 16, 4),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Archived. Its history is kept; unarchive it to run it again.',
style: pipelineMutedStyle(context),
),
PipelineTextButton(
key: const Key('pipeline-archived-unarchive'),
label: 'Unarchive',
onPressed: () => archiveOrUnarchive(context, controller, detail),
),
],
),
);
}
}
Future<bool> _confirmArchive(BuildContext context, String name) async {
final title = Text('Archive $name?');
final body = Text(archiveConfirmation(name));
final confirmed = useCupertinoControls(context)
? await showCupertinoDialog<bool>(
context: context,
builder: (context) => CupertinoAlertDialog(
title: title,
content: body,
actions: [
CupertinoDialogAction(
onPressed: () => Navigator.pop(context, false),
child: const Text('Cancel'),
),
CupertinoDialogAction(
key: const Key('pipeline-archive-confirm'),
isDefaultAction: true,
onPressed: () => Navigator.pop(context, true),
child: const Text('Archive'),
),
],
),
)
: await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: title,
content: body,
actions: [
TextButton(
onPressed: () => Navigator.pop(context, false),
child: const Text('Cancel'),
),
FilledButton(
key: const Key('pipeline-archive-confirm'),
onPressed: () => Navigator.pop(context, true),
child: const Text('Archive'),
),
],
),
);
return confirmed == true;
}
Future<void> _showRefusal(BuildContext context, String title, String message) {
if (useCupertinoControls(context)) {
return showCupertinoDialog<void>(
context: context,
builder: (context) => CupertinoAlertDialog(
title: Text(title),
content: Text(message),
actions: [
CupertinoDialogAction(
isDefaultAction: true,
onPressed: () => Navigator.pop(context),
child: const Text('OK'),
),
],
),
);
}
return showDialog<void>(
context: context,
builder: (context) => AlertDialog(
title: Text(title),
content: Text(message),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('OK'),
),
],
),
);
}
@@ -14,6 +14,7 @@ import '../pipeline_models.dart';
import '../pipeline_query.dart';
import '../pipelines_controller.dart';
import '../ui/run_pipeline_action.dart';
import 'pipeline_archive_action.dart';
import 'pipeline_controls.dart';
import 'pipeline_bar_buttons.dart';
import '../../../ui/text/markdown_source_view.dart';
@@ -114,6 +115,8 @@ class _PipelineDetailPanelState extends State<PipelineDetailPanel> {
_applyStageRequest(context, detail);
final notices = [
if (!inBar) _header(context, detail),
if (detail.archived)
PipelineArchivedNotice(controller: _controller, detail: detail),
if (_controller.detailLoading)
const Padding(
padding: EdgeInsets.symmetric(horizontal: 16),
@@ -394,8 +397,9 @@ class _PipelineDetailPanelState extends State<PipelineDetailPanel> {
);
}
/// Runs and the primary Run: the top bar's actions, never floating over
/// the content (where they used to cover the version history).
/// Runs, the primary Run and the pipeline's actions menu: the top bar's
/// actions, never floating over the content (where they used to cover the
/// version history). An archived pipeline cannot run, so it offers no Run.
List<Widget> _actions(BuildContext context, PipelineDetail detail) => [
pipelineBarIconButton(
context,
@@ -409,13 +413,15 @@ class _PipelineDetailPanelState extends State<PipelineDetailPanel> {
? null
: () => widget.onViewPipelineRuns!(detail.id),
),
RunPipelineAction(
controller: _controller,
detail: detail,
gateway: widget.gateway,
onRunStarted: widget.onRunStarted,
inBar: true,
),
if (!detail.archived)
RunPipelineAction(
controller: _controller,
detail: detail,
gateway: widget.gateway,
onRunStarted: widget.onRunStarted,
inBar: true,
),
pipelineActionsMenu(context, _controller, detail),
];
Widget _source(BuildContext context, PipelineDetail detail) {
@@ -82,18 +82,24 @@ class PipelineListPanel extends StatelessWidget {
/// The web's compact toolbar: filter (whose page carries the name search),
/// sort and clear, on the list's 12px inset with a separator underneath.
/// All pipelines, or only those with a schedule.
/// All pipelines, only those with a schedule, or the archived ones.
Widget _scope(BuildContext context, PipelineFilters filters) {
final scheduled = filters.schedule == ScheduleFilter.scheduled;
void pick(bool value) => controller.setFilters(
filters.copyWith(
schedule: value ? ScheduleFilter.scheduled : ScheduleFilter.any,
),
);
final control = PipelineScopeControl(
scheduled: scheduled,
onSelected: pick,
);
final scope = controller.showArchived
? PipelineScope.archived
: filters.schedule == ScheduleFilter.scheduled
? PipelineScope.scheduled
: PipelineScope.all;
void pick(PipelineScope value) {
controller.setShowArchived(value == PipelineScope.archived);
final schedule = value == PipelineScope.scheduled
? ScheduleFilter.scheduled
: ScheduleFilter.any;
if (filters.schedule != schedule) {
controller.setFilters(filters.copyWith(schedule: schedule));
}
}
final control = PipelineScopeControl(scope: scope, onSelected: pick);
return Padding(
padding: const EdgeInsets.fromLTRB(
kPipelineListInset,
@@ -3,18 +3,32 @@ import 'package:flutter/material.dart';
import 'pipeline_controls.dart';
/// The list's scope: every active pipeline, only scheduled ones, or the
/// archived pipelines (which the other two never show).
enum PipelineScope {
all('All'),
scheduled('Scheduled'),
archived('Archived');
const PipelineScope(this.label);
final String label;
}
/// Uses a native picker when the segmented labels cannot fit at the user's
/// text scale. The decision is content-measured, not a fixed pane width.
class PipelineScopeControl extends StatelessWidget {
const PipelineScopeControl({
super.key,
required this.scheduled,
required this.scope,
required this.onSelected,
});
final bool scheduled;
final ValueChanged<bool> onSelected;
final PipelineScope scope;
final ValueChanged<PipelineScope> onSelected;
static const labels = {false: 'All', true: 'Scheduled'};
static final labels = {
for (final scope in PipelineScope.values) scope: scope.label,
};
@override
Widget build(BuildContext context) {
@@ -36,30 +50,31 @@ class PipelineScopeControl extends StatelessWidget {
builder: (context, constraints) {
if (constraints.maxWidth >= requiredWidth) {
return cupertino
? CupertinoSlidingSegmentedControl<bool>(
? CupertinoSlidingSegmentedControl<PipelineScope>(
key: const Key('pipeline-scope'),
groupValue: scheduled,
onValueChanged: (value) => onSelected(value ?? false),
groupValue: scope,
onValueChanged: (value) =>
onSelected(value ?? PipelineScope.all),
children: {
for (final entry in labels.entries)
entry.key: Text(entry.value),
},
)
: SegmentedButton<bool>(
: SegmentedButton<PipelineScope>(
key: const Key('pipeline-scope'),
showSelectedIcon: false,
segments: [
for (final entry in labels.entries)
ButtonSegment(value: entry.key, label: Text(entry.value)),
],
selected: {scheduled},
selected: {scope},
onSelectionChanged: (value) => onSelected(value.single),
);
}
if (!cupertino) {
return DropdownButton<bool>(
return DropdownButton<PipelineScope>(
key: const Key('pipeline-scope'),
value: scheduled,
value: scope,
isExpanded: true,
items: [
for (final entry in labels.entries)
@@ -104,7 +119,7 @@ class PipelineScopeControl extends StatelessWidget {
children: [
Expanded(
child: Text(
labels[scheduled]!,
labels[scope]!,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
@@ -0,0 +1,184 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/pipelines/screen.dart';
import 'package:pipelines_app/features/pipelines/ui/run_pipeline_action.dart';
import 'fixtures.dart';
import 'test_helpers.dart';
/// A fixture server that remembers archive state, like the real one: the list
/// carries `archived_at` and archive replies return the updated detail.
FakeGateway archiveGateway(PipelineFixture fixture, {String? refusal}) {
final archived = <int, String>{};
Map<String, dynamic> mark(Map<String, dynamic> row) => {
...row,
if (archived[row['id']] != null) 'archived_at': archived[row['id']],
};
return FakeGateway((type, fields) {
switch (type) {
case 'list_pipelines':
return pipelineListReply([
for (final row in fixture.summaries) mark(row),
]);
case 'list_runs':
return runListReply(fixture.runs);
case 'get_pipeline':
return pipelineDetailReply(
mark(
fixture.detailFor(
fields['pipeline_id'] as int,
fields['version'] as int,
)!,
),
);
case 'archive_pipeline' || 'unarchive_pipeline':
if (refusal != null) return errorReply(refusal);
final id = fields['pipeline_id'] as int;
if (type == 'archive_pipeline') {
archived[id] = '2026-11-04T12:00:00Z';
} else {
archived.remove(id);
}
return {
'type': type == 'archive_pipeline'
? 'pipeline_archived'
: 'pipeline_unarchived',
'detail': mark(fixture.detailFor(id, 0)!),
};
}
return errorReply('unexpected $type');
});
}
Future<void> pump(
WidgetTester tester,
FakeGateway gateway, {
bool cupertino = false,
}) async {
tester.view.physicalSize = const Size(1100, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final screen = PipelinesScreen(gateway: gateway);
await tester.pumpWidget(
cupertino ? CupertinoApp(home: screen) : MaterialApp(home: screen),
);
await tester.pumpAndSettle();
}
Finder rowNamed(String name) => find.descendant(
of: find.byKey(const Key('pipeline-list')),
matching: find.text(name),
);
Future<void> openMenuItem(WidgetTester tester, String key) async {
await tester.tap(find.byKey(const Key('pipeline-actions-menu')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(Key(key)));
await tester.pumpAndSettle();
}
void main() {
testWidgets('Archive from the pipeline menu hides it after confirmation', (
tester,
) async {
final gateway = archiveGateway(PipelineFixture());
await pump(tester, gateway);
expect(gateway.callsOf('list_pipelines').first.fields, {
'include_archived': true,
});
await tester.tap(rowNamed('Beta deploy'));
await tester.pumpAndSettle();
await openMenuItem(tester, 'pipeline-archive');
expect(find.text('Archive Beta deploy?'), findsOneWidget);
expect(
find.textContaining('runs, artifacts and search history are kept'),
findsOneWidget,
);
await tester.tap(find.text('Cancel'));
await tester.pumpAndSettle();
expect(gateway.callsOf('archive_pipeline'), isEmpty);
await openMenuItem(tester, 'pipeline-archive');
await tester.tap(find.byKey(const Key('pipeline-archive-confirm')));
await tester.pumpAndSettle();
expect(gateway.callsOf('archive_pipeline').single.fields, {
'pipeline_id': 2,
'expected_version': 1,
});
expect(rowNamed('Beta deploy'), findsNothing);
expect(rowNamed('Alpha review'), findsOneWidget);
// The open detail stays, says it is archived and offers no Run.
expect(find.byKey(const Key('pipeline-archived-notice')), findsOneWidget);
expect(find.byType(RunPipelineAction), findsNothing);
});
testWidgets('the Archived scope lists archived pipelines and unarchives', (
tester,
) async {
final gateway = archiveGateway(PipelineFixture());
await pump(tester, gateway);
await tester.tap(rowNamed('Gamma legacy'));
await tester.pumpAndSettle();
await openMenuItem(tester, 'pipeline-archive');
await tester.tap(find.byKey(const Key('pipeline-archive-confirm')));
await tester.pumpAndSettle();
await pickScope(tester, 'Archived');
expect(rowNamed('Gamma legacy'), findsOneWidget);
expect(rowNamed('Alpha review'), findsNothing);
expect(rowNamed('Beta deploy'), findsNothing);
await openMenuItem(tester, 'pipeline-unarchive');
expect(gateway.callsOf('unarchive_pipeline').single.fields, {
'pipeline_id': 3,
'expected_version': 1,
});
expect(find.text('No archived pipelines.'), findsOneWidget);
expect(find.byKey(const Key('pipeline-archived-notice')), findsNothing);
await pickScope(tester, 'All');
expect(rowNamed('Gamma legacy'), findsOneWidget);
});
testWidgets('a refused archive shows the server reason', (tester) async {
const reason =
'pipeline "Alpha review" has enabled schedule(s) "nightly" (#4); '
'pause or repoint them before archiving';
final gateway = archiveGateway(PipelineFixture(), refusal: reason);
await pump(tester, gateway);
await tester.tap(rowNamed('Alpha review'));
await tester.pumpAndSettle();
await openMenuItem(tester, 'pipeline-archive');
await tester.tap(find.byKey(const Key('pipeline-archive-confirm')));
await tester.pumpAndSettle();
expect(find.text('Could not archive'), findsOneWidget);
expect(find.text(reason), findsOneWidget);
await tester.tap(find.text('OK'));
await tester.pumpAndSettle();
expect(rowNamed('Alpha review'), findsOneWidget);
});
testWidgets('Cupertino archives through the action sheet and alert', (
tester,
) async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
try {
final gateway = archiveGateway(PipelineFixture());
await pump(tester, gateway, cupertino: true);
await tester.tap(rowNamed('Beta deploy'));
await tester.pumpAndSettle();
await openMenuItem(tester, 'pipeline-archive');
expect(find.byType(CupertinoAlertDialog), findsOneWidget);
await tester.tap(find.byKey(const Key('pipeline-archive-confirm')));
await tester.pumpAndSettle();
expect(gateway.callsOf('archive_pipeline'), hasLength(1));
expect(rowNamed('Beta deploy'), findsNothing);
} finally {
debugDefaultTargetPlatformOverride = null;
}
});
}
@@ -9,14 +9,14 @@ void main() {
testWidgets(
'native scope remains usable at $width, Cupertino=$cupertino',
(tester) async {
var scheduled = false;
var scope = PipelineScope.all;
final control = StatefulBuilder(
builder: (context, setState) => Center(
child: SizedBox(
width: width,
child: PipelineScopeControl(
scheduled: scheduled,
onSelected: (value) => setState(() => scheduled = value),
scope: scope,
onSelected: (value) => setState(() => scope = value),
),
),
),
@@ -35,7 +35,7 @@ void main() {
await tester.tap(find.text('Scheduled'));
}
await tester.pumpAndSettle();
expect(scheduled, isTrue);
expect(scope, PipelineScope.scheduled);
expect(tester.takeException(), isNull);
},
);
@@ -50,7 +50,10 @@ void main() {
width: 500,
child: Align(
alignment: AlignmentDirectional.centerStart,
child: PipelineScopeControl(scheduled: false, onSelected: (_) {}),
child: PipelineScopeControl(
scope: PipelineScope.all,
onSelected: (_) {},
),
),
),
),
@@ -31,7 +31,7 @@ void main() {
'list_pipelines',
'list_runs',
]);
expect(gateway.calls[0].fields, isEmpty);
expect(gateway.calls[0].fields, {'include_archived': true});
expect(gateway.calls[1].fields, isEmpty);
expect(controller.pipelines.map((pipeline) => pipeline.id), [1, 2, 3]);
expect(controller.pipelinesLoaded, isTrue);
@@ -127,24 +127,12 @@ void main() {
expect(find.text('Alpha review'), findsOneWidget);
expect(find.text('Gamma legacy'), findsOneWidget);
await tester.tap(
find.descendant(
of: find.byKey(const Key('pipeline-scope')),
matching: find.text('Scheduled'),
),
);
await tester.pumpAndSettle();
await pickScope(tester, 'Scheduled');
// Beta has no schedule in the fixture; Alpha has one.
expect(find.text('Alpha review'), findsOneWidget);
expect(find.text('Beta deploy'), findsNothing);
await tester.tap(
find.descendant(
of: find.byKey(const Key('pipeline-scope')),
matching: find.text('All'),
),
);
await tester.pumpAndSettle();
await pickScope(tester, 'All');
expect(find.text('Beta deploy'), findsOneWidget);
});
@@ -115,13 +115,16 @@ void main() {
expect(find.bySemanticsLabel('View runs of Alpha review'), findsOneWidget);
// Run and Runs share the detail pane's actions pill at the top right,
// Runs before the primary Run; nothing floats over the content.
// Runs before the primary Run and the pipeline's overflow menu last;
// nothing floats over the content.
final runs = tester.getRect(find.byKey(const Key('pipeline-view-runs')));
final run = tester.getRect(find.byKey(runPipelineActionKey));
final menu = tester.getRect(find.byKey(const Key('pipeline-actions-menu')));
final screen = tester.view.physicalSize / tester.view.devicePixelRatio;
expect(runs.right, lessThanOrEqualTo(run.left));
expect(run.right, lessThanOrEqualTo(menu.left));
expect((runs.center.dy - run.center.dy).abs(), lessThan(1));
expect(run.right, greaterThan(screen.width - 40));
expect(menu.right, greaterThan(screen.width - 40));
expect(run.bottom, lessThan(screen.height / 4));
await tester.tap(find.byKey(const Key('pipeline-view-runs')));
expect(opened, [1]);
@@ -44,3 +44,20 @@ Future<void> pumpWide(WidgetTester tester, FakeGateway gateway) async {
Finder selectableText(String text) => find.byWidgetPredicate(
(widget) => widget is SelectableText && widget.data == text,
);
/// Picks a scope from the segments, or from the menu a pane too narrow for
/// the segments shows instead.
Future<void> pickScope(WidgetTester tester, String label) async {
final segment = find.descendant(
of: find.byKey(const Key('pipeline-scope')),
matching: find.text(label),
);
if (segment.evaluate().isEmpty) {
await tester.tap(find.byKey(const Key('pipeline-scope')));
await tester.pumpAndSettle();
await tester.tap(find.text(label).last);
} else {
await tester.tap(segment);
}
await tester.pumpAndSettle();
}
@@ -225,7 +225,19 @@ List<JsonMap> probeRuns() => [
..._fillerRuns(),
];
/// Pipelines this fixture session archived, with their archive time.
final _probeArchived = <int, String>{};
List<JsonMap> probePipelines() => [
for (final pipeline in _probePipelineRows())
{
...pipeline,
if (_probeArchived[pipeline['id']] != null)
'archived_at': _probeArchived[pipeline['id']],
},
];
List<JsonMap> _probePipelineRows() => [
{
'id': 24,
'name': 'Release train',
@@ -503,6 +515,29 @@ JsonMap? probeReply(JsonMap request) {
'type': 'pipeline',
'detail': probePipelineDetail(pipelineId, version is int ? version : 0),
};
case 'archive_pipeline':
case 'unarchive_pipeline':
// Mirrors the server: an enabled schedule blocks archiving.
final pipelineId = request['pipeline_id'];
final row = probePipelines().where((p) => p['id'] == pipelineId);
if (row.isEmpty) return error('pipeline not found');
final archive = type == 'archive_pipeline';
if (archive && (row.first['enabled_schedule_count'] as int) > 0) {
return error(
'pipeline "${row.first['name']}" has enabled schedule(s) '
'"Nightly docs" (#3); pause or repoint them before archiving',
);
}
if (archive) {
_probeArchived[pipelineId as int] = '2026-10-20T09:30:00Z';
} else {
_probeArchived.remove(pipelineId);
}
return {
'id': id,
'type': archive ? 'pipeline_archived' : 'pipeline_unarchived',
'detail': probePipelineDetail(pipelineId as int, 0),
};
case 'search':
// The app must send exactly the browser's SearchRequest body; anything
// else is answered with a visible refusal so the capture cannot pass.