feat(app): schedule a recorded run with its options
The run detail now offers the web's "Schedule this run" action when the
run names a positive pipeline and pinned version. It opens the existing
create editor seeded from the run and sends nothing until Save.
The seed preserves every field the browser's scheduleDraft({ run })
copies: title (following the title_source rule), all input keys with
prompt kept editable, pinned version, workspace, notify mode, write
paths, tool access, model, stage models and output format. build() emits
the same conditional payload as serializeSchedule.
One request key is minted per editor opening so a refused save retries
without duplicating the schedule. Advanced options are seed-only for
now: the editor has no controls for them yet.
This commit is contained in:
@@ -0,0 +1,262 @@
|
||||
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/core/transport/connection_state.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_actions.dart';
|
||||
import 'package:pipelines_app/features/schedules/ui/editor/schedule_editor_wording.dart';
|
||||
import 'package:pipelines_app/features/schedules/ui/run/schedule_run_action.dart';
|
||||
|
||||
/// Records every `save_schedule` and refuses the first one on demand. No socket
|
||||
/// or Pipelines server is involved.
|
||||
class SaveGateway implements ApiGateway {
|
||||
final calls = <Map<String, dynamic>>[];
|
||||
bool refuseNext = false;
|
||||
|
||||
@override
|
||||
Stream<JsonMap> get frames => const Stream.empty();
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
||||
if (type != 'save_schedule') throw UnsupportedError('unexpected $type');
|
||||
calls.add(Map<String, dynamic>.from(fields));
|
||||
if (refuseNext) {
|
||||
refuseNext = false;
|
||||
throw const ProtocolError('conflict: revision 4 is stale');
|
||||
}
|
||||
final schedule = Map<String, dynamic>.from(fields['schedule'] as Map);
|
||||
return {
|
||||
'type': 'schedule_saved',
|
||||
'schedule': {...schedule, 'id': 12, 'revision': 1},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
JsonMap runFixture({
|
||||
Object? version = 5,
|
||||
Object? pipelineId = 4,
|
||||
String title = 'Nightly build',
|
||||
String prompt = 'Summarise the release notes.',
|
||||
String workspace = '/srv/run-workspace',
|
||||
}) => {
|
||||
'id': 7,
|
||||
'title': title,
|
||||
'pipeline_id': ?pipelineId,
|
||||
'version': ?version,
|
||||
'status': 'succeeded',
|
||||
'input': {
|
||||
'prompt': prompt,
|
||||
'nested': {'kept': true},
|
||||
},
|
||||
'workspace': workspace,
|
||||
};
|
||||
|
||||
/// A run carrying every option the browser's run seed preserves.
|
||||
JsonMap restrictedRunFixture() => {
|
||||
...runFixture(),
|
||||
'title_source': 'explicit',
|
||||
'input': {
|
||||
'prompt': 'Summarise the release notes.',
|
||||
'topic': 'release notes',
|
||||
'nested': {'kept': true},
|
||||
},
|
||||
'notify_mode': 'off',
|
||||
'write_paths': ['src/file.go', 'notes'],
|
||||
'allow_tools': true,
|
||||
'model': 'provider/model',
|
||||
'stage_models': {'research': 'provider/other'},
|
||||
'output_format': 'json',
|
||||
};
|
||||
|
||||
Future<void> pumpAction(
|
||||
WidgetTester tester,
|
||||
Widget child, {
|
||||
bool cupertino = false,
|
||||
}) async {
|
||||
tester.view.physicalSize = const Size(390, 1600);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(
|
||||
home: CupertinoPageScaffold(child: SafeArea(child: child)),
|
||||
)
|
||||
: MaterialApp(
|
||||
home: Scaffold(body: SafeArea(child: child)),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Future<void> tapSave(WidgetTester tester) async {
|
||||
// A focused field keeps itself visible, so drop focus before scrolling.
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
await tester.pumpAndSettle();
|
||||
final finder = find.byKey(scheduleEditorSubmitKey);
|
||||
await tester.ensureVisible(finder);
|
||||
await tester.pump();
|
||||
await tester.tap(finder);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
String materialField(WidgetTester tester, Key key) =>
|
||||
tester.widget<TextField>(find.byKey(key)).controller!.text;
|
||||
|
||||
void main() {
|
||||
testWidgets('opens a create editor seeded from the run without sending', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = SaveGateway();
|
||||
await pumpAction(
|
||||
tester,
|
||||
ScheduleRunAction(run: runFixture(), gateway: gateway),
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(scheduleRunActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.calls, isEmpty);
|
||||
expect(find.text('Add schedule'), findsOneWidget);
|
||||
expect(materialField(tester, scheduleEditorNameKey), 'Nightly build');
|
||||
expect(
|
||||
materialField(tester, scheduleEditorPromptKey),
|
||||
'Summarise the release notes.',
|
||||
);
|
||||
expect(materialField(tester, scheduleEditorVersionKey), '5');
|
||||
expect(
|
||||
materialField(tester, scheduleEditorWorkspaceKey),
|
||||
'/srv/run-workspace',
|
||||
);
|
||||
expect(materialField(tester, scheduleEditorEveryKey), '24h');
|
||||
expect(materialField(tester, scheduleEditorTimezoneKey), '');
|
||||
expect(gateway.calls, isEmpty);
|
||||
});
|
||||
|
||||
testWidgets('saves the run\'s input, restrictions and overrides once, and '
|
||||
'reuses the one key after a refusal', (tester) async {
|
||||
final gateway = SaveGateway()..refuseNext = true;
|
||||
await pumpAction(
|
||||
tester,
|
||||
ScheduleRunAction(run: restrictedRunFixture(), gateway: gateway),
|
||||
);
|
||||
await tester.tap(find.byKey(scheduleRunActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tapSave(tester);
|
||||
|
||||
expect(gateway.calls, hasLength(1));
|
||||
final key = gateway.calls.single['request_key'];
|
||||
expect(key, isA<String>());
|
||||
expect(key, isNotEmpty);
|
||||
expect('$key'.length, lessThanOrEqualTo(128));
|
||||
expect(
|
||||
find.textContaining('conflict: revision 4 is stale'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.textContaining('Your draft is preserved.'), findsOneWidget);
|
||||
expect(find.byKey(scheduleEditorSubmitKey), findsOneWidget);
|
||||
expect(
|
||||
materialField(tester, scheduleEditorPromptKey),
|
||||
'Summarise the release notes.',
|
||||
);
|
||||
|
||||
await tapSave(tester);
|
||||
|
||||
expect(gateway.calls, hasLength(2));
|
||||
expect(gateway.calls[0]['request_key'], key);
|
||||
expect(gateway.calls[1]['request_key'], key);
|
||||
expect(gateway.calls[1]['schedule'], {
|
||||
'id': 0,
|
||||
'name': 'Nightly build',
|
||||
'pipeline_id': 4,
|
||||
'version': 5,
|
||||
'enabled': true,
|
||||
'input': {
|
||||
'prompt': 'Summarise the release notes.',
|
||||
'topic': 'release notes',
|
||||
'nested': {'kept': true},
|
||||
},
|
||||
'workspace': '/srv/run-workspace',
|
||||
'rule': {'every': '24h'},
|
||||
'notify_mode': 'off',
|
||||
'write_paths': ['src/file.go', 'notes'],
|
||||
'allow_tools': true,
|
||||
'model': 'provider/model',
|
||||
'stage_models': {'research': 'provider/other'},
|
||||
'title': 'Nightly build',
|
||||
'output_format': 'json',
|
||||
});
|
||||
expect(find.byKey(scheduleEditorSubmitKey), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('the action is wired into run detail and hidden without a pin', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = SaveGateway();
|
||||
await pumpAction(
|
||||
tester,
|
||||
RunDetailActions(
|
||||
run: runFixture(),
|
||||
gateway: gateway,
|
||||
onRunChanged: (_) {},
|
||||
),
|
||||
);
|
||||
expect(find.byKey(scheduleRunActionKey), findsOneWidget);
|
||||
expect(find.text(scheduleRunActionLabel), findsOneWidget);
|
||||
|
||||
await pumpAction(
|
||||
tester,
|
||||
RunDetailActions(
|
||||
run: runFixture(version: 0),
|
||||
gateway: gateway,
|
||||
onRunChanged: (_) {},
|
||||
),
|
||||
);
|
||||
expect(find.byKey(scheduleRunActionKey), findsNothing);
|
||||
|
||||
await pumpAction(
|
||||
tester,
|
||||
RunDetailActions(
|
||||
run: runFixture(pipelineId: null),
|
||||
gateway: gateway,
|
||||
onRunChanged: (_) {},
|
||||
),
|
||||
);
|
||||
expect(find.byKey(scheduleRunActionKey), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('Cupertino uses the native action and fields', (tester) async {
|
||||
final gateway = SaveGateway();
|
||||
await pumpAction(
|
||||
tester,
|
||||
ScheduleRunAction(run: runFixture(), gateway: gateway),
|
||||
cupertino: true,
|
||||
);
|
||||
|
||||
final action = find.byKey(scheduleRunActionKey);
|
||||
expect(
|
||||
find.widgetWithText(CupertinoButton, scheduleRunActionLabel),
|
||||
findsOne,
|
||||
);
|
||||
await tester.tap(action);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.calls, isEmpty);
|
||||
expect(find.byKey(scheduleEditorSubmitKey), findsOneWidget);
|
||||
expect(
|
||||
tester
|
||||
.widget<CupertinoTextField>(find.byKey(scheduleEditorVersionKey))
|
||||
.controller
|
||||
?.text,
|
||||
'5',
|
||||
);
|
||||
expect(
|
||||
tester
|
||||
.widget<CupertinoTextField>(find.byKey(scheduleEditorWorkspaceKey))
|
||||
.controller
|
||||
?.text,
|
||||
'/srv/run-workspace',
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user