Gitea CI / Assemble and validate CI artifacts (push) Successful in 1m47s
Gitea CI / Check code and tests (push) Successful in 7m15s
Gitea CI / Build Android APK (push) Successful in 4m6s
Gitea CI / Build Windows x64 app (push) Successful in 3m34s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m29s
Gitea CI / Gitea CI passed (push) Successful in 1s
Gitea Release / Prepare draft Release (push) Failing after 8s
Gitea Release / Upload Android to draft Release (push) Skipped
Gitea Release / Upload Windows to draft Release (push) Skipped
Gitea Release / Verify and publish Release (push) Skipped
185 lines
6.2 KiB
Dart
185 lines
6.2 KiB
Dart
import 'package:cutdex/errors/app_failure.dart';
|
|
|
|
import 'dart:async';
|
|
|
|
import 'package:cutdex/features/assistant/agent_composer_controller.dart';
|
|
import 'package:cutdex/features/assistant/agent_composer_store.dart';
|
|
import 'package:cutdex/workspace/external_media_import.dart';
|
|
import 'package:cutdex/workspace/media_import.dart';
|
|
import 'package:cutdex_core/project.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
final _asset = AssetDocument(
|
|
id: 'asset',
|
|
name: 'Photo',
|
|
storage: AssetStorage.external,
|
|
location: 'file:///photo.png',
|
|
metadata: {'kind': 'image'},
|
|
);
|
|
|
|
void main() {
|
|
test(
|
|
'deleting a conversation discards its pending attachment destination',
|
|
() async {
|
|
final completed = Completer<ExternalMediaSelection?>();
|
|
final started = Completer<void>();
|
|
final store = AgentComposerStore(
|
|
createComposer: (_) => AgentComposerController(
|
|
canImport: () => true,
|
|
pickFiles: () async => [],
|
|
importMedia: (_) {
|
|
started.complete();
|
|
return completed.future;
|
|
},
|
|
),
|
|
);
|
|
addTearDown(store.dispose);
|
|
final old = store.composer('project', 'chat');
|
|
final pending = old.importAttachments([
|
|
const ExternalMediaFile(path: '/photo.png'),
|
|
]);
|
|
await started.future;
|
|
store.removeConversation('project', 'chat');
|
|
final replacement = store.composer('project', 'chat');
|
|
completed.complete(ExternalMediaSelection(selected: [_asset]));
|
|
await pending;
|
|
expect(old.attachments, isEmpty);
|
|
expect(replacement.attachments, isEmpty);
|
|
},
|
|
);
|
|
|
|
test('promoting a draft preserves controllers and pending imports until deletion', () async {
|
|
final completed = Completer<ExternalMediaSelection?>();
|
|
final started = Completer<void>();
|
|
final store = AgentComposerStore(
|
|
createComposer: (_) => AgentComposerController(
|
|
canImport: () => true,
|
|
pickFiles: () async => [],
|
|
importMedia: (_) {
|
|
started.complete();
|
|
return completed.future;
|
|
},
|
|
),
|
|
);
|
|
addTearDown(store.dispose);
|
|
final input = store.input('project', null)..text = 'Follow-up';
|
|
final composer = store.composer('project', 'draft');
|
|
final pending = composer.importAttachments([
|
|
const ExternalMediaFile(path: '/photo.png'),
|
|
]);
|
|
await started.future;
|
|
store.promoteDraft('project', 'draft', 'chat');
|
|
store.removeDraft('project', 'draft');
|
|
expect(store.input('project', 'chat'), same(input));
|
|
expect(store.composer('project', 'chat'), same(composer));
|
|
expect(store.input('project', null), isNot(same(input)));
|
|
expect(store.input('project', null).text, isEmpty);
|
|
completed.complete(ExternalMediaSelection(selected: [_asset]));
|
|
await pending;
|
|
expect(composer.attachments.single.id, _asset.id);
|
|
expect(input.text, 'Follow-up');
|
|
store.removeConversation('project', 'chat');
|
|
expect(store.input('project', 'chat'), isNot(same(input)));
|
|
expect(store.composer('project', 'chat'), isNot(same(composer)));
|
|
});
|
|
|
|
test('partial import failures survive until consumed, successful imports add no notice', () async {
|
|
var fail = true;
|
|
final composer = AgentComposerController(
|
|
canImport: () => true,
|
|
pickFiles: () async => [const ExternalMediaFile(path: '/photo.png')],
|
|
importMedia: (_) async => fail
|
|
? const ExternalMediaSelection(
|
|
selected: [],
|
|
result: MediaImportResult(
|
|
assets: [],
|
|
added: 0,
|
|
duplicates: 0,
|
|
failures: [
|
|
MediaImportFailure(
|
|
name: 'photo.png',
|
|
failure: AppFailure(
|
|
AppErrorCode.diagnostic,
|
|
diagnostic: 'unreadable',
|
|
),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
: ExternalMediaSelection(selected: [_asset]),
|
|
);
|
|
addTearDown(composer.dispose);
|
|
await composer.pickAttachments();
|
|
expect(composer.feedback.hasPending, isTrue);
|
|
expect(
|
|
composer.feedback.takePending().single!.result!.failures.single.name,
|
|
'photo.png',
|
|
);
|
|
expect(composer.feedback.hasPending, isFalse);
|
|
fail = false;
|
|
await composer.pickAttachments();
|
|
expect(composer.attachments.single.id, _asset.id);
|
|
expect(composer.feedback.hasPending, isFalse);
|
|
});
|
|
|
|
test(
|
|
'changing projects while file picking does not import into another project',
|
|
() async {
|
|
var active = true;
|
|
var imports = 0;
|
|
final files = Completer<List<ExternalMediaFile>>();
|
|
final composer = AgentComposerController(
|
|
canImport: () => active,
|
|
pickFiles: () => files.future,
|
|
importMedia: (_) async {
|
|
imports++;
|
|
return ExternalMediaSelection(selected: [_asset]);
|
|
},
|
|
);
|
|
addTearDown(composer.dispose);
|
|
final pending = composer.pickAttachments();
|
|
active = false;
|
|
files.complete([const ExternalMediaFile(path: '/photo.png')]);
|
|
await pending;
|
|
expect(imports, 0);
|
|
expect(composer.attachments, isEmpty);
|
|
expect(composer.busy, isFalse);
|
|
},
|
|
);
|
|
|
|
test(
|
|
'attachment commands serialize and recover after import failure',
|
|
() async {
|
|
final completed = Completer<ExternalMediaSelection?>();
|
|
var calls = 0;
|
|
final composer = AgentComposerController(
|
|
canImport: () => true,
|
|
pickFiles: () async => [],
|
|
importMedia: (_) {
|
|
calls++;
|
|
return completed.future;
|
|
},
|
|
);
|
|
addTearDown(composer.dispose);
|
|
final first = composer.importAttachments([
|
|
const ExternalMediaFile(path: '/photo.png'),
|
|
]);
|
|
await Future<void>.delayed(Duration.zero);
|
|
expect(composer.busy, isTrue);
|
|
expect(
|
|
await composer.importAttachments([
|
|
const ExternalMediaFile(path: '/second.png'),
|
|
]),
|
|
isNull,
|
|
);
|
|
completed.completeError(StateError('import failed'));
|
|
await expectLater(first, throwsStateError);
|
|
expect(calls, 1);
|
|
expect(composer.busy, isFalse);
|
|
expect(composer.feedback.hasPending, isTrue);
|
|
expect(composer.feedback.takePending(), [null]);
|
|
expect(composer.feedback.hasPending, isFalse);
|
|
},
|
|
);
|
|
}
|