feat(app): add native authored stage definition pane
This commit is contained in:
@@ -0,0 +1,159 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/graph/domain/stage_definition.dart';
|
||||
|
||||
import 'graph_fixtures.dart';
|
||||
|
||||
JsonMap _stage() => <String, dynamic>{
|
||||
'key': 'build',
|
||||
'prompt': 'Implement the planned change.',
|
||||
'output': 'A committed change.',
|
||||
'edges': <String, String?>{
|
||||
'success': 'audit',
|
||||
'approved': '#',
|
||||
'error': '#failure',
|
||||
},
|
||||
'fallback_error': true,
|
||||
'configs': <String, dynamic>{
|
||||
'provider': 'openai',
|
||||
'model': 'gpt-5',
|
||||
'budget_usd': 12.5,
|
||||
'retries': 2,
|
||||
'harness': 'codex',
|
||||
'timeout': '15m',
|
||||
'skipped_blank': ' ',
|
||||
'skipped_null': null,
|
||||
},
|
||||
'blocks': <String, dynamic>{'tools': 'shell\nread_file'},
|
||||
'limits': <String, dynamic>{
|
||||
'max_visits': 3,
|
||||
'on': <String>['success', 'error'],
|
||||
},
|
||||
'memory': <String, dynamic>{'context': 'latest', 'notes': 'keep'},
|
||||
'notify': <String, dynamic>{
|
||||
'on': <String>['failure'],
|
||||
'destination': 'ops@example.test',
|
||||
'artifacts': <String>['run.log'],
|
||||
},
|
||||
'custom_flag': true,
|
||||
};
|
||||
|
||||
void main() {
|
||||
group('stage fields', () {
|
||||
test('follow the web pane order, labels and blank-field rules', () {
|
||||
final fields = stageDefinitionFields(_stage());
|
||||
|
||||
expect(fields.map((field) => field.label), <String>[
|
||||
'Type',
|
||||
'Prompt',
|
||||
'Output',
|
||||
'Outcomes',
|
||||
'Budget (USD)',
|
||||
'Harness',
|
||||
'Model',
|
||||
'Provider',
|
||||
'Retries',
|
||||
'Timeout',
|
||||
'Tools',
|
||||
'Max visits',
|
||||
'Limit on',
|
||||
'Memory',
|
||||
'Notify on',
|
||||
'Notify destination',
|
||||
'Notify artifacts',
|
||||
]);
|
||||
expect(fields.first.value, 'model');
|
||||
expect(fields[1].block, isTrue);
|
||||
expect(fields[2].value, 'A committed change.');
|
||||
expect(
|
||||
fields[3].value,
|
||||
'success → audit\n'
|
||||
'approved → SUCCESS (terminal)\n'
|
||||
'error → FAILURE (terminal)',
|
||||
);
|
||||
expect(fields[4].value, '12.5');
|
||||
expect(fields[5].value, 'codex');
|
||||
expect(fields[10].value, 'shell\nread_file');
|
||||
expect(fields[11].value, '3');
|
||||
expect(fields[12].value, 'success, error');
|
||||
expect(fields[13].value, 'context: latest\nnotes: keep');
|
||||
expect(fields[14].value, 'failure');
|
||||
expect(fields[15].value, 'ops@example.test');
|
||||
expect(fields[16].value, 'run.log');
|
||||
});
|
||||
|
||||
test('a blank or absent type reads model; an authored type is kept', () {
|
||||
expect(effectiveStageType(null), 'model');
|
||||
expect(effectiveStageType(' '), 'model');
|
||||
expect(effectiveStageType('shell'), 'shell');
|
||||
expect(
|
||||
stageDefinitionFields(<String, dynamic>{'key': 'a'}).single.value,
|
||||
'model',
|
||||
);
|
||||
});
|
||||
|
||||
test('config keys outside the known labels are shown verbatim', () {
|
||||
final fields = stageDefinitionFields(<String, dynamic>{
|
||||
'key': 'a',
|
||||
'configs': <String, dynamic>{'temperature': 0},
|
||||
});
|
||||
|
||||
expect(fields.map((field) => field.label), contains('temperature'));
|
||||
expect(
|
||||
fields.firstWhere((field) => field.label == 'temperature').value,
|
||||
'0',
|
||||
);
|
||||
});
|
||||
|
||||
test('zero visits and missing limits emit no invented rows', () {
|
||||
final fields = stageDefinitionFields(<String, dynamic>{
|
||||
'key': 'a',
|
||||
'limits': <String, dynamic>{'max_visits': 0, 'on': <String>[]},
|
||||
});
|
||||
|
||||
expect(fields.map((field) => field.label), <String>['Type']);
|
||||
});
|
||||
|
||||
test(
|
||||
'the stage lookup preserves unknown keys and the last declaration',
|
||||
() {
|
||||
final graph = <String, dynamic>{
|
||||
'stages': <dynamic>[
|
||||
<String, dynamic>{'key': 'build', 'type': 'old'},
|
||||
_stage(),
|
||||
],
|
||||
};
|
||||
final stage = stageDefinitionFor(graph, 'build');
|
||||
|
||||
expect(stage?['type'], isNull);
|
||||
expect(effectiveStageType(stage?['type']), 'model');
|
||||
expect(stage?['custom_flag'], isTrue);
|
||||
expect(stageDefinitionFor(graph, 'ghost'), isNull);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('terminal fields', () {
|
||||
test('list incoming definition routes, including the fallback marker', () {
|
||||
expect(terminalDefinitionFields(linearGraph(), '#failure'), hasLength(1));
|
||||
final fields = terminalDefinitionFields(linearGraph(), '#failure');
|
||||
expect(
|
||||
fields.single.value,
|
||||
'plan · error* → FAILURE\nship · error → FAILURE',
|
||||
);
|
||||
expect(fields.single.block, isTrue);
|
||||
expect(
|
||||
terminalDefinitionFields(linearGraph(), '#success').single.value,
|
||||
'ship · success → SUCCESS',
|
||||
);
|
||||
});
|
||||
|
||||
test('a terminal with no routes has no fields to invent', () {
|
||||
expect(
|
||||
terminalDefinitionFields(<String, dynamic>{}, '#success'),
|
||||
isEmpty,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,286 @@
|
||||
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/domain/stage_definition.dart';
|
||||
import 'package:pipelines_app/features/graph/widgets/stage_definition_view.dart';
|
||||
|
||||
JsonMap _graph() => <String, dynamic>{
|
||||
'stages': <dynamic>[
|
||||
<String, dynamic>{
|
||||
'key': 'plan',
|
||||
'type': 'model',
|
||||
'prompt': 'Plan the change.',
|
||||
'edges': <String, String?>{'success': 'build', 'error': '#'},
|
||||
'fallback_error': true,
|
||||
'configs': <String, dynamic>{'provider': 'openai', 'model': 'gpt-5'},
|
||||
'limits': <String, dynamic>{
|
||||
'max_visits': 2,
|
||||
'on': <String>['error'],
|
||||
},
|
||||
'future_field': <String, dynamic>{'kept': true},
|
||||
},
|
||||
<String, dynamic>{
|
||||
'key': 'build',
|
||||
'type': 'shell',
|
||||
'edges': <String, String?>{'success': '#success', 'error': '#failure'},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
Widget _material(Widget child) => MaterialApp(
|
||||
home: Scaffold(
|
||||
appBar: AppBar(title: const Text('plan definition')),
|
||||
body: child,
|
||||
),
|
||||
);
|
||||
|
||||
Widget _cupertino(Widget child, {bool dark = false}) => CupertinoApp(
|
||||
theme: CupertinoThemeData(
|
||||
brightness: dark ? Brightness.dark : Brightness.light,
|
||||
),
|
||||
home: CupertinoPageScaffold(child: child),
|
||||
);
|
||||
|
||||
StageDefinitionView _view({String key = 'plan'}) => StageDefinitionView(
|
||||
graph: _graph(),
|
||||
stageKey: key,
|
||||
pipelineId: 41,
|
||||
pipelineName: 'Demo pipeline',
|
||||
version: 7,
|
||||
);
|
||||
|
||||
/// Finds visible text, including SelectableText's editable body.
|
||||
Finder _text(String value) => find.byWidgetPredicate(
|
||||
(widget) =>
|
||||
(widget is Text && widget.data == value) ||
|
||||
(widget is SelectableText && widget.data == value),
|
||||
);
|
||||
|
||||
void main() {
|
||||
testWidgets('a declared stage shows pinned identity and web field values', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(_material(_view()));
|
||||
|
||||
expect(_text('Demo pipeline · v7'), findsOneWidget);
|
||||
expect(_text('model'), findsOneWidget);
|
||||
expect(_text('Plan the change.'), findsOneWidget);
|
||||
expect(
|
||||
_text('success → build\nerror → FAILURE (terminal)'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(_text('Provider'), findsOneWidget);
|
||||
expect(_text('openai'), findsOneWidget);
|
||||
expect(_text('Model'), findsOneWidget);
|
||||
expect(_text('gpt-5'), findsOneWidget);
|
||||
expect(_text('Max visits'), findsOneWidget);
|
||||
expect(_text('2'), findsOneWidget);
|
||||
expect(_text('Limit on'), findsOneWidget);
|
||||
expect(_text('error'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('the raw section keeps unknown fields exact and selectable', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(_material(_view()));
|
||||
|
||||
expect(_text(rawStageDefinitionTitle), findsOneWidget);
|
||||
final raw = tester
|
||||
.widgetList<SelectableText>(find.byType(SelectableText))
|
||||
.map((widget) => widget.data ?? '')
|
||||
.join('\n');
|
||||
expect(raw, contains('"future_field": {'));
|
||||
expect(raw, contains('"kept": true'));
|
||||
expect(raw, contains('"fallback_error": true'));
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('unknown stages get an explicit missing state, never defaults', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(_material(_view(key: 'ghost')));
|
||||
|
||||
expect(_text(unknownStageDefinition), findsOneWidget);
|
||||
expect(_text('model'), findsNothing);
|
||||
expect(_text(rawStageDefinitionTitle), findsNothing);
|
||||
expect(find.byType(SelectableText), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('terminals explain definition targets and incoming routes', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(_material(_view(key: '#failure')));
|
||||
|
||||
expect(_text(terminalDefinitionNote), findsOneWidget);
|
||||
expect(_text('Incoming routes'), findsOneWidget);
|
||||
expect(
|
||||
_text('plan · error* → FAILURE\nbuild · error → FAILURE'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(_text(rawStageDefinitionTitle), findsNothing);
|
||||
expect(_text('successful'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('Cupertino uses its theme roles in dark mode', (tester) async {
|
||||
late Color secondary;
|
||||
await tester.pumpWidget(
|
||||
_cupertino(
|
||||
Builder(
|
||||
builder: (context) {
|
||||
secondary = CupertinoColors.secondaryLabel.resolveFrom(context);
|
||||
return _view();
|
||||
},
|
||||
),
|
||||
dark: true,
|
||||
),
|
||||
);
|
||||
|
||||
final identity = tester.widget<Text>(_text('Demo pipeline · v7'));
|
||||
expect(identity.style?.color, secondary);
|
||||
expect(_text('Plan the change.'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('the Material helper opens one bar and Back closes it', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Builder(
|
||||
builder: (context) => Scaffold(
|
||||
body: TextButton(
|
||||
onPressed: () => openStageDefinition(
|
||||
context,
|
||||
graph: _graph(),
|
||||
stageKey: 'plan',
|
||||
pipelineId: 41,
|
||||
pipelineName: 'Demo pipeline',
|
||||
version: 7,
|
||||
),
|
||||
child: const Text('Open definition'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.text('Open definition'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(_text('plan definition'), findsOneWidget);
|
||||
expect(find.byType(AppBar), findsOneWidget);
|
||||
expect(find.byType(BackButton), findsOneWidget);
|
||||
final route = ModalRoute.of(
|
||||
tester.element(find.byType(StageDefinitionView)),
|
||||
);
|
||||
expect(route?.settings.name, 'stage-definition/41/7/plan');
|
||||
|
||||
await tester.pageBack();
|
||||
await tester.pumpAndSettle();
|
||||
expect(_text('Open definition'), findsOneWidget);
|
||||
expect(find.byType(StageDefinitionView), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('the Cupertino helper opens one native bar and Back closes it', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
CupertinoApp(
|
||||
home: Builder(
|
||||
builder: (context) => CupertinoPageScaffold(
|
||||
child: CupertinoButton(
|
||||
onPressed: () => openStageDefinition(
|
||||
context,
|
||||
graph: _graph(),
|
||||
stageKey: '#success',
|
||||
pipelineId: 41,
|
||||
pipelineName: 'Demo pipeline',
|
||||
version: 7,
|
||||
),
|
||||
child: const Text('Open terminal'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.text('Open terminal'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(_text('Success definition'), findsOneWidget);
|
||||
expect(_text('#success definition'), findsNothing);
|
||||
expect(find.byType(CupertinoNavigationBar), findsOneWidget);
|
||||
expect(find.byType(CupertinoNavigationBarBackButton), findsOneWidget);
|
||||
expect(_text('Incoming routes'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byType(CupertinoNavigationBarBackButton));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_text('Open terminal'), findsOneWidget);
|
||||
expect(find.byType(StageDefinitionView), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('the Material helper titles a terminal with its display label', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Builder(
|
||||
builder: (context) => Scaffold(
|
||||
body: TextButton(
|
||||
onPressed: () => openStageDefinition(
|
||||
context,
|
||||
graph: _graph(),
|
||||
stageKey: '#failure',
|
||||
pipelineId: 41,
|
||||
pipelineName: 'Demo pipeline',
|
||||
version: 7,
|
||||
),
|
||||
child: const Text('Open failure'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.text('Open failure'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(_text('Failure definition'), findsOneWidget);
|
||||
expect(_text('#failure definition'), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('selectable blocks force the host strut for one line rhythm', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(_cupertino(_view()));
|
||||
|
||||
final selectable = tester
|
||||
.widgetList<SelectableText>(find.byType(SelectableText))
|
||||
.toList();
|
||||
expect(selectable.length, greaterThanOrEqualTo(2));
|
||||
for (final widget in selectable) {
|
||||
final strut = widget.strutStyle;
|
||||
expect(strut, isNotNull);
|
||||
// The host's own metrics, forced: a fallback glyph cannot widen a block.
|
||||
expect(strut!.forceStrutHeight, isTrue);
|
||||
expect(strut.fontFamily, widget.style?.fontFamily);
|
||||
expect(strut.fontSize, widget.style?.fontSize);
|
||||
}
|
||||
final outcomes = selectable.firstWhere(
|
||||
(widget) => (widget.data ?? '').contains('success → build'),
|
||||
);
|
||||
final raw = selectable.firstWhere(
|
||||
(widget) => (widget.data ?? '').startsWith('{'),
|
||||
);
|
||||
expect(outcomes.strutStyle, raw.strutStyle);
|
||||
});
|
||||
|
||||
test('field labels are the web words', () {
|
||||
expect(stageConfigLabel('budget_usd'), 'Budget (USD)');
|
||||
expect(stageConfigLabel('budget_tokens'), 'Budget (tokens)');
|
||||
expect(stageConfigLabel('custom'), 'custom');
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user