Add the Flutter video editing application with project management, media import, timeline editing, preview, AI assistance, diagnostics and settings. Include shared UI and native host packages, platform runners, application tests and release tooling. Provide usage and contribution guides, the MIT license and third-party notices. Exclude local credentials, build outputs and validation data.
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_sdk/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);
|
|
},
|
|
);
|
|
}
|