From 596365d914208cda8fe7922e894ef0d5af7d9ca5 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Wed, 21 Oct 2026 18:46:18 +0100 Subject: [PATCH] feat(app): add read-only native artifact visit list Render recorded artifact groups for the active host, with visit-scoped selection and an explicit selection callback. Material uses ListTile, Cupertino uses inset grouped sections with separate heading semantics. Recorded names, MIME and size are shown verbatim with honest fallbacks; nothing is resolved, fetched, previewed, downloaded or fabricated. Adds widget, host and semantics regressions plus an isolated browser probe. --- .../artifacts/ui/artifact_visit_list.dart | 231 ++++++++++++++++++ app/notes/A1-list.md | 150 ++++++++++++ .../ui/artifact_visit_list_fixture.dart | 87 +++++++ .../artifact_visit_list_semantics_test.dart | 170 +++++++++++++ .../ui/artifact_visit_list_test.dart | 230 +++++++++++++++++ app/tool/artifact_list_probe.dart | 194 +++++++++++++++ 6 files changed, 1062 insertions(+) create mode 100644 app/lib/features/artifacts/ui/artifact_visit_list.dart create mode 100644 app/notes/A1-list.md create mode 100644 app/test/features/artifacts/ui/artifact_visit_list_fixture.dart create mode 100644 app/test/features/artifacts/ui/artifact_visit_list_semantics_test.dart create mode 100644 app/test/features/artifacts/ui/artifact_visit_list_test.dart create mode 100644 app/tool/artifact_list_probe.dart diff --git a/app/lib/features/artifacts/ui/artifact_visit_list.dart b/app/lib/features/artifacts/ui/artifact_visit_list.dart new file mode 100644 index 00000000..82cf0aa8 --- /dev/null +++ b/app/lib/features/artifacts/ui/artifact_visit_list.dart @@ -0,0 +1,231 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +import '../../../ui/adaptive/host.dart'; +import '../domain/artifact_groups.dart'; +import '../domain/artifact_kind.dart'; +import '../domain/artifact_record.dart'; + +/// A selection callback carrying the recorded group and the exact record the +/// operator chose, so the visit is never lost when two groups share a name. +typedef ArtifactSelected = + void Function(ArtifactGroup group, ArtifactRecord artifact); + +/// The identity of [artifact] inside [group], for +/// [ArtifactVisitList.selectedIdentity]. +/// +/// The recorded stage visit is part of the key, so two visits that both +/// recorded `result.csv` stay distinct even when their urls are identical. +/// A filename alone is never an identity. +String artifactVisitIdentity(ArtifactGroup group, ArtifactRecord artifact) { + final recorded = artifact.hasUrl ? artifact.url : artifact.name; + return '${group.stageKey}\u0000${group.visit}\u0000$recorded'; +} + +/// A read-only, selectable list of recorded artifact groups. +/// +/// Each group shows its recorded stage and visit, and each row its recorded +/// filename, content type and size. Rendering uses the host's own controls: +/// Material list tiles under [MaterialApp] and grouped Cupertino list sections +/// under [CupertinoApp]. It never resolves a url, opens a preview, downloads, +/// shares or filters; the only action is [onSelected]. +class ArtifactVisitList extends StatelessWidget { + const ArtifactVisitList({ + super.key, + required this.groups, + this.selectedIdentity, + this.onSelected, + }); + + final List groups; + + /// [artifactVisitIdentity] of the selected artifact, or null for none. + final String? selectedIdentity; + + final ArtifactSelected? onSelected; + + @override + Widget build(BuildContext context) { + if (groups.isEmpty) { + return const _NoArtifacts(); + } + if (usesCupertinoHost(context)) { + return ListView( + children: [ + for (final group in groups) + CupertinoListSection.insetGrouped( + // `container` keeps the heading a separate semantics node. Without + // it the heading merges into the neighbouring row button, so it is + // not navigable as a heading and activating it selects the row. + header: Semantics( + container: true, + header: true, + child: Text(_groupLabel(group)), + ), + hasLeading: false, + children: [ + for (var index = 0; index < group.artifacts.length; index += 1) + _CupertinoRow( + key: _rowKey(group, group.artifacts[index], index), + group: group, + artifact: group.artifacts[index], + selected: _isSelected(group, group.artifacts[index]), + onSelected: onSelected, + ), + ], + ), + ], + ); + } + return ListView( + children: [ + for (final group in groups) ...[ + Padding( + padding: const EdgeInsetsDirectional.fromSTEB(16, 16, 16, 4), + child: Semantics( + container: true, + header: true, + child: Text(_groupLabel(group)), + ), + ), + for (var index = 0; index < group.artifacts.length; index += 1) + _MaterialRow( + key: _rowKey(group, group.artifacts[index], index), + group: group, + artifact: group.artifacts[index], + selected: _isSelected(group, group.artifacts[index]), + onSelected: onSelected, + ), + ], + ], + ); + } + + bool _isSelected(ArtifactGroup group, ArtifactRecord artifact) => + selectedIdentity == artifactVisitIdentity(group, artifact); + + static Key _rowKey(ArtifactGroup group, ArtifactRecord artifact, int index) => + ValueKey('${artifactVisitIdentity(group, artifact)}\u0000$index'); +} + +/// The recorded group heading, matching the web client's group vocabulary. +String _groupLabel(ArtifactGroup group) => + '${group.stageKey} · visit ${group.visit}'; + +/// The displayed artifact name: a missing server name stays explicit. +String _displayName(ArtifactRecord artifact) => + artifact.name.isEmpty ? '(unnamed artifact)' : artifact.name; + +/// The recorded MIME and byte size, never inferred from the name. +/// +/// The value and its unit are joined by a non-breaking space so a narrow row +/// never wraps `120.6` away from `KiB`. +String _facts(ArtifactRecord artifact) { + final type = artifact.contentType.split(';').first.trim(); + final mime = type.isEmpty ? 'type not recorded' : type; + final size = humanBytes(artifact.sizeBytes).replaceFirst(' ', '\u00a0'); + return '$mime · $size'; +} + +class _MaterialRow extends StatelessWidget { + const _MaterialRow({ + super.key, + required this.group, + required this.artifact, + required this.selected, + required this.onSelected, + }); + + final ArtifactGroup group; + final ArtifactRecord artifact; + final bool selected; + final ArtifactSelected? onSelected; + + @override + Widget build(BuildContext context) { + return ListTile( + selected: selected, + title: Text(_displayName(artifact)), + subtitle: Text(_facts(artifact)), + trailing: selected ? const Icon(Icons.check) : null, + onTap: onSelected == null ? null : () => onSelected!(group, artifact), + ); + } +} + +class _CupertinoRow extends StatelessWidget { + const _CupertinoRow({ + super.key, + required this.group, + required this.artifact, + required this.selected, + required this.onSelected, + }); + + final ArtifactGroup group; + final ArtifactRecord artifact; + final bool selected; + final ArtifactSelected? onSelected; + + @override + Widget build(BuildContext context) { + final textTheme = CupertinoTheme.of(context).textTheme; + final factsStyle = textTheme.textStyle.copyWith( + color: CupertinoColors.secondaryLabel.resolveFrom(context), + ); + final content = DefaultTextStyle.merge( + style: textTheme.textStyle, + child: Row( + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(_displayName(artifact)), + Text(_facts(artifact), style: factsStyle), + ], + ), + ), + if (selected) const Icon(CupertinoIcons.check_mark), + ], + ), + ); + // `container` makes this row its own semantics node, so the section + // heading stays a separate header node and never covers the row. + return Semantics( + container: true, + selected: selected, + child: SizedBox( + width: double.infinity, + // A read-only row is not a button: a disabled CupertinoButton would + // still expose a button role to assistive technology. + child: onSelected == null + ? Padding( + padding: kCupertinoButtonPadding[CupertinoButtonSize.large]!, + child: content, + ) + : CupertinoButton( + alignment: AlignmentDirectional.centerStart, + onPressed: () => onSelected!(group, artifact), + child: content, + ), + ), + ); + } +} + +class _NoArtifacts extends StatelessWidget { + const _NoArtifacts(); + + @override + Widget build(BuildContext context) { + return ListView( + children: const [ + Padding( + padding: EdgeInsets.all(16), + child: Text('No stage artifacts recorded.'), + ), + ], + ); + } +} diff --git a/app/notes/A1-list.md b/app/notes/A1-list.md new file mode 100644 index 00000000..0c51c8f3 --- /dev/null +++ b/app/notes/A1-list.md @@ -0,0 +1,150 @@ +# A1-list — read-only artifact visit list with selection + +## What changed + +All files are new; no existing file was edited. Nothing under `lib/main.dart`, +`lib/shell/`, another feature, `pubspec.*`, `web/`, the Go server or `android/` +was touched. No dependency was added and no network, url, preview, share, +download, filter or gallery code was written. + +| File | Lines | Responsibility | +| --- | --- | --- | +| `lib/features/artifacts/ui/artifact_visit_list.dart` | 231 | One public read-only widget, its selection callback, and the visit-scoped identity helper | +| `test/features/artifacts/ui/artifact_visit_list_fixture.dart` | 85 | Shared recorded fixtures and the native host composition used by the tests | +| `test/features/artifacts/ui/artifact_visit_list_test.dart` | 230 | Identity, Material/Cupertino rows, duplicate filename selection, 2x wrapping, honest fallbacks, empty wording | +| `test/features/artifacts/ui/artifact_visit_list_semantics_test.dart` | 165 | Header semantics, heading/row separation, read-only rows, selected state | +| `tool/artifact_list_probe.dart` | 194 | Isolated fixture entry for browser captures; never changes `main.dart` or the shell | + +## API + +```dart +typedef ArtifactSelected = + void Function(ArtifactGroup group, ArtifactRecord artifact); + +String artifactVisitIdentity(ArtifactGroup group, ArtifactRecord artifact); + +ArtifactVisitList({ + required List groups, + String? selectedIdentity, + ArtifactSelected? onSelected, +}) +``` + +`artifactVisitIdentity` combines the recorded stage key, the group's recorded +display visit and the record's recorded url (or its name when no url was +recorded). A filename alone is never an identity, so `result.csv` from visit 1 +and visit 2 remain distinct even when both records carry the same url. The +callback returns the exact `ArtifactGroup` and `ArtifactRecord` that was tapped. + +## Behaviour + +- Each group heading is the web client's vocabulary: `stage · visit N`, taken + from the existing `ArtifactGroup` (`displayVisit` already owns the number). +- Each row shows the recorded filename, the recorded MIME (parameters trimmed) + and the recorded size via the existing `humanBytes`. An empty name renders + `(unnamed artifact)` and an empty content type renders `type not recorded`; + nothing is inferred from the extension, and no url is displayed or resolved. +- The size value and unit are joined by a non-breaking space, so `120.6 KiB` + never splits across lines at narrow widths. +- Material hosts get `ListTile` rows (title = name, subtitle = facts); Cupertino + hosts get `CupertinoListSection.insetGrouped` with a native `CupertinoButton` + row so the name can wrap (the stock `CupertinoListTile` title is forced to one + line). Name uses the theme text style and facts use the platform + `secondaryLabel` colour, so the recorded name leads the hierarchy. No custom + font, palette or fixed row/button dimensions are declared; rows grow with + content and text scale. +- Cupertino rows set `hasLeading: false`, so the inter-row divider aligns with + the text instead of an absent leading column. +- Both hosts expose every group heading as its own header semantics node, and + every Cupertino row as its own node. A heading can neither be read as part of + a row nor activate one (see the regression tests). +- A row without `onSelected` is read-only: Material has no tap action, and the + Cupertino row is a plain padded row rather than a disabled `CupertinoButton` + (which still exposes a button role). It never renders as a button; the + semantics regression asserts both no tap action and no button role. +- Empty input says `No stage artifacts recorded.`, the web client's wording. +- The only action is `onSelected`. No capture/visit facts are invented or masked. + +## Fixes from UI review visit 1 + +1. **Cupertino heading semantics.** `CupertinoListSection` does not create + semantics for its header. The header is now wrapped in + `Semantics(container: true, header: true, …)` and each Cupertino row is its + own `Semantics(container: true, …)` node. Browser check: three + `

` nodes now exist, the `review · visit 2` heading rect is + `[20, 482.5, 118.2, 23]` and its row `[20, 511.5, 350, 72]`; the row label is + `result.csv / text/csv · 4.0 KiB` without the heading. Clicking the heading + centre leaves the selection at `Selected: none`. +2. **Cupertino grouped background seam.** The probe composition now sets + `CupertinoPageScaffold(backgroundColor: CupertinoColors.systemGroupedBackground)`. + At logical x=10 the whole 390×844 viewport is uniformly `rgb(242,242,247)` + in light mode, before and after selection; no white band below the last + section. **Requirement for the future gallery:** the composing page must set + the same background, or paint the grouped background behind the list. + +Advisories from both earlier reviews were addressed where they touch this +slice: dangling `selectedIdentity` doc link, divider inset, name/metadata +hierarchy, value/unit wrapping and read-only rows. Unit coverage now uses a +record the server actually sent without a url, so the identity fallback to the +recorded name is exercised directly, alongside the unnamed and +missing-content-type fallbacks. The 2x wrap regression asserts a multi-line +height rather than a single-line threshold. + +## Real browser evidence + +Built with `flutter build web -t tool/artifact_list_probe.dart` and driven in an +isolated headless Chrome (Chrome 155, DevTools protocol, `prefers-color-scheme: +light`, 390×844 at DPR 2) against a loopback static server on an OS-assigned +port. No production server, no real run data. The probe fixture contains two +same-named `result.csv` records in different visits. + +- Initial: `Selected: none`; three heading nodes `build · visit 1`, + `review · visit 1`, `review · visit 2`. +- Heading `review · visit 2` clicked: status stays `Selected: none`; no + `aria-current` row. +- Row `review · visit 2` clicked: `Selected: review · visit 2 · result.csv`; + only that row has `aria-current="true"`. +- Material host still exposes three `

` headings and the same four rows. + +Shared evidence: + +- `/Users/alan/.local/share/pipelines/data/artifacts/65/public/a1-code-cupertino-390-initial.png` +- `/Users/alan/.local/share/pipelines/data/artifacts/65/public/a1-code-cupertino-390-visit2.png` +- `/Users/alan/.local/share/pipelines/data/artifacts/65/public/a1-code-material-390.png` +- `/Users/alan/.local/share/pipelines/data/artifacts/65/public/a1-code-manifest.json` + +The capture driver is stage-private (`04-Code/private/capture_a1_fix.mjs`); +Chrome and its temporary profile were removed after the run. + +## Checks actually run + +On the branch after merging `main` (fast-forward, no conflicts): + +``` +flutter test test/features/artifacts/ui # 11 passed +flutter test test/features/artifacts # 71 passed +flutter test # 524 passed (whole app) +flutter analyze # No issues found! (1.4s) +dart format --set-exit-if-changed # 5 files, 0 changed +flutter build web -t tool/artifact_list_probe.dart # ✓ Built build/web (15.9s) +``` + +`git status --short --untracked-files=all` lists only the six new files above; +`pubspec.yaml`/`pubspec.lock` are unchanged. The branch merges current `main` +with no conflicts and nothing is pushed or deployed. + +## Honest limits + +- No gallery screen, shell registration, preview, viewer, share or download is + part of this slice; the widget is ready for the manager to compose. +- The list is scrollable and requires bounded height (a `ListView`); composition + into the run detail is a later slice. The gallery must supply the grouped page + background noted above. +- The browser pass covered Cupertino light 390 (initial and visit 2) and a + Material heading/row check; large-text Cupertino and dark-mode recaptures were + not repeated this visit. The 2x wrapping regression runs in the widget tests. + Full rendered acceptance belongs to the UI review stage. +- Mobile is unverified: only web was built and captured; no Android/iOS build, + emulator, ADB or device was used. +- Handed to landing: committed on `flutter/a1-visit-list` after merging `main`; + the manager owns integration into `main` and delivery. diff --git a/app/test/features/artifacts/ui/artifact_visit_list_fixture.dart b/app/test/features/artifacts/ui/artifact_visit_list_fixture.dart new file mode 100644 index 00000000..a781a34d --- /dev/null +++ b/app/test/features/artifacts/ui/artifact_visit_list_fixture.dart @@ -0,0 +1,87 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:pipelines_app/features/artifacts/domain/artifact_groups.dart'; +import 'package:pipelines_app/features/artifacts/domain/artifact_record.dart'; +import 'package:pipelines_app/features/artifacts/ui/artifact_visit_list.dart'; + +import '../domain/artifact_fixtures.dart'; + +/// A recorded name long enough to wrap at large text sizes. +const longArtifactName = + 'a-very-long-recorded-artifact-file-name-that-must-wrap-across-' + 'several-lines-at-large-text-sizes.csv'; + +/// The non-breaking space the row inserts between a size value and its unit. +const nonBreakingSpace = '\u00a0'; + +/// One recorded artifact. An empty [url] falls back to the fixture's url; use +/// [unaddressedArtifact] for a record the server sent without one. +ArtifactRecord recordedArtifact( + String name, { + String url = '', + String contentType = '', + int sizeBytes = 0, +}) { + return ArtifactRecord.fromJson( + artifact( + name, + url: url.isEmpty ? null : url, + contentType: contentType, + sizeBytes: sizeBytes, + ), + ); +} + +/// A record with no recorded url or content type, never completed locally. +/// +/// [name] defaults to empty, so the record is otherwise entirely unaddressed. +ArtifactRecord unaddressedArtifact({String name = ''}) { + return ArtifactRecord.fromJson({ + 'name': name, + 'url': '', + 'content_type': '', + 'size_bytes': 0, + }); +} + +ArtifactGroup visitGroup({ + String stageKey = 'review', + int visit = 1, + List artifacts = const [], +}) { + return ArtifactGroup(stageKey: stageKey, visit: visit, artifacts: artifacts); +} + +/// The list under the native host it is composed into, with the optional +/// grouped page colour a gallery must supply. +Widget artifactListHost({ + required bool cupertino, + required List groups, + String? selectedIdentity, + ArtifactSelected? onSelected, + double textScale = 1, +}) { + final list = ArtifactVisitList( + groups: groups, + selectedIdentity: selectedIdentity, + onSelected: onSelected, + ); + Widget scaled(BuildContext context, Widget? child) => MediaQuery( + data: MediaQuery.of( + context, + ).copyWith(textScaler: TextScaler.linear(textScale)), + child: child ?? const SizedBox.shrink(), + ); + return cupertino + ? CupertinoApp( + builder: scaled, + home: CupertinoPageScaffold( + backgroundColor: CupertinoColors.systemGroupedBackground, + child: list, + ), + ) + : MaterialApp( + builder: scaled, + home: Scaffold(body: list), + ); +} diff --git a/app/test/features/artifacts/ui/artifact_visit_list_semantics_test.dart b/app/test/features/artifacts/ui/artifact_visit_list_semantics_test.dart new file mode 100644 index 00000000..8e18f58b --- /dev/null +++ b/app/test/features/artifacts/ui/artifact_visit_list_semantics_test.dart @@ -0,0 +1,170 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/semantics.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/features/artifacts/domain/artifact_groups.dart'; +import 'package:pipelines_app/features/artifacts/ui/artifact_visit_list.dart'; + +import 'artifact_visit_list_fixture.dart'; + +List _threeGroups() => [ + visitGroup( + stageKey: 'build', + visit: 1, + artifacts: [ + recordedArtifact(longArtifactName, url: '/artifacts/7/3/long.xlsx'), + ], + ), + visitGroup( + visit: 1, + artifacts: [ + recordedArtifact('result.csv', url: '/artifacts/7/1/result.csv'), + recordedArtifact('notes.md', url: '/artifacts/7/1/notes.md'), + ], + ), + visitGroup( + visit: 2, + artifacts: [ + recordedArtifact('result.csv', url: '/artifacts/7/2/result.csv'), + ], + ), +]; + +void main() { + testWidgets('every group heading is a header node under both hosts', ( + tester, + ) async { + final handle = tester.ensureSemantics(); + + for (final cupertino in [false, true]) { + await tester.pumpWidget( + artifactListHost(cupertino: cupertino, groups: _threeGroups()), + ); + for (final label in [ + 'build · visit 1', + 'review · visit 1', + 'review · visit 2', + ]) { + expect( + tester.getSemantics(find.text(label)), + isSemantics(label: label, isHeader: true), + reason: + '${cupertino ? 'Cupertino' : 'Material'} must expose $label as a ' + 'heading', + ); + } + } + handle.dispose(); + }); + + testWidgets('a Cupertino heading stays separate from its single row', ( + tester, + ) async { + final handle = tester.ensureSemantics(); + final group = visitGroup( + visit: 2, + artifacts: [ + recordedArtifact( + 'result.csv', + url: '/artifacts/7/2/result.csv', + contentType: 'text/csv', + sizeBytes: 4096, + ), + ], + ); + await tester.pumpWidget( + artifactListHost(cupertino: true, groups: [group], onSelected: (_, _) {}), + ); + + final heading = tester.getSemantics(find.text('review · visit 2')); + expect(heading, isSemantics(label: 'review · visit 2', isHeader: true)); + expect( + heading.getSemanticsData().hasAction(SemanticsAction.tap), + isFalse, + reason: 'a heading must never activate the artifact below it', + ); + + final button = tester.getSemantics(find.byType(CupertinoButton)); + expect(button, isSemantics(isButton: true, hasTapAction: true)); + expect(button.label, contains('result.csv')); + expect( + button.label, + isNot(contains('review · visit 2')), + reason: 'the row accessible name must not repeat the group heading', + ); + + final headingRect = tester.getRect(find.text('review · visit 2')); + final rowRect = tester.getRect(find.byType(CupertinoButton)); + expect( + rowRect.top, + greaterThanOrEqualTo(headingRect.bottom), + reason: 'the row must not cover the heading', + ); + handle.dispose(); + }); + + testWidgets('rows without a callback expose no tap action under both hosts', ( + tester, + ) async { + final handle = tester.ensureSemantics(); + final group = visitGroup( + artifacts: [ + recordedArtifact('result.csv', url: '/artifacts/7/1/result.csv'), + ], + ); + + for (final cupertino in [false, true]) { + await tester.pumpWidget( + artifactListHost(cupertino: cupertino, groups: [group]), + ); + final row = tester.getSemantics(find.text('result.csv')); + expect( + row.getSemanticsData().hasAction(SemanticsAction.tap), + isFalse, + reason: 'without onSelected the row is read-only', + ); + expect( + row, + isSemantics(isButton: false), + reason: 'a read-only row must not expose a button role', + ); + await tester.tap(find.text('result.csv')); + expect(tester.takeException(), isNull); + } + handle.dispose(); + }); + + testWidgets('the selected row carries the selected semantics state', ( + tester, + ) async { + final handle = tester.ensureSemantics(); + final first = visitGroup( + visit: 1, + artifacts: [recordedArtifact('result.csv', url: '/artifacts/7/1/a.csv')], + ); + final second = visitGroup( + visit: 2, + artifacts: [recordedArtifact('result.csv', url: '/artifacts/7/2/b.csv')], + ); + await tester.pumpWidget( + artifactListHost( + cupertino: true, + groups: [first, second], + selectedIdentity: artifactVisitIdentity( + second, + second.artifacts.single, + ), + onSelected: (_, _) {}, + ), + ); + + expect( + tester.getSemantics(find.text('result.csv').last), + isSemantics(isSelected: true), + ); + expect( + tester.getSemantics(find.text('result.csv').first), + isSemantics(isSelected: false), + ); + handle.dispose(); + }); +} diff --git a/app/test/features/artifacts/ui/artifact_visit_list_test.dart b/app/test/features/artifacts/ui/artifact_visit_list_test.dart new file mode 100644 index 00000000..b9fb9585 --- /dev/null +++ b/app/test/features/artifacts/ui/artifact_visit_list_test.dart @@ -0,0 +1,230 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/features/artifacts/domain/artifact_groups.dart'; +import 'package:pipelines_app/features/artifacts/domain/artifact_record.dart'; +import 'package:pipelines_app/features/artifacts/ui/artifact_visit_list.dart'; + +import 'artifact_visit_list_fixture.dart'; + +void main() { + test('a shared filename in two visits has distinct identities', () { + const url = '/artifacts/7/result.csv'; + final first = visitGroup( + visit: 1, + artifacts: [ + recordedArtifact('result.csv', url: url, contentType: 'text/csv'), + ], + ); + final second = visitGroup( + visit: 2, + artifacts: [ + recordedArtifact('result.csv', url: url, contentType: 'text/csv'), + ], + ); + + expect( + artifactVisitIdentity(first, first.artifacts.single), + isNot(artifactVisitIdentity(second, second.artifacts.single)), + ); + expect( + artifactVisitIdentity(first, first.artifacts.single), + artifactVisitIdentity(first, first.artifacts.single), + ); + }); + + test('an unaddressed record is identified by its recorded name', () { + final addressed = visitGroup( + visit: 1, + artifacts: [ + recordedArtifact('result.csv', url: '/artifacts/7/1/result.csv'), + ], + ); + final unaddressed = visitGroup( + visit: 1, + artifacts: [unaddressedArtifact(name: 'result.csv')], + ); + + expect( + artifactVisitIdentity(unaddressed, unaddressed.artifacts.single), + 'review\u00001\u0000result.csv', + ); + expect( + artifactVisitIdentity(unaddressed, unaddressed.artifacts.single), + isNot(artifactVisitIdentity(addressed, addressed.artifacts.single)), + ); + }); + + testWidgets('Material rows show recorded visit, MIME and size', ( + tester, + ) async { + final first = visitGroup( + visit: 1, + artifacts: [ + recordedArtifact( + 'result.csv', + url: '/artifacts/7/1/result.csv', + contentType: 'text/csv', + sizeBytes: 2048, + ), + ], + ); + final second = visitGroup( + visit: 2, + artifacts: [ + recordedArtifact( + 'result.csv', + url: '/artifacts/7/2/result.csv', + contentType: 'text/csv; charset=utf-8', + sizeBytes: 4096, + ), + ], + ); + ArtifactGroup? pickedGroup; + ArtifactRecord? pickedArtifact; + await tester.pumpWidget( + artifactListHost( + cupertino: false, + groups: [first, second], + selectedIdentity: artifactVisitIdentity( + second, + second.artifacts.single, + ), + onSelected: (selectedGroup, selectedArtifact) { + pickedGroup = selectedGroup; + pickedArtifact = selectedArtifact; + }, + ), + ); + + expect(find.text('review · visit 1'), findsOneWidget); + expect(find.text('review · visit 2'), findsOneWidget); + expect(find.text('result.csv'), findsNWidgets(2)); + expect(find.text('text/csv · 2.0${nonBreakingSpace}KiB'), findsOneWidget); + expect(find.text('text/csv · 4.0${nonBreakingSpace}KiB'), findsOneWidget); + expect(find.byIcon(Icons.check), findsOneWidget); + + await tester.tap(find.text('result.csv').first); + expect(pickedGroup, same(first)); + expect(pickedArtifact, same(first.artifacts.single)); + + await tester.tap(find.text('result.csv').last); + expect(pickedGroup, same(second)); + expect(pickedArtifact!.url, '/artifacts/7/2/result.csv'); + }); + + testWidgets('Cupertino uses grouped native controls and selects per visit', ( + tester, + ) async { + final first = visitGroup( + visit: 1, + artifacts: [ + recordedArtifact('result.csv', url: '/artifacts/7/1/result.csv'), + ], + ); + final second = visitGroup( + visit: 2, + artifacts: [ + recordedArtifact('result.csv', url: '/artifacts/7/2/result.csv'), + ], + ); + ArtifactGroup? pickedGroup; + await tester.pumpWidget( + artifactListHost( + cupertino: true, + groups: [first, second], + selectedIdentity: artifactVisitIdentity(first, first.artifacts.single), + onSelected: (selectedGroup, _) => pickedGroup = selectedGroup, + ), + ); + + expect(find.byType(CupertinoListSection), findsNWidgets(2)); + expect(find.byType(CupertinoButton), findsNWidgets(2)); + expect(find.byType(ListTile), findsNothing); + expect(find.byIcon(CupertinoIcons.check_mark), findsOneWidget); + + await tester.tap(find.text('result.csv').last); + expect(pickedGroup, same(second)); + }); + + testWidgets('long names wrap at 2x under both native hosts', (tester) async { + tester.view.devicePixelRatio = 2; + tester.view.physicalSize = const Size(780, 1560); + addTearDown(tester.view.resetPhysicalSize); + addTearDown(tester.view.resetDevicePixelRatio); + final withLongName = visitGroup( + visit: 3, + artifacts: [ + recordedArtifact( + longArtifactName, + url: '/artifacts/7/3/$longArtifactName', + contentType: + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + sizeBytes: 123456, + ), + ], + ); + + for (final cupertino in [false, true]) { + await tester.pumpWidget( + artifactListHost( + cupertino: cupertino, + groups: [withLongName], + textScale: 2, + onSelected: (_, _) {}, + ), + ); + expect(tester.takeException(), isNull); + final name = tester.renderObject(find.text(longArtifactName)); + expect( + name.size.height, + greaterThan(120), + reason: 'the recorded name must wrap over several lines, not one', + ); + expect( + find.text( + 'application/vnd.openxmlformats-officedocument.' + 'spreadsheetml.sheet · 120.6${nonBreakingSpace}KiB', + ), + findsOneWidget, + ); + } + }); + + testWidgets('a missing name and content type stay explicit', (tester) async { + final group = visitGroup( + artifacts: [ + unaddressedArtifact(), + recordedArtifact( + 'notes.md', + url: '/artifacts/7/1/notes.md', + contentType: 'text/markdown', + sizeBytes: 812, + ), + ], + ); + await tester.pumpWidget( + artifactListHost(cupertino: false, groups: [group]), + ); + + expect(find.text('(unnamed artifact)'), findsOneWidget); + expect( + find.text('type not recorded · 0${nonBreakingSpace}B'), + findsOneWidget, + ); + expect(find.text('notes.md'), findsOneWidget); + expect( + find.text('text/markdown · 812${nonBreakingSpace}B'), + findsOneWidget, + ); + expect(find.byIcon(Icons.check), findsNothing); + }); + + testWidgets('empty groups keep the honest empty wording', (tester) async { + await tester.pumpWidget( + artifactListHost(cupertino: false, groups: const []), + ); + expect(find.text('No stage artifacts recorded.'), findsOneWidget); + expect(find.byType(ListTile), findsNothing); + }); +} diff --git a/app/tool/artifact_list_probe.dart b/app/tool/artifact_list_probe.dart new file mode 100644 index 00000000..aecd9775 --- /dev/null +++ b/app/tool/artifact_list_probe.dart @@ -0,0 +1,194 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:pipelines_app/features/artifacts/domain/artifact_groups.dart'; +import 'package:pipelines_app/features/artifacts/domain/artifact_record.dart'; +import 'package:pipelines_app/features/artifacts/ui/artifact_visit_list.dart'; + +/// A fixture entry point for browser captures of [ArtifactVisitList]. It never +/// contacts a server: the groups below are recorded shapes, and the selection +/// line only echoes the widget's callback. +/// +/// Query parameters: +/// platform=ios render the Cupertino host instead of Material +/// scale=1.5 large-text check +/// state=empty no recorded groups +/// state=disabled rows rendered without a selection callback +/// state=unrecorded a record with no name, url or content type +void main() { + final params = Uri.base.queryParameters; + runApp( + _ProbeApp(cupertino: params['platform'] == 'ios', state: params['state']), + ); +} + +ArtifactRecord _record( + String name, { + required String url, + required String contentType, + required int sizeBytes, +}) { + return ArtifactRecord.fromJson({ + 'name': name, + 'url': url, + 'content_type': contentType, + 'size_bytes': sizeBytes, + }); +} + +const longName = + 'a-very-long-recorded-artifact-file-name-that-must-wrap-across-' + 'several-lines-at-large-text-sizes.xlsx'; + +final List _groups = [ + ArtifactGroup( + stageKey: 'build', + visit: 1, + artifacts: [ + _record( + longName, + url: '/artifacts/7/3/$longName', + contentType: + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + sizeBytes: 123456, + ), + ], + ), + ArtifactGroup( + stageKey: 'review', + visit: 1, + artifacts: [ + _record( + 'result.csv', + url: '/artifacts/7/1/result.csv', + contentType: 'text/csv', + sizeBytes: 2048, + ), + _record( + 'notes.md', + url: '/artifacts/7/1/notes.md', + contentType: 'text/markdown', + sizeBytes: 812, + ), + ], + ), + ArtifactGroup( + stageKey: 'review', + visit: 2, + artifacts: [ + _record( + 'result.csv', + url: '/artifacts/7/2/result.csv', + contentType: 'text/csv', + sizeBytes: 4096, + ), + ], + ), +]; + +/// Records the server sent without a name, url or content type. The list must +/// show the honest fallbacks rather than infer any of them. +final List _unrecordedGroups = [ + ArtifactGroup( + stageKey: 'review', + visit: 1, + artifacts: [ + ArtifactRecord.fromJson(const { + 'name': '', + 'url': '', + 'content_type': '', + 'size_bytes': 0, + }), + ArtifactRecord.fromJson(const { + 'name': 'notes.md', + 'url': '/artifacts/7/1/notes.md', + 'content_type': '', + 'size_bytes': 812, + }), + ], + ), +]; + +List _groupsFor(String? state) => switch (state) { + 'empty' => const [], + 'unrecorded' => _unrecordedGroups, + _ => _groups, +}; + +class _ProbeApp extends StatefulWidget { + const _ProbeApp({required this.cupertino, this.state}); + + final bool cupertino; + final String? state; + + @override + State<_ProbeApp> createState() => _ProbeAppState(); +} + +class _ProbeAppState extends State<_ProbeApp> { + ArtifactGroup? _selectedGroup; + ArtifactRecord? _selectedArtifact; + + String? get _selectedIdentity => _selectedGroup == null + ? null + : artifactVisitIdentity(_selectedGroup!, _selectedArtifact!); + + @override + Widget build(BuildContext context) { + final scale = + double.tryParse(Uri.base.queryParameters['scale'] ?? '') ?? 1.0; + final selected = _selectedGroup == null + ? 'Selected: none' + : 'Selected: ${_selectedGroup!.stageKey} · visit ' + '${_selectedGroup!.visit} · ${_selectedArtifact!.name}'; + final groups = _groupsFor(widget.state); + final selectable = widget.state != 'disabled'; + final body = Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Padding( + padding: const EdgeInsetsDirectional.fromSTEB(16, 16, 16, 0), + child: Text('Artifact visit list probe'), + ), + Padding( + padding: const EdgeInsetsDirectional.fromSTEB(16, 4, 16, 0), + child: Text(selected), + ), + Expanded( + child: ArtifactVisitList( + groups: groups, + selectedIdentity: _selectedIdentity, + onSelected: selectable + ? (group, artifact) => setState(() { + _selectedGroup = group; + _selectedArtifact = artifact; + }) + : null, + ), + ), + ], + ); + Widget scaled(BuildContext context, Widget? child) => MediaQuery( + data: MediaQuery.of( + context, + ).copyWith(textScaler: TextScaler.linear(scale)), + child: child ?? const SizedBox.shrink(), + ); + if (widget.cupertino) { + return CupertinoApp( + debugShowCheckedModeBanner: false, + builder: scaled, + home: CupertinoPageScaffold( + // Sections paint the grouped background; the page must match it or a + // white seam shows below the last section in light mode. + backgroundColor: CupertinoColors.systemGroupedBackground, + child: body, + ), + ); + } + return MaterialApp( + debugShowCheckedModeBanner: false, + builder: scaled, + home: Scaffold(body: body), + ); + } +}