WIP: message delivery status and refresh safety; fix reconcile listener recursion
The transcript listener read the lazily built _controller while _attach was still building it (load() notifies synchronously), so it built another controller, recursively, until the test process ran out of memory.
This commit is contained in:
@@ -90,41 +90,47 @@ void main() {
|
||||
expect(controller.sending, isFalse);
|
||||
});
|
||||
|
||||
test('a refused unchanged intent retries with the same identity', () async {
|
||||
var fail = true;
|
||||
gateway.prompt = (_, _) async {
|
||||
if (fail) throw StateError('response lost');
|
||||
return const {};
|
||||
};
|
||||
await controller.setDraft(' keep me ');
|
||||
test(
|
||||
'a refused intent is kept as Not sent and Retry reuses its identity',
|
||||
() async {
|
||||
var fail = true;
|
||||
gateway.prompt = (_, _) async {
|
||||
if (fail) throw StateError('response lost');
|
||||
return const {};
|
||||
};
|
||||
await controller.setDraft(' keep me ');
|
||||
|
||||
await controller.send();
|
||||
expect(controller.error, contains('response lost'));
|
||||
expect(controller.draft, ' keep me ');
|
||||
expect(await drafts.read('s'), ' keep me ');
|
||||
expect(rejected.single, contains('response lost'));
|
||||
await controller.send();
|
||||
expect(controller.error, contains('response lost'));
|
||||
// The composer is free for the next message; the refused one is kept.
|
||||
expect(controller.draft, '');
|
||||
expect(rejected.single, contains('response lost'));
|
||||
expect(controller.deliveries.unsent.single.operationId, 'op/1');
|
||||
expect(drafts.unsentEntries['s'], hasLength(1));
|
||||
|
||||
fail = false;
|
||||
await controller.send();
|
||||
expect(gateway.promptBodies.map((body) => body['operation_id']), [
|
||||
'op/1',
|
||||
'op/1',
|
||||
]);
|
||||
expect(gateway.promptBodies.map((body) => body['native_message_id']), [
|
||||
'msg_op1',
|
||||
'msg_op1',
|
||||
]);
|
||||
expect(controller.draft, '');
|
||||
expect(controller.error, isNull);
|
||||
fail = false;
|
||||
expect(await controller.retry('op/1'), isTrue);
|
||||
expect(gateway.promptBodies.map((body) => body['operation_id']), [
|
||||
'op/1',
|
||||
'op/1',
|
||||
]);
|
||||
expect(gateway.promptBodies.map((body) => body['native_message_id']), [
|
||||
'msg_op1',
|
||||
'msg_op1',
|
||||
]);
|
||||
expect(controller.error, isNull);
|
||||
expect(controller.deliveries.unsent, isEmpty);
|
||||
expect(drafts.unsentEntries, isEmpty);
|
||||
|
||||
fail = true;
|
||||
await controller.setDraft('other');
|
||||
await controller.send();
|
||||
expect(gateway.promptBodies.last['operation_id'], 'op/2');
|
||||
expect(gateway.promptBodies.last['native_message_id'], 'msg_op2');
|
||||
});
|
||||
fail = true;
|
||||
await controller.setDraft('other');
|
||||
await controller.send();
|
||||
expect(gateway.promptBodies.last['operation_id'], 'op/2');
|
||||
expect(gateway.promptBodies.last['native_message_id'], 'msg_op2');
|
||||
},
|
||||
);
|
||||
|
||||
test('a refusal keeps newer typing instead of restoring the draft', () async {
|
||||
test('a refusal keeps newer typing and the refused message apart', () async {
|
||||
final reply = Completer<Map<String, dynamic>>();
|
||||
gateway.prompt = (_, _) => reply.future;
|
||||
await controller.setDraft('original');
|
||||
@@ -140,8 +146,13 @@ void main() {
|
||||
expect(await drafts.read('s'), 'newer');
|
||||
expect(controller.error, contains('refused'));
|
||||
expect(rejected.single, contains('refused'));
|
||||
// The optimistic turn still carries the intent that was refused.
|
||||
expect(optimistic.single.text, 'original');
|
||||
expect(controller.deliveries.unsent.single.text, 'original');
|
||||
|
||||
// Edit puts the refused text after the newer typing and forgets it.
|
||||
await controller.edit('op/1');
|
||||
expect(controller.draft, 'newer\noriginal');
|
||||
expect(controller.deliveries.unsent, isEmpty);
|
||||
expect(drafts.unsentEntries, isEmpty);
|
||||
});
|
||||
|
||||
test(
|
||||
|
||||
Reference in New Issue
Block a user