From 5e682bac3a8c96254eae23dbbe2dc0288fe4e98b Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Thu, 22 Oct 2026 03:00:32 +0100 Subject: [PATCH] feat(app): label pipeline rows from recorded version and stages --- .../features/pipelines/pipeline_models.dart | 37 ++++- .../features/pipelines/pipeline_query.dart | 13 +- .../pipelines/pipeline_row_metadata_test.dart | 128 ++++++++++++++++++ 3 files changed, 175 insertions(+), 3 deletions(-) create mode 100644 app/test/features/pipelines/pipeline_row_metadata_test.dart diff --git a/app/lib/features/pipelines/pipeline_models.dart b/app/lib/features/pipelines/pipeline_models.dart index 25be85e3..40dfb344 100644 --- a/app/lib/features/pipelines/pipeline_models.dart +++ b/app/lib/features/pipelines/pipeline_models.dart @@ -22,16 +22,24 @@ class PipelineSummary { required this.scheduled, required this.scheduleCount, required this.enabledScheduleCount, + this.recordedStages, + this.flowStages, }); factory PipelineSummary.fromJson(PipelineJson json) { final scheduleCount = _optionalInt(json['schedule_count']); final scheduled = json['scheduled']; + final recordedStages = _optionalInt(json['stages']); return PipelineSummary( id: _int(json['id']), name: _string(json['name']), version: _int(json['version']), - stages: _int(json['stages']), + stages: recordedStages ?? 0, + recordedStages: recordedStages, + // A summary may omit `stages` while still carrying the current + // version's flow (`shape`); keep that recorded count for the list row + // without changing the summary's own field or its sorting. + flowStages: _flowStageCount(json['shape']), createdAt: _string(json['created_at']), updatedAt: _string(json['updated_at']), scheduled: scheduled is bool ? scheduled : null, @@ -50,6 +58,21 @@ class PipelineSummary { final int? scheduleCount; final int? enabledScheduleCount; + /// The stage count the summary itself recorded, or null when it omitted it. + /// + /// Kept apart from [stages] so sorting keeps the web's rule (its own + /// `stages` field, never the flow) while the list row can use the recorded + /// flow below. + final int? recordedStages; + + /// The stage count recorded by the current version's optional `shape` flow. + final int? flowStages; + + /// 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. + int get rowStageCount => recordedStages ?? flowStages ?? stages; + String get displayName => name.isEmpty ? 'pipeline $id' : name; /// Mirrors the web's schedule configuration rule, including its fallbacks @@ -111,6 +134,8 @@ class PipelineDetail extends PipelineSummary { required super.scheduled, required super.scheduleCount, required super.enabledScheduleCount, + super.recordedStages, + super.flowStages, required this.latestVersion, required this.versionCreatedAt, required this.contentHash, @@ -133,6 +158,8 @@ class PipelineDetail extends PipelineSummary { scheduled: summary.scheduled, scheduleCount: summary.scheduleCount, enabledScheduleCount: summary.enabledScheduleCount, + recordedStages: summary.recordedStages, + flowStages: summary.flowStages, latestVersion: _int(json['latest_version']), versionCreatedAt: _string(json['version_created_at']), contentHash: _string(json['content_hash']), @@ -237,6 +264,14 @@ int? _optionalInt(Object? value) { String _string(Object? value) => value is String ? value : ''; +/// 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) { + if (value is! Map) return null; + final stages = value['stages']; + return stages is List ? stages.length : null; +} + /// A raw JSON object exactly as a reply carried it, or null when absent. PipelineJson? _jsonObject(Object? value) => value is Map ? Map.from(value) : null; diff --git a/app/lib/features/pipelines/pipeline_query.dart b/app/lib/features/pipelines/pipeline_query.dart index eb200f4b..eeb5701d 100644 --- a/app/lib/features/pipelines/pipeline_query.dart +++ b/app/lib/features/pipelines/pipeline_query.dart @@ -59,10 +59,19 @@ String? _finishedDuration(PipelineRun run) { return seconds == null ? null : formatDuration(seconds); } +/// The web's version label for a pipeline: `v{n}`. +String pipelineVersionLabel(PipelineSummary pipeline) => 'v${pipeline.version}'; + +/// The row's flow summary: the web's `{N stages}` label for the recorded stage +/// count. A summary without `stages` falls back to its recorded `shape` flow, +/// so a count is never taken from an unrecorded flow. +String pipelineStageSummary(PipelineSummary pipeline) => + stageCountText(pipeline.rowStageCount); + /// `id {id} · v{version} · {N stages}`. String pipelineSubtitle(PipelineSummary pipeline) => - 'id ${pipeline.id} · v${pipeline.version} · ' - '${stageCountText(pipeline.stages)}'; + 'id ${pipeline.id} · ${pipelineVersionLabel(pipeline)} · ' + '${pipelineStageSummary(pipeline)}'; /// `updated d MMM HH:mm`, or null when the timestamp is unusable. String? pipelineUpdatedLine(PipelineSummary pipeline) { diff --git a/app/test/features/pipelines/pipeline_row_metadata_test.dart b/app/test/features/pipelines/pipeline_row_metadata_test.dart new file mode 100644 index 00000000..678ec5b8 --- /dev/null +++ b/app/test/features/pipelines/pipeline_row_metadata_test.dart @@ -0,0 +1,128 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/features/pipelines/pipeline_models.dart'; +import 'package:pipelines_app/features/pipelines/pipeline_query.dart'; + +import 'fixtures.dart'; +import 'test_helpers.dart'; + +/// The list row's recorded metadata only: version, stage count (including the +/// recorded flow's fallback), updated time and name. Nothing may be filled in +/// for a field the reply did not record. +void main() { + group('pipeline row metadata', () { + test('version, stage count and name come from the reply', () { + final pipeline = PipelineSummary.fromJson( + pipelineSummary(id: 7, name: 'Seven', version: 3, stages: 2), + ); + + expect(pipelineVersionLabel(pipeline), 'v3'); + expect(pipelineStageSummary(pipeline), '2 stages'); + expect(pipelineSubtitle(pipeline), 'id 7 · v3 · 2 stages'); + expect(pipeline.displayName, 'Seven'); + }); + + test('one recorded stage keeps the web singular label', () { + final pipeline = PipelineSummary.fromJson( + pipelineSummary(id: 1, name: 'Solo', version: 1, stages: 1), + ); + + expect(pipelineStageSummary(pipeline), '1 stage'); + }); + + test('a recorded flow supplies the count when stages is absent', () { + final json = pipelineSummary(id: 8, name: 'Flow')..remove('stages'); + json['shape'] = reviewGraph(); + + final pipeline = PipelineSummary.fromJson(json); + + expect(pipeline.stages, 0); + expect(pipeline.rowStageCount, 2); + expect(pipelineStageSummary(pipeline), '2 stages'); + expect(pipelineSubtitle(pipeline), 'id 8 · v1 · 2 stages'); + }); + + test('a recorded stage count wins over the recorded flow', () { + final json = pipelineSummary(id: 9, name: 'Pinned', stages: 1) + ..['shape'] = reviewGraph(); + + final pipeline = PipelineSummary.fromJson(json); + + expect(pipelineStageSummary(pipeline), '1 stage'); + }); + + test('neither recorded reads the web zero-stage fallback', () { + final json = pipelineSummary(id: 10, name: 'Bare')..remove('stages'); + final malformed = pipelineSummary(id: 11, name: 'Odd') + ..remove('stages') + ..['shape'] = {'stages': 'not a list'}; + + expect(pipelineStageSummary(PipelineSummary.fromJson(json)), '0 stages'); + expect( + pipelineStageSummary(PipelineSummary.fromJson(malformed)), + '0 stages', + ); + }); + + test('the updated line is exact and omitted when unrecorded', () { + final recorded = PipelineSummary.fromJson( + pipelineSummary(id: 11, name: 'Timed'), + ); + final absent = PipelineSummary.fromJson( + pipelineSummary(id: 12, name: 'Untimed', updatedAt: ''), + ); + final unparseable = PipelineSummary.fromJson( + pipelineSummary(id: 13, name: 'Bad time', updatedAt: 'not a time'), + ); + + expect(pipelineUpdatedLine(recorded), 'updated 17 Oct 21:26'); + expect(pipelineUpdatedLine(absent), isNull); + expect(pipelineUpdatedLine(unparseable), isNull); + }); + + test('a blank name reads the web fallback, never an empty title', () { + final pipeline = PipelineSummary.fromJson( + pipelineSummary(id: 14, name: '', version: 2, stages: 3), + ); + + expect(pipeline.displayName, 'pipeline 14'); + }); + + testWidgets('the row shows recorded metadata and hides absent values', ( + tester, + ) async { + final fixture = PipelineFixture(); + final shapeOnly = pipelineSummary(id: 8, name: '', version: 1) + ..remove('stages') + ..['shape'] = reviewGraph() + ..['updated_at'] = ''; + final zeroStages = pipelineSummary( + id: 9, + name: 'Zero', + version: 4, + stages: 0, + updatedAt: 'not a time', + )..['shape'] = reviewGraph(); + final gateway = gatewayFor( + fixture, + summaries: [ + pipelineSummary(id: 7, name: 'Seven', version: 3, stages: 2), + shapeOnly, + zeroStages, + ], + ); + + await pumpWide(tester, gateway); + + expect(find.text('Seven'), findsOneWidget); + expect(find.text('id 7 · v3 · 2 stages'), findsOneWidget); + expect(find.text('updated 17 Oct 21:26'), findsOneWidget); + + expect(find.text('pipeline 8'), findsOneWidget); + expect(find.text('id 8 · v1 · 2 stages'), findsOneWidget); + + expect(find.text('id 9 · v4 · 0 stages'), findsOneWidget); + expect(find.textContaining('updated '), findsOneWidget); + expect(find.text('no runs recorded'), findsNWidgets(3)); + }); + }); +}