b9639650e5
Port the web client's list/save/delete schedule request shapes and reply checks, with a typed record that preserves the whole server payload including unknown fields. Revision stays the CAS token; server refusals propagate unchanged.
84 lines
2.3 KiB
Dart
84 lines
2.3 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:pipelines_app/core/api_gateway.dart';
|
|
|
|
class RecordedCall {
|
|
const RecordedCall(this.type, this.fields);
|
|
final String type;
|
|
final JsonMap fields;
|
|
}
|
|
|
|
/// Records the exact request built by the repository and replays queued
|
|
/// replies. Both are deep-copied, so a test can prove the repository neither
|
|
/// mutated its input nor depended on alias mutation of a reply.
|
|
class RecordingGateway implements ApiGateway {
|
|
final calls = <RecordedCall>[];
|
|
final replies = <JsonMap>[];
|
|
Object? failure;
|
|
|
|
@override
|
|
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
|
calls.add(RecordedCall(type, deepCopy(fields)));
|
|
if (failure case final error?) throw error;
|
|
if (replies.isEmpty) throw StateError('No recorded reply for $type');
|
|
return deepCopy(replies.removeAt(0));
|
|
}
|
|
|
|
@override
|
|
Stream<JsonMap> get frames => const Stream.empty();
|
|
}
|
|
|
|
JsonMap deepCopy(JsonMap value) => jsonDecode(jsonEncode(value)) as JsonMap;
|
|
|
|
/// A complete server record including fields this client does not interpret
|
|
/// yet, an unknown nested rule field and unknown input.
|
|
JsonMap savedRecord() => {
|
|
'id': 8,
|
|
'revision': 3,
|
|
'name': 'Research batteries',
|
|
'pipeline_id': 4,
|
|
'version': 2,
|
|
'enabled': true,
|
|
'input': {
|
|
'prompt': 'Research batteries',
|
|
'custom': {'nested': 'kept'},
|
|
},
|
|
'workspace': '/srv/research',
|
|
'write_paths': ['reports/research.md'],
|
|
'allow_tools': true,
|
|
'model': 'openai/gpt-5',
|
|
'stage_models': {'one': 'openai/gpt-5'},
|
|
'notify_mode': 'off',
|
|
'title': 'Battery research',
|
|
'output_format': 'markdown',
|
|
'rule': {
|
|
'every': '24h',
|
|
'days': ['mon', 'wed'],
|
|
'timezone': 'Europe/London',
|
|
'future_rule_field': 'kept',
|
|
},
|
|
'next_due': '2026-10-22T09:00:00Z',
|
|
'created_at': '2026-10-20T09:00:00Z',
|
|
'updated_at': '2026-10-21T09:00:00Z',
|
|
'future_server_field': {
|
|
'nested': [
|
|
1,
|
|
2,
|
|
{'deep': true},
|
|
],
|
|
},
|
|
};
|
|
|
|
/// The create form of the record: id 0 is the server's create sentinel and no
|
|
/// revision has been issued yet.
|
|
JsonMap createRecord() => {
|
|
'id': 0,
|
|
'name': 'Research batteries',
|
|
'pipeline_id': 4,
|
|
'version': 2,
|
|
'enabled': true,
|
|
'input': {'prompt': 'Research batteries'},
|
|
'workspace': '/srv/research',
|
|
'rule': {'every': '24h', 'timezone': 'Europe/London'},
|
|
};
|