Files
pipelines/app/tool/pipelines_probe_fixture.dart
T
alan a44f31b989 feat(app): add native pipelines list and detail screen
Read-only Pipelines screen for the Flutter client:

- list_pipelines and list_runs with a last-run join, plus get_pipeline
  with an explicit version (0 = latest); no mutation requests.
- Name, run-presence, last-run-status and schedule filters; six sort
  orders; clear filters; truthful loading, empty and error states.
- Detail Summary, selectable Source and version history with selection
  and return to latest.
- Sequenced list/detail requests so stale replies cannot replace a newer
  selection or open a cleared one; refresh keeps the selected pipeline
  and version.
- Material controls on Android/desktop and Cupertino on iOS; a
  per-label segmented tab row at narrow widths and scaled text, with the
  native control kept wherever an equal share fits.
- Fixture probe entry and Chrome scripts for the rendered evidence;
  widget tests cover filters, sorting, formatting, sequencing, layout
  and the tab row.

Graph rendering remains P2: the Graph tab states that it is pending and
exposes a host hook. PipelinesScreen is not yet registered in the shell.

Evidence and limits: app/notes/P1.md.
2026-10-21 19:09:29 +01:00

243 lines
5.9 KiB
Dart

import 'dart:async';
import 'package:pipelines_app/core/api_gateway.dart';
/// Deterministic in-memory data for the browser fixture preview. This is not a
/// live connection and is used only by `tool/pipelines_probe_entry.dart`.
class PipelinesProbeGateway implements ApiGateway {
PipelinesProbeGateway({this.delay = const Duration(milliseconds: 120)});
final Duration delay;
static const _pipelines = <Map<String, dynamic>>[
{
'id': 3,
'name': 'Release verification',
'version': 3,
'stages': 4,
'created_at': '2026-09-28T10:12:00',
'updated_at': '2026-10-21T09:40:00',
'scheduled': true,
'schedule_count': 2,
'enabled_schedule_count': 1,
},
{
'id': 7,
'name': 'Nightly documentation',
'version': 1,
'stages': 2,
'created_at': '2026-10-02T18:20:00',
'updated_at': '2026-10-20T22:05:00',
'scheduled': true,
'schedule_count': 1,
'enabled_schedule_count': 1,
},
{
'id': 11,
'name': 'Hotfix triage',
'version': 2,
'stages': 3,
'created_at': '2026-10-11T08:00:00',
'updated_at': '2026-10-19T16:32:00',
'scheduled': false,
'schedule_count': 0,
'enabled_schedule_count': 0,
},
{
'id': 14,
'name': 'Legacy import (no schedule metadata)',
'version': 1,
'stages': 1,
'created_at': '2026-08-04T11:45:00',
'updated_at': '2026-10-14T12:10:00',
'scheduled': null,
'schedule_count': null,
'enabled_schedule_count': null,
},
];
static const _runs = <Map<String, dynamic>>[
{
'id': 488,
'pipeline_id': 3,
'status': 'succeeded',
'created_at': '2026-10-21T09:30:00',
'finished_at': '2026-10-21T09:34:12',
'executing': false,
},
{
'id': 487,
'pipeline_id': 7,
'status': 'running',
'created_at': '2026-10-21T09:20:00',
'finished_at': '',
'executing': true,
},
{
'id': 486,
'pipeline_id': 11,
'status': 'failed',
'created_at': '2026-10-19T16:20:00',
'finished_at': '2026-10-19T16:28:40',
'executing': false,
},
{
'id': 480,
'pipeline_id': 3,
'status': 'waiting',
'created_at': '2026-10-18T13:00:00',
'finished_at': '',
'executing': false,
},
];
static const _versionRows = <int, List<Map<String, dynamic>>>{
3: [
{'version': 1, 'stages': 2, 'created_at': '2026-09-28T10:12:00'},
{'version': 2, 'stages': 3, 'created_at': '2026-10-08T15:44:00'},
{'version': 3, 'stages': 4, 'created_at': '2026-10-21T09:12:00'},
],
7: [
{'version': 1, 'stages': 2, 'created_at': '2026-10-02T18:20:00'},
],
11: [
{'version': 1, 'stages': 2, 'created_at': '2026-10-11T08:00:00'},
{'version': 2, 'stages': 3, 'created_at': '2026-10-18T09:30:00'},
],
14: [
{'version': 1, 'stages': 1, 'created_at': '2026-08-04T11:45:00'},
],
};
static const _sources = <int, String>{
3: '''
name: Release verification
stages:
inspect:
type: model
output: report
edges:
pass: verify
fail: '#failure'
verify:
type: model
output: verdict
edges:
pass: package
fail: '#failure'
package:
type: human
output: approval
edges:
approve: publish
hold: '#success'
publish:
type: model
output: release
edges:
done: '#success'
''',
7: '''
name: Nightly documentation
stages:
collect:
type: model
output: notes
edges:
done: write
write:
type: model
output: report
edges:
done: '#success'
''',
11: '''
name: Hotfix triage
stages:
classify:
type: model
output: severity
edges:
urgent: patch
normal: document
patch:
type: model
output: change
edges:
done: '#success'
document:
type: human
output: note
edges:
done: '#success'
''',
14: '''
name: Legacy import
stages:
import:
type: model
output: summary
edges:
done: '#success'
''',
};
@override
Stream<JsonMap> get frames => const Stream<JsonMap>.empty();
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
if (delay > Duration.zero) await Future<void>.delayed(delay);
switch (type) {
case 'list_pipelines':
return {'type': 'pipelines', 'pipelines': _pipelines};
case 'list_runs':
return {'type': 'runs', 'runs': _runs};
case 'get_pipeline':
return _detail(
fields['pipeline_id'] as int? ?? 0,
fields['version'] as int? ?? 0,
);
}
return {'type': 'error', 'error': 'The fixture does not answer $type.'};
}
JsonMap _detail(int id, int requestedVersion) {
final summary = _pipelines.where((pipeline) => pipeline['id'] == id).first;
final versions = _versionRows[id] ?? const <Map<String, dynamic>>[];
final latest = versions.isEmpty
? summary['version'] as int
: versions.last['version'] as int;
final resolved = requestedVersion > 0 ? requestedVersion : latest;
final version = versions.firstWhere(
(row) => row['version'] == resolved,
orElse: () => versions.isEmpty ? summary : versions.last,
);
return {
'type': 'pipeline',
'detail': {
...summary,
'version': resolved,
'stages': version['stages'] as int,
'latest_version': latest,
'version_created_at': _versionCreatedAt(versions, resolved),
'content_hash': 'sha256:fixture-$id-v$resolved',
'source': '${_sources[id]}\n# selected version $resolved\n',
'versions': versions,
},
};
}
static String _versionCreatedAt(
List<Map<String, dynamic>> versions,
int resolved,
) {
for (final version in versions) {
if (version['version'] == resolved) {
return version['created_at'] as String;
}
}
return versions.isEmpty ? '' : versions.last['created_at'] as String;
}
}