feat(app): add native authored stage definition pane

This commit is contained in:
2026-10-21 22:26:34 +01:00
parent 76fb2cdd87
commit d88213deb4
7 changed files with 1529 additions and 0 deletions
@@ -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,
);
});
});
}