feat(app): add the Graph tab and recorded-stage selection to run detail
This commit is contained in:
@@ -48,12 +48,15 @@ class RunChangesButton extends StatelessWidget {
|
|||||||
return CupertinoButton.tinted(
|
return CupertinoButton.tinted(
|
||||||
key: runChangesButtonKey,
|
key: runChangesButtonKey,
|
||||||
onPressed: open,
|
onPressed: open,
|
||||||
|
// The label keeps its intrinsic size until scaled text no longer fits
|
||||||
|
// the detail's narrowest pane; then it wraps inside the native button
|
||||||
|
// instead of overflowing the header row.
|
||||||
child: const Row(
|
child: const Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Icon(CupertinoIcons.doc_text),
|
Icon(CupertinoIcons.doc_text),
|
||||||
SizedBox(width: 6),
|
SizedBox(width: 6),
|
||||||
Text(runChangesLabel),
|
Flexible(child: Text(runChangesLabel)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -7,7 +7,17 @@ import '../domain/run_models.dart';
|
|||||||
typedef DetailMetric = ({String label, String value});
|
typedef DetailMetric = ({String label, String value});
|
||||||
|
|
||||||
/// One recorded visit in the run detail's timeline.
|
/// One recorded visit in the run detail's timeline.
|
||||||
typedef DetailVisit = ({String title, String subtitle});
|
///
|
||||||
|
/// [stage] and [sequence] are the visit's exact recorded identity, so the
|
||||||
|
/// Graph tab can select the row of the stage it was clicked for without
|
||||||
|
/// guessing from the display title. [sequence] is null only when the server
|
||||||
|
/// sent no usable sequence.
|
||||||
|
typedef DetailVisit = ({
|
||||||
|
String stage,
|
||||||
|
int? sequence,
|
||||||
|
String title,
|
||||||
|
String subtitle,
|
||||||
|
});
|
||||||
|
|
||||||
/// The run's primary label: the stored title, else the pipeline name, and only
|
/// The run's primary label: the stored title, else the pipeline name, and only
|
||||||
/// then the numeric identity.
|
/// then the numeric identity.
|
||||||
@@ -89,6 +99,10 @@ List<DetailVisit> detailTimeline(dynamic steps) {
|
|||||||
return [
|
return [
|
||||||
for (final step in steps.whereType<Map>())
|
for (final step in steps.whereType<Map>())
|
||||||
(
|
(
|
||||||
|
stage: '${step['stage'] ?? ''}'.trim(),
|
||||||
|
sequence: step['sequence'] is num
|
||||||
|
? (step['sequence'] as num).toInt()
|
||||||
|
: null,
|
||||||
title:
|
title:
|
||||||
'${_text(step['stage'], 'Stage unavailable')} · visit '
|
'${_text(step['stage'], 'Stage unavailable')} · visit '
|
||||||
'${step['sequence'] is num ? (step['sequence'] as num).toInt() : 'unavailable'}',
|
'${step['sequence'] is num ? (step['sequence'] as num).toInt() : 'unavailable'}',
|
||||||
@@ -97,6 +111,28 @@ List<DetailVisit> detailTimeline(dynamic steps) {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The latest recorded visit of [stageKey], or null when this run never
|
||||||
|
/// recorded that stage.
|
||||||
|
///
|
||||||
|
/// The Graph tab opens the same latest visit the web client opens. An
|
||||||
|
/// unvisited node has no visit here, so no row is invented for it.
|
||||||
|
DetailVisit? latestDetailVisit(dynamic steps, String stageKey) {
|
||||||
|
DetailVisit? latest;
|
||||||
|
for (final visit in detailTimeline(steps)) {
|
||||||
|
if (visit.stage == stageKey) latest = visit;
|
||||||
|
}
|
||||||
|
return latest;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The run's own pinned definition graph, or null when the reply omitted it.
|
||||||
|
///
|
||||||
|
/// The server sends the graph it pinned for the run's pipeline version; the
|
||||||
|
/// detail never reconstructs one from the current source.
|
||||||
|
JsonMap? detailGraph(JsonMap run) {
|
||||||
|
final graph = run['graph'];
|
||||||
|
return graph is Map ? JsonMap.from(graph) : null;
|
||||||
|
}
|
||||||
|
|
||||||
String _visitSubtitle(Map step) {
|
String _visitSubtitle(Map step) {
|
||||||
final status = _text(step['status'], 'Status unavailable');
|
final status = _text(step['status'], 'Status unavailable');
|
||||||
final outcome = '${step['outcome'] ?? ''}'.trim();
|
final outcome = '${step['outcome'] ?? ''}'.trim();
|
||||||
|
|||||||
@@ -4,10 +4,12 @@ import '../../../core/api_gateway.dart';
|
|||||||
import '../domain/run_models.dart';
|
import '../domain/run_models.dart';
|
||||||
import 'run_changes_action.dart';
|
import 'run_changes_action.dart';
|
||||||
import 'run_detail_content.dart';
|
import 'run_detail_content.dart';
|
||||||
|
import 'run_detail_tabs.dart';
|
||||||
|
|
||||||
/// The runs detail with standard Cupertino controls. It has no Material
|
/// The runs detail with standard Cupertino controls. It has no Material
|
||||||
/// ancestor: sections use native Cupertino expansion tiles and grouped list
|
/// ancestor: the host header keeps native navigation, actions and notices, and
|
||||||
/// sections, and copy feedback is an inline live-region status.
|
/// the shared tab body uses native Cupertino expansion tiles and grouped list
|
||||||
|
/// sections. Copy feedback is an inline live-region status.
|
||||||
Widget buildCupertinoRunDetail({
|
Widget buildCupertinoRunDetail({
|
||||||
required BuildContext context,
|
required BuildContext context,
|
||||||
required JsonMap run,
|
required JsonMap run,
|
||||||
@@ -20,148 +22,66 @@ Widget buildCupertinoRunDetail({
|
|||||||
required VoidCallback onCopy,
|
required VoidCallback onCopy,
|
||||||
}) {
|
}) {
|
||||||
final theme = CupertinoTheme.of(context);
|
final theme = CupertinoTheme.of(context);
|
||||||
final prompt = detailPrompt(run);
|
return RunDetailTabs(
|
||||||
final visits = detailTimeline(run['steps']);
|
run: run,
|
||||||
final metrics = detailUsageMetrics(run['usage']);
|
cupertino: true,
|
||||||
return ListView(
|
copying: copying,
|
||||||
key: ValueKey<String>('run-detail-${run['id']}'),
|
copyStatus: copyStatus,
|
||||||
children: [
|
onCopy: onCopy,
|
||||||
Padding(
|
header: Column(
|
||||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0),
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
child: Wrap(
|
children: [
|
||||||
alignment: WrapAlignment.spaceBetween,
|
|
||||||
crossAxisAlignment: WrapCrossAlignment.center,
|
|
||||||
spacing: 8,
|
|
||||||
runSpacing: 4,
|
|
||||||
children: [
|
|
||||||
CupertinoButton(
|
|
||||||
padding: EdgeInsets.zero,
|
|
||||||
onPressed: onBack,
|
|
||||||
child: Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
const Icon(CupertinoIcons.back),
|
|
||||||
const SizedBox(width: 4),
|
|
||||||
const Text('Back'),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (showRunChangesAction(run)) RunChangesButton(run: run),
|
|
||||||
if (copying) const CupertinoActivityIndicator(),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
detailTitle(run),
|
|
||||||
style: theme.textTheme.navLargeTitleTextStyle,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 4),
|
|
||||||
Text(runStatusLabel(run)),
|
|
||||||
Text('Run ${run['id']} · Pipeline ${detailPipeline(run)}'),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0),
|
|
||||||
child: Align(
|
|
||||||
alignment: AlignmentDirectional.centerStart,
|
|
||||||
child: headerActions,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (detailLoading) const _CupertinoNotice('Refreshing run details…'),
|
|
||||||
if (error != null) _CupertinoNotice(error),
|
|
||||||
if (prompt != null)
|
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 16, 16, 0),
|
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0),
|
||||||
child: Column(
|
child: Wrap(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
alignment: WrapAlignment.spaceBetween,
|
||||||
|
crossAxisAlignment: WrapCrossAlignment.center,
|
||||||
|
spacing: 8,
|
||||||
|
runSpacing: 4,
|
||||||
children: [
|
children: [
|
||||||
Wrap(
|
CupertinoButton(
|
||||||
alignment: WrapAlignment.spaceBetween,
|
padding: EdgeInsets.zero,
|
||||||
crossAxisAlignment: WrapCrossAlignment.center,
|
onPressed: onBack,
|
||||||
spacing: 8,
|
child: Row(
|
||||||
runSpacing: 4,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
const Icon(CupertinoIcons.back),
|
||||||
'Original prompt',
|
const SizedBox(width: 4),
|
||||||
style: theme.textTheme.navTitleTextStyle,
|
const Text('Back'),
|
||||||
),
|
],
|
||||||
CupertinoButton(
|
|
||||||
padding: EdgeInsets.zero,
|
|
||||||
onPressed: copying ? null : onCopy,
|
|
||||||
child: const Text('Copy prompt'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
_CupertinoSelectableText(prompt),
|
|
||||||
if (copyStatus != null)
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(top: 4),
|
|
||||||
child: Semantics(liveRegion: true, child: Text(copyStatus)),
|
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
if (showRunChangesAction(run)) RunChangesButton(run: run),
|
||||||
|
if (copying) const CupertinoActivityIndicator(),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
_fieldSection('Input', run['input'], 'No input recorded.'),
|
Padding(
|
||||||
_fieldSection('Output', run['output'], 'No output recorded.'),
|
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0),
|
||||||
CupertinoListSection.insetGrouped(
|
child: Column(
|
||||||
header: const Text('Timeline'),
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
if (visits.isEmpty)
|
Text(
|
||||||
const CupertinoListTile(title: Text('No visits recorded.'))
|
detailTitle(run),
|
||||||
else
|
style: theme.textTheme.navLargeTitleTextStyle,
|
||||||
for (final visit in visits)
|
|
||||||
CupertinoListTile(
|
|
||||||
leading: const Icon(CupertinoIcons.circle),
|
|
||||||
title: Text(visit.title),
|
|
||||||
subtitle: Text(visit.subtitle),
|
|
||||||
),
|
),
|
||||||
],
|
const SizedBox(height: 4),
|
||||||
),
|
Text(runStatusLabel(run)),
|
||||||
CupertinoListSection.insetGrouped(
|
Text('Run ${run['id']} · Pipeline ${detailPipeline(run)}'),
|
||||||
children: [
|
],
|
||||||
CupertinoExpansionTile(
|
|
||||||
title: const Text('Metrics'),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 16),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
||||||
children: [
|
|
||||||
if (metrics.isEmpty)
|
|
||||||
const Text('No reported usage.')
|
|
||||||
else
|
|
||||||
for (final metric in metrics)
|
|
||||||
CupertinoListTile(
|
|
||||||
title: Text(metric.label),
|
|
||||||
subtitle: Text(metric.value),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _fieldSection(String title, dynamic value, String empty) {
|
|
||||||
final text = detailEmpty(value) ? empty : detailJson(value);
|
|
||||||
return CupertinoListSection.insetGrouped(
|
|
||||||
children: [
|
|
||||||
CupertinoExpansionTile(
|
|
||||||
title: Text(title),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 16),
|
|
||||||
child: _CupertinoSelectableText(text),
|
|
||||||
),
|
),
|
||||||
),
|
Padding(
|
||||||
],
|
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0),
|
||||||
|
child: Align(
|
||||||
|
alignment: AlignmentDirectional.centerStart,
|
||||||
|
child: headerActions,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (detailLoading) const _CupertinoNotice('Refreshing run details…'),
|
||||||
|
if (error != null) _CupertinoNotice(error),
|
||||||
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,42 +95,3 @@ class _CupertinoNotice extends StatelessWidget {
|
|||||||
child: Semantics(liveRegion: true, child: Text(text)),
|
child: Semantics(liveRegion: true, child: Text(text)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A read-only Cupertino text control: plain, selectable text without a
|
|
||||||
/// Material dependency, while keeping native selection and copy affordances.
|
|
||||||
class _CupertinoSelectableText extends StatefulWidget {
|
|
||||||
const _CupertinoSelectableText(this.text);
|
|
||||||
final String text;
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<_CupertinoSelectableText> createState() =>
|
|
||||||
_CupertinoSelectableTextState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _CupertinoSelectableTextState extends State<_CupertinoSelectableText> {
|
|
||||||
late final TextEditingController _controller = TextEditingController(
|
|
||||||
text: widget.text,
|
|
||||||
);
|
|
||||||
|
|
||||||
@override
|
|
||||||
void didUpdateWidget(_CupertinoSelectableText oldWidget) {
|
|
||||||
super.didUpdateWidget(oldWidget);
|
|
||||||
if (widget.text != oldWidget.text) _controller.text = widget.text;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
_controller.dispose();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) => CupertinoTextField(
|
|
||||||
controller: _controller,
|
|
||||||
readOnly: true,
|
|
||||||
maxLines: null,
|
|
||||||
padding: EdgeInsets.zero,
|
|
||||||
decoration: const BoxDecoration(),
|
|
||||||
style: CupertinoTheme.of(context).textTheme.textStyle,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -4,8 +4,12 @@ import '../../../core/api_gateway.dart';
|
|||||||
import '../domain/run_models.dart';
|
import '../domain/run_models.dart';
|
||||||
import 'run_changes_action.dart';
|
import 'run_changes_action.dart';
|
||||||
import 'run_detail_content.dart';
|
import 'run_detail_content.dart';
|
||||||
|
import 'run_detail_tabs.dart';
|
||||||
|
|
||||||
/// The runs detail with standard Material controls.
|
/// The runs detail with standard Material controls.
|
||||||
|
///
|
||||||
|
/// The host header keeps the run identity, status and every action; the shared
|
||||||
|
/// tab body supplies Summary, Graph, Input, Output and Timeline.
|
||||||
Widget buildMaterialRunDetail({
|
Widget buildMaterialRunDetail({
|
||||||
required BuildContext context,
|
required BuildContext context,
|
||||||
required JsonMap run,
|
required JsonMap run,
|
||||||
@@ -18,107 +22,53 @@ Widget buildMaterialRunDetail({
|
|||||||
required VoidCallback onCopy,
|
required VoidCallback onCopy,
|
||||||
}) {
|
}) {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
final prompt = detailPrompt(run);
|
return RunDetailTabs(
|
||||||
final visits = detailTimeline(run['steps']);
|
run: run,
|
||||||
final metrics = detailUsageMetrics(run['usage']);
|
cupertino: false,
|
||||||
return ListView(
|
copying: copying,
|
||||||
key: ValueKey<String>('run-detail-${run['id']}'),
|
copyStatus: copyStatus,
|
||||||
padding: const EdgeInsets.all(16),
|
onCopy: onCopy,
|
||||||
children: [
|
header: Column(
|
||||||
Wrap(
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
spacing: 8,
|
children: [
|
||||||
runSpacing: 4,
|
Padding(
|
||||||
crossAxisAlignment: WrapCrossAlignment.center,
|
padding: const EdgeInsets.fromLTRB(16, 8, 16, 0),
|
||||||
children: [
|
child: Wrap(
|
||||||
TextButton.icon(
|
spacing: 8,
|
||||||
onPressed: onBack,
|
runSpacing: 4,
|
||||||
icon: const Icon(Icons.arrow_back),
|
crossAxisAlignment: WrapCrossAlignment.center,
|
||||||
label: const Text('Back to list'),
|
children: [
|
||||||
),
|
TextButton.icon(
|
||||||
if (showRunChangesAction(run)) RunChangesButton(run: run),
|
onPressed: onBack,
|
||||||
],
|
icon: const Icon(Icons.arrow_back),
|
||||||
),
|
label: const Text('Back to list'),
|
||||||
Text(detailTitle(run), style: theme.textTheme.headlineSmall),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
Wrap(
|
|
||||||
spacing: 8,
|
|
||||||
runSpacing: 4,
|
|
||||||
crossAxisAlignment: WrapCrossAlignment.center,
|
|
||||||
children: [
|
|
||||||
Chip(label: Text(runStatusLabel(run))),
|
|
||||||
Text('Run ${run['id']}'),
|
|
||||||
Text('Pipeline ${detailPipeline(run)}'),
|
|
||||||
headerActions,
|
|
||||||
],
|
|
||||||
),
|
|
||||||
if (detailLoading) const _Notice('Refreshing run details…'),
|
|
||||||
if (error != null) _Notice(error),
|
|
||||||
if (prompt != null) ...[
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
Row(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
'Original prompt',
|
|
||||||
style: theme.textTheme.titleMedium,
|
|
||||||
),
|
),
|
||||||
),
|
if (showRunChangesAction(run)) RunChangesButton(run: run),
|
||||||
IconButton(
|
],
|
||||||
tooltip: 'Copy prompt',
|
|
||||||
onPressed: copying ? null : onCopy,
|
|
||||||
icon: const Icon(Icons.copy),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
SelectableText(prompt),
|
|
||||||
if (copyStatus != null)
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(top: 4),
|
|
||||||
child: Semantics(liveRegion: true, child: Text(copyStatus)),
|
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(16, 8, 16, 0),
|
||||||
|
child: Text(detailTitle(run), style: theme.textTheme.headlineSmall),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(16, 8, 16, 0),
|
||||||
|
child: Wrap(
|
||||||
|
spacing: 8,
|
||||||
|
runSpacing: 4,
|
||||||
|
crossAxisAlignment: WrapCrossAlignment.center,
|
||||||
|
children: [
|
||||||
|
Chip(label: Text(runStatusLabel(run))),
|
||||||
|
Text('Run ${run['id']}'),
|
||||||
|
Text('Pipeline ${detailPipeline(run)}'),
|
||||||
|
headerActions,
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (detailLoading) const _Notice('Refreshing run details…'),
|
||||||
|
if (error != null) _Notice(error),
|
||||||
],
|
],
|
||||||
_fieldSection('Input', run['input'], 'No input recorded.'),
|
),
|
||||||
_fieldSection('Output', run['output'], 'No output recorded.'),
|
|
||||||
Text('Timeline', style: theme.textTheme.titleLarge),
|
|
||||||
if (visits.isEmpty)
|
|
||||||
const Text('No visits recorded.')
|
|
||||||
else
|
|
||||||
...visits.map(
|
|
||||||
(visit) => ListTile(
|
|
||||||
leading: const Icon(Icons.circle_outlined),
|
|
||||||
title: Text(visit.title),
|
|
||||||
subtitle: Text(visit.subtitle),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
ExpansionTile(
|
|
||||||
title: const Text('Metrics'),
|
|
||||||
children: [
|
|
||||||
if (metrics.isEmpty)
|
|
||||||
const Padding(
|
|
||||||
padding: EdgeInsets.all(16),
|
|
||||||
child: Text('No reported usage.'),
|
|
||||||
)
|
|
||||||
else
|
|
||||||
...metrics.map(
|
|
||||||
(metric) => ListTile(
|
|
||||||
title: Text(metric.label),
|
|
||||||
subtitle: Text(metric.value),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _fieldSection(String title, dynamic value, String empty) {
|
|
||||||
final text = detailEmpty(value) ? empty : detailJson(value);
|
|
||||||
return ExpansionTile(
|
|
||||||
title: Text(title),
|
|
||||||
children: [
|
|
||||||
Padding(padding: const EdgeInsets.all(16), child: SelectableText(text)),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +78,7 @@ class _Notice extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) => Padding(
|
Widget build(BuildContext context) => Padding(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||||
child: Semantics(liveRegion: true, child: Text(text)),
|
child: Semantics(liveRegion: true, child: Text(text)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
/// The run-detail sections in the web's order: Summary first, the run Graph
|
||||||
|
/// second, then the recorded Input, Output and Timeline.
|
||||||
|
///
|
||||||
|
/// The stable keys match the web client's `RUN_DETAIL_TABS`; the visible labels
|
||||||
|
/// are the same words.
|
||||||
|
enum RunDetailTab {
|
||||||
|
summary('Summary'),
|
||||||
|
graph('Graph'),
|
||||||
|
input('Input'),
|
||||||
|
output('Output'),
|
||||||
|
timeline('Timeline');
|
||||||
|
|
||||||
|
const RunDetailTab(this.label);
|
||||||
|
|
||||||
|
final String label;
|
||||||
|
}
|
||||||
@@ -0,0 +1,204 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../../../core/api_gateway.dart';
|
||||||
|
import 'run_detail_content.dart';
|
||||||
|
|
||||||
|
/// The Summary tab: the stored original prompt with its copy control and the
|
||||||
|
/// reported usage metrics. Neither the prompt nor a metric is replaced by a
|
||||||
|
/// fallback value.
|
||||||
|
Widget runDetailSummaryTab({
|
||||||
|
required BuildContext context,
|
||||||
|
required JsonMap run,
|
||||||
|
required bool cupertino,
|
||||||
|
required bool copying,
|
||||||
|
required String? copyStatus,
|
||||||
|
required VoidCallback onCopy,
|
||||||
|
}) {
|
||||||
|
final prompt = detailPrompt(run);
|
||||||
|
final metrics = detailUsageMetrics(run['usage']);
|
||||||
|
if (cupertino) {
|
||||||
|
final theme = CupertinoTheme.of(context);
|
||||||
|
return ListView(
|
||||||
|
key: const Key('run-detail-tab-body-summary'),
|
||||||
|
children: [
|
||||||
|
if (prompt != null)
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsetsDirectional.fromSTEB(16, 16, 16, 0),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Wrap(
|
||||||
|
alignment: WrapAlignment.spaceBetween,
|
||||||
|
crossAxisAlignment: WrapCrossAlignment.center,
|
||||||
|
spacing: 8,
|
||||||
|
runSpacing: 4,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'Original prompt',
|
||||||
|
style: theme.textTheme.navTitleTextStyle,
|
||||||
|
),
|
||||||
|
CupertinoButton(
|
||||||
|
padding: EdgeInsets.zero,
|
||||||
|
onPressed: copying ? null : onCopy,
|
||||||
|
child: const Text('Copy prompt'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
_CupertinoSelectableText(prompt),
|
||||||
|
if (copyStatus != null)
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 4),
|
||||||
|
child: Semantics(liveRegion: true, child: Text(copyStatus)),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
_cupertinoMetrics(metrics),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
return ListView(
|
||||||
|
key: const Key('run-detail-tab-body-summary'),
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
children: [
|
||||||
|
if (prompt != null) ...[
|
||||||
|
Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
'Original prompt',
|
||||||
|
style: theme.textTheme.titleMedium,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
tooltip: 'Copy prompt',
|
||||||
|
onPressed: copying ? null : onCopy,
|
||||||
|
icon: const Icon(Icons.copy),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
SelectableText(prompt),
|
||||||
|
if (copyStatus != null)
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 4),
|
||||||
|
child: Semantics(liveRegion: true, child: Text(copyStatus)),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
],
|
||||||
|
_materialMetrics(metrics),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// One recorded Input or Output field as its own tab.
|
||||||
|
Widget runDetailFieldTab({
|
||||||
|
required String tabKey,
|
||||||
|
required dynamic value,
|
||||||
|
required String empty,
|
||||||
|
required bool cupertino,
|
||||||
|
}) {
|
||||||
|
final text = detailEmpty(value) ? empty : detailJson(value);
|
||||||
|
if (cupertino) {
|
||||||
|
return ListView(
|
||||||
|
key: Key('run-detail-tab-body-$tabKey'),
|
||||||
|
children: [
|
||||||
|
CupertinoListSection.insetGrouped(
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 16),
|
||||||
|
child: _CupertinoSelectableText(text),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return ListView(
|
||||||
|
key: Key('run-detail-tab-body-$tabKey'),
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
children: [SelectableText(text)],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _materialMetrics(List<DetailMetric> metrics) => ExpansionTile(
|
||||||
|
title: const Text('Metrics'),
|
||||||
|
children: [
|
||||||
|
if (metrics.isEmpty)
|
||||||
|
const Padding(
|
||||||
|
padding: EdgeInsets.all(16),
|
||||||
|
child: Text('No reported usage.'),
|
||||||
|
)
|
||||||
|
else
|
||||||
|
...metrics.map(
|
||||||
|
(metric) =>
|
||||||
|
ListTile(title: Text(metric.label), subtitle: Text(metric.value)),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
Widget _cupertinoMetrics(List<DetailMetric> metrics) =>
|
||||||
|
CupertinoListSection.insetGrouped(
|
||||||
|
children: [
|
||||||
|
CupertinoExpansionTile(
|
||||||
|
title: const Text('Metrics'),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 16),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
if (metrics.isEmpty)
|
||||||
|
const Text('No reported usage.')
|
||||||
|
else
|
||||||
|
for (final metric in metrics)
|
||||||
|
CupertinoListTile(
|
||||||
|
title: Text(metric.label),
|
||||||
|
subtitle: Text(metric.value),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
/// A read-only Cupertino text control: plain, selectable text without a
|
||||||
|
/// Material dependency, while keeping native selection and copy affordances.
|
||||||
|
class _CupertinoSelectableText extends StatefulWidget {
|
||||||
|
const _CupertinoSelectableText(this.text);
|
||||||
|
final String text;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<_CupertinoSelectableText> createState() =>
|
||||||
|
_CupertinoSelectableTextState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _CupertinoSelectableTextState extends State<_CupertinoSelectableText> {
|
||||||
|
late final TextEditingController _controller = TextEditingController(
|
||||||
|
text: widget.text,
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didUpdateWidget(_CupertinoSelectableText oldWidget) {
|
||||||
|
super.didUpdateWidget(oldWidget);
|
||||||
|
if (widget.text != oldWidget.text) _controller.text = widget.text;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_controller.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) => CupertinoTextField(
|
||||||
|
controller: _controller,
|
||||||
|
readOnly: true,
|
||||||
|
maxLines: null,
|
||||||
|
padding: EdgeInsets.zero,
|
||||||
|
decoration: const BoxDecoration(),
|
||||||
|
style: CupertinoTheme.of(context).textTheme.textStyle,
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,133 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/gestures.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../../../ui/adaptive/host.dart';
|
||||||
|
import 'run_detail_tab.dart';
|
||||||
|
|
||||||
|
/// The run detail's platform tab strip: a Material segmented button or a
|
||||||
|
/// Cupertino segmented control, in the web's Summary/Graph/Input/Output/
|
||||||
|
/// Timeline order.
|
||||||
|
///
|
||||||
|
/// The native control keeps every label at its intrinsic width: a narrow pane
|
||||||
|
/// or scaled text scrolls the strip horizontally instead of squeezing or
|
||||||
|
/// wrapping the words. A tab selected by the Graph (not tapped in the strip)
|
||||||
|
/// is scrolled into view, so the operator can see which section is selected.
|
||||||
|
class RunDetailTabStrip extends StatefulWidget {
|
||||||
|
const RunDetailTabStrip({
|
||||||
|
super.key,
|
||||||
|
required this.selected,
|
||||||
|
required this.onSelected,
|
||||||
|
});
|
||||||
|
|
||||||
|
final RunDetailTab selected;
|
||||||
|
final ValueChanged<RunDetailTab> onSelected;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<RunDetailTabStrip> createState() => _RunDetailTabStripState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RunDetailTabStripState extends State<RunDetailTabStrip> {
|
||||||
|
final Map<RunDetailTab, GlobalKey> _labels = {
|
||||||
|
for (final tab in RunDetailTab.values) tab: GlobalKey(),
|
||||||
|
};
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didUpdateWidget(covariant RunDetailTabStrip oldWidget) {
|
||||||
|
super.didUpdateWidget(oldWidget);
|
||||||
|
if (oldWidget.selected == widget.selected) return;
|
||||||
|
// The Graph can select Timeline without a strip tap. Wait for the new
|
||||||
|
// segment to be laid out, then reveal it inside the strip's own scroll.
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
if (!mounted) return;
|
||||||
|
final context = _labels[widget.selected]?.currentContext;
|
||||||
|
if (context == null) return;
|
||||||
|
Scrollable.ensureVisible(
|
||||||
|
context,
|
||||||
|
alignment: 0.5,
|
||||||
|
duration: const Duration(milliseconds: 200),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final cupertino = usesCupertinoHost(context);
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||||
|
child: _ScrollWhenOverflowing(
|
||||||
|
child: KeyedSubtree(
|
||||||
|
key: const Key('run-detail-tabs'),
|
||||||
|
child: cupertino ? _cupertinoControl() : _materialControl(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _materialControl() => SegmentedButton<RunDetailTab>(
|
||||||
|
segments: [
|
||||||
|
for (final tab in RunDetailTab.values)
|
||||||
|
ButtonSegment(value: tab, label: _label(tab)),
|
||||||
|
],
|
||||||
|
selected: {widget.selected},
|
||||||
|
showSelectedIcon: false,
|
||||||
|
onSelectionChanged: (selection) => widget.onSelected(selection.single),
|
||||||
|
);
|
||||||
|
|
||||||
|
Widget _cupertinoControl() => CupertinoSegmentedControl<RunDetailTab>(
|
||||||
|
groupValue: widget.selected,
|
||||||
|
onValueChanged: widget.onSelected,
|
||||||
|
children: {
|
||||||
|
for (final tab in RunDetailTab.values)
|
||||||
|
tab: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||||
|
child: _label(tab),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
Widget _label(RunDetailTab tab) => KeyedSubtree(
|
||||||
|
key: _labels[tab],
|
||||||
|
child: KeyedSubtree(
|
||||||
|
key: ValueKey('run-detail-tab-${tab.name}'),
|
||||||
|
child: Text(tab.label, maxLines: 1, softWrap: false),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Gives [child] at least the pane width, then scrolls instead of squeezing it
|
||||||
|
/// below its content width.
|
||||||
|
class _ScrollWhenOverflowing extends StatelessWidget {
|
||||||
|
const _ScrollWhenOverflowing({required this.child});
|
||||||
|
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return LayoutBuilder(
|
||||||
|
builder: (context, constraints) {
|
||||||
|
if (!constraints.hasBoundedWidth) return child;
|
||||||
|
return ScrollConfiguration(
|
||||||
|
// Desktop pointer scrolling is vertical only, so a mouse can drag
|
||||||
|
// the tab row as well as touch and trackpad.
|
||||||
|
behavior: ScrollConfiguration.of(context).copyWith(
|
||||||
|
dragDevices: const {
|
||||||
|
PointerDeviceKind.touch,
|
||||||
|
PointerDeviceKind.mouse,
|
||||||
|
PointerDeviceKind.stylus,
|
||||||
|
PointerDeviceKind.invertedStylus,
|
||||||
|
PointerDeviceKind.trackpad,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
child: ConstrainedBox(
|
||||||
|
constraints: BoxConstraints(minWidth: constraints.maxWidth),
|
||||||
|
child: child,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,174 @@
|
|||||||
|
import 'dart:math' as math;
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../../../core/api_gateway.dart';
|
||||||
|
import '../../graph/widgets/run_graph_view.dart';
|
||||||
|
import 'run_detail_content.dart';
|
||||||
|
import 'run_detail_tab.dart';
|
||||||
|
import 'run_detail_tab_bodies.dart';
|
||||||
|
import 'run_detail_tab_strip.dart';
|
||||||
|
import 'run_detail_timeline.dart';
|
||||||
|
|
||||||
|
/// The least height the selected tab keeps for its own content.
|
||||||
|
///
|
||||||
|
/// A header and tab strip that would leave the tab less than this may scroll
|
||||||
|
/// instead, so scaled title text or a short window cannot squeeze the Graph
|
||||||
|
/// canvas away. The Graph view's own legend is one wrapped row pair; this
|
||||||
|
/// reserve keeps its bounded canvas positive at 320px with 2x text.
|
||||||
|
const double kRunDetailMinContentHeight = 240;
|
||||||
|
|
||||||
|
/// The run detail's tabbed body: the host-built header and platform tab strip
|
||||||
|
/// above the bounded selected tab.
|
||||||
|
///
|
||||||
|
/// The Graph tab fills its slot with [RunGraphView] from the run's own pinned
|
||||||
|
/// graph and recorded steps. A visited stage click selects that stage's latest
|
||||||
|
/// recorded visit and switches to Timeline, where the row is highlighted. A
|
||||||
|
/// node with no recorded visit reports nothing, so no visit is invented.
|
||||||
|
class RunDetailTabs extends StatefulWidget {
|
||||||
|
const RunDetailTabs({
|
||||||
|
super.key,
|
||||||
|
required this.run,
|
||||||
|
required this.header,
|
||||||
|
required this.cupertino,
|
||||||
|
required this.copying,
|
||||||
|
required this.copyStatus,
|
||||||
|
required this.onCopy,
|
||||||
|
});
|
||||||
|
|
||||||
|
final JsonMap run;
|
||||||
|
|
||||||
|
/// The host's own header: identity, status and the run actions. It stays
|
||||||
|
/// outside the tab body, so switching tabs never drops an action.
|
||||||
|
final Widget header;
|
||||||
|
|
||||||
|
final bool cupertino;
|
||||||
|
final bool copying;
|
||||||
|
final String? copyStatus;
|
||||||
|
final VoidCallback onCopy;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<RunDetailTabs> createState() => _RunDetailTabsState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RunDetailTabsState extends State<RunDetailTabs> {
|
||||||
|
RunDetailTab _tab = RunDetailTab.summary;
|
||||||
|
String? _selectedStage;
|
||||||
|
int? _selectedVisit;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didUpdateWidget(covariant RunDetailTabs oldWidget) {
|
||||||
|
super.didUpdateWidget(oldWidget);
|
||||||
|
// A different run is a different detail: its visits and graph do not carry
|
||||||
|
// the previous run's selection.
|
||||||
|
if ('${widget.run['id']}' != '${oldWidget.run['id']}') {
|
||||||
|
_tab = RunDetailTab.summary;
|
||||||
|
_selectedStage = null;
|
||||||
|
_selectedVisit = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Selects the stage's latest recorded visit. An unvisited stage has none,
|
||||||
|
/// so the detail stays where it is rather than fabricating a visit.
|
||||||
|
void _openStage(String stageKey) {
|
||||||
|
final visit = latestDetailVisit(widget.run['steps'], stageKey);
|
||||||
|
if (visit == null) return;
|
||||||
|
setState(() {
|
||||||
|
_selectedStage = stageKey;
|
||||||
|
_selectedVisit = visit.sequence;
|
||||||
|
_tab = RunDetailTab.timeline;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return LayoutBuilder(
|
||||||
|
builder: (context, constraints) {
|
||||||
|
final headerLimit = _headerLimit(constraints);
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
ConstrainedBox(
|
||||||
|
constraints: BoxConstraints(maxHeight: headerLimit),
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
key: ValueKey('run-detail-header-${widget.run['id']}'),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
widget.header,
|
||||||
|
RunDetailTabStrip(
|
||||||
|
selected: _tab,
|
||||||
|
onSelected: (tab) => setState(() => _tab = tab),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
// Every tab gets the bounded remaining height. The scrolling tabs
|
||||||
|
// own their content; the Graph tab fills the slot so its canvas is
|
||||||
|
// never asked for an unbounded extent.
|
||||||
|
Expanded(
|
||||||
|
key: ValueKey('run-detail-body-${widget.run['id']}'),
|
||||||
|
child: _body(),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _body() {
|
||||||
|
switch (_tab) {
|
||||||
|
case RunDetailTab.summary:
|
||||||
|
return runDetailSummaryTab(
|
||||||
|
context: context,
|
||||||
|
run: widget.run,
|
||||||
|
cupertino: widget.cupertino,
|
||||||
|
copying: widget.copying,
|
||||||
|
copyStatus: widget.copyStatus,
|
||||||
|
onCopy: widget.onCopy,
|
||||||
|
);
|
||||||
|
case RunDetailTab.graph:
|
||||||
|
return RunGraphView(
|
||||||
|
key: const Key('run-detail-graph'),
|
||||||
|
graph: detailGraph(widget.run),
|
||||||
|
run: widget.run,
|
||||||
|
selectedStage: _selectedStage,
|
||||||
|
onStageSelected: _openStage,
|
||||||
|
);
|
||||||
|
case RunDetailTab.input:
|
||||||
|
return runDetailFieldTab(
|
||||||
|
tabKey: 'input',
|
||||||
|
value: widget.run['input'],
|
||||||
|
empty: 'No input recorded.',
|
||||||
|
cupertino: widget.cupertino,
|
||||||
|
);
|
||||||
|
case RunDetailTab.output:
|
||||||
|
return runDetailFieldTab(
|
||||||
|
tabKey: 'output',
|
||||||
|
value: widget.run['output'],
|
||||||
|
empty: 'No output recorded.',
|
||||||
|
cupertino: widget.cupertino,
|
||||||
|
);
|
||||||
|
case RunDetailTab.timeline:
|
||||||
|
return RunTimelineList(
|
||||||
|
visits: detailTimeline(widget.run['steps']),
|
||||||
|
selectedSequence: _selectedVisit,
|
||||||
|
cupertino: widget.cupertino,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The header keeps its natural height while at least
|
||||||
|
/// [kRunDetailMinContentHeight] remains for the tab, and never more than the
|
||||||
|
/// detail itself; past that it scrolls.
|
||||||
|
double _headerLimit(BoxConstraints constraints) {
|
||||||
|
if (!constraints.hasBoundedHeight) return double.infinity;
|
||||||
|
final height = constraints.maxHeight;
|
||||||
|
// Below twice the reserve the two shares meet at 40%, so the header stays
|
||||||
|
// reachable even when the detail is shorter than the reserve itself.
|
||||||
|
final floorShare = height * 0.4;
|
||||||
|
final reserve = height - kRunDetailMinContentHeight;
|
||||||
|
return math.max(floorShare, reserve).clamp(0.0, height);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'run_detail_content.dart';
|
||||||
|
|
||||||
|
/// The Timeline tab's recorded visits, one native row per visit.
|
||||||
|
///
|
||||||
|
/// [selectedSequence] is the server sequence of the visit selected from the
|
||||||
|
/// Graph tab. Only an actual recorded visit can match, so an unvisited stage
|
||||||
|
/// leaves every row unselected.
|
||||||
|
class RunTimelineList extends StatelessWidget {
|
||||||
|
const RunTimelineList({
|
||||||
|
super.key,
|
||||||
|
required this.visits,
|
||||||
|
required this.cupertino,
|
||||||
|
this.selectedSequence,
|
||||||
|
});
|
||||||
|
|
||||||
|
final List<DetailVisit> visits;
|
||||||
|
final bool cupertino;
|
||||||
|
final int? selectedSequence;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
if (visits.isEmpty) {
|
||||||
|
return ListView(
|
||||||
|
key: const Key('run-detail-tab-body-timeline'),
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
children: const [Text('No visits recorded.')],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
final rows = [
|
||||||
|
for (var index = 0; index < visits.length; index += 1)
|
||||||
|
RunTimelineRow(
|
||||||
|
key: ValueKey(
|
||||||
|
'run-timeline-visit-${visits[index].sequence ?? index}',
|
||||||
|
),
|
||||||
|
visit: visits[index],
|
||||||
|
selected: visits[index].sequence == selectedSequence,
|
||||||
|
cupertino: cupertino,
|
||||||
|
),
|
||||||
|
];
|
||||||
|
if (cupertino) {
|
||||||
|
return ListView(
|
||||||
|
key: const Key('run-detail-tab-body-timeline'),
|
||||||
|
children: [
|
||||||
|
CupertinoListSection.insetGrouped(
|
||||||
|
header: const Text('Timeline'),
|
||||||
|
children: rows,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return ListView(
|
||||||
|
key: const Key('run-detail-tab-body-timeline'),
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||||
|
children: rows,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// One recorded visit. [selected] highlights the row the Graph tab selected;
|
||||||
|
/// it is never true for a stage with no recorded visit.
|
||||||
|
class RunTimelineRow extends StatelessWidget {
|
||||||
|
const RunTimelineRow({
|
||||||
|
super.key,
|
||||||
|
required this.visit,
|
||||||
|
required this.selected,
|
||||||
|
required this.cupertino,
|
||||||
|
});
|
||||||
|
|
||||||
|
final DetailVisit visit;
|
||||||
|
final bool selected;
|
||||||
|
final bool cupertino;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
if (cupertino) {
|
||||||
|
return Semantics(
|
||||||
|
selected: selected,
|
||||||
|
child: CupertinoListTile(
|
||||||
|
leading: Icon(
|
||||||
|
selected
|
||||||
|
? CupertinoIcons.check_mark_circled_solid
|
||||||
|
: CupertinoIcons.circle,
|
||||||
|
),
|
||||||
|
title: Text(visit.title),
|
||||||
|
subtitle: Text(visit.subtitle),
|
||||||
|
trailing: selected ? const Icon(CupertinoIcons.check_mark) : null,
|
||||||
|
backgroundColor: selected
|
||||||
|
? CupertinoDynamicColor.resolve(
|
||||||
|
CupertinoColors.secondarySystemFill,
|
||||||
|
context,
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return ListTile(
|
||||||
|
selected: selected,
|
||||||
|
leading: Icon(selected ? Icons.check_circle : Icons.circle_outlined),
|
||||||
|
title: Text(visit.title),
|
||||||
|
subtitle: Text(visit.subtitle),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
# R3 — run detail Graph tab
|
||||||
|
|
||||||
|
## Delivered
|
||||||
|
|
||||||
|
The real run detail is now tabbed in the web's order: **Summary, Graph, Input,
|
||||||
|
Output, Timeline**. The host-built header (Back, Changes, title, status,
|
||||||
|
Rename, Retry, Cancel, Decide, Artifacts) stays above the tabs, so switching
|
||||||
|
tabs never removes an action.
|
||||||
|
|
||||||
|
- **Summary** keeps the original prompt with its copy control and the reported
|
||||||
|
usage metrics (unknown stays `Unavailable`, never a fabricated zero).
|
||||||
|
- **Graph** mounts the landed `RunGraphView` from `run['graph']` (the run's own
|
||||||
|
pinned definition) and `run['steps']`. It shows the exact `Executed` /
|
||||||
|
`Not executed` legend and fills a bounded `Expanded` slot. A reply without a
|
||||||
|
graph shows `This server did not include the run graph.` and no canvas.
|
||||||
|
- **Input** / **Output** render the recorded field as their own tab.
|
||||||
|
- **Timeline** lists every recorded visit. A graph click on a visited stage
|
||||||
|
selects that stage's latest recorded visit and switches to Timeline, where
|
||||||
|
the row is highlighted (`ListTile.selected` on Material; native tint +
|
||||||
|
checkmark and selected semantics on Cupertino). The strip scrolls the
|
||||||
|
programmatically selected Timeline segment into view at narrow widths. An
|
||||||
|
unvisited node has no visit: clicking it does nothing and no row is invented.
|
||||||
|
|
||||||
|
The header may scroll when scaled text or a short viewport would otherwise
|
||||||
|
squeeze the tab away; the tab keeps at least `kRunDetailMinContentHeight`
|
||||||
|
(240) so the graph's own legend and canvas stay positive at 320px/2x.
|
||||||
|
|
||||||
|
## Files
|
||||||
|
|
||||||
|
Added:
|
||||||
|
|
||||||
|
- `app/lib/features/runs/ui/run_detail_tab.dart` — tab keys/labels in web order.
|
||||||
|
- `app/lib/features/runs/ui/run_detail_tab_strip.dart` — adaptive segmented
|
||||||
|
control with horizontal scrolling when labels do not fit.
|
||||||
|
- `app/lib/features/runs/ui/run_detail_tabs.dart` — tab state, bounded layout,
|
||||||
|
graph selection → Timeline handoff.
|
||||||
|
- `app/lib/features/runs/ui/run_detail_tab_bodies.dart` — Summary/Input/Output
|
||||||
|
bodies and metrics in both hosts.
|
||||||
|
- `app/lib/features/runs/ui/run_detail_timeline.dart` — timeline rows and
|
||||||
|
selected highlight.
|
||||||
|
- `app/test/features/runs/ui/run_detail_graph_tab_test.dart`,
|
||||||
|
`run_detail_tabs_test.dart`, `run_detail_graph_support.dart`.
|
||||||
|
- `app/tool/run_detail_graph_probe.dart`, `run_detail_graph_probe.mjs`.
|
||||||
|
- `app/notes/R3-graph.md`.
|
||||||
|
|
||||||
|
Changed:
|
||||||
|
|
||||||
|
- `run_detail_content.dart` — `DetailVisit` now carries the exact `stage` and
|
||||||
|
`sequence`; `latestDetailVisit`, `detailGraph`.
|
||||||
|
- `run_detail_material.dart`, `run_detail_cupertino.dart` — host headers plus
|
||||||
|
`RunDetailTabs`; no content or action dropped.
|
||||||
|
- `run_changes_action.dart` — the Cupertino Changes button label is `Flexible`
|
||||||
|
so 320px/2x text wraps inside the native button instead of overflowing the
|
||||||
|
header by 14px (surfaced by the new bounded-layout test).
|
||||||
|
- `run_detail_widget_test.dart` — existing prompt/copy/metrics/timeline and
|
||||||
|
refresh-retention coverage adapted to the tabs.
|
||||||
|
|
||||||
|
## Checks run
|
||||||
|
|
||||||
|
From `app/` with Flutter 3.44.6:
|
||||||
|
|
||||||
|
- `flutter analyze` — no issues.
|
||||||
|
- `flutter test` — **960 tests passed** (full suite, including the new tab
|
||||||
|
tests and the existing cancel/retry/decision/changes/artifacts wiring).
|
||||||
|
- `flutter build web` — built `build/web`.
|
||||||
|
- Probe build: `flutter build web --target tool/run_detail_graph_probe.dart
|
||||||
|
--output build/probe-run-detail-graph` — succeeded.
|
||||||
|
|
||||||
|
## Browser evidence
|
||||||
|
|
||||||
|
Probe drives the real `RunDetailView` over a server-shaped fake gateway. Each
|
||||||
|
run checks: Graph opens; `Executed`/`Not executed` legend; recorded `plan` and
|
||||||
|
`build` statuses; `audit` unvisited; a plan click selects `plan · visit 1`
|
||||||
|
(`aria-current=true` on the row), reveals the Timeline tab in the strip and
|
||||||
|
shows no `audit · visit`; the missing-graph case shows the exact sentence and no
|
||||||
|
canvas.
|
||||||
|
|
||||||
|
| Host | Viewport | Captures |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| Material | 1280×900, dark, 1x | `r3-graph/run-detail-graph-material-dark-1x-1280x900-{graph,selected-visit,missing-graph}.png` |
|
||||||
|
| Material | 320×700, dark, 2x | `r3-graph/run-detail-graph-material-dark-2x-320x700-{graph,selected-visit,missing-graph}.png` |
|
||||||
|
| Cupertino | 1280×900, dark, 1x | `r3-graph/run-detail-graph-cupertino-dark-1x-1280x900-{graph,selected-visit,missing-graph}.png` |
|
||||||
|
| Cupertino | 320×700, dark, 2x | `r3-graph/run-detail-graph-cupertino-dark-2x-320x700-{graph,selected-visit,missing-graph}.png` |
|
||||||
|
|
||||||
|
Evidence JSON: `r3-graph/evidence-{material,cupertino}-{1x-1280x900,2x-320x700}.json`
|
||||||
|
under the run's public artifacts. At 320/2x the canvas is panned so the later
|
||||||
|
`audit` node can be outside the visible viewport; the unvisited-node check is
|
||||||
|
therefore recorded as skipped there and is covered by the widget test at every
|
||||||
|
host.
|
||||||
|
|
||||||
|
## Not done / unverified
|
||||||
|
|
||||||
|
- No commit, push, merge or deployment.
|
||||||
|
- Android/iOS builds and device behavior were not run (web only, per the app
|
||||||
|
working agreement); source remains portable to both.
|
||||||
|
- No backend changes.
|
||||||
|
|
||||||
|
## Manager completion after the server evidence failure
|
||||||
|
|
||||||
|
The run ended with the server's re-saved-visit evidence bug (fixed and redeployed
|
||||||
|
separately). The retained tree is complete: 147 runs tests pass. Manager merged it
|
||||||
|
directly. The detail now owns Summary/Graph/Input/Output/Timeline tabs, renders the
|
||||||
|
run's pinned graph with the executed/not-executed legend, and a node click selects
|
||||||
|
the recorded visit and shows it in the timeline; an unvisited node reports nothing.
|
||||||
@@ -0,0 +1,143 @@
|
|||||||
|
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/graph/widgets/graph_stage_node.dart';
|
||||||
|
import 'package:pipelines_app/features/runs/data/runs_repository.dart';
|
||||||
|
import 'package:pipelines_app/features/runs/ui/run_detail_tab.dart';
|
||||||
|
import 'package:pipelines_app/features/runs/ui/run_detail_view.dart';
|
||||||
|
import 'package:pipelines_app/features/runs/ui/runs_controller.dart';
|
||||||
|
|
||||||
|
/// Shared run-detail Graph fixtures and host helpers for the tab tests.
|
||||||
|
enum RunDetailTestPlatform { material, cupertino }
|
||||||
|
|
||||||
|
class RunDetailFakeGateway implements ApiGateway {
|
||||||
|
RunDetailFakeGateway(this.detail);
|
||||||
|
|
||||||
|
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});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// plan -> build -> audit, with an implicit failure fallback on plan.
|
||||||
|
JsonMap graphFixture() => <String, dynamic>{
|
||||||
|
'stages': <dynamic>[
|
||||||
|
<String, dynamic>{
|
||||||
|
'key': 'plan',
|
||||||
|
'type': 'model',
|
||||||
|
'edges': <String, String?>{'success': 'build', 'error': '#'},
|
||||||
|
'fallback_error': true,
|
||||||
|
},
|
||||||
|
<String, dynamic>{
|
||||||
|
'key': 'build',
|
||||||
|
'type': 'model',
|
||||||
|
'edges': <String, String?>{'success': 'audit', 'error': '#'},
|
||||||
|
},
|
||||||
|
<String, dynamic>{
|
||||||
|
'key': 'audit',
|
||||||
|
'type': 'model',
|
||||||
|
'edges': <String, String?>{'success': '#success', 'error': '#failure'},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
/// A succeeded run that recorded plan and build; audit stays unvisited.
|
||||||
|
JsonMap graphRunFixture({bool graph = true}) => <String, dynamic>{
|
||||||
|
'id': 51,
|
||||||
|
'title': 'Graph run',
|
||||||
|
'name': 'release',
|
||||||
|
'status': 'succeeded',
|
||||||
|
'input': <String, dynamic>{'prompt': 'ship it'},
|
||||||
|
'output': <String, dynamic>{'result': 'ok'},
|
||||||
|
'steps': <dynamic>[
|
||||||
|
<String, dynamic>{
|
||||||
|
'stage': 'plan',
|
||||||
|
'sequence': 1,
|
||||||
|
'status': 'completed',
|
||||||
|
'outcome': 'success',
|
||||||
|
'target': 'build',
|
||||||
|
},
|
||||||
|
<String, dynamic>{
|
||||||
|
'stage': 'build',
|
||||||
|
'sequence': 2,
|
||||||
|
'status': 'completed',
|
||||||
|
'outcome': 'success',
|
||||||
|
'target': 'audit',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
if (graph) 'graph': graphFixture(),
|
||||||
|
};
|
||||||
|
|
||||||
|
Future<RunsController> pumpRunDetail(
|
||||||
|
WidgetTester tester,
|
||||||
|
RunDetailTestPlatform platform, {
|
||||||
|
JsonMap? run,
|
||||||
|
Size size = const Size(900, 1000),
|
||||||
|
double scale = 1,
|
||||||
|
}) async {
|
||||||
|
tester.view.physicalSize = size;
|
||||||
|
tester.view.devicePixelRatio = 1;
|
||||||
|
addTearDown(tester.view.reset);
|
||||||
|
final gateway = RunDetailFakeGateway(run ?? graphRunFixture());
|
||||||
|
final controller = RunsController(RunsRepository(gateway));
|
||||||
|
addTearDown(controller.dispose);
|
||||||
|
await controller.select(51);
|
||||||
|
final view = RunDetailView(
|
||||||
|
controller: controller,
|
||||||
|
gateway: gateway,
|
||||||
|
onBack: () {},
|
||||||
|
);
|
||||||
|
final page = MediaQuery(
|
||||||
|
data: MediaQueryData.fromView(
|
||||||
|
tester.view,
|
||||||
|
).copyWith(textScaler: TextScaler.linear(scale)),
|
||||||
|
child: view,
|
||||||
|
);
|
||||||
|
await tester.pumpWidget(
|
||||||
|
platform == RunDetailTestPlatform.material
|
||||||
|
? MaterialApp(home: Scaffold(body: page))
|
||||||
|
: CupertinoApp(
|
||||||
|
home: CupertinoPageScaffold(child: SafeArea(child: page)),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
return controller;
|
||||||
|
}
|
||||||
|
|
||||||
|
Finder runDetailTab(RunDetailTab tab) =>
|
||||||
|
find.byKey(ValueKey('run-detail-tab-${tab.name}'));
|
||||||
|
|
||||||
|
Future<void> openRunDetailTab(WidgetTester tester, RunDetailTab tab) async {
|
||||||
|
await tester.ensureVisible(runDetailTab(tab));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
await tester.tap(runDetailTab(tab));
|
||||||
|
await tester.pump();
|
||||||
|
await tester.pump();
|
||||||
|
await tester.pump();
|
||||||
|
}
|
||||||
|
|
||||||
|
Finder graphNode(String key) => find.byWidgetPredicate(
|
||||||
|
(widget) => widget is GraphStageNode && widget.node.key == key,
|
||||||
|
);
|
||||||
|
|
||||||
|
Future<void> tapGraphNode(WidgetTester tester, String key) async {
|
||||||
|
final viewport = tester.getRect(find.byType(InteractiveViewer));
|
||||||
|
final node = tester.getRect(graphNode(key));
|
||||||
|
if (!viewport.contains(node.center)) {
|
||||||
|
await tester.drag(
|
||||||
|
find.byType(InteractiveViewer),
|
||||||
|
viewport.center - node.center,
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
}
|
||||||
|
await tester.tap(graphNode(key), warnIfMissed: false);
|
||||||
|
await tester.pump();
|
||||||
|
await tester.pump();
|
||||||
|
}
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pipelines_app/features/graph/widgets/graph_stage_node.dart';
|
||||||
|
import 'package:pipelines_app/features/graph/widgets/run_graph_canvas.dart';
|
||||||
|
import 'package:pipelines_app/features/graph/widgets/run_graph_view.dart';
|
||||||
|
import 'package:pipelines_app/features/runs/ui/run_detail_tab.dart';
|
||||||
|
import 'package:pipelines_app/features/runs/ui/run_detail_timeline.dart';
|
||||||
|
|
||||||
|
import 'run_detail_graph_support.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
for (final platform in RunDetailTestPlatform.values) {
|
||||||
|
testWidgets('${platform.name} Graph draws the recorded run with legend', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
await pumpRunDetail(tester, platform);
|
||||||
|
await openRunDetailTab(tester, RunDetailTab.graph);
|
||||||
|
|
||||||
|
expect(find.byType(RunGraphView), findsOneWidget);
|
||||||
|
expect(find.text(runGraphExecuted), findsOneWidget);
|
||||||
|
expect(find.text(runGraphNotExecuted), findsOneWidget);
|
||||||
|
expect(
|
||||||
|
tester.widget<GraphStageNode>(graphNode('plan')).recordedStatus,
|
||||||
|
'completed',
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
tester.widget<GraphStageNode>(graphNode('build')).recordedStatus,
|
||||||
|
'completed',
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
tester.widget<GraphStageNode>(graphNode('audit')).recordedStatus,
|
||||||
|
isNull,
|
||||||
|
);
|
||||||
|
final layer = tester.widget<RunGraphEdgeLayer>(
|
||||||
|
find.byType(RunGraphEdgeLayer),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
layer.executedRoutes.map((route) => '${route.source}/${route.target}'),
|
||||||
|
['plan/build', 'build/audit'],
|
||||||
|
);
|
||||||
|
expect(tester.takeException(), isNull);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('${platform.name} stage click highlights its recorded visit', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
await pumpRunDetail(tester, platform);
|
||||||
|
await openRunDetailTab(tester, RunDetailTab.graph);
|
||||||
|
await tapGraphNode(tester, 'plan');
|
||||||
|
|
||||||
|
// The Graph reports the stage and the detail moves to Timeline, where the
|
||||||
|
// exact recorded visit is selected.
|
||||||
|
expect(find.byType(RunGraphView), findsNothing);
|
||||||
|
expect(
|
||||||
|
find.byKey(const Key('run-detail-tab-body-timeline')),
|
||||||
|
findsOneWidget,
|
||||||
|
);
|
||||||
|
final selected = tester.widget<RunTimelineRow>(
|
||||||
|
find.byKey(const ValueKey('run-timeline-visit-1')),
|
||||||
|
);
|
||||||
|
expect(selected.selected, isTrue);
|
||||||
|
expect(
|
||||||
|
tester
|
||||||
|
.widget<RunTimelineRow>(
|
||||||
|
find.byKey(const ValueKey('run-timeline-visit-2')),
|
||||||
|
)
|
||||||
|
.selected,
|
||||||
|
isFalse,
|
||||||
|
);
|
||||||
|
expect(find.textContaining('audit · visit'), findsNothing);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('${platform.name} unvisited node invents no visit', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
await pumpRunDetail(tester, platform);
|
||||||
|
await openRunDetailTab(tester, RunDetailTab.graph);
|
||||||
|
// `audit` was never recorded: its node is not a control and a click must
|
||||||
|
// leave the detail on the Graph tab.
|
||||||
|
await tapGraphNode(tester, 'audit');
|
||||||
|
expect(find.byType(RunGraphView), findsOneWidget);
|
||||||
|
expect(
|
||||||
|
find.byKey(const Key('run-detail-tab-body-timeline')),
|
||||||
|
findsNothing,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'${platform.name} programmatic Timeline selection is revealed',
|
||||||
|
(tester) async {
|
||||||
|
await pumpRunDetail(
|
||||||
|
tester,
|
||||||
|
platform,
|
||||||
|
size: const Size(320, 568),
|
||||||
|
scale: 2,
|
||||||
|
);
|
||||||
|
await openRunDetailTab(tester, RunDetailTab.graph);
|
||||||
|
await tapGraphNode(tester, 'plan');
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
// At 320/2x the strip scrolls. A Graph-driven switch must scroll the
|
||||||
|
// selected Timeline segment into view, not leave Summary/Graph showing.
|
||||||
|
final timeline = tester.getRect(runDetailTab(RunDetailTab.timeline));
|
||||||
|
expect(timeline.left, greaterThanOrEqualTo(0));
|
||||||
|
expect(timeline.right, lessThanOrEqualTo(320));
|
||||||
|
expect(
|
||||||
|
find.byKey(const Key('run-detail-tab-body-timeline')),
|
||||||
|
findsOneWidget,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pipelines_app/features/graph/widgets/run_graph_view.dart';
|
||||||
|
import 'package:pipelines_app/features/runs/actions/title_wording.dart';
|
||||||
|
import 'package:pipelines_app/features/runs/ui/run_detail_tab.dart';
|
||||||
|
|
||||||
|
import 'run_detail_graph_support.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
for (final platform in RunDetailTestPlatform.values) {
|
||||||
|
testWidgets('${platform.name} tabs keep the web order and the actions', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
await pumpRunDetail(tester, platform);
|
||||||
|
|
||||||
|
for (final label in ['Summary', 'Graph', 'Input', 'Output', 'Timeline']) {
|
||||||
|
expect(find.text(label), findsOneWidget);
|
||||||
|
}
|
||||||
|
var previous = double.negativeInfinity;
|
||||||
|
for (final tab in RunDetailTab.values) {
|
||||||
|
final center = tester.getCenter(runDetailTab(tab));
|
||||||
|
expect(center.dx, greaterThan(previous));
|
||||||
|
previous = center.dx;
|
||||||
|
}
|
||||||
|
expect(find.byKey(runTitleActionKey), findsOneWidget);
|
||||||
|
|
||||||
|
for (final tab in [
|
||||||
|
RunDetailTab.graph,
|
||||||
|
RunDetailTab.input,
|
||||||
|
RunDetailTab.output,
|
||||||
|
RunDetailTab.timeline,
|
||||||
|
RunDetailTab.summary,
|
||||||
|
]) {
|
||||||
|
await openRunDetailTab(tester, tab);
|
||||||
|
expect(find.byKey(runTitleActionKey), findsOneWidget);
|
||||||
|
expect(find.text('Graph run'), findsOneWidget);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('${platform.name} missing graph states the exact wording', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
await pumpRunDetail(tester, platform, run: graphRunFixture(graph: false));
|
||||||
|
await openRunDetailTab(tester, RunDetailTab.graph);
|
||||||
|
|
||||||
|
expect(find.text(runGraphMissing), findsOneWidget);
|
||||||
|
expect(find.byType(InteractiveViewer), findsNothing);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('${platform.name} Graph stays bounded at 320 with 2x text', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
await pumpRunDetail(
|
||||||
|
tester,
|
||||||
|
platform,
|
||||||
|
size: const Size(320, 568),
|
||||||
|
scale: 2,
|
||||||
|
);
|
||||||
|
await openRunDetailTab(tester, RunDetailTab.graph);
|
||||||
|
|
||||||
|
expect(tester.takeException(), isNull);
|
||||||
|
final slot = tester.getSize(find.byType(RunGraphView));
|
||||||
|
expect(slot.height, greaterThan(0));
|
||||||
|
expect(slot.width, lessThanOrEqualTo(320));
|
||||||
|
expect(find.byType(InteractiveViewer), findsOneWidget);
|
||||||
|
expect(find.text(runGraphExecuted), findsOneWidget);
|
||||||
|
expect(find.text(runGraphNotExecuted), findsOneWidget);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -79,8 +79,9 @@ Future<void> pumpDetail(
|
|||||||
FakeGateway gateway, {
|
FakeGateway gateway, {
|
||||||
VoidCallback? onBack,
|
VoidCallback? onBack,
|
||||||
bool settle = true,
|
bool settle = true,
|
||||||
|
Size size = const Size(390, 1600),
|
||||||
}) async {
|
}) async {
|
||||||
tester.view.physicalSize = const Size(390, 1600);
|
tester.view.physicalSize = size;
|
||||||
tester.view.devicePixelRatio = 1;
|
tester.view.devicePixelRatio = 1;
|
||||||
addTearDown(tester.view.resetPhysicalSize);
|
addTearDown(tester.view.resetPhysicalSize);
|
||||||
addTearDown(tester.view.resetDevicePixelRatio);
|
addTearDown(tester.view.resetDevicePixelRatio);
|
||||||
@@ -147,55 +148,68 @@ void main() {
|
|||||||
testWidgets('${platform.name} detail at 390 with 2x text', (tester) async {
|
testWidgets('${platform.name} detail at 390 with 2x text', (tester) async {
|
||||||
gateway.detail = runFixture(steps: 12);
|
gateway.detail = runFixture(steps: 12);
|
||||||
await controller.select(1);
|
await controller.select(1);
|
||||||
await pumpDetail(tester, platform, controller, gateway);
|
await pumpDetail(
|
||||||
|
tester,
|
||||||
|
platform,
|
||||||
|
controller,
|
||||||
|
gateway,
|
||||||
|
size: const Size(390, 1200),
|
||||||
|
);
|
||||||
expect(tester.takeException(), isNull);
|
expect(tester.takeException(), isNull);
|
||||||
expect(find.text('Nightly build'), findsOneWidget);
|
expect(find.text('Nightly build'), findsOneWidget);
|
||||||
expect(find.textContaining('Original prompt'), findsOneWidget);
|
expect(find.textContaining('Original prompt'), findsOneWidget);
|
||||||
if (platform == AppPlatform.material) {
|
if (platform == AppPlatform.material) {
|
||||||
expect(find.byType(Chip), findsOneWidget);
|
expect(find.byType(Chip), findsOneWidget);
|
||||||
expect(find.byType(ExpansionTile), findsNWidgets(2));
|
expect(find.byType(ExpansionTile), findsOneWidget);
|
||||||
} else {
|
} else {
|
||||||
expect(find.byType(Material), findsNothing);
|
expect(find.byType(Material), findsNothing);
|
||||||
expect(find.byType(Chip), findsNothing);
|
expect(find.byType(Chip), findsNothing);
|
||||||
expect(find.byType(CupertinoExpansionTile), findsNWidgets(2));
|
expect(find.byType(CupertinoExpansionTile), findsOneWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
await tester.tap(find.text('Input'));
|
Future<void> tapTab(String label) async {
|
||||||
await tester.pumpAndSettle();
|
await tester.ensureVisible(find.text(label));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
await tester.tap(find.text(label));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
}
|
||||||
|
|
||||||
|
await tapTab('Input');
|
||||||
expect(find.textContaining('"alpha": 1'), findsOneWidget);
|
expect(find.textContaining('"alpha": 1'), findsOneWidget);
|
||||||
await tester.dragUntilVisible(
|
|
||||||
find.text('Output').hitTestable(),
|
await tapTab('Output');
|
||||||
find.byType(ListView).first,
|
|
||||||
const Offset(0, -200),
|
|
||||||
);
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
await tester.tap(find.text('Output'));
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
await tester.dragUntilVisible(
|
|
||||||
find.textContaining('"ok": true').hitTestable(),
|
|
||||||
find.byType(ListView).first,
|
|
||||||
const Offset(0, -100),
|
|
||||||
);
|
|
||||||
expect(find.textContaining('"ok": true'), findsOneWidget);
|
expect(find.textContaining('"ok": true'), findsOneWidget);
|
||||||
|
|
||||||
|
await tapTab('Timeline');
|
||||||
|
final timelineScroll = find.descendant(
|
||||||
|
of: find.byKey(const Key('run-detail-tab-body-timeline')),
|
||||||
|
matching: find.byType(Scrollable),
|
||||||
|
);
|
||||||
await tester.scrollUntilVisible(
|
await tester.scrollUntilVisible(
|
||||||
find.textContaining('build · visit 3'),
|
find.textContaining('build · visit 3'),
|
||||||
200,
|
200,
|
||||||
scrollable: find.byType(Scrollable).first,
|
scrollable: timelineScroll,
|
||||||
);
|
);
|
||||||
expect(find.textContaining('build · visit 3'), findsOneWidget);
|
expect(find.textContaining('build · visit 3'), findsOneWidget);
|
||||||
|
await tester.scrollUntilVisible(
|
||||||
|
find.textContaining('test · visit 4'),
|
||||||
|
200,
|
||||||
|
scrollable: timelineScroll,
|
||||||
|
);
|
||||||
expect(find.textContaining('test · visit 4'), findsOneWidget);
|
expect(find.textContaining('test · visit 4'), findsOneWidget);
|
||||||
if (platform == AppPlatform.material) {
|
|
||||||
final scrollable = tester.state<ScrollableState>(
|
final before = tester
|
||||||
find.byType(Scrollable).first,
|
.state<ScrollableState>(timelineScroll)
|
||||||
);
|
.position
|
||||||
final before = scrollable.position.pixels;
|
.pixels;
|
||||||
expect(before, greaterThan(0));
|
expect(before, greaterThan(0));
|
||||||
gateway.detail = runFixture(steps: 13);
|
gateway.detail = runFixture(steps: 13);
|
||||||
await controller.select(1);
|
await controller.select(1);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(scrollable.position.pixels, closeTo(before, 0.1));
|
expect(
|
||||||
}
|
tester.state<ScrollableState>(timelineScroll).position.pixels,
|
||||||
|
closeTo(before, 0.1),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('${platform.name} loading and error stay honest', (
|
testWidgets('${platform.name} loading and error stay honest', (
|
||||||
|
|||||||
@@ -0,0 +1,157 @@
|
|||||||
|
// Standalone fixture entry for real-browser run-detail Graph evidence.
|
||||||
|
//
|
||||||
|
// Build and probe (from app/):
|
||||||
|
// flutter build web --target tool/run_detail_graph_probe.dart \
|
||||||
|
// --output build/probe-run-detail-graph
|
||||||
|
// PROBE_VARIANT=material OPENCODE_ARTIFACT_DIR=DIR \
|
||||||
|
// node tool/run_detail_graph_probe.mjs
|
||||||
|
//
|
||||||
|
// Server-shaped fixtures only: a fake gateway answers the same get_run envelope
|
||||||
|
// the app consumes. The run's own pinned graph and recorded steps drive the
|
||||||
|
// Graph tab; 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';
|
||||||
|
|
||||||
|
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});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// plan -> build -> audit, with plan and build recorded and audit unvisited.
|
||||||
|
JsonMap _graph() => <String, dynamic>{
|
||||||
|
'name': 'Release verification',
|
||||||
|
'stages': <dynamic>[
|
||||||
|
<String, dynamic>{
|
||||||
|
'key': 'plan',
|
||||||
|
'type': 'model',
|
||||||
|
'edges': <String, String?>{'success': 'build', 'error': '#'},
|
||||||
|
'fallback_error': true,
|
||||||
|
},
|
||||||
|
<String, dynamic>{
|
||||||
|
'key': 'build',
|
||||||
|
'type': 'model',
|
||||||
|
'edges': <String, String?>{'success': 'audit', 'error': '#'},
|
||||||
|
},
|
||||||
|
<String, dynamic>{
|
||||||
|
'key': 'audit',
|
||||||
|
'type': 'model',
|
||||||
|
'edges': <String, String?>{'success': '#success', 'error': '#failure'},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
JsonMap _run({required bool graph}) => <String, dynamic>{
|
||||||
|
'id': 488,
|
||||||
|
'title': 'Release verification',
|
||||||
|
'name': 'release',
|
||||||
|
'status': 'succeeded',
|
||||||
|
'executing': false,
|
||||||
|
'input': <String, dynamic>{'prompt': 'Verify the candidate release.'},
|
||||||
|
'output': <String, dynamic>{'result': 'verified'},
|
||||||
|
'steps': <dynamic>[
|
||||||
|
<String, dynamic>{
|
||||||
|
'stage': 'plan',
|
||||||
|
'sequence': 1,
|
||||||
|
'status': 'completed',
|
||||||
|
'outcome': 'success',
|
||||||
|
'target': 'build',
|
||||||
|
},
|
||||||
|
<String, dynamic>{
|
||||||
|
'stage': 'build',
|
||||||
|
'sequence': 2,
|
||||||
|
'status': 'completed',
|
||||||
|
'outcome': 'success',
|
||||||
|
'target': 'audit',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
if (graph) 'graph': _graph(),
|
||||||
|
};
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
final params = Uri.base.queryParameters;
|
||||||
|
final cupertino = params['platform'] == 'cupertino';
|
||||||
|
final dark = params['theme'] == 'dark';
|
||||||
|
final scale = double.tryParse(params['scale'] ?? '') ?? 1;
|
||||||
|
final run = _run(graph: params['case'] != 'missing');
|
||||||
|
runApp(_ProbeBody(cupertino: cupertino, dark: dark, scale: scale, run: run));
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ProbeBody extends StatefulWidget {
|
||||||
|
const _ProbeBody({
|
||||||
|
required this.cupertino,
|
||||||
|
required this.dark,
|
||||||
|
required this.scale,
|
||||||
|
required this.run,
|
||||||
|
});
|
||||||
|
|
||||||
|
final bool cupertino;
|
||||||
|
final bool dark;
|
||||||
|
final double scale;
|
||||||
|
final JsonMap run;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<_ProbeBody> createState() => _ProbeBodyState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ProbeBodyState extends State<_ProbeBody> {
|
||||||
|
late final _FakeGateway _gateway = _FakeGateway(widget.run);
|
||||||
|
late final RunsController _controller = RunsController(
|
||||||
|
RunsRepository(_gateway),
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_controller.select(488);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_controller.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final detail = RunDetailView(
|
||||||
|
controller: _controller,
|
||||||
|
gateway: _gateway,
|
||||||
|
onBack: () {},
|
||||||
|
);
|
||||||
|
final theme = widget.dark ? Brightness.dark : Brightness.light;
|
||||||
|
Widget scaled(BuildContext context, Widget? app) => MediaQuery(
|
||||||
|
data: MediaQuery.of(
|
||||||
|
context,
|
||||||
|
).copyWith(textScaler: TextScaler.linear(widget.scale)),
|
||||||
|
child: app!,
|
||||||
|
);
|
||||||
|
if (widget.cupertino) {
|
||||||
|
return CupertinoApp(
|
||||||
|
title: 'Run graph fixture',
|
||||||
|
theme: CupertinoThemeData(brightness: theme),
|
||||||
|
builder: scaled,
|
||||||
|
home: CupertinoPageScaffold(child: SafeArea(child: detail)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return MaterialApp(
|
||||||
|
title: 'Run graph fixture',
|
||||||
|
theme: ThemeData(brightness: theme, platform: TargetPlatform.android),
|
||||||
|
builder: scaled,
|
||||||
|
home: Scaffold(body: SafeArea(child: detail)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,292 @@
|
|||||||
|
// Real-browser acceptance for the run detail's Graph tab.
|
||||||
|
//
|
||||||
|
// Serves the probe build (`flutter build web -t tool/run_detail_graph_probe.dart`)
|
||||||
|
// on an OS-assigned loopback port and drives the actual RunDetailView over a
|
||||||
|
// server-shaped fixture. It checks the Graph tab's recorded evidence and legend,
|
||||||
|
// that an unvisited node does nothing, that a visited stage click selects the
|
||||||
|
// recorded visit in Timeline, and the exact missing-graph wording. Captures are
|
||||||
|
// written for both hosts.
|
||||||
|
//
|
||||||
|
// PROBE_VARIANT=material|cupertino PROBE_SCHEME=dark|light PROBE_SCALE=1|2 \
|
||||||
|
// PROBE_WIDTH=1280 PROBE_HEIGHT=900 PROBE_WEB_ROOT=<probe build> \
|
||||||
|
// OPENCODE_ARTIFACT_DIR=<dir> node tool/run_detail_graph_probe.mjs
|
||||||
|
import { createServer } from 'node:http';
|
||||||
|
import { spawn } from 'node:child_process';
|
||||||
|
import { once } from 'node:events';
|
||||||
|
import { setTimeout as delay } from 'node:timers/promises';
|
||||||
|
import { join, extname, resolve, sep } from 'node:path';
|
||||||
|
import { tmpdir } from 'node:os';
|
||||||
|
import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
|
||||||
|
|
||||||
|
const root = resolve(
|
||||||
|
process.env.PROBE_WEB_ROOT ??
|
||||||
|
join(process.cwd(), 'build/probe-run-detail-graph'),
|
||||||
|
);
|
||||||
|
const variant = process.env.PROBE_VARIANT ?? 'material';
|
||||||
|
const scheme = process.env.PROBE_SCHEME ?? 'dark';
|
||||||
|
const scale = process.env.PROBE_SCALE ?? '1';
|
||||||
|
const width = Number(process.env.PROBE_WIDTH ?? 1280);
|
||||||
|
const height = Number(process.env.PROBE_HEIGHT ?? 900);
|
||||||
|
const chromePath = process.env.CHROME_PATH ??
|
||||||
|
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
|
||||||
|
const artifactDir = process.env.OPENCODE_ARTIFACT_DIR;
|
||||||
|
if (!artifactDir) throw new Error('Set OPENCODE_ARTIFACT_DIR for the probe captures');
|
||||||
|
await mkdir(artifactDir, { recursive: true });
|
||||||
|
const prefix = `run-detail-graph-${variant}-${scheme}-${scale}x-${width}x${height}`;
|
||||||
|
const mime = {
|
||||||
|
'.html': 'text/html',
|
||||||
|
'.js': 'text/javascript',
|
||||||
|
'.json': 'application/json',
|
||||||
|
'.wasm': 'application/wasm',
|
||||||
|
'.png': 'image/png',
|
||||||
|
'.ico': 'image/x-icon',
|
||||||
|
'.otf': 'font/otf',
|
||||||
|
'.ttf': 'font/ttf',
|
||||||
|
};
|
||||||
|
const server = createServer(async (req, res) => {
|
||||||
|
try {
|
||||||
|
const path = resolve(root, '.' + decodeURIComponent(new URL(req.url, 'http://localhost').pathname));
|
||||||
|
if (path !== root && !path.startsWith(root + sep)) return res.writeHead(403).end();
|
||||||
|
const filePath = path === root || path.endsWith('/') ? join(path, 'index.html') : path;
|
||||||
|
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 port = server.address().port;
|
||||||
|
const profile = await mkdtemp(join(tmpdir(), 'run-detail-graph-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) => {
|
||||||
|
for (let i = 0; i < 140; i++) {
|
||||||
|
const value = await fn();
|
||||||
|
if (value) return value;
|
||||||
|
await delay(100);
|
||||||
|
}
|
||||||
|
throw new Error('Timed out waiting for Chrome DevTools');
|
||||||
|
};
|
||||||
|
let ws;
|
||||||
|
try {
|
||||||
|
const endpoint = await waitFor(() => stderr.match(/DevTools listening on (ws:\/\/[^\s]+)/)?.[1]);
|
||||||
|
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.method === 'Runtime.exceptionThrown') {
|
||||||
|
console.error('PAGE EXCEPTION', JSON.stringify(message.params?.exceptionDetails?.exception?.description));
|
||||||
|
}
|
||||||
|
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' });
|
||||||
|
const target = created.result.targetId;
|
||||||
|
const session = (await send('Target.attachToTarget', { targetId: target, flatten: true })).result.sessionId;
|
||||||
|
await send('Page.enable', {}, session);
|
||||||
|
await send('Runtime.enable', {}, session);
|
||||||
|
await send('Emulation.setEmulatedMedia', {
|
||||||
|
features: [{ name: 'prefers-color-scheme', value: scheme }],
|
||||||
|
}, session);
|
||||||
|
await send('Emulation.setDeviceMetricsOverride', {
|
||||||
|
width, height, deviceScaleFactor: 1, mobile: width < 600,
|
||||||
|
}, 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 semantics = () => evaluate(`[...document.querySelectorAll('flt-semantics')].map(x => {
|
||||||
|
const r = x.getBoundingClientRect();
|
||||||
|
return {
|
||||||
|
label: (x.getAttribute('aria-label') || (x.innerText || '')).trim(),
|
||||||
|
selected: x.getAttribute('aria-selected') || x.getAttribute('aria-current'),
|
||||||
|
tappable: x.hasAttribute('flt-tappable'),
|
||||||
|
x: r.x, y: r.y, width: r.width, height: r.height,
|
||||||
|
visible: r.width > 0 && r.height > 0 && r.bottom > 0 && r.top < innerHeight,
|
||||||
|
};
|
||||||
|
})`);
|
||||||
|
const labels = async () => (await semantics()).map((item) => item.label).filter(Boolean);
|
||||||
|
const bodyText = async () => [await evaluate('document.body.innerText'), ...(await labels())].join('\n');
|
||||||
|
const waitForText = async (needle, context) => {
|
||||||
|
for (let attempt = 0; attempt < 60; attempt++) {
|
||||||
|
if ((await bodyText()).includes(needle)) return;
|
||||||
|
await delay(250);
|
||||||
|
}
|
||||||
|
throw new Error(`${context}: missing ${JSON.stringify(needle)}\n${await bodyText()}`);
|
||||||
|
};
|
||||||
|
const clickItem = async (item) => {
|
||||||
|
const x = item.x + item.width / 2;
|
||||||
|
const y = item.y + item.height / 2;
|
||||||
|
await send('Input.dispatchMouseEvent', {
|
||||||
|
type: 'mousePressed', x, y, button: 'left', clickCount: 1,
|
||||||
|
}, session);
|
||||||
|
await send('Input.dispatchMouseEvent', {
|
||||||
|
type: 'mouseReleased', x, y, button: 'left', clickCount: 1,
|
||||||
|
}, session);
|
||||||
|
await delay(1000);
|
||||||
|
};
|
||||||
|
const findVisible = async (predicate) => {
|
||||||
|
const items = (await semantics()).filter((item) => item.visible && predicate(item));
|
||||||
|
items.sort((a, b) => a.width * a.height - b.width * b.height);
|
||||||
|
return items[0] ?? null;
|
||||||
|
};
|
||||||
|
// A native control's semantics node is the one the engine listens to; a
|
||||||
|
// synthetic DOM click avoids coordinate ambiguity in a horizontally scrolled
|
||||||
|
// tab strip and in a panned graph canvas.
|
||||||
|
const clickSemantics = async (wanted, prefix = false) => {
|
||||||
|
const clicked = await evaluate(`(() => {
|
||||||
|
const wanted = ${JSON.stringify(wanted)};
|
||||||
|
const prefix = ${prefix ? 'true' : 'false'};
|
||||||
|
const text = (x) => (x.getAttribute('aria-label') || x.innerText || '').trim();
|
||||||
|
const matches = [...document.querySelectorAll('flt-semantics')]
|
||||||
|
.filter((x) => x.hasAttribute('flt-tappable'))
|
||||||
|
.filter((x) => prefix ? text(x).startsWith(wanted) : text(x) === wanted);
|
||||||
|
if (!matches.length) return false;
|
||||||
|
matches.sort((a, b) => {
|
||||||
|
const ra = a.getBoundingClientRect();
|
||||||
|
const rb = b.getBoundingClientRect();
|
||||||
|
return ra.width * ra.height - rb.width * rb.height;
|
||||||
|
});
|
||||||
|
matches[0].click();
|
||||||
|
return true;
|
||||||
|
})()`);
|
||||||
|
if (!clicked) throw new Error(`Missing tappable ${JSON.stringify(wanted)}: ${JSON.stringify(await labels())}`);
|
||||||
|
await delay(1000);
|
||||||
|
};
|
||||||
|
const clickLabel = (label) => clickSemantics(label);
|
||||||
|
const clickPrefix = (prefix) => clickSemantics(prefix, true);
|
||||||
|
const capture = async (name) => {
|
||||||
|
const data = (await send('Page.captureScreenshot', {
|
||||||
|
format: 'png', captureBeyondViewport: false,
|
||||||
|
}, session)).result.data;
|
||||||
|
const file = `${prefix}-${name}.png`;
|
||||||
|
await writeFile(join(artifactDir, file), Buffer.from(data, 'base64'));
|
||||||
|
return file;
|
||||||
|
};
|
||||||
|
const evidence = { variant, scheme, scale, width, height, checks: [], captures: [] };
|
||||||
|
const check = (text, value) => evidence.checks.push({ check: text, value });
|
||||||
|
const activate = async () => {
|
||||||
|
await delay(3200);
|
||||||
|
await evaluate("document.querySelector('flt-semantics-placeholder')?.click()");
|
||||||
|
await delay(900);
|
||||||
|
};
|
||||||
|
const navigate = async (query, needle) => {
|
||||||
|
const navigation = await send('Page.navigate', { url: `http://127.0.0.1:${port}/${query}` }, session);
|
||||||
|
if (navigation.error || navigation.result?.errorText) throw new Error(JSON.stringify(navigation));
|
||||||
|
await activate();
|
||||||
|
await waitForText(needle, 'fixture load');
|
||||||
|
};
|
||||||
|
|
||||||
|
await navigate(
|
||||||
|
`?platform=${variant}&theme=${scheme === 'dark' ? 1 : 0}&scale=${scale}&case=default`,
|
||||||
|
'Release verification',
|
||||||
|
);
|
||||||
|
check('the real run detail opened over the recorded fixture', true);
|
||||||
|
|
||||||
|
await clickLabel('Graph');
|
||||||
|
await waitForText('Executed', 'graph legend');
|
||||||
|
await waitForText('Not executed', 'graph legend');
|
||||||
|
const graphLabels = await labels();
|
||||||
|
const plan = await findVisible((entry) => entry.label.startsWith('plan') && entry.tappable);
|
||||||
|
const build = await findVisible((entry) => entry.label.startsWith('build') && entry.tappable);
|
||||||
|
const audit = await findVisible((entry) => entry.label === 'audit');
|
||||||
|
if (!plan) throw new Error(`Visited stage node is missing: ${JSON.stringify(graphLabels)}`);
|
||||||
|
if (audit?.tappable) throw new Error('An unvisited node is a tap target');
|
||||||
|
if (plan.y + plan.height > height) {
|
||||||
|
throw new Error(`Graph node falls outside the bounded viewport: ${JSON.stringify({ plan, height })}`);
|
||||||
|
}
|
||||||
|
check(
|
||||||
|
'Graph draws the recorded stages inside the viewport',
|
||||||
|
`${Math.round(plan.width)}x${Math.round(plan.height)} plan${build ? ', build visible' : ''}`,
|
||||||
|
);
|
||||||
|
check('Graph legend shows Executed and Not executed', true);
|
||||||
|
evidence.captures.push(await capture('graph'));
|
||||||
|
|
||||||
|
// An unvisited node is not a control: clicking its label leaves the Graph tab
|
||||||
|
// exactly as it was and creates no visit. At 320/2x the canvas is panned, so
|
||||||
|
// the later node may sit outside the visible viewport; the widget test covers
|
||||||
|
// that case there.
|
||||||
|
if (audit) {
|
||||||
|
await clickItem(audit);
|
||||||
|
await waitForText('Executed', 'graph after unvisited click');
|
||||||
|
if ((await bodyText()).includes('plan · visit 1')) {
|
||||||
|
throw new Error('An unvisited node invented a timeline visit');
|
||||||
|
}
|
||||||
|
check('an unvisited node does nothing and invents no visit', true);
|
||||||
|
} else {
|
||||||
|
check('unvisited node is outside this bounded viewport; widget test covers it', 'skipped');
|
||||||
|
}
|
||||||
|
|
||||||
|
await clickPrefix('plan');
|
||||||
|
await waitForText('plan · visit 1', 'timeline after stage click');
|
||||||
|
await waitForText('Timeline', 'timeline tab');
|
||||||
|
const timeline = await semantics();
|
||||||
|
const rowCandidates = timeline
|
||||||
|
.filter((entry) => entry.visible && entry.label.startsWith('plan · visit 1'))
|
||||||
|
.sort((a, b) => a.width * a.height - b.width * b.height);
|
||||||
|
const row = rowCandidates[0];
|
||||||
|
if (!row) throw new Error(`Selected timeline row missing: ${JSON.stringify(timeline.map((entry) => entry.label))}`);
|
||||||
|
if (row.selected !== 'true') {
|
||||||
|
throw new Error(`Timeline row is not selected: ${JSON.stringify(rowCandidates)}`);
|
||||||
|
}
|
||||||
|
if ((await bodyText()).includes('audit · visit')) {
|
||||||
|
throw new Error('A visit was invented for the unvisited stage');
|
||||||
|
}
|
||||||
|
check('a stage click selects the recorded visit in Timeline', row.selected);
|
||||||
|
// The programmatic switch must reveal its own tab, not leave an offscreen
|
||||||
|
// selection behind a strip still showing Summary/Graph.
|
||||||
|
const timelineTab = await findVisible((entry) => entry.label === 'Timeline' && entry.tappable);
|
||||||
|
if (!timelineTab) throw new Error(`Timeline tab is not visible: ${JSON.stringify(await labels())}`);
|
||||||
|
if (timelineTab.x < 0 || timelineTab.x + timelineTab.width > width) {
|
||||||
|
throw new Error(`Selected Timeline tab is clipped: ${JSON.stringify({ timelineTab, width })}`);
|
||||||
|
}
|
||||||
|
check('the selected Timeline tab is revealed in the strip', `${Math.round(timelineTab.x)}..${Math.round(timelineTab.x + timelineTab.width)}`);
|
||||||
|
evidence.selectedRow = row;
|
||||||
|
evidence.captures.push(await capture('selected-visit'));
|
||||||
|
|
||||||
|
await navigate(
|
||||||
|
`?platform=${variant}&theme=${scheme === 'dark' ? 1 : 0}&scale=${scale}&case=missing`,
|
||||||
|
'Release verification',
|
||||||
|
);
|
||||||
|
await clickLabel('Graph');
|
||||||
|
await waitForText('This server did not include the run graph.', 'missing graph');
|
||||||
|
if ((await semantics()).some((entry) => entry.label === 'audit')) {
|
||||||
|
throw new Error('A run without a graph still drew stage nodes');
|
||||||
|
}
|
||||||
|
check('a run without a graph states the exact missing wording', true);
|
||||||
|
evidence.captures.push(await capture('missing-graph'));
|
||||||
|
|
||||||
|
console.log(JSON.stringify(evidence, null, 2));
|
||||||
|
} finally {
|
||||||
|
if (ws?.readyState === WebSocket.OPEN) {
|
||||||
|
ws.send(JSON.stringify({ id: 2147483647, method: 'Browser.close' }));
|
||||||
|
}
|
||||||
|
await Promise.race([once(chrome, 'exit'), delay(3000)]);
|
||||||
|
ws?.close();
|
||||||
|
if (chrome.exitCode === null) chrome.kill('SIGTERM');
|
||||||
|
chrome.stderr.destroy();
|
||||||
|
chrome.unref();
|
||||||
|
await new Promise((resolveClose) => {
|
||||||
|
server.close(resolveClose);
|
||||||
|
server.closeAllConnections();
|
||||||
|
});
|
||||||
|
await rm(profile, { recursive: true, force: true });
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user