feat(app): finish native run Changes wiring and scaled form menus
This commit is contained in:
@@ -11,7 +11,7 @@ export 'domain/change_wording.dart';
|
||||
export 'domain/file_change.dart';
|
||||
export 'domain/run_changes.dart';
|
||||
export 'domain/unified_patch.dart';
|
||||
export 'widgets/change_style.dart' show DiffForm, usesCupertino;
|
||||
export 'widgets/change_style.dart' show DiffForm, hostTextTheme, usesCupertino;
|
||||
export 'widgets/changes_viewer.dart';
|
||||
export 'widgets/file_diff_viewer.dart';
|
||||
export 'widgets/patch_view.dart';
|
||||
|
||||
@@ -44,6 +44,13 @@ class RunChanges {
|
||||
RunChanges runChanges(List<JsonMap> steps) =>
|
||||
runChangesFor(stageCaptures(steps));
|
||||
|
||||
/// Whether the run-wide final-state aggregate may be presented. Ported from
|
||||
/// `web/src/changes.js` `showRunChangesSummary`: only a settled succeeded run
|
||||
/// has a final workspace state. A failed or running run keeps its evidence in
|
||||
/// each visit's own captured section instead of claiming a settled summary.
|
||||
bool showRunChangesSummary(Object? status) =>
|
||||
status != null && '$status'.trim().toLowerCase() == 'succeeded';
|
||||
|
||||
/// The same aggregate over already-derived [stageCaptures], so a caller that
|
||||
/// shows both the summary and the sections parses each capture only once.
|
||||
RunChanges runChangesFor(List<StageCapture> visits) {
|
||||
|
||||
@@ -2,104 +2,52 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../domain/unified_patch.dart';
|
||||
import 'diff_form_control.dart';
|
||||
|
||||
/// Which form of a recorded patch the viewer is showing.
|
||||
enum DiffForm { rendered, raw }
|
||||
export 'diff_form_control.dart';
|
||||
|
||||
/// The app's established platform switch: Material for Android/desktop/web,
|
||||
/// Cupertino for iOS and macOS. Feature widgets stay portable across all three
|
||||
/// targets instead of hard-coding one control set.
|
||||
bool usesCupertino(BuildContext context) {
|
||||
final platform = Theme.of(context).platform;
|
||||
return platform == TargetPlatform.iOS || platform == TargetPlatform.macOS;
|
||||
}
|
||||
|
||||
/// Patch text inherits the host's typography, including its font and scaler.
|
||||
/// A diff is not an exception to the native-defaults requirement.
|
||||
/// Patch text inherits the host's typography without a diff-specific font.
|
||||
TextStyle nativeDiffText(TextStyle base) => base;
|
||||
|
||||
/// Native semantic colours, never a bespoke diff palette. The recorded +/-
|
||||
/// markers carry meaning independently of colour. No background tint is added.
|
||||
/// Keep Material-derived metadata roles readable inside a Cupertino host.
|
||||
ThemeData hostTextTheme(BuildContext context) => ThemeData(
|
||||
brightness: CupertinoTheme.brightnessOf(context),
|
||||
platform: Theme.of(context).platform,
|
||||
);
|
||||
|
||||
/// Native semantic roles, never a bespoke palette or added row tint. The exact
|
||||
/// recorded +/- markers also distinguish changes without relying on colour.
|
||||
({Color text, Color? background}) diffLineColors(
|
||||
BuildContext context,
|
||||
ChangeLineKind kind,
|
||||
) {
|
||||
return switch (kind) {
|
||||
ChangeLineKind.add => (
|
||||
text: usesCupertino(context)
|
||||
? CupertinoColors.systemGreen.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.primary,
|
||||
background: null,
|
||||
),
|
||||
ChangeLineKind.remove => (
|
||||
text: usesCupertino(context)
|
||||
? CupertinoColors.destructiveRed.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.error,
|
||||
background: null,
|
||||
),
|
||||
ChangeLineKind.context => (text: labelColor(context), background: null),
|
||||
};
|
||||
}
|
||||
) => switch (kind) {
|
||||
ChangeLineKind.add => (
|
||||
text: usesCupertino(context)
|
||||
? CupertinoColors.systemGreen.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.primary,
|
||||
background: null,
|
||||
),
|
||||
ChangeLineKind.remove => (
|
||||
text: usesCupertino(context)
|
||||
? CupertinoColors.destructiveRed.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.error,
|
||||
background: null,
|
||||
),
|
||||
ChangeLineKind.context => (text: labelColor(context), background: null),
|
||||
};
|
||||
|
||||
/// The plain body/label colour for non-diff text inside the viewer.
|
||||
Color labelColor(BuildContext context) => usesCupertino(context)
|
||||
? CupertinoColors.label.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurface;
|
||||
|
||||
/// The muted colour for gutters, notes and secondary metadata.
|
||||
Color mutedColor(BuildContext context) => usesCupertino(context)
|
||||
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
|
||||
/// The hunk header's fill.
|
||||
Color hunkHeaderColor(BuildContext context) => usesCupertino(context)
|
||||
? CupertinoColors.tertiarySystemFill.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.surfaceContainerHighest;
|
||||
|
||||
/// The viewer's shared Rendered/Raw control: a native segmented control on each
|
||||
/// platform, with the same two words the browser uses.
|
||||
Widget diffFormControl(
|
||||
BuildContext context, {
|
||||
required DiffForm form,
|
||||
required ValueChanged<DiffForm> onChanged,
|
||||
}) {
|
||||
if (usesCupertino(context)) {
|
||||
return CupertinoSlidingSegmentedControl<DiffForm>(
|
||||
groupValue: form,
|
||||
onValueChanged: (value) {
|
||||
if (value != null) onChanged(value);
|
||||
},
|
||||
children: const {
|
||||
DiffForm.rendered: _SegmentLabel('Rendered'),
|
||||
DiffForm.raw: _SegmentLabel('Raw patch'),
|
||||
},
|
||||
);
|
||||
}
|
||||
return SegmentedButton<DiffForm>(
|
||||
segments: const [
|
||||
ButtonSegment(value: DiffForm.rendered, label: Text('Rendered')),
|
||||
ButtonSegment(value: DiffForm.raw, label: Text('Raw patch')),
|
||||
],
|
||||
selected: {form},
|
||||
showSelectedIcon: false,
|
||||
onSelectionChanged: (selection) {
|
||||
if (selection.isNotEmpty) onChanged(selection.first);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
class _SegmentLabel extends StatelessWidget {
|
||||
const _SegmentLabel(this.label);
|
||||
|
||||
final String label;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) =>
|
||||
Padding(padding: const EdgeInsets.all(6), child: Text(label));
|
||||
}
|
||||
|
||||
/// Copy the server's raw patch exactly as recorded. Disabled when the entry has
|
||||
/// no readable patch, so the action never copies a fabricated empty diff.
|
||||
Widget copyPatchControl(
|
||||
BuildContext context, {
|
||||
required bool enabled,
|
||||
@@ -128,7 +76,6 @@ Widget copyPatchControl(
|
||||
);
|
||||
}
|
||||
|
||||
/// The standard close action, labelled exactly on both platforms.
|
||||
Widget closeDiffControl(BuildContext context, VoidCallback onClose) {
|
||||
if (usesCupertino(context)) {
|
||||
return Semantics(
|
||||
|
||||
@@ -17,7 +17,11 @@ import 'file_diff_viewer.dart';
|
||||
/// Scaffold body, tab body or Expanded child). It never opens its own socket or
|
||||
/// requests data; the caller passes the run detail's `steps`.
|
||||
class ChangesViewer extends StatefulWidget {
|
||||
const ChangesViewer({super.key, required this.steps});
|
||||
const ChangesViewer({
|
||||
super.key,
|
||||
required this.steps,
|
||||
this.showSummary = true,
|
||||
});
|
||||
|
||||
/// The run detail's steps exactly as the server returned them. Each step's
|
||||
/// `file_changes` may be null (no capture), a complete/partial/unavailable
|
||||
@@ -27,6 +31,11 @@ class ChangesViewer extends StatefulWidget {
|
||||
/// captures and the summary are derived from it rather than on every rebuild.
|
||||
final List<JsonMap> steps;
|
||||
|
||||
/// Whether the run-wide final-state header and filter are shown. The web
|
||||
/// client gates its aggregate on [showRunChangesSummary]; the per-stage
|
||||
/// sections stay the evidence for a run without a settled final state.
|
||||
final bool showSummary;
|
||||
|
||||
@override
|
||||
State<ChangesViewer> createState() => _ChangesViewerState();
|
||||
}
|
||||
@@ -67,49 +76,51 @@ class _ChangesViewerState extends State<ChangesViewer> {
|
||||
Widget build(BuildContext context) {
|
||||
final run = _run;
|
||||
final captures = _captures;
|
||||
final showSummary = widget.showSummary;
|
||||
final hasFiles = captures.any(
|
||||
(visit) => visit.capture?.files.isNotEmpty ?? false,
|
||||
);
|
||||
final note = runChangesNote(run);
|
||||
final note = showSummary ? runChangesNote(run) : '';
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 16, 16, 8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
runChangesHeader(run),
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
if (note.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 4),
|
||||
child: Text(
|
||||
note,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
if (showSummary)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 16, 16, 8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
runChangesHeader(run),
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
if (hasFiles)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Text(
|
||||
'The summary counts each path once, as the last recorded '
|
||||
'visit left it. Each stage/visit below lists what its own '
|
||||
'capture recorded.',
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
if (note.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 4),
|
||||
child: Text(
|
||||
note,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
if (hasFiles)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Text(
|
||||
'The summary counts each path once, as the last recorded '
|
||||
'visit left it. Each stage/visit below lists what its own '
|
||||
'capture recorded.',
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (hasFiles)
|
||||
if (showSummary && hasFiles)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 8),
|
||||
child: _filterField(context, run),
|
||||
),
|
||||
const Divider(height: 1),
|
||||
if (showSummary) const Divider(height: 1),
|
||||
Expanded(
|
||||
child: captures.isEmpty
|
||||
? SingleChildScrollView(
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../ui/adaptive/host.dart';
|
||||
|
||||
enum DiffForm { rendered, raw }
|
||||
|
||||
bool usesCupertino(BuildContext context) => usesCupertinoHost(context);
|
||||
|
||||
const diffFormLabels = <DiffForm, String>{
|
||||
DiffForm.rendered: 'Rendered',
|
||||
DiffForm.raw: 'Raw patch',
|
||||
};
|
||||
|
||||
/// Conservatively choose between two stock controls using the current native
|
||||
/// label role and text scaler. This does not size or restyle either control.
|
||||
bool diffFormSegmentsFit(BuildContext context, double maxWidth) {
|
||||
final style = usesCupertino(context)
|
||||
? CupertinoTheme.of(context).textTheme.textStyle
|
||||
: Theme.of(context).textTheme.labelLarge ??
|
||||
DefaultTextStyle.of(context).style;
|
||||
var widest = 0.0;
|
||||
for (final label in diffFormLabels.values) {
|
||||
final painter = TextPainter(
|
||||
text: TextSpan(text: label, style: style),
|
||||
textDirection: Directionality.of(context),
|
||||
textScaler: MediaQuery.textScalerOf(context),
|
||||
maxLines: 1,
|
||||
)..layout();
|
||||
widest = math.max(widest, painter.width);
|
||||
painter.dispose();
|
||||
}
|
||||
return (widest + 48) * 2 <= maxWidth;
|
||||
}
|
||||
|
||||
Widget diffFormControl(
|
||||
BuildContext context, {
|
||||
required DiffForm form,
|
||||
required ValueChanged<DiffForm> onChanged,
|
||||
}) {
|
||||
if (usesCupertino(context)) {
|
||||
return CupertinoSlidingSegmentedControl<DiffForm>(
|
||||
groupValue: form,
|
||||
onValueChanged: (value) {
|
||||
if (value != null) onChanged(value);
|
||||
},
|
||||
children: {
|
||||
for (final entry in diffFormLabels.entries)
|
||||
entry.key: Padding(
|
||||
padding: const EdgeInsets.all(6),
|
||||
child: Text(entry.value),
|
||||
),
|
||||
},
|
||||
);
|
||||
}
|
||||
return SegmentedButton<DiffForm>(
|
||||
segments: [
|
||||
for (final entry in diffFormLabels.entries)
|
||||
ButtonSegment(value: entry.key, label: Text(entry.value)),
|
||||
],
|
||||
selected: {form},
|
||||
showSelectedIcon: false,
|
||||
onSelectionChanged: (selection) {
|
||||
if (selection.isNotEmpty) onChanged(selection.first);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Native action sheet/bottom sheet when fixed segment labels cannot fit.
|
||||
Widget diffFormMenu(
|
||||
BuildContext context, {
|
||||
required DiffForm form,
|
||||
required ValueChanged<DiffForm> onChanged,
|
||||
}) {
|
||||
if (usesCupertino(context)) {
|
||||
return Semantics(
|
||||
label: 'Diff form',
|
||||
button: true,
|
||||
child: CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: () => showCupertinoModalPopup<void>(
|
||||
context: context,
|
||||
builder: (sheetContext) => CupertinoActionSheet(
|
||||
title: const Text('Diff form'),
|
||||
actions: [
|
||||
for (final entry in diffFormLabels.entries)
|
||||
CupertinoActionSheetAction(
|
||||
isDefaultAction: entry.key == form,
|
||||
onPressed: () {
|
||||
Navigator.of(sheetContext).pop();
|
||||
onChanged(entry.key);
|
||||
},
|
||||
child: Text(entry.value),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
child: const Icon(CupertinoIcons.ellipsis),
|
||||
),
|
||||
);
|
||||
}
|
||||
return IconButton(
|
||||
tooltip: 'Diff form',
|
||||
icon: const Icon(Icons.more_vert),
|
||||
onPressed: () => showModalBottomSheet<void>(
|
||||
context: context,
|
||||
showDragHandle: true,
|
||||
builder: (sheetContext) => SafeArea(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 8),
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: Text(
|
||||
'Diff form',
|
||||
style: Theme.of(sheetContext).textTheme.titleMedium,
|
||||
),
|
||||
),
|
||||
),
|
||||
for (final entry in diffFormLabels.entries)
|
||||
ListTile(
|
||||
title: Text(entry.value),
|
||||
selected: entry.key == form,
|
||||
onTap: () {
|
||||
Navigator.of(sheetContext).pop();
|
||||
onChanged(entry.key);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import '../domain/file_change.dart';
|
||||
import '../domain/unified_patch.dart';
|
||||
import 'change_style.dart';
|
||||
import 'patch_view.dart';
|
||||
import 'raw_patch_view.dart';
|
||||
|
||||
/// The reusable viewer for one recorded file change: its kind, path, stat,
|
||||
/// tags, the rendered or raw unified patch, Copy patch (the server's exact
|
||||
@@ -38,6 +39,8 @@ class _FileDiffViewerState extends State<FileDiffViewer> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _selectForm(DiffForm value) => setState(() => _form = value);
|
||||
|
||||
void _close() {
|
||||
final close = widget.onClose;
|
||||
if (close != null) {
|
||||
@@ -147,16 +150,33 @@ class _FileDiffViewerState extends State<FileDiffViewer> {
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
if (file.hasPatch)
|
||||
diffFormControl(
|
||||
context,
|
||||
form: _form,
|
||||
onChanged: (value) => setState(() => _form = value),
|
||||
LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
// Two native segmented-control segments cannot show both
|
||||
// fixed words at 2x text on a narrow host; their menu
|
||||
// shows the same labels whole, one per row.
|
||||
final control =
|
||||
diffFormSegmentsFit(context, constraints.maxWidth)
|
||||
? diffFormControl(
|
||||
context,
|
||||
form: _form,
|
||||
onChanged: _selectForm,
|
||||
)
|
||||
: diffFormMenu(
|
||||
context,
|
||||
form: _form,
|
||||
onChanged: _selectForm,
|
||||
);
|
||||
return control;
|
||||
},
|
||||
),
|
||||
_scrollsWhenTooWide(
|
||||
copyPatchControl(
|
||||
context,
|
||||
enabled: file.hasPatch,
|
||||
copied: _copied,
|
||||
onPressed: _copy,
|
||||
),
|
||||
copyPatchControl(
|
||||
context,
|
||||
enabled: file.hasPatch,
|
||||
copied: _copied,
|
||||
onPressed: _copy,
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -167,13 +187,13 @@ class _FileDiffViewerState extends State<FileDiffViewer> {
|
||||
? CupertinoColors.separator.resolveFrom(context)
|
||||
: Theme.of(context).dividerColor,
|
||||
),
|
||||
Flexible(child: _body(context, cupertino, mono)),
|
||||
Flexible(child: _body(context, mono)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _body(BuildContext context, bool cupertino, TextStyle mono) {
|
||||
Widget _body(BuildContext context, TextStyle mono) {
|
||||
final file = widget.file;
|
||||
if (file.binary) return _message(context, binaryDiffMessage);
|
||||
if (!file.hasPatch) {
|
||||
@@ -184,24 +204,7 @@ class _FileDiffViewerState extends State<FileDiffViewer> {
|
||||
container: true,
|
||||
label: 'Raw patch for ${file.path}',
|
||||
value: file.patch,
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
|
||||
child: SingleChildScrollView(
|
||||
// Raw patch bytes are one line each: scroll them sideways like the
|
||||
// web view instead of wrapping a continuation under a new line.
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: ExcludeSemantics(
|
||||
child: SelectionArea(
|
||||
child: Text(
|
||||
file.patch!,
|
||||
style: mono,
|
||||
softWrap: false,
|
||||
overflow: TextOverflow.visible,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
child: RawPatchView(patch: file.patch!, style: mono),
|
||||
);
|
||||
}
|
||||
return SingleChildScrollView(
|
||||
@@ -218,6 +221,15 @@ class _FileDiffViewerState extends State<FileDiffViewer> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Gives a native control its intrinsic width and lets it scroll sideways when
|
||||
/// the dialog is narrower than the control, instead of letting the control clip
|
||||
/// or break one of its fixed labels.
|
||||
///
|
||||
/// The scroll view shrink-wraps when the control already fits, so the action
|
||||
/// keeps its usual layout until scaled text or a narrow phone demands more room.
|
||||
Widget _scrollsWhenTooWide(Widget control) =>
|
||||
SingleChildScrollView(scrollDirection: Axis.horizontal, child: control);
|
||||
|
||||
/// Open [file] in the platform's standard modal: a Material dialog on
|
||||
/// Android/desktop/web, a Cupertino dialog with a popup surface on iOS/macOS.
|
||||
Future<void> showFileDiffViewer(BuildContext context, FileChange file) {
|
||||
@@ -231,15 +243,20 @@ Future<void> showFileDiffViewer(BuildContext context, FileChange file) {
|
||||
// A popup surface spans the window unless it is inset; on a phone the
|
||||
// screen edge would clip its native rounded corners.
|
||||
final width = MediaQuery.sizeOf(dialogContext).width;
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: width < 600 ? 16 : 40,
|
||||
vertical: 24,
|
||||
),
|
||||
child: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 900),
|
||||
child: CupertinoPopupSurface(child: SafeArea(child: viewer)),
|
||||
return Theme(
|
||||
// Dialogs open on the app Navigator, above the Changes page's own
|
||||
// brightness-aware theme, so the popup needs its own.
|
||||
data: hostTextTheme(dialogContext),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: width < 600 ? 16 : 40,
|
||||
vertical: 24,
|
||||
),
|
||||
child: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 900),
|
||||
child: CupertinoPopupSurface(child: SafeArea(child: viewer)),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'change_style.dart';
|
||||
|
||||
/// The recorded raw patch bytes, one recorded line per line, in the host's own
|
||||
/// selectable body.
|
||||
///
|
||||
/// Material uses [SelectionArea]; a Cupertino host has no
|
||||
/// [MaterialLocalizations], so it renders the same text in the read-only
|
||||
/// [CupertinoTextField] the run detail already uses for plain selectable text.
|
||||
/// Both forms keep their intrinsic line width, so long lines scroll sideways
|
||||
/// instead of wrapping a continuation under a new line.
|
||||
class RawPatchView extends StatefulWidget {
|
||||
const RawPatchView({super.key, required this.patch, required this.style});
|
||||
|
||||
final String patch;
|
||||
final TextStyle style;
|
||||
|
||||
@override
|
||||
State<RawPatchView> createState() => _RawPatchViewState();
|
||||
}
|
||||
|
||||
class _RawPatchViewState extends State<RawPatchView> {
|
||||
late final TextEditingController _text = TextEditingController(
|
||||
text: widget.patch,
|
||||
);
|
||||
|
||||
@override
|
||||
void didUpdateWidget(RawPatchView oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.patch != _text.text) _text.text = widget.patch;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_text.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino = usesCupertino(context);
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: cupertino
|
||||
? IntrinsicWidth(
|
||||
child: ExcludeSemantics(
|
||||
child: CupertinoTextField(
|
||||
key: const ValueKey('raw-patch-field'),
|
||||
controller: _text,
|
||||
readOnly: true,
|
||||
maxLines: null,
|
||||
padding: EdgeInsets.zero,
|
||||
decoration: const BoxDecoration(),
|
||||
style: widget.style,
|
||||
),
|
||||
),
|
||||
)
|
||||
: ExcludeSemantics(
|
||||
child: SelectionArea(
|
||||
child: Text(
|
||||
widget.patch,
|
||||
style: widget.style,
|
||||
softWrap: false,
|
||||
overflow: TextOverflow.visible,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../../ui/adaptive/host.dart';
|
||||
import '../../changes/changes.dart';
|
||||
|
||||
/// The run detail's action and page label. The viewer itself owns the
|
||||
/// recorded summary and capture wording, so this bar stays neutral.
|
||||
const runChangesLabel = 'Changes';
|
||||
const runChangesButtonKey = ValueKey<String>('run-detail-changes');
|
||||
|
||||
/// The detail's `steps` exactly as returned by the server. The pushed page
|
||||
/// snapshots the returned list once, so it never re-derives on each rebuild.
|
||||
List<JsonMap> runDetailChangeSteps(JsonMap run) {
|
||||
final steps = run['steps'];
|
||||
if (steps is List<JsonMap>) return steps;
|
||||
if (steps is List) return steps.cast<JsonMap>();
|
||||
return const <JsonMap>[];
|
||||
}
|
||||
|
||||
const _executingStatuses = {'queued', 'running', 'waiting'};
|
||||
|
||||
/// Whether the run detail offers the action at all. The opened page is a
|
||||
/// snapshot of the recorded steps, so it is offered only once nothing is
|
||||
/// executing: the server's own `executing` flag (which can stay true on a
|
||||
/// failed run whose step is still active) or a queued/running/waiting status
|
||||
/// would otherwise show a page that silently goes stale.
|
||||
bool showRunChangesAction(JsonMap run) =>
|
||||
run['executing'] != true &&
|
||||
!_executingStatuses.contains('${run['status'] ?? ''}'.trim().toLowerCase());
|
||||
|
||||
/// A standard native button for the run detail body. It opens the recorded
|
||||
/// changes in a platform page whose single navigation bar is the only chrome.
|
||||
class RunChangesButton extends StatelessWidget {
|
||||
const RunChangesButton({super.key, required this.run});
|
||||
|
||||
final JsonMap run;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final steps = runDetailChangeSteps(run);
|
||||
// The web client shows the run-wide aggregate only for a succeeded run; a
|
||||
// failed run still keeps each visit's own recorded capture.
|
||||
final summary = showRunChangesSummary(run['status']);
|
||||
void open() => showRunChanges(context, steps: steps, showSummary: summary);
|
||||
if (usesCupertinoHost(context)) {
|
||||
return CupertinoButton.tinted(
|
||||
key: runChangesButtonKey,
|
||||
onPressed: open,
|
||||
child: const Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(CupertinoIcons.doc_text),
|
||||
SizedBox(width: 6),
|
||||
Text(runChangesLabel),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
return FilledButton.tonalIcon(
|
||||
key: runChangesButtonKey,
|
||||
onPressed: open,
|
||||
icon: const Icon(Icons.difference_outlined),
|
||||
label: const Text(runChangesLabel),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Opens the already-landed [ChangesViewer] for [steps] on a native page.
|
||||
/// The bar is the one title bar; the viewer's own summary and capture facts
|
||||
/// are passed through untouched, except for the caller's [showSummary] gate.
|
||||
Future<void> showRunChanges(
|
||||
BuildContext context, {
|
||||
required List<JsonMap> steps,
|
||||
required bool showSummary,
|
||||
}) {
|
||||
final cupertino = usesCupertinoHost(context);
|
||||
return Navigator.of(context).push<void>(
|
||||
cupertino
|
||||
? CupertinoPageRoute<void>(
|
||||
builder: (_) =>
|
||||
_CupertinoChangesPage(steps: steps, showSummary: showSummary),
|
||||
)
|
||||
: MaterialPageRoute<void>(
|
||||
builder: (_) =>
|
||||
_MaterialChangesPage(steps: steps, showSummary: showSummary),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _MaterialChangesPage extends StatelessWidget {
|
||||
const _MaterialChangesPage({required this.steps, required this.showSummary});
|
||||
|
||||
final List<JsonMap> steps;
|
||||
final bool showSummary;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Scaffold(
|
||||
appBar: AppBar(title: const Text(runChangesLabel)),
|
||||
body: SafeArea(
|
||||
top: false,
|
||||
child: ChangesViewer(steps: steps, showSummary: showSummary),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _CupertinoChangesPage extends StatelessWidget {
|
||||
const _CupertinoChangesPage({required this.steps, required this.showSummary});
|
||||
|
||||
final List<JsonMap> steps;
|
||||
final bool showSummary;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => CupertinoPageScaffold(
|
||||
navigationBar: const CupertinoNavigationBar(middle: Text(runChangesLabel)),
|
||||
child: SafeArea(
|
||||
// A CupertinoApp supplies no Material theme; follow the host brightness
|
||||
// so the viewer's Material-derived section text stays readable.
|
||||
child: Theme(
|
||||
data: hostTextTheme(context),
|
||||
child: ChangesViewer(steps: steps, showSummary: showSummary),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../domain/run_models.dart';
|
||||
import 'run_changes_action.dart';
|
||||
import 'run_detail_content.dart';
|
||||
|
||||
/// The runs detail with standard Cupertino controls. It has no Material
|
||||
@@ -26,7 +27,11 @@ Widget buildCupertinoRunDetail({
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0),
|
||||
child: Row(
|
||||
child: Wrap(
|
||||
alignment: WrapAlignment.spaceBetween,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
spacing: 8,
|
||||
runSpacing: 4,
|
||||
children: [
|
||||
CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
@@ -40,7 +45,7 @@ Widget buildCupertinoRunDetail({
|
||||
],
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
if (showRunChangesAction(run)) RunChangesButton(run: run),
|
||||
if (copying) const CupertinoActivityIndicator(),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../domain/run_models.dart';
|
||||
import 'run_changes_action.dart';
|
||||
import 'run_detail_content.dart';
|
||||
|
||||
/// The runs detail with standard Material controls.
|
||||
@@ -23,13 +24,18 @@ Widget buildMaterialRunDetail({
|
||||
key: ValueKey<String>('run-detail-${run['id']}'),
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: TextButton.icon(
|
||||
onPressed: onBack,
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
label: const Text('Back to list'),
|
||||
),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 4,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
TextButton.icon(
|
||||
onPressed: onBack,
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
label: const Text('Back to list'),
|
||||
),
|
||||
if (showRunChangesAction(run)) RunChangesButton(run: run),
|
||||
],
|
||||
),
|
||||
Text(detailTitle(run), style: theme.textTheme.headlineSmall),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
# D1-wire — native Changes action in the run detail
|
||||
|
||||
## Manager completion after retained stage limit
|
||||
|
||||
The final Code visit completed its fixes, but the runner could not revisit Review
|
||||
again (visit limit3). No implementation was rerun or discarded. Manager checked
|
||||
the retained source, focused changes/wiring tests and analyzer, then rebuilt and
|
||||
drove the real RunDetailView fixture:15 checks/20 captures pass, including both
|
||||
320px/2x native menus and selected Raw patch. Narrow hosts use a standard native
|
||||
sheet, never a custom segmented clone. Manager separated the cohesive form
|
||||
controls into diff_form_control.dart and used the actual host/native label style
|
||||
instead of a hard-coded font measurement. No font/size/palette override remains.
|
||||
Evidence: approved temp/changes-wiring-manager-browser. Actual shell merges and
|
||||
publication are tracked separately in WORK.md; earlier notes below are historical.
|
||||
|
||||
Adds one standard native action to the existing run-detail bodies and reuses the
|
||||
landed `ChangesViewer`. No API call, shell/main or pubspec edit; no commit, push
|
||||
or deploy.
|
||||
|
||||
## Behaviour
|
||||
|
||||
- Material: `FilledButton.tonalIcon` labelled **Changes** beside **Back to
|
||||
list**. It pushes a `MaterialPageRoute` whose only bar is an
|
||||
`AppBar(title: Text('Changes'))` above the viewer.
|
||||
- Cupertino: `CupertinoButton.tinted` labelled **Changes** in the detail's
|
||||
header row. It pushes a `CupertinoPageRoute` whose only bar is a
|
||||
`CupertinoNavigationBar`; native back is automatic.
|
||||
- The action is offered once the run has stopped executing: the server's
|
||||
`executing` flag must be false and the status must not be
|
||||
`queued`/`running`/`waiting`. The opened page snapshots the recorded steps, so
|
||||
an executing run is not given a page that could go stale or miss a later
|
||||
settlement; its evidence belongs to the live visit pane when that slice
|
||||
lands. `showRunChangesAction` holds that check.
|
||||
- The run-wide aggregate is shown only for `succeeded`, matching
|
||||
`web/src/changes.js` `showRunChangesSummary` and PARITY R4. A failed run keeps
|
||||
each visit's own recorded capture (stage, visit number, status, capture
|
||||
counters/scope/diagnostic and file rows) without claiming a settled final
|
||||
state; `ChangesViewer` gained a `showSummary` input for that.
|
||||
- `runDetailChangeSteps` passes the server's `steps` unchanged; the page
|
||||
snapshots the list once.
|
||||
- No capture, visit, partial/missing/unavailable wording or diff rendering is
|
||||
reinterpreted by the wiring; the changes domain still owns all of it.
|
||||
|
||||
## Review findings addressed
|
||||
|
||||
1. **Failed/running runs no longer receive a settled Changes page.** The
|
||||
aggregate and filter are hidden unless the status is `succeeded`; failed
|
||||
runs still open the per-visit evidence. Executing runs get no action at all,
|
||||
which also removes the stale-snapshot case. Covered by failed and running
|
||||
regressions plus browser checks.
|
||||
2. **Cupertino Raw patch no longer asserts.** The raw body moved to
|
||||
`RawPatchView`: Material keeps `SelectionArea`; Cupertino renders the exact
|
||||
recorded bytes in a read-only `CupertinoTextField` (the pattern the run
|
||||
detail already uses), with its intrinsic line width and horizontal scrolling,
|
||||
so no `MaterialLocalizations` are required. A Cupertino Raw regression taps
|
||||
the control and checks the native field, and the browser probe opens it.
|
||||
3. **Dark Cupertino Changes now follows the host.** Both the Cupertino page and
|
||||
the file-diff popup it opens wrap the viewer in `hostTextTheme(context)`
|
||||
(`change_style.dart`): a `Theme` with `CupertinoTheme.brightnessOf(context)`
|
||||
and the host platform. The popup matters because dialogs open on the app
|
||||
Navigator, above the page's own theme, so the first fix alone left the diff
|
||||
header light-theme near-black on the dark popup. Widget regression opens the
|
||||
file from the dark page and asserts the `Modified` header is light; the probe
|
||||
measures the rendered header pixels (luminance 0.87; 0.15 without the fix),
|
||||
and captures cover dark Changes and dark diff.
|
||||
4. **The diff form labels stay whole at 320 px and 2x text.** A two-segment
|
||||
control cannot keep `Rendered` and `Raw patch` on one line there: Material
|
||||
broke `Rendered` mid-word and Cupertino clipped `Raw patch` to `Raw`, with no
|
||||
way to see the rest. `diffFormSegmentsFit` measures the two fixed words at
|
||||
the host's text scale and, when the native segmented control cannot fit both,
|
||||
the viewer uses the host's standard menu instead (a Material bottom sheet or
|
||||
a Cupertino action sheet) with the same two words, one per row. The current
|
||||
mode is highlighted and the menu is titled `Diff form`. The `Copy patch`
|
||||
action keeps its intrinsic width in a horizontal strip rather than breaking
|
||||
its words. Widget regressions on both hosts assert that no label breaks
|
||||
inside a word, is clipped vertically or is clipped horizontally, and that
|
||||
choosing `Raw patch` from the menu shows the recorded raw body. Browser
|
||||
captures cover the 320x2 menu and raw state on both hosts.
|
||||
|
||||
The action gate now also honours the server's `executing` flag (web's
|
||||
`isExecuting`), so a failed run whose step is still active is not offered the
|
||||
snapshot page; the status list remains as the fallback for replies without the
|
||||
flag.
|
||||
|
||||
The earlier comment claiming `runDetailChangeSteps` returns the same list
|
||||
instance was corrected. The browser/system Back advisory is unchanged and
|
||||
unresolved: it needs `AppRouterDelegate.popRoute`/Router work in `lib/shell/`,
|
||||
which this lane must not edit. The probe's Back checks exercise the page's own
|
||||
back control only.
|
||||
|
||||
## Files
|
||||
|
||||
```
|
||||
lib/features/runs/ui/run_changes_action.dart new, 126 lines
|
||||
lib/features/runs/ui/run_detail_material.dart +13/-7
|
||||
lib/features/runs/ui/run_detail_cupertino.dart +8/-2
|
||||
lib/features/changes/changes.dart export hostTextTheme
|
||||
lib/features/changes/domain/run_changes.dart +7
|
||||
lib/features/changes/widgets/change_style.dart +hostTextTheme, fit check, native menu
|
||||
lib/features/changes/widgets/changes_viewer.dart showSummary gate
|
||||
lib/features/changes/widgets/file_diff_viewer.dart raw body, themed dialog, form menu
|
||||
lib/features/changes/widgets/raw_patch_view.dart new, 75 lines
|
||||
test/features/runs/ui/run_changes_action_test.dart new, 177 lines
|
||||
test/features/runs/ui/run_changes_status_test.dart new, 204 lines
|
||||
test/features/changes/diff_presentation_test.dart +2x label regressions
|
||||
test/features/changes/changes_viewer_test.dart 2x control expectation
|
||||
test/features/changes/run_changes_test.dart +9 (status gate)
|
||||
tool/diff_wiring_probe.dart fixture entry, scale=2
|
||||
tool/diff_wiring_probe.mjs browser driver, pixel probe, 2x/320
|
||||
```
|
||||
|
||||
## Checks (actual results)
|
||||
|
||||
- `flutter test test/features/changes test/features/runs` — **159 tests passed**.
|
||||
- `flutter test test/features/runs/ui/run_changes_action_test.dart
|
||||
test/features/runs/ui/run_changes_status_test.dart
|
||||
test/features/runs/ui/run_detail_widget_test.dart test/features/changes` —
|
||||
**67 tests passed**.
|
||||
- `flutter analyze` — **No issues found**.
|
||||
- `dart format --output=none --set-exit-if-changed` on every touched Dart file —
|
||||
clean (0 changed).
|
||||
- `node --check tool/diff_wiring_probe.mjs` — passed.
|
||||
- `flutter build web --target tool/diff_wiring_probe.dart --output
|
||||
build/probe-wire` — built.
|
||||
- `flutter build web --output build/web-wire-check` — built.
|
||||
|
||||
Widget regressions cover both hosts: the happy path (recorded filename, stat,
|
||||
per-stage Visit 1, rendered diff, Close diff, Back), unavailable capture
|
||||
wording, a failed run without the aggregate but with its visit capture, an
|
||||
executing run with no action, the dark host text colour on both the Changes page
|
||||
and the opened diff header, the Cupertino Raw native field, and the 320x720 2x
|
||||
labels: no mid-word break, no vertical or horizontal clipping, the native menu
|
||||
labels and choosing `Raw patch` in it, and the unchanged segmented control on a
|
||||
wide host.
|
||||
|
||||
## Real browser evidence
|
||||
|
||||
`tool/diff_wiring_probe.dart` renders the real `RunDetailView` over a fake
|
||||
`get_run` gateway; `tool/diff_wiring_probe.mjs` serves it on an OS-assigned
|
||||
loopback port and drives headless Chrome. Query parameters select the fixture:
|
||||
`?run=failed`, `?run=running`, `?capture=unavailable`,
|
||||
`?platform=cupertino&theme=light|dark` and `?scale=2` for the 2x text states.
|
||||
No server or operator run was touched.
|
||||
|
||||
All **15/15 checks** passed (`d1-wire/d1-wire-probe.json`), 20 captures:
|
||||
|
||||
- Material run detail shows the native Changes action; it opens the recorded
|
||||
`lib/features/runs/ui/run_changes_action.dart` with `1 file changed · +2 -1`
|
||||
and its implementer visit section.
|
||||
- The recorded file opens its actual diff (`- const label = "Old";`,
|
||||
`+ const recorded = true;`) with Rendered/Raw patch/Copy patch/Close diff;
|
||||
Close diff and Back return.
|
||||
- `?capture=unavailable` shows `Changes · capture unavailable` and the server
|
||||
diagnostic, never "No changes observed".
|
||||
- `?run=failed` keeps the visit capture and shows no run-wide `file changed`
|
||||
summary.
|
||||
- `?run=running` offers no Changes action.
|
||||
- Cupertino shows the tinted Changes button, one bar, the recorded file and
|
||||
diff; Raw patch renders in the native field with the other actions intact;
|
||||
Close diff and Back return.
|
||||
- Cupertino dark renders the summary and the recorded diff with light text; the
|
||||
diff header is sampled from the rendered capture (max luminance 0.87, above
|
||||
the 0.5 readable-text gate) instead of only checking that the words exist.
|
||||
- `?scale=2` at 320x720 opens the same diff on both hosts, shows the `Diff form`
|
||||
menu with `Rendered` and `Raw patch` whole, and renders the recorded raw body
|
||||
after choosing `Raw patch`.
|
||||
|
||||
Captures in the shared `d1-wire/` folder (390x844, plus the 320x720 2x states):
|
||||
|
||||
```
|
||||
d1-wire-material-detail.png d1-wire-material-changes.png
|
||||
d1-wire-material-diff.png d1-wire-material-back.png
|
||||
d1-wire-material-unavailable.png d1-wire-material-failed.png
|
||||
d1-wire-material-running.png d1-wire-cupertino-detail.png
|
||||
d1-wire-cupertino-changes.png d1-wire-cupertino-diff.png
|
||||
d1-wire-cupertino-raw.png d1-wire-cupertino-back.png
|
||||
d1-wire-cupertino-dark-changes.png d1-wire-cupertino-dark-diff.png
|
||||
d1-wire-material-2x-320-diff.png d1-wire-material-2x-320-menu.png
|
||||
d1-wire-material-2x-320-raw.png d1-wire-cupertino-2x-320-diff.png
|
||||
d1-wire-cupertino-2x-320-menu.png d1-wire-cupertino-2x-320-raw.png
|
||||
```
|
||||
|
||||
## Not verified / remaining
|
||||
|
||||
- Browser and Android system Back on the pushed page are unverified; the
|
||||
advisory Router integration was not changed.
|
||||
- Active-run per-visit changes are not shown anywhere yet; that belongs to the
|
||||
live run visit pane, not this snapshot page.
|
||||
- Mobile targets were not built, installed or run; Cupertino is verified through
|
||||
widget tests and browser rendering only, so **mobile remains unverified**.
|
||||
- All data is fixture data; no live server or operator run was used.
|
||||
@@ -466,7 +466,9 @@ void main() {
|
||||
),
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.text('Rendered'), findsOneWidget);
|
||||
// The host is too narrow for a two-segment control at 2x, so the same form
|
||||
// selection is offered through the native menu instead.
|
||||
expect(find.byTooltip('Diff form'), findsOneWidget);
|
||||
expect(find.text('Copy patch'), findsOneWidget);
|
||||
expect(find.byTooltip('Close diff'), findsOneWidget);
|
||||
});
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/changes/changes.dart';
|
||||
import 'package:pipelines_app/features/changes/widgets/change_style.dart';
|
||||
@@ -16,6 +17,64 @@ const _raggedPatch =
|
||||
'-x\n'
|
||||
' tail\n';
|
||||
|
||||
/// Opens the real single-file diff modal from a host, so the test covers the
|
||||
/// dialog's own width and insets rather than the viewer in isolation.
|
||||
Widget _diffDialogOpener(FileChange file) => Builder(
|
||||
builder: (context) => TextButton(
|
||||
onPressed: () => showFileDiffViewer(context, file),
|
||||
child: const Text('Open diff'),
|
||||
),
|
||||
);
|
||||
|
||||
/// Fails when a fixed control label is broken inside a word or clipped by its
|
||||
/// control. A label may wrap only between whole words, which is how a native
|
||||
/// menu keeps an accessibility-size label readable.
|
||||
void _expectWholeLabel(WidgetTester tester, Finder finder, String label) {
|
||||
final paragraph = tester.renderObject<RenderParagraph>(
|
||||
find.descendant(of: finder, matching: find.byType(RichText)),
|
||||
);
|
||||
final span = paragraph.text as TextSpan;
|
||||
expect(span.toPlainText(), label);
|
||||
expect(paragraph.didExceedMaxLines, isFalse);
|
||||
final boxes = paragraph
|
||||
.getBoxesForSelection(
|
||||
TextSelection(baseOffset: 0, extentOffset: label.length),
|
||||
)
|
||||
.toList();
|
||||
expect(boxes, isNotEmpty);
|
||||
// The laid-out paragraph must be tall enough to paint every line it broke.
|
||||
expect(
|
||||
boxes.last.bottom,
|
||||
lessThanOrEqualTo(paragraph.size.height + 0.5),
|
||||
reason: '"$label" must not be clipped vertically',
|
||||
);
|
||||
final widestLine = boxes
|
||||
.map((box) => box.right - box.left)
|
||||
.reduce((a, b) => a > b ? a : b);
|
||||
final style = span.style ?? const TextStyle();
|
||||
var widestWord = 0.0;
|
||||
for (final word in label.split(' ')) {
|
||||
final painter = TextPainter(
|
||||
text: TextSpan(text: word, style: style),
|
||||
textDirection: TextDirection.ltr,
|
||||
textScaler: paragraph.textScaler,
|
||||
)..layout();
|
||||
if (painter.width > widestWord) widestWord = painter.width;
|
||||
}
|
||||
// A line narrower than a whole word means the label broke mid-word.
|
||||
expect(
|
||||
widestLine,
|
||||
greaterThanOrEqualTo(widestWord - 0.5),
|
||||
reason: '"$label" must not break inside a word',
|
||||
);
|
||||
// A clipped line would paint wider than the paragraph's laid-out box.
|
||||
expect(
|
||||
widestLine,
|
||||
lessThanOrEqualTo(paragraph.size.width + 0.5),
|
||||
reason: '"$label" must not be clipped horizontally',
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
test(
|
||||
'patch typography preserves the native host style without overrides',
|
||||
@@ -139,6 +198,49 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('the Cupertino raw patch is a native selectable field', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
cupertinoHost(
|
||||
SizedBox(
|
||||
height: 400,
|
||||
child: FileDiffViewer(
|
||||
file: FileChange(
|
||||
path: 'lib/feature.dart',
|
||||
kind: ChangeKind.modified,
|
||||
patch: multiHunkPatch,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('Raw patch'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// A CupertinoApp has no MaterialLocalizations, so Raw must not use the
|
||||
// Material SelectionArea; it renders the recorded bytes in a native field.
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.byType(SelectionArea), findsNothing);
|
||||
final field = tester.widget<CupertinoTextField>(
|
||||
find.byKey(const ValueKey('raw-patch-field')),
|
||||
);
|
||||
expect(field.readOnly, isTrue);
|
||||
expect(field.maxLines, isNull);
|
||||
expect(field.controller?.text, multiHunkPatch);
|
||||
expect(
|
||||
find.ancestor(
|
||||
of: find.byKey(const ValueKey('raw-patch-field')),
|
||||
matching: find.byWidgetPredicate(
|
||||
(widget) =>
|
||||
widget is SingleChildScrollView &&
|
||||
widget.scrollDirection == Axis.horizontal,
|
||||
),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('a Cupertino row wraps its recorded path instead of clipping it', (
|
||||
tester,
|
||||
) async {
|
||||
@@ -203,4 +305,98 @@ void main() {
|
||||
expect(rect.right, lessThan(382));
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
final diffFile = FileChange(
|
||||
path: 'lib/feature.dart',
|
||||
kind: ChangeKind.modified,
|
||||
patch: multiHunkPatch,
|
||||
);
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
final host = cupertino ? 'Cupertino' : 'Material';
|
||||
|
||||
testWidgets('$host diff labels stay whole at 320x720 with 2x text', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(320, 720);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final opener = _diffDialogOpener(diffFile);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? cupertinoHost(opener, scaler: const TextScaler.linear(2))
|
||||
: materialHost(opener, scaler: const TextScaler.linear(2)),
|
||||
);
|
||||
await tester.tap(find.text('Open diff'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// A segmented control cannot keep both fixed words at this size, so the
|
||||
// host's native menu carries them instead. "Rendered" used to break
|
||||
// mid-word and "Raw patch" used to be clipped to "Raw".
|
||||
expect(find.byType(SegmentedButton<DiffForm>), findsNothing);
|
||||
expect(
|
||||
find.byType(CupertinoSlidingSegmentedControl<DiffForm>),
|
||||
findsNothing,
|
||||
);
|
||||
|
||||
// Copy patch stays a standard action at intrinsic width; it must not
|
||||
// break its two words either.
|
||||
_expectWholeLabel(tester, find.text('Copy patch'), 'Copy patch');
|
||||
|
||||
await tester.tap(
|
||||
cupertino
|
||||
? find.byIcon(CupertinoIcons.ellipsis)
|
||||
: find.byTooltip('Diff form'),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final items = cupertino
|
||||
? find.byType(CupertinoActionSheetAction)
|
||||
: find.byType(ListTile);
|
||||
expect(items, findsNWidgets(2));
|
||||
for (final label in ['Rendered', 'Raw patch']) {
|
||||
_expectWholeLabel(
|
||||
tester,
|
||||
find.descendant(of: items, matching: find.text(label)),
|
||||
label,
|
||||
);
|
||||
}
|
||||
|
||||
await tester.tap(
|
||||
find.descendant(of: items, matching: find.text('Raw patch')),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
if (cupertino) {
|
||||
expect(find.byKey(const ValueKey('raw-patch-field')), findsOneWidget);
|
||||
} else {
|
||||
expect(find.text(multiHunkPatch), findsOneWidget);
|
||||
}
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets(
|
||||
'${cupertino ? 'Cupertino' : 'Material'} wide host keeps the native '
|
||||
'segmented control',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? cupertinoHost(_diffDialogOpener(diffFile))
|
||||
: materialHost(_diffDialogOpener(diffFile)),
|
||||
);
|
||||
await tester.tap(find.text('Open diff'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
cupertino
|
||||
? find.byType(CupertinoSlidingSegmentedControl<DiffForm>)
|
||||
: find.byType(SegmentedButton<DiffForm>),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Rendered'), findsOneWidget);
|
||||
expect(find.text('Raw patch'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -415,6 +415,15 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
test('showRunChangesSummary is true only for a settled succeeded run', () {
|
||||
expect(showRunChangesSummary('succeeded'), isTrue);
|
||||
expect(showRunChangesSummary(' Succeeded '), isTrue);
|
||||
for (final status in ['failed', 'running', 'waiting', 'canceled', '']) {
|
||||
expect(showRunChangesSummary(status), isFalse, reason: status);
|
||||
}
|
||||
expect(showRunChangesSummary(null), isFalse);
|
||||
});
|
||||
|
||||
test('header covers every empty-capture variant', () {
|
||||
expect(
|
||||
runChangesHeader(_run(unavailable: true, files: const [])),
|
||||
|
||||
@@ -0,0 +1,177 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
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/changes/changes.dart';
|
||||
import 'package:pipelines_app/features/runs/data/runs_repository.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_changes_action.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_view.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/runs_controller.dart';
|
||||
|
||||
import '../../changes/fixtures.dart';
|
||||
|
||||
enum _Platform { material, cupertino }
|
||||
|
||||
class _FakeGateway implements ApiGateway {
|
||||
_FakeGateway(this.detail);
|
||||
final JsonMap detail;
|
||||
|
||||
@override
|
||||
Stream<JsonMap> get frames => const Stream<JsonMap>.empty();
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
||||
if (type != 'get_run') throw UnsupportedError(type);
|
||||
return Future.value({'run_detail': detail});
|
||||
}
|
||||
}
|
||||
|
||||
JsonMap _run({
|
||||
JsonMap? fileChanges,
|
||||
String status = 'succeeded',
|
||||
String stepStatus = 'completed',
|
||||
}) => {
|
||||
'id': 9,
|
||||
'title': 'Wiring run',
|
||||
'name': 'release',
|
||||
'status': status,
|
||||
'steps': [
|
||||
stepFixture(
|
||||
stage: 'implementer',
|
||||
sequence: 1,
|
||||
status: stepStatus,
|
||||
fileChanges: fileChanges,
|
||||
),
|
||||
stepFixture(
|
||||
stage: 'reviewer',
|
||||
sequence: 2,
|
||||
status: stepStatus,
|
||||
fileChanges: null,
|
||||
),
|
||||
],
|
||||
};
|
||||
|
||||
Future<void> _pumpDetail(
|
||||
WidgetTester tester,
|
||||
_Platform platform,
|
||||
RunsController controller,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(500, 1200);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final view = RunDetailView(controller: controller, onBack: () {});
|
||||
await tester.pumpWidget(
|
||||
platform == _Platform.material
|
||||
? MaterialApp(home: Scaffold(body: view))
|
||||
: CupertinoApp(
|
||||
// The real host chooses Cupertino on iOS/macOS; state that platform
|
||||
// without mutating the global debug override, as the Changes tests do.
|
||||
builder: (context, app) => Theme(
|
||||
data: ThemeData(platform: TargetPlatform.iOS),
|
||||
child: app!,
|
||||
),
|
||||
home: CupertinoPageScaffold(child: view),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final platform in _Platform.values) {
|
||||
testWidgets(
|
||||
'${platform.name}: Changes opens the recorded files, diff and returns',
|
||||
(tester) async {
|
||||
final controller = RunsController(
|
||||
RunsRepository(
|
||||
_FakeGateway(
|
||||
_run(
|
||||
fileChanges: captureFixture(
|
||||
files: [
|
||||
fileChangeFixture(
|
||||
path: 'lib/feature.dart',
|
||||
patch: multiHunkPatch,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
addTearDown(controller.dispose);
|
||||
await controller.select(9);
|
||||
await _pumpDetail(tester, platform, controller);
|
||||
|
||||
await tester.tap(find.byKey(runChangesButtonKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Changes'), findsOneWidget);
|
||||
expect(find.text('lib/feature.dart'), findsOneWidget);
|
||||
expect(
|
||||
find.text('1 file changed · +2 -2 · capture incomplete'),
|
||||
findsOneWidget,
|
||||
);
|
||||
// Visit numbers are per stage, so both stages' first visits say Visit 1.
|
||||
expect(find.text('Visit 1 · completed'), findsNWidgets(2));
|
||||
|
||||
await tester.tap(
|
||||
find.byKey(const ValueKey('change-1-lib/feature.dart')),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final rendered = tester
|
||||
.widgetList<RichText>(find.byType(RichText))
|
||||
.map((rich) => rich.text.toPlainText())
|
||||
.join('\n');
|
||||
expect(rendered, contains('+ added line'));
|
||||
expect(rendered, contains('- removed line'));
|
||||
|
||||
if (platform == _Platform.material) {
|
||||
await tester.tap(find.byTooltip('Close diff'));
|
||||
} else {
|
||||
await tester.tap(find.byIcon(CupertinoIcons.xmark));
|
||||
}
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('lib/feature.dart'), findsOneWidget);
|
||||
|
||||
if (platform == _Platform.material) {
|
||||
await tester.tap(find.byTooltip('Back'));
|
||||
} else {
|
||||
await tester.tap(find.byType(CupertinoNavigationBarBackButton));
|
||||
}
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Wiring run'), findsOneWidget);
|
||||
expect(find.byKey(runChangesButtonKey), findsOneWidget);
|
||||
expect(find.text('lib/feature.dart'), findsNothing);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'${platform.name}: an unavailable capture keeps its gap wording',
|
||||
(tester) async {
|
||||
final diagnostic =
|
||||
'Workspace snapshot unavailable; changes could not be compared.';
|
||||
final controller = RunsController(
|
||||
RunsRepository(
|
||||
_FakeGateway(
|
||||
_run(
|
||||
fileChanges: captureFixture(
|
||||
status: 'unavailable',
|
||||
diagnostic: diagnostic,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
addTearDown(controller.dispose);
|
||||
await controller.select(9);
|
||||
await _pumpDetail(tester, platform, controller);
|
||||
|
||||
await tester.tap(find.byKey(runChangesButtonKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Changes · capture unavailable'), findsOneWidget);
|
||||
expect(find.text(diagnostic), findsWidgets);
|
||||
expect(find.text(emptyCaptureDetail), findsNothing);
|
||||
expect(find.text('No changes observed'), findsNothing);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
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/data/runs_repository.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_changes_action.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_view.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/runs_controller.dart';
|
||||
|
||||
import '../../changes/fixtures.dart';
|
||||
|
||||
enum _Platform { material, cupertino }
|
||||
|
||||
class _FakeGateway implements ApiGateway {
|
||||
_FakeGateway(this.detail);
|
||||
final JsonMap detail;
|
||||
|
||||
@override
|
||||
Stream<JsonMap> get frames => const Stream<JsonMap>.empty();
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
||||
if (type != 'get_run') throw UnsupportedError(type);
|
||||
return Future.value({'run_detail': detail});
|
||||
}
|
||||
}
|
||||
|
||||
JsonMap _run({
|
||||
required String status,
|
||||
JsonMap? fileChanges,
|
||||
String stepStatus = 'completed',
|
||||
}) => {
|
||||
'id': 9,
|
||||
'title': 'Wiring run',
|
||||
'name': 'release',
|
||||
'status': status,
|
||||
'steps': [
|
||||
stepFixture(
|
||||
stage: 'implementer',
|
||||
sequence: 1,
|
||||
status: stepStatus,
|
||||
fileChanges: fileChanges,
|
||||
),
|
||||
stepFixture(
|
||||
stage: 'reviewer',
|
||||
sequence: 2,
|
||||
status: stepStatus,
|
||||
fileChanges: null,
|
||||
),
|
||||
],
|
||||
};
|
||||
|
||||
Future<void> _pumpDetail(
|
||||
WidgetTester tester,
|
||||
_Platform platform,
|
||||
JsonMap run, {
|
||||
Brightness brightness = Brightness.light,
|
||||
}) async {
|
||||
tester.view.physicalSize = const Size(500, 1200);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final controller = RunsController(RunsRepository(_FakeGateway(run)));
|
||||
addTearDown(controller.dispose);
|
||||
await controller.select(9);
|
||||
final view = RunDetailView(controller: controller, onBack: () {});
|
||||
await tester.pumpWidget(
|
||||
platform == _Platform.material
|
||||
? MaterialApp(
|
||||
theme: ThemeData(brightness: brightness),
|
||||
home: Scaffold(body: view),
|
||||
)
|
||||
: CupertinoApp(
|
||||
theme: CupertinoThemeData(brightness: brightness),
|
||||
builder: (context, app) => Theme(
|
||||
data: ThemeData(platform: TargetPlatform.iOS),
|
||||
child: app!,
|
||||
),
|
||||
home: CupertinoPageScaffold(child: view),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Future<void> _openChanges(
|
||||
WidgetTester tester,
|
||||
_Platform platform,
|
||||
JsonMap run, {
|
||||
Brightness brightness = Brightness.light,
|
||||
}) async {
|
||||
await _pumpDetail(tester, platform, run, brightness: brightness);
|
||||
await tester.tap(find.byKey(runChangesButtonKey));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('the Changes action waits for the run to stop executing', () {
|
||||
for (final status in ['queued', 'running', 'waiting', ' RUNNING ']) {
|
||||
expect(showRunChangesAction({'status': status}), isFalse, reason: status);
|
||||
}
|
||||
for (final status in ['succeeded', 'failed', 'canceled', 'interrupted']) {
|
||||
expect(showRunChangesAction({'status': status}), isTrue, reason: status);
|
||||
}
|
||||
// The server can keep a failed run flagged while one of its steps is still
|
||||
// active; the snapshot page would go stale, so the flag wins.
|
||||
expect(
|
||||
showRunChangesAction({'status': 'failed', 'executing': true}),
|
||||
isFalse,
|
||||
);
|
||||
expect(
|
||||
showRunChangesAction({'status': 'succeeded', 'executing': false}),
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
|
||||
for (final platform in _Platform.values) {
|
||||
testWidgets(
|
||||
'${platform.name}: a failed run keeps visit evidence, not a summary',
|
||||
(tester) async {
|
||||
await _openChanges(
|
||||
tester,
|
||||
platform,
|
||||
_run(
|
||||
status: 'failed',
|
||||
fileChanges: captureFixture(
|
||||
files: [fileChangeFixture(path: 'lib/feature.dart')],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// The web client shows the aggregate only for succeeded runs.
|
||||
expect(find.textContaining('file changed ·'), findsNothing);
|
||||
expect(
|
||||
find.textContaining('The summary counts each path once'),
|
||||
findsNothing,
|
||||
);
|
||||
// The visit's own recorded capture stays reachable.
|
||||
expect(find.text('lib/feature.dart'), findsOneWidget);
|
||||
expect(find.text('Visit 1 · completed'), findsNWidgets(2));
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'${platform.name}: an active run offers no snapshot Changes page',
|
||||
(tester) async {
|
||||
await _pumpDetail(
|
||||
tester,
|
||||
platform,
|
||||
_run(status: 'running', stepStatus: 'running'),
|
||||
);
|
||||
|
||||
// The opened page would not follow live captures, so an executing run
|
||||
// has no action until the live visit pane can show them.
|
||||
expect(find.byKey(runChangesButtonKey), findsNothing);
|
||||
expect(find.text('Changes'), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'${platform.name}: the Changes page follows a dark host theme',
|
||||
(tester) async {
|
||||
await _openChanges(
|
||||
tester,
|
||||
platform,
|
||||
_run(
|
||||
status: 'succeeded',
|
||||
fileChanges: captureFixture(
|
||||
files: [fileChangeFixture(path: 'lib/feature.dart')],
|
||||
),
|
||||
),
|
||||
brightness: Brightness.dark,
|
||||
);
|
||||
|
||||
final header = tester.widget<Text>(
|
||||
find.textContaining('1 file changed'),
|
||||
);
|
||||
final color = header.style?.color;
|
||||
expect(color, isNotNull);
|
||||
expect(
|
||||
color!.computeLuminance(),
|
||||
greaterThan(0.5),
|
||||
reason: 'section text must be light on a dark host: $color',
|
||||
);
|
||||
|
||||
// The diff opens on the app Navigator, above the page's theme, so its
|
||||
// own header must follow the host brightness too.
|
||||
await tester.tap(
|
||||
find.byKey(const ValueKey('change-1-lib/feature.dart')),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final title = tester.widget<Text>(find.text('Modified'));
|
||||
final titleColor = title.style?.color;
|
||||
expect(titleColor, isNotNull);
|
||||
expect(
|
||||
titleColor!.computeLuminance(),
|
||||
greaterThan(0.5),
|
||||
reason: 'diff header must be light on a dark host: $titleColor',
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
// Standalone fixture entry for real-browser run-detail Changes wiring evidence.
|
||||
//
|
||||
// Build and probe (from app/):
|
||||
// flutter build web --target tool/diff_wiring_probe.dart --output build/probe-wire
|
||||
// node tool/diff_wiring_probe.mjs --root build/probe-wire --out DIR
|
||||
//
|
||||
// Server-shaped fixtures only: a fake gateway answers the same get_run envelope
|
||||
// the app consumes. No server or operator run is touched.
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/runs/data/runs_repository.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_view.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/runs_controller.dart';
|
||||
|
||||
const _patch =
|
||||
'--- "a/lib/features/runs/ui/run_changes_action.dart"\n'
|
||||
'+++ "b/lib/features/runs/ui/run_changes_action.dart"\n'
|
||||
'@@ -1,3 +1,4 @@\n'
|
||||
' import package:flutter/material.dart;\n'
|
||||
'-const label = "Old";\n'
|
||||
'+const label = "Changes";\n'
|
||||
'+const recorded = true;\n'
|
||||
' // end\n';
|
||||
|
||||
class _FakeGateway implements ApiGateway {
|
||||
_FakeGateway(this.detail);
|
||||
|
||||
final JsonMap detail;
|
||||
|
||||
@override
|
||||
Stream<JsonMap> get frames => const Stream<JsonMap>.empty();
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
||||
if (type != 'get_run') throw UnsupportedError(type);
|
||||
return Future.value({'run_detail': detail});
|
||||
}
|
||||
}
|
||||
|
||||
JsonMap _run({
|
||||
required bool unavailable,
|
||||
String status = 'succeeded',
|
||||
String stepStatus = 'completed',
|
||||
}) => {
|
||||
'id': 12,
|
||||
'title': 'Changes wiring probe',
|
||||
'name': 'probe',
|
||||
'status': status,
|
||||
'steps': [
|
||||
{
|
||||
'stage': 'implementer',
|
||||
'sequence': 1,
|
||||
'status': stepStatus,
|
||||
'file_changes': unavailable
|
||||
? {
|
||||
'status': 'unavailable',
|
||||
'skipped': 0,
|
||||
'omitted': 0,
|
||||
'diagnostic':
|
||||
'Workspace snapshot unavailable; changes could not be '
|
||||
'compared.',
|
||||
'files': <JsonMap>[],
|
||||
}
|
||||
: status == 'running'
|
||||
? null
|
||||
: {
|
||||
'status': 'complete',
|
||||
'scope': 'Git tracked and nonignored files in the run directory',
|
||||
'skipped': 0,
|
||||
'omitted': 0,
|
||||
'diagnostic': '',
|
||||
'files': [
|
||||
{
|
||||
'path': 'lib/features/runs/ui/run_changes_action.dart',
|
||||
'kind': 'modified',
|
||||
'patch': _patch,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
void main() {
|
||||
final params = Uri.base.queryParameters;
|
||||
final cupertino = params['platform'] == 'cupertino';
|
||||
final stepsUnavailable = params['capture'] == 'unavailable';
|
||||
final status = params['run'] == 'failed'
|
||||
? 'failed'
|
||||
: params['run'] == 'running'
|
||||
? 'running'
|
||||
: 'succeeded';
|
||||
final stepStatus = status == 'running' ? 'running' : 'completed';
|
||||
final theme = params['theme'] == 'light' ? Brightness.light : Brightness.dark;
|
||||
// Browser text scaling is a fixture input like platform and theme: the
|
||||
// accessibility states are otherwise unreachable from CDP metrics alone.
|
||||
final textScale = double.tryParse(params['scale'] ?? '') ?? 1;
|
||||
final body = _ProbeBody(
|
||||
unavailable: stepsUnavailable,
|
||||
status: status,
|
||||
stepStatus: stepStatus,
|
||||
);
|
||||
Widget scaled(BuildContext context, Widget? app) => MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(textScaler: TextScaler.linear(textScale)),
|
||||
child: app!,
|
||||
);
|
||||
if (cupertino) {
|
||||
runApp(
|
||||
CupertinoApp(
|
||||
title: 'Run changes probe',
|
||||
theme: CupertinoThemeData(brightness: theme),
|
||||
builder: (context, app) => Theme(
|
||||
data: ThemeData(platform: TargetPlatform.iOS),
|
||||
child: scaled(context, app),
|
||||
),
|
||||
home: body,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
runApp(
|
||||
MaterialApp(
|
||||
title: 'Run changes probe',
|
||||
theme: ThemeData(brightness: theme, platform: TargetPlatform.android),
|
||||
builder: scaled,
|
||||
home: body,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ProbeBody extends StatefulWidget {
|
||||
const _ProbeBody({
|
||||
required this.unavailable,
|
||||
required this.status,
|
||||
required this.stepStatus,
|
||||
});
|
||||
|
||||
final bool unavailable;
|
||||
final String status;
|
||||
final String stepStatus;
|
||||
|
||||
@override
|
||||
State<_ProbeBody> createState() => _ProbeBodyState();
|
||||
}
|
||||
|
||||
class _ProbeBodyState extends State<_ProbeBody> {
|
||||
late final RunsController _controller = RunsController(
|
||||
RunsRepository(
|
||||
_FakeGateway(
|
||||
_run(
|
||||
unavailable: widget.unavailable,
|
||||
status: widget.status,
|
||||
stepStatus: widget.stepStatus,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller.select(12);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final detail = RunDetailView(controller: _controller, onBack: () {});
|
||||
if (Theme.of(context).platform == TargetPlatform.iOS) {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: const CupertinoNavigationBar(middle: Text('Runs')),
|
||||
child: SafeArea(child: detail),
|
||||
);
|
||||
}
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Runs')),
|
||||
body: detail,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,498 @@
|
||||
// Real-browser evidence for the run-detail Changes action wiring.
|
||||
//
|
||||
// Usage (from app/):
|
||||
// flutter build web --target tool/diff_wiring_probe.dart --output build/probe-wire
|
||||
// node tool/diff_wiring_probe.mjs --root build/probe-wire --out DIR
|
||||
//
|
||||
// The fixture serves the actual RunDetailView over a fake gateway, then drives
|
||||
// headless Chrome over loopback: the native Changes button, the recorded file,
|
||||
// its diff, Close diff, Back, the failed-run evidence without a run-wide
|
||||
// summary, the absent action while executing, and the Cupertino raw/dark
|
||||
// surfaces. No server or operator run is touched.
|
||||
import { createServer } from 'node:http';
|
||||
import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
|
||||
import { spawn } from 'node:child_process';
|
||||
import { once } from 'node:events';
|
||||
import { setTimeout as delay } from 'node:timers/promises';
|
||||
import { extname, join, resolve, sep } from 'node:path';
|
||||
import { tmpdir } from 'node:os';
|
||||
|
||||
const args = new Map();
|
||||
for (let i = 2; i < process.argv.length; i++) {
|
||||
const value = process.argv[i];
|
||||
if (value.startsWith('--')) args.set(value.slice(2), process.argv[++i]);
|
||||
}
|
||||
const root = resolve(args.get('root') ?? 'build/probe-wire');
|
||||
const out = resolve(args.get('out') ?? 'build/diff-wiring-probe');
|
||||
const chromePath =
|
||||
process.env.CHROME_PATH ?? '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
|
||||
await mkdir(out, { recursive: true });
|
||||
|
||||
const mime = {
|
||||
'.html': 'text/html; charset=utf-8',
|
||||
'.js': 'text/javascript; charset=utf-8',
|
||||
'.mjs': 'text/javascript; charset=utf-8',
|
||||
'.json': 'application/json; charset=utf-8',
|
||||
'.wasm': 'application/wasm',
|
||||
'.png': 'image/png',
|
||||
'.svg': 'image/svg+xml',
|
||||
'.ico': 'image/x-icon',
|
||||
'.ttf': 'font/ttf',
|
||||
'.otf': 'font/otf',
|
||||
'.woff': 'font/woff',
|
||||
'.woff2': 'font/woff2',
|
||||
'.bin': 'application/octet-stream',
|
||||
'.frag': 'application/octet-stream',
|
||||
};
|
||||
|
||||
const server = createServer(async (req, res) => {
|
||||
try {
|
||||
const pathname = decodeURIComponent(new URL(req.url, 'http://localhost').pathname);
|
||||
let filePath = resolve(root, '.' + pathname);
|
||||
if (filePath !== root && !filePath.startsWith(root + sep)) {
|
||||
res.writeHead(403).end();
|
||||
return;
|
||||
}
|
||||
if (pathname === '/' || pathname.endsWith('/')) filePath = join(filePath, 'index.html');
|
||||
const file = await readFile(filePath);
|
||||
res.writeHead(200, { 'content-type': mime[extname(filePath)] ?? 'application/octet-stream' }).end(file);
|
||||
} catch {
|
||||
res.writeHead(404).end('not found');
|
||||
}
|
||||
});
|
||||
server.listen(0, '127.0.0.1');
|
||||
await once(server, 'listening');
|
||||
const origin = `http://127.0.0.1:${server.address().port}`;
|
||||
|
||||
const profile = await mkdtemp(join(tmpdir(), 'd1-wire-chrome-'));
|
||||
const chrome = spawn(
|
||||
chromePath,
|
||||
['--headless=new', '--no-first-run', '--no-default-browser-check', '--disable-gpu',
|
||||
'--remote-debugging-port=0', `--user-data-dir=${profile}`, 'about:blank'],
|
||||
{ stdio: ['ignore', 'ignore', 'pipe'] },
|
||||
);
|
||||
let stderr = '';
|
||||
chrome.stderr.on('data', (data) => {
|
||||
stderr += data;
|
||||
});
|
||||
|
||||
const waitFor = async (fn, what) => {
|
||||
for (let i = 0; i < 120; i++) {
|
||||
const value = await fn();
|
||||
if (value) return value;
|
||||
await delay(100);
|
||||
}
|
||||
throw new Error(`Timed out waiting for ${what}: ${stderr.slice(-1500)}`);
|
||||
};
|
||||
|
||||
const file = 'lib/features/runs/ui/run_changes_action.dart';
|
||||
const rowPrefix = `Open diff for ${file}`;
|
||||
const evidence = { origin, captures: [], checks: [] };
|
||||
let ws;
|
||||
try {
|
||||
const endpoint = await waitFor(
|
||||
() => stderr.match(/DevTools listening on (ws:\/\/[^\s]+)/)?.[1],
|
||||
'Chrome DevTools',
|
||||
);
|
||||
ws = new WebSocket(endpoint);
|
||||
await once(ws, 'open');
|
||||
let id = 0;
|
||||
const pending = new Map();
|
||||
ws.addEventListener('message', (event) => {
|
||||
const message = JSON.parse(event.data);
|
||||
if (message.id && pending.has(message.id)) {
|
||||
pending.get(message.id)(message);
|
||||
pending.delete(message.id);
|
||||
}
|
||||
});
|
||||
const send = (method, params = {}, sessionId) =>
|
||||
new Promise((resolveCall) => {
|
||||
const callId = ++id;
|
||||
pending.set(callId, resolveCall);
|
||||
ws.send(JSON.stringify({ id: callId, method, params, ...(sessionId ? { sessionId } : {}) }));
|
||||
});
|
||||
|
||||
const created = await send('Target.createTarget', { url: 'about:blank' });
|
||||
if (!created.result) throw new Error(`Target creation failed: ${JSON.stringify(created)}`);
|
||||
const session = (await send('Target.attachToTarget', {
|
||||
targetId: created.result.targetId,
|
||||
flatten: true,
|
||||
})).result.sessionId;
|
||||
await send('Page.enable', {}, session);
|
||||
await send('Runtime.enable', {}, session);
|
||||
await send('Emulation.setDeviceMetricsOverride', {
|
||||
width: 390, height: 844, deviceScaleFactor: 1, mobile: true,
|
||||
}, session);
|
||||
|
||||
const evaluate = async (expression) => {
|
||||
const response = await send(
|
||||
'Runtime.evaluate',
|
||||
{ expression, returnByValue: true, awaitPromise: true },
|
||||
session,
|
||||
);
|
||||
if (response.error) throw new Error(`Runtime.evaluate failed: ${JSON.stringify(response)}`);
|
||||
return response.result?.result?.value;
|
||||
};
|
||||
const labels = () =>
|
||||
evaluate(
|
||||
"[...document.querySelectorAll('flt-semantics')].map(x => x.getAttribute('aria-label') || (x.innerText || '').trim()).filter(Boolean)",
|
||||
);
|
||||
const bodyText = () => evaluate('document.body.innerText');
|
||||
const hasLabel = async (label) => (await labels()).includes(label);
|
||||
const hasPrefix = async (prefix) =>
|
||||
(await labels()).some((label) => label.startsWith(prefix));
|
||||
const clickExact = async (label) => {
|
||||
const clicked = await evaluate(`(() => {
|
||||
const wanted = ${JSON.stringify(label)};
|
||||
const nodes = [...document.querySelectorAll('flt-semantics')];
|
||||
const node = nodes.find(x => x.getAttribute('aria-label') === wanted)
|
||||
|| nodes.find(x => (x.innerText || '').trim() === wanted);
|
||||
if (!node) return false;
|
||||
node.click();
|
||||
return true;
|
||||
})()`);
|
||||
if (!clicked) throw new Error(`No exact semantics label ${JSON.stringify(label)}: ${JSON.stringify(await labels())}`);
|
||||
await delay(500);
|
||||
};
|
||||
const clickPrefix = async (prefix) => {
|
||||
const clicked = await evaluate(`(() => {
|
||||
const wanted = ${JSON.stringify(prefix)};
|
||||
const nodes = [...document.querySelectorAll('flt-semantics')];
|
||||
const candidates = nodes.filter((x) =>
|
||||
(x.getAttribute('aria-label') || '').startsWith(wanted)
|
||||
|| (x.innerText || '').trim().startsWith(wanted));
|
||||
if (candidates.length === 0) return false;
|
||||
// Click the actionable row, not an ancestor semantics container whose
|
||||
// innerText happens to start with the same text.
|
||||
const actionable = candidates.filter((x) => x.hasAttribute('flt-tappable'));
|
||||
const target = (actionable.length > 0 ? actionable : candidates)
|
||||
.sort((a, b) => (a.innerText || '').length - (b.innerText || '').length)[0];
|
||||
target.click();
|
||||
return true;
|
||||
})()`);
|
||||
if (!clicked) throw new Error(`No semantics label starting ${JSON.stringify(prefix)}: ${JSON.stringify(await labels())}`);
|
||||
await delay(500);
|
||||
};
|
||||
const activate = async () => {
|
||||
await delay(3200);
|
||||
await evaluate("document.querySelector('flt-semantics-placeholder')?.click()");
|
||||
await delay(900);
|
||||
const current = await labels();
|
||||
if (!current.some((label) => label.includes('Changes wiring probe'))) {
|
||||
throw new Error(`Flutter semantics unavailable: ${JSON.stringify(current)}`);
|
||||
}
|
||||
};
|
||||
const navigate = async (url) => {
|
||||
const navigation = await send('Page.navigate', { url }, session);
|
||||
if (navigation.error || navigation.result?.errorText) throw new Error(JSON.stringify(navigation));
|
||||
await activate();
|
||||
};
|
||||
const capture = async (name, width = 390, height = 844, scale = 1) => {
|
||||
await send('Emulation.setDeviceMetricsOverride', {
|
||||
width, height, deviceScaleFactor: scale, mobile: width < 600,
|
||||
}, session);
|
||||
await delay(350);
|
||||
const data = (await send('Page.captureScreenshot', { format: 'png' }, session)).result.data;
|
||||
const path = join(out, `${name}.png`);
|
||||
await writeFile(path, Buffer.from(data, 'base64'));
|
||||
evidence.captures.push(path);
|
||||
};
|
||||
|
||||
// Semantics expose a widget's box in CSS pixels; the pixel probe then reads
|
||||
// the rendered screen so a text colour can be asserted, not just presence.
|
||||
const rectOfLabel = (prefix) =>
|
||||
evaluate(`(() => {
|
||||
const wanted = ${JSON.stringify(prefix)};
|
||||
const text = (x) => x.getAttribute('aria-label') || (x.innerText || '').trim();
|
||||
const node = [...document.querySelectorAll('flt-semantics')]
|
||||
.find(x => text(x).startsWith(wanted));
|
||||
if (!node) return null;
|
||||
const r = node.getBoundingClientRect();
|
||||
return { x: r.x, y: r.y, width: r.width, height: r.height };
|
||||
})()`);
|
||||
const brightestPixel = async (rect) => {
|
||||
const shot = await send('Page.captureScreenshot', {
|
||||
format: 'png',
|
||||
clip: { ...rect, scale: 2 },
|
||||
}, session);
|
||||
if (!shot.result?.data) throw new Error(`Screenshot clip failed: ${JSON.stringify(shot)}`);
|
||||
return evaluate(`(async () => {
|
||||
const img = new Image();
|
||||
img.src = 'data:image/png;base64,${shot.result.data}';
|
||||
await img.decode();
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = img.width;
|
||||
canvas.height = img.height;
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(img, 0, 0);
|
||||
const data = ctx.getImageData(0, 0, img.width, img.height).data;
|
||||
let max = 0;
|
||||
let bright = 0;
|
||||
for (let i = 0; i < data.length; i += 4) {
|
||||
const lum = (0.2126 * data[i] + 0.7152 * data[i + 1] + 0.0722 * data[i + 2]) / 255;
|
||||
if (lum > max) max = lum;
|
||||
if (lum > 0.5) bright++;
|
||||
}
|
||||
return { max, bright, pixels: data.length / 4, width: img.width, height: img.height };
|
||||
})()`);
|
||||
};
|
||||
|
||||
await navigate(`${origin}/`);
|
||||
const detailBody = await bodyText();
|
||||
if (!detailBody.includes('Changes wiring probe')) {
|
||||
throw new Error(`Run detail did not render: ${JSON.stringify(detailBody)}`);
|
||||
}
|
||||
if (!(await hasLabel('Changes'))) {
|
||||
throw new Error(`Run detail has no Changes action: ${JSON.stringify(await labels())}`);
|
||||
}
|
||||
evidence.checks.push({ check: 'run detail shows the native Changes action', value: true });
|
||||
await capture('d1-wire-material-detail');
|
||||
|
||||
await clickExact('Changes');
|
||||
const changesBody = await bodyText();
|
||||
if (changesBody === detailBody) throw new Error('Changes did not open a new page');
|
||||
if (!changesBody.includes(file)) throw new Error(`Recorded filename missing: ${JSON.stringify(changesBody)}`);
|
||||
if (!changesBody.includes('1 file changed · +2 -1')) {
|
||||
throw new Error(`Recorded stat missing: ${JSON.stringify(changesBody)}`);
|
||||
}
|
||||
evidence.checks.push({ check: 'Changes opened the recorded filename and stat', value: true });
|
||||
await capture('d1-wire-material-changes');
|
||||
await delay(1200);
|
||||
await clickPrefix(rowPrefix);
|
||||
const diffBody = await bodyText();
|
||||
if (!diffBody.includes('const recorded = true;')
|
||||
|| !diffBody.includes('const label = "Old";')) {
|
||||
throw new Error(`Recorded diff lines missing: ${JSON.stringify(diffBody)}`);
|
||||
}
|
||||
for (const label of ['Rendered', 'Raw patch', 'Copy patch', 'Close diff']) {
|
||||
if (!(await hasLabel(label))) throw new Error(`Diff is missing ${label}: ${JSON.stringify(await labels())}`);
|
||||
}
|
||||
evidence.checks.push({ check: 'the recorded file opened its actual diff', value: true });
|
||||
await capture('d1-wire-material-diff');
|
||||
|
||||
await clickExact('Close diff');
|
||||
if (!(await bodyText()).includes(file)) throw new Error('Close diff did not return to Changes');
|
||||
await clickExact('Back');
|
||||
const backBody = await bodyText();
|
||||
if (!backBody.includes('Changes wiring probe') || !(await hasLabel('Changes'))) {
|
||||
throw new Error(`Back did not return to the run detail: ${JSON.stringify(backBody)}`);
|
||||
}
|
||||
evidence.checks.push({ check: 'Close diff and Back returned to the previous pages', value: true });
|
||||
await capture('d1-wire-material-back');
|
||||
|
||||
await navigate(`${origin}/?capture=unavailable`);
|
||||
await clickExact('Changes');
|
||||
const unavailableBody = await bodyText();
|
||||
if (!unavailableBody.includes('Changes · capture unavailable')) {
|
||||
throw new Error(`Unavailable capture wording missing: ${JSON.stringify(unavailableBody)}`);
|
||||
}
|
||||
if (!unavailableBody.includes('Workspace snapshot unavailable; changes could not be compared.')) {
|
||||
throw new Error('Unavailable diagnostic missing');
|
||||
}
|
||||
if (unavailableBody.includes('No changes observed')) {
|
||||
throw new Error('Unavailable capture claimed no changes');
|
||||
}
|
||||
evidence.checks.push({ check: 'unavailable capture keeps its gap wording', value: true });
|
||||
await capture('d1-wire-material-unavailable');
|
||||
|
||||
await navigate(`${origin}/?run=failed`);
|
||||
await clickExact('Changes');
|
||||
await capture('d1-wire-material-failed');
|
||||
const failedBody = await bodyText();
|
||||
const failedText = [failedBody, ...(await labels())].join('\n');
|
||||
if (!failedText.includes(file)) {
|
||||
throw new Error(`Failed run lost its visit capture: ${JSON.stringify(failedText)}`);
|
||||
}
|
||||
if (failedText.includes('file changed')) {
|
||||
throw new Error(`Failed run showed a settled run-wide summary: ${JSON.stringify(failedText)}`);
|
||||
}
|
||||
if (!failedText.includes('Visit 1')) {
|
||||
throw new Error(`Failed run visit section missing: ${JSON.stringify(failedText)}`);
|
||||
}
|
||||
evidence.checks.push({ check: 'a failed run keeps visit evidence without a summary', value: true });
|
||||
|
||||
await navigate(`${origin}/?run=running`);
|
||||
if (await hasLabel('Changes')) {
|
||||
throw new Error('An executing run offered the snapshot Changes page');
|
||||
}
|
||||
const runningBody = await bodyText();
|
||||
if (!runningBody.includes('running')) {
|
||||
throw new Error(`Running run detail did not render its status: ${JSON.stringify(runningBody)}`);
|
||||
}
|
||||
evidence.checks.push({ check: 'an executing run offers no snapshot Changes page', value: true });
|
||||
await capture('d1-wire-material-running');
|
||||
|
||||
await navigate(`${origin}/?platform=cupertino&theme=light`);
|
||||
if (!(await hasLabel('Changes'))) {
|
||||
throw new Error(`Cupertino run detail has no Changes action: ${JSON.stringify(await labels())}`);
|
||||
}
|
||||
await capture('d1-wire-cupertino-detail');
|
||||
await clickExact('Changes');
|
||||
const cupertinoChanges = await bodyText();
|
||||
if (!cupertinoChanges.includes(file)) {
|
||||
throw new Error(`Cupertino Changes did not open the recorded file: ${JSON.stringify(cupertinoChanges)}`);
|
||||
}
|
||||
evidence.checks.push({ check: 'Cupertino Changes opened the recorded file', value: true });
|
||||
await capture('d1-wire-cupertino-changes');
|
||||
|
||||
await clickPrefix(rowPrefix);
|
||||
if (!(await bodyText()).includes('const recorded = true;')) {
|
||||
throw new Error('Cupertino recorded diff missing');
|
||||
}
|
||||
await capture('d1-wire-cupertino-diff');
|
||||
await clickExact('Raw patch');
|
||||
const rawLabels = await labels();
|
||||
const rawBody = await bodyText();
|
||||
if (!rawLabels.some((label) => label.includes('Raw patch for'))
|
||||
&& !rawBody.includes('const recorded = true;')) {
|
||||
throw new Error(`Cupertino raw patch did not render: ${JSON.stringify(rawLabels)}`);
|
||||
}
|
||||
if (!(await hasLabel('Copy patch'))) {
|
||||
throw new Error(`Cupertino raw view lost its actions: ${JSON.stringify(await labels())}`);
|
||||
}
|
||||
evidence.checks.push({ check: 'Cupertino Raw patch uses a native selectable body', value: true });
|
||||
await capture('d1-wire-cupertino-raw');
|
||||
await clickExact('Close diff');
|
||||
await delay(600);
|
||||
await clickExact('Back');
|
||||
await delay(800);
|
||||
if (!(await bodyText()).includes('Changes wiring probe')) {
|
||||
throw new Error('Cupertino Back did not return to the run detail');
|
||||
}
|
||||
evidence.checks.push({ check: 'Cupertino diff and Back returned', value: true });
|
||||
await capture('d1-wire-cupertino-back');
|
||||
|
||||
await navigate(`${origin}/?platform=cupertino&theme=dark`);
|
||||
await clickExact('Changes');
|
||||
const darkText = [await bodyText(), ...(await labels())].join('\n');
|
||||
if (!darkText.includes(file) || !darkText.includes('file changed')) {
|
||||
throw new Error(`Cupertino dark Changes did not render: ${JSON.stringify(darkText)}`);
|
||||
}
|
||||
evidence.checks.push({ check: 'Cupertino dark Changes renders the recorded summary', value: true });
|
||||
await capture('d1-wire-cupertino-dark-changes');
|
||||
await clickPrefix(rowPrefix);
|
||||
if (!(await bodyText()).includes('const recorded = true;')) {
|
||||
throw new Error('Cupertino dark recorded diff missing');
|
||||
}
|
||||
// The header is a merged semantics label, so anchor the pixel crop on the
|
||||
// controls below it: the form control and the title share the 16 px inset,
|
||||
// and the close control shares the header's top line.
|
||||
const formRect = await rectOfLabel('Rendered');
|
||||
const closeRect = await rectOfLabel('Close diff');
|
||||
if (!formRect || !closeRect) {
|
||||
throw new Error(`Dark diff controls are missing: ${JSON.stringify(await labels())}`);
|
||||
}
|
||||
const titleLuminance = await brightestPixel({
|
||||
x: formRect.x,
|
||||
y: closeRect.y,
|
||||
width: 60,
|
||||
height: 22,
|
||||
});
|
||||
if (titleLuminance.max < 0.5) {
|
||||
throw new Error(`Dark Cupertino diff header is not light: ${JSON.stringify(titleLuminance)}`);
|
||||
}
|
||||
evidence.checks.push({
|
||||
check: 'Cupertino dark diff header text is light on the popup surface',
|
||||
value: true,
|
||||
luminance: titleLuminance.max,
|
||||
});
|
||||
evidence.checks.push({ check: 'Cupertino dark diff renders its recorded lines', value: true });
|
||||
await capture('d1-wire-cupertino-dark-diff');
|
||||
|
||||
// A 320-px host at 2x text is the narrowest documented state. The native
|
||||
// controls must keep the whole browser words; the strip scrolls and reveals
|
||||
// the selected segment instead of clipping or breaking a label.
|
||||
const scroll = async ({ x, y, deltaX = 0, deltaY = 0 }) => {
|
||||
await send('Input.dispatchMouseEvent', {
|
||||
type: 'mouseWheel', x, y, deltaX, deltaY,
|
||||
}, session);
|
||||
await delay(400);
|
||||
};
|
||||
const openScaledDiff = async ({ platform, prefix }) => {
|
||||
await send('Emulation.setDeviceMetricsOverride', {
|
||||
width: 320, height: 720, deviceScaleFactor: 1, mobile: true,
|
||||
}, session);
|
||||
const query = platform === 'cupertino'
|
||||
? '?platform=cupertino&theme=light&scale=2'
|
||||
: '?theme=light&scale=2';
|
||||
await navigate(`${origin}/${query}`);
|
||||
await clickExact('Changes');
|
||||
// The 2x summary pushes the recorded file below the fold: scroll the
|
||||
// Changes list until its row is built and offered.
|
||||
for (let i = 0; i < 8 && !(await hasPrefix(rowPrefix)); i++) {
|
||||
await scroll({ x: 160, y: 600, deltaY: 400 });
|
||||
}
|
||||
if (!(await hasPrefix(rowPrefix))) {
|
||||
throw new Error(`2x Changes did not offer the recorded file: ${JSON.stringify(await labels())}`);
|
||||
}
|
||||
await clickPrefix(rowPrefix);
|
||||
await delay(800);
|
||||
const body = await bodyText();
|
||||
if (!body.includes('const recorded = true;')) {
|
||||
throw new Error(`2x diff did not render: ${JSON.stringify(body)}`);
|
||||
}
|
||||
for (const label of ['Copy patch', 'Close diff', 'Diff form']) {
|
||||
if (!(await hasLabel(label))) {
|
||||
throw new Error(`2x diff is missing ${label}: ${JSON.stringify(await labels())}`);
|
||||
}
|
||||
}
|
||||
await capture(`${prefix}-diff`, 320, 720, 1);
|
||||
|
||||
// The native menu carries both fixed words on a host too narrow for the
|
||||
// segmented control; the sheet/list must show each of them whole. A real
|
||||
// pointer tap is used because the Cupertino label sits on a semantic
|
||||
// wrapper above the actual button.
|
||||
const menuRect = await rectOfLabel('Diff form');
|
||||
if (!menuRect) {
|
||||
throw new Error(`2x diff has no Diff form control: ${JSON.stringify(await labels())}`);
|
||||
}
|
||||
const tap = {
|
||||
x: menuRect.x + menuRect.width / 2,
|
||||
y: menuRect.y + menuRect.height / 2,
|
||||
};
|
||||
await send('Input.dispatchMouseEvent', {
|
||||
type: 'mousePressed', ...tap, button: 'left', clickCount: 1,
|
||||
}, session);
|
||||
await send('Input.dispatchMouseEvent', {
|
||||
type: 'mouseReleased', ...tap, button: 'left', clickCount: 1,
|
||||
}, session);
|
||||
await delay(900);
|
||||
for (const label of ['Rendered', 'Raw patch']) {
|
||||
if (!(await hasLabel(label))) {
|
||||
throw new Error(`2x diff menu is missing ${label}: ${JSON.stringify(await labels())}`);
|
||||
}
|
||||
}
|
||||
await capture(`${prefix}-menu`, 320, 720, 1);
|
||||
|
||||
await clickExact('Raw patch');
|
||||
await delay(900);
|
||||
const raw = await bodyText();
|
||||
const rawLabels = await labels();
|
||||
if (!rawLabels.some((label) => label.includes('Raw patch for'))
|
||||
&& !raw.includes('const recorded = true;')) {
|
||||
throw new Error(`2x Raw patch did not render: ${JSON.stringify(rawLabels)}`);
|
||||
}
|
||||
await capture(`${prefix}-raw`, 320, 720, 1);
|
||||
await clickExact('Close diff');
|
||||
await delay(600);
|
||||
};
|
||||
|
||||
await openScaledDiff({ platform: 'material', prefix: 'd1-wire-material-2x-320' });
|
||||
evidence.checks.push({
|
||||
check: 'Material 2x/320 diff keeps its controls and opens Raw patch',
|
||||
value: true,
|
||||
});
|
||||
await openScaledDiff({ platform: 'cupertino', prefix: 'd1-wire-cupertino-2x-320' });
|
||||
evidence.checks.push({
|
||||
check: 'Cupertino 2x/320 diff keeps its controls and opens Raw patch',
|
||||
value: true,
|
||||
});
|
||||
|
||||
console.log(JSON.stringify(evidence, null, 2));
|
||||
} finally {
|
||||
ws?.close();
|
||||
chrome.kill('SIGTERM');
|
||||
await Promise.race([once(chrome, 'exit'), delay(3000)]);
|
||||
server.close();
|
||||
await rm(profile, { recursive: true, force: true });
|
||||
}
|
||||
Reference in New Issue
Block a user