Gitea CI / Check code and tests (pull_request) Successful in 6m16s
Gitea CI / Audit and package Windows x64 (pull_request) Successful in 1m31s
Gitea CI / Gitea CI passed (pull_request) Successful in 3s
Gitea CI / Build Android APK (pull_request) Successful in 5m13s
Gitea CI / Build Windows x64 app (pull_request) Successful in 19m20s
Gitea CI / Assemble and validate CI artifacts (pull_request) Successful in 1m1s
Launch the standard-library MCP bridge directly with the Flutter SDK native Dart executable, without shell or pub startup. Verify it works without Dart on PATH and include stderr when its existing response deadline expires. Share native Dart selection with generated-code checks and wait for subtitle workflow completion notifications instead of a fixed 10 ms delay.
1968 lines
62 KiB
Dart
1968 lines
62 KiB
Dart
import 'support/creation_names.dart';
|
|
import 'support/dart_executable.dart';
|
|
|
|
import 'package:cutdex/app/editor_theme.dart';
|
|
import 'package:cutdex/l10n/app_localizations.dart';
|
|
import 'package:cutdex/workspace/project_assets_changed.dart';
|
|
import 'package:cutdex/features/properties/animation_labels.dart';
|
|
import 'package:cutdex/integrations/editor_command_host.dart';
|
|
import 'package:cutdex_sdk/editor.dart';
|
|
import 'package:cutdex_sdk/timeline/engine.dart';
|
|
import 'package:cutdex/workspace/media_import.dart';
|
|
|
|
import 'dart:convert';
|
|
import 'dart:async';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'dart:io';
|
|
|
|
import 'package:cutdex/integrations/editor_tools.dart';
|
|
import 'package:cutdex/integrations/mcp/local_mcp_bridge.dart';
|
|
import 'package:cutdex/integrations/mcp/mcp_settings.dart';
|
|
import 'package:cutdex/persistence/app_settings_repositories.dart';
|
|
|
|
import 'support/memory_app_settings.dart';
|
|
import 'support/project_write_lock.dart';
|
|
|
|
import 'package:cutdex/workspace/persistence/project_workspace.dart';
|
|
import 'package:cutdex/workspace/timeline_session.dart';
|
|
import 'package:cutdex/workspace/timeline_provider.dart';
|
|
import 'package:cutdex/features/properties/picture_properties.dart';
|
|
import 'package:cutdex/features/preview/preview_panel.dart';
|
|
import 'package:cutdex_agent/cutdex_agent.dart';
|
|
import 'package:cutdex_sdk/project.dart';
|
|
import 'package:cutdex_sdk/timeline/model.dart';
|
|
import 'package:cutdex_sdk/tools.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
TimelineDto _sequence(String id) => TimelineDto(
|
|
id: SequenceId(id),
|
|
format: TimelineFormat.fps30,
|
|
primaryStorylineId: StorylineId('primary'),
|
|
storylines: [
|
|
StorylineDto(
|
|
id: StorylineId('primary'),
|
|
elementIds: [ElementId('a'), ElementId('b')],
|
|
),
|
|
],
|
|
elements: [
|
|
for (final name in ['a', 'b'])
|
|
ElementDto(
|
|
id: ElementId(name),
|
|
name: name,
|
|
structure: ElementStructure.content,
|
|
duration: RationalTime.seconds(10),
|
|
sourceRange: TimeRange(
|
|
start: RationalTime.zero,
|
|
duration: RationalTime.seconds(10),
|
|
),
|
|
mediaRange: TimeRange(
|
|
start: RationalTime.zero,
|
|
duration: RationalTime.seconds(20),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
|
|
Map<String, Object?> _request(String name, Map<String, Object?> arguments) => {
|
|
'jsonrpc': '2.0',
|
|
'id': 1,
|
|
'method': 'tools/call',
|
|
'params': {
|
|
'_meta': {
|
|
'io.modelcontextprotocol/protocolVersion': '2026-07-28',
|
|
'io.modelcontextprotocol/clientCapabilities': <String, Object?>{},
|
|
},
|
|
'name': name,
|
|
'arguments': arguments,
|
|
},
|
|
};
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
late Directory root;
|
|
late ProjectWorkspace workspace;
|
|
late EditorTimelineSession session;
|
|
late EditorToolAccess access;
|
|
final sequence = SequenceId('one');
|
|
late String projectId;
|
|
|
|
setUp(() async {
|
|
root = await Directory.systemTemp.createTemp('cutdex-commands-');
|
|
workspace = ProjectWorkspace(creationNames: testCreationNames);
|
|
await workspace.open('${root.path}/Project.cutdex', name: 'Test');
|
|
projectId = workspace.project!.info.id;
|
|
await workspace.project!.saveTimeline(
|
|
TimelineDocument(
|
|
id: 'project',
|
|
name: 'Commands',
|
|
sequences: [_sequence('one'), _sequence('two')],
|
|
defaultSequenceId: sequence,
|
|
),
|
|
);
|
|
session = await workspace.openTimelineSession(
|
|
projectId,
|
|
await workspace.loadTimeline(projectId, 'project'),
|
|
);
|
|
access = EditorToolAccess(session);
|
|
});
|
|
tearDown(() async {
|
|
await workspace.close();
|
|
await root.delete(recursive: true);
|
|
});
|
|
|
|
test(
|
|
'reopening the same session receives usable tools after access disposal',
|
|
() async {
|
|
await access.dispose();
|
|
access = EditorToolAccess(session);
|
|
final tools = access.workspaces.values.first;
|
|
final result = await tools.invoke(
|
|
name: 'timeline.query',
|
|
arguments: const {},
|
|
context: const CommandContext(operationId: 'reopened-query'),
|
|
);
|
|
expect(result.isError, isFalse);
|
|
},
|
|
);
|
|
|
|
ClipTransform transform([String clip = 'a']) {
|
|
final query = session.view(sequence).version.kernelVersion.query();
|
|
return ClipTransform.fromRecord(
|
|
query.element(query.elementById(ElementId(clip))!),
|
|
);
|
|
}
|
|
|
|
Map<String, Object?> position(double x, {String? version}) => {
|
|
'clipId': 'a',
|
|
'at': {'numerator': '0', 'denominator': 1},
|
|
'x': x,
|
|
'y': 54,
|
|
'expectedVersion': ?version,
|
|
};
|
|
Future<CommandResult> invoke(
|
|
String name,
|
|
String operation,
|
|
Map<String, Object?> args,
|
|
) => editorToolsFor(session, sequence).invoke(
|
|
name: name,
|
|
arguments: args,
|
|
context: CommandContext(operationId: operation),
|
|
);
|
|
|
|
test(
|
|
'default SDK tool host exposes verification without Agent adapters',
|
|
() async {
|
|
final dispatcher = EditorToolDispatcher(
|
|
host: EditorSessionCommandHost(session, sequence),
|
|
);
|
|
addTearDown(dispatcher.dispose);
|
|
Future<CommandResult> verify(String name) => dispatcher.invoke(
|
|
name: 'editor.verify',
|
|
arguments: {
|
|
'expectations': [
|
|
{
|
|
'kind': 'clip',
|
|
'workspaceId': 'one',
|
|
'expected': {'clipId': 'a', 'name': name},
|
|
},
|
|
],
|
|
},
|
|
context: const CommandContext(operationId: 'verification'),
|
|
);
|
|
final good = await verify('a');
|
|
expect(good.status, CommandStatus.succeeded);
|
|
expect(good.data['verified'], isTrue);
|
|
expect((await verify('wrong')).data['verified'], isFalse);
|
|
final invalid = await dispatcher.invoke(
|
|
name: 'editor.verify',
|
|
arguments: {
|
|
'expectations': [
|
|
{'kind': 'clip', 'workspaceId': 'one'},
|
|
],
|
|
},
|
|
context: const CommandContext(operationId: 'invalid-verification'),
|
|
);
|
|
expect(invalid.code, 'invalidArguments');
|
|
expect(session.dirty, isFalse);
|
|
},
|
|
);
|
|
|
|
test(
|
|
'split receipt survives restart and deduplicates repeated invocation',
|
|
() async {
|
|
final dispatcher = editorToolsFor(session, sequence);
|
|
final args = <String, Object?>{
|
|
'clipId': 'a',
|
|
'at': {'numerator': '5', 'denominator': 1},
|
|
'expectedVersion': session.version,
|
|
};
|
|
final result = await dispatcher.invoke(
|
|
name: 'timeline.split',
|
|
arguments: args,
|
|
context: const CommandContext(operationId: 'durable-split'),
|
|
);
|
|
expect(result.isError, isFalse);
|
|
final before = await workspace.project!.loadTimeline('project');
|
|
expect(before.sequences.first.elements, hasLength(3));
|
|
await access.dispose();
|
|
await workspace.close();
|
|
workspace = ProjectWorkspace(creationNames: testCreationNames);
|
|
await workspace.open('${root.path}/Project.cutdex');
|
|
session = await workspace.openTimelineSession(
|
|
projectId,
|
|
await workspace.loadTimeline(projectId, 'project'),
|
|
);
|
|
access = EditorToolAccess(session);
|
|
final fresh = editorToolsFor(session, sequence);
|
|
final recovered = await fresh.recoverInvocation(
|
|
operationId: 'durable-split',
|
|
name: 'timeline.split',
|
|
arguments: args,
|
|
);
|
|
expect(recovered.state, OperationState.completed);
|
|
expect(recovered.result!.toJson(), result.toJson());
|
|
for (var i = 0; i < 2; i++) {
|
|
final duplicate = await fresh.invoke(
|
|
name: 'timeline.split',
|
|
arguments: args,
|
|
context: const CommandContext(operationId: 'durable-split'),
|
|
);
|
|
expect(duplicate.toJson(), result.toJson());
|
|
}
|
|
final after = await workspace.project!.loadTimeline('project');
|
|
expect(after.revision, before.revision);
|
|
expect(
|
|
after.sequences.first.elements.map((e) => e.id),
|
|
before.sequences.first.elements.map((e) => e.id),
|
|
);
|
|
final conflict = await fresh.invoke(
|
|
name: 'timeline.split',
|
|
arguments: {...args, 'clipId': 'b'},
|
|
context: const CommandContext(operationId: 'durable-split'),
|
|
);
|
|
expect(conflict.code, 'operationIdConflict');
|
|
},
|
|
);
|
|
|
|
test('edit undo and redo receipts acknowledge persisted state', () async {
|
|
Future<void> expectSaved(double expectedX) async {
|
|
expect(session.dirty, isFalse);
|
|
final stored = await workspace.project!.loadTimeline('project');
|
|
final clip = stored.sequences.first.elements.first;
|
|
final curves = clip.parameters.where(
|
|
(curve) => curve.definition.id == 'canvas.position.x',
|
|
);
|
|
final x = curves.isEmpty ? 0.0 : curves.first.definition.defaultValue;
|
|
expect(x, closeTo(expectedX, 1e-9));
|
|
}
|
|
|
|
final edit = await invoke(
|
|
'clip.setTransform',
|
|
'durable-edit',
|
|
position(192),
|
|
);
|
|
expect(edit.edit, EditOutcome.committed);
|
|
expect(edit.data['saveState'], 'saved');
|
|
await expectSaved(192 / session.canvas.width);
|
|
final undo = await invoke('timeline.undo', 'durable-undo', {});
|
|
expect(undo.edit, EditOutcome.committed);
|
|
await expectSaved(0);
|
|
final redo = await invoke('timeline.redo', 'durable-redo', {});
|
|
expect(redo.edit, EditOutcome.committed);
|
|
await expectSaved(192 / session.canvas.width);
|
|
});
|
|
|
|
test('selection tools share UI selection, validate atomically and keep history unchanged', () async {
|
|
final view = session.view(sequence);
|
|
final version = session.version;
|
|
final dirty = session.dirty;
|
|
final undo = session.canUndo(sequence);
|
|
var notifications = 0;
|
|
view.addListener(() => notifications++);
|
|
final result = await invoke('selection.set', 'select', {
|
|
'clipIds': ['a', 'b'],
|
|
});
|
|
expect(result.status, CommandStatus.succeeded);
|
|
expect(result.edit, EditOutcome.notApplicable);
|
|
expect(view.selectedIdentities, hasLength(2));
|
|
expect(notifications, 1);
|
|
expect((await invoke('selection.query', 'query', {})).data['clipIds'], [
|
|
'a',
|
|
'b',
|
|
]);
|
|
expect(
|
|
(await invoke('selection.set', 'missing', {
|
|
'clipIds': ['a', 'missing'],
|
|
})).status,
|
|
CommandStatus.rejected,
|
|
);
|
|
expect(view.selectedIdentities, hasLength(2));
|
|
expect(
|
|
(await invoke('selection.set', 'duplicate', {
|
|
'clipIds': ['a', 'a'],
|
|
})).status,
|
|
CommandStatus.rejected,
|
|
);
|
|
await invoke('selection.set', 'clear', {'clipIds': []});
|
|
expect(view.selectedIdentities, isEmpty);
|
|
// Replaying a recorded selection must not override a newer UI selection.
|
|
await invoke('selection.set', 'select', {
|
|
'clipIds': ['a', 'b'],
|
|
});
|
|
expect(view.selectedIdentities, isEmpty);
|
|
view.setSelection([
|
|
view.version.kernelVersion.query().elementById(ElementId('b'))!,
|
|
]);
|
|
expect((await invoke('selection.query', 'query', {})).data['clipIds'], [
|
|
'b',
|
|
]);
|
|
expect(session.version, version);
|
|
expect(session.dirty, dirty);
|
|
expect(session.canUndo(sequence), undo);
|
|
});
|
|
|
|
test('export tool reaches an isolated native session, journals receipt and closes it', () async {
|
|
const native = MethodChannel('cutdex_runtime');
|
|
const events = MethodChannel('cutdex_runtime/sessions/export-test');
|
|
final messenger =
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
|
|
final calls = <String>[];
|
|
messenger.setMockMethodCallHandler(events, (call) async {
|
|
if (call.method == 'listen') {
|
|
scheduleMicrotask(
|
|
() => messenger.handlePlatformMessage(
|
|
events.name,
|
|
const StandardMethodCodec().encodeSuccessEnvelope({
|
|
'type': 'attached',
|
|
}),
|
|
(_) {},
|
|
),
|
|
);
|
|
}
|
|
return null;
|
|
});
|
|
messenger.setMockMethodCallHandler(native, (call) async {
|
|
calls.add(call.method);
|
|
final args = call.arguments as Map;
|
|
switch (call.method) {
|
|
case 'capabilities':
|
|
return {'contractVersion': 1, 'features': <String, String>{}};
|
|
case 'createSession':
|
|
return {'sessionId': 'export-test'};
|
|
case 'export':
|
|
expect(args['sessionId'], 'export-test');
|
|
expect((args['plan'] as Map)['visualLayers'], isNotEmpty);
|
|
final uri = Uri.parse(args['destination'] as String);
|
|
await File.fromUri(uri).writeAsBytes([1, 2, 3]);
|
|
return uri.toString();
|
|
case 'close':
|
|
return null;
|
|
default:
|
|
throw StateError('Unexpected native call: ${call.method}');
|
|
}
|
|
});
|
|
addTearDown(() {
|
|
messenger.setMockMethodCallHandler(native, null);
|
|
messenger.setMockMethodCallHandler(events, null);
|
|
});
|
|
await invoke('timeline.deleteMany', 'clear-fixture', {
|
|
'clipIds': ['a', 'b'],
|
|
});
|
|
final image = Uri.file('${root.path}/image.png');
|
|
await workspace.project!.saveAsset(
|
|
AssetDocument(
|
|
id: 'export-image',
|
|
name: 'Image',
|
|
storage: AssetStorage.external,
|
|
location: image.toString(),
|
|
),
|
|
);
|
|
session.insertAsset(
|
|
sequenceId: sequence,
|
|
assetId: 'export-image',
|
|
assetName: 'Image',
|
|
uri: image,
|
|
duration: RationalTime.seconds(1),
|
|
position: 0,
|
|
kind: 'image',
|
|
hasAudio: false,
|
|
);
|
|
final before = session.version;
|
|
final destination = '${root.path}/result.mp4';
|
|
final result = await invoke('project.export', 'encode', {
|
|
'destination': destination,
|
|
});
|
|
expect(result.status, CommandStatus.succeeded);
|
|
expect(result.edit, EditOutcome.notApplicable);
|
|
expect(result.data['exportedVersion'], before);
|
|
expect(await File(destination).exists(), true);
|
|
expect(calls, ['capabilities', 'createSession', 'export', 'close']);
|
|
expect(session.version, before);
|
|
await invoke('project.export', 'encode', {'destination': destination});
|
|
expect(calls.where((value) => value == 'export'), hasLength(1));
|
|
final collision = await invoke('project.export', 'other', {
|
|
'destination': destination,
|
|
});
|
|
expect(collision.code, 'destinationExists');
|
|
expect(collision.edit, EditOutcome.notApplicable);
|
|
expect(await File(destination).readAsBytes(), [1, 2, 3]);
|
|
expect(calls.where((value) => value == 'createSession'), hasLength(1));
|
|
});
|
|
|
|
test('grouped keys validate atomically, undo together and preserve other channels', () async {
|
|
final before = session.version;
|
|
final at = {'numerator': '1', 'denominator': 1};
|
|
Map<String, Object?> key(String id, double value) => {
|
|
'parameterId': id,
|
|
'action': 'set',
|
|
'at': at,
|
|
'value': value,
|
|
};
|
|
for (final edits in [
|
|
[key('canvas.position.x', .2), key('missing', .4)],
|
|
<Map<String, Object?>>[],
|
|
]) {
|
|
final result = await invoke('keyframe.editMany', 'bad-group-$edits', {
|
|
'clipId': 'a',
|
|
'edits': edits,
|
|
});
|
|
expect(result.status, CommandStatus.rejected);
|
|
expect(session.version, before);
|
|
}
|
|
final args = {
|
|
'clipId': 'a',
|
|
'edits': [key('canvas.position.x', .2), key('canvas.position.y', .4)],
|
|
};
|
|
final result = await invoke('keyframe.editMany', 'group', args);
|
|
expect(result.edit, EditOutcome.committed, reason: '${result.toJson()}');
|
|
final dto = session.persistence.timeline(sequence).exportDto();
|
|
final curves = dto.elements.first.parameters;
|
|
expect(
|
|
curves
|
|
.firstWhere((c) => c.definition.id == 'canvas.position.x')
|
|
.keyframes
|
|
.single
|
|
.value,
|
|
.2,
|
|
);
|
|
expect(
|
|
curves
|
|
.firstWhere((c) => c.definition.id == 'canvas.position.y')
|
|
.keyframes
|
|
.single
|
|
.value,
|
|
.4,
|
|
);
|
|
await invoke('keyframe.editMany', 'group', args);
|
|
expect(session.version, result.version);
|
|
session.view(sequence).undo();
|
|
expect(
|
|
session.persistence
|
|
.timeline(sequence)
|
|
.exportDto()
|
|
.elements
|
|
.first
|
|
.parameters,
|
|
isEmpty,
|
|
);
|
|
expect(
|
|
(await invoke('keyframe.editMany', 'stale-group', {
|
|
...args,
|
|
'expectedVersion': result.version,
|
|
})).code,
|
|
'staleVersion',
|
|
);
|
|
});
|
|
|
|
test('MCP grouped editing and Agent saving use the shared session', () async {
|
|
final connection = access.server.connect();
|
|
addTearDown(connection.close);
|
|
final response = await connection.handleJson(
|
|
jsonEncode(
|
|
_request('keyframe.editMany', {
|
|
'workspaceId': access.workspaces.keys.first,
|
|
'operationId': 'wire-group',
|
|
'clipId': 'a',
|
|
'edits': [
|
|
for (final parameter in ['canvas.position.x', 'canvas.position.y'])
|
|
{
|
|
'parameterId': parameter,
|
|
'action': 'set',
|
|
'at': {'numerator': '1', 'denominator': 1},
|
|
},
|
|
],
|
|
}),
|
|
),
|
|
);
|
|
expect((response!['result'] as Map)['isError'], false, reason: '$response');
|
|
final tool = access.agentTools.singleWhere(
|
|
(tool) => tool.name == 'project_save',
|
|
);
|
|
final saved = await tool.execute(
|
|
ToolCall(
|
|
id: 'save',
|
|
name: tool.name,
|
|
arguments: {'workspaceId': access.workspaces.keys.first},
|
|
),
|
|
ToolContext(
|
|
sessionId: 's',
|
|
runId: 'r',
|
|
operationId: 'agent-save',
|
|
cancellation: CancellationToken(),
|
|
onProgress: (_) {},
|
|
),
|
|
);
|
|
expect(saved.isError, false);
|
|
expect(session.dirty, false);
|
|
session.view(sequence).undo();
|
|
expect(
|
|
session.persistence
|
|
.timeline(sequence)
|
|
.exportDto()
|
|
.elements
|
|
.first
|
|
.parameters,
|
|
isEmpty,
|
|
);
|
|
expect(access.agentTools.map((tool) => tool.name), contains('clip_align'));
|
|
});
|
|
|
|
test(
|
|
'save tool retries blocked persistence without changing edit history',
|
|
() async {
|
|
final release = blockProjectWrites(workspace.project!.directory.path);
|
|
addTearDown(release);
|
|
session.commands.setTransform(
|
|
sequence: sequence,
|
|
clip: ElementId('a'),
|
|
tick: 0,
|
|
change: (value) => value.copyWith(x: 100 / session.canvas.width),
|
|
);
|
|
final version = session.version;
|
|
final failed = await invoke('project.save', 'failed-save', {});
|
|
expect(failed.status, CommandStatus.unknown);
|
|
expect(failed.edit, EditOutcome.notApplicable);
|
|
expect(session.dirty, true);
|
|
expect(
|
|
(await invoke('timeline.query', 'failed-state', {})).data['saveState'],
|
|
'failed',
|
|
);
|
|
release();
|
|
final replay = await invoke('project.save', 'failed-save', {});
|
|
expect(replay.status, CommandStatus.unknown);
|
|
final saved = await invoke('project.save', 'retry-save', {});
|
|
expect(saved.status, CommandStatus.succeeded);
|
|
expect(saved.edit, EditOutcome.notApplicable);
|
|
expect(saved.data['saveState'], 'saved');
|
|
expect(session.saveError, isNull);
|
|
expect(session.version, version);
|
|
final stored = await workspace.project!.loadTimeline('project');
|
|
expect(stored.sequences.first.elements.first.parameters, isNotEmpty);
|
|
session.view(sequence).undo();
|
|
expect(transform().x, 0);
|
|
expect(
|
|
(await invoke('project.save', 'stale-save', {
|
|
'expectedVersion': version,
|
|
})).code,
|
|
'staleVersion',
|
|
);
|
|
},
|
|
);
|
|
|
|
test(
|
|
'batch deletion validates all targets and creates one undo entry',
|
|
() async {
|
|
final before = session.commands.version;
|
|
for (final ids in [
|
|
['a', 'missing'],
|
|
['a', 'a'],
|
|
<String>[],
|
|
]) {
|
|
final result = await invoke('timeline.deleteMany', 'invalid-$ids', {
|
|
'clipIds': ids,
|
|
});
|
|
expect(result.status, CommandStatus.rejected);
|
|
expect(session.commands.version, before);
|
|
}
|
|
final result = await invoke('timeline.deleteMany', 'batch-delete', {
|
|
'clipIds': ['a', 'b'],
|
|
});
|
|
expect(result.edit, EditOutcome.committed, reason: '${result.toJson()}');
|
|
expect(
|
|
session.persistence.timeline(sequence).exportDto().elements,
|
|
isEmpty,
|
|
);
|
|
final replay = await invoke('timeline.deleteMany', 'batch-delete', {
|
|
'clipIds': ['a', 'b'],
|
|
});
|
|
expect(replay.version, result.version);
|
|
await invoke('timeline.undo', 'undo-batch', {});
|
|
expect(
|
|
session.persistence
|
|
.timeline(sequence)
|
|
.exportDto()
|
|
.elements
|
|
.map((e) => e.id.value),
|
|
['a', 'b'],
|
|
);
|
|
},
|
|
);
|
|
|
|
test(
|
|
'batch split rejects partial success and commits one split history',
|
|
() async {
|
|
final before = session.commands.version;
|
|
final invalid = await invoke('timeline.splitMany', 'bad-split', {
|
|
'clipIds': ['a', 'b'],
|
|
'at': {'numerator': '5', 'denominator': 1},
|
|
});
|
|
expect(invalid.status, CommandStatus.rejected);
|
|
expect(session.commands.version, before);
|
|
final result = await invoke('timeline.splitMany', 'split-batch', {
|
|
'clipIds': ['a'],
|
|
'at': {'numerator': '5', 'denominator': 1},
|
|
});
|
|
expect(result.edit, EditOutcome.committed, reason: '${result.toJson()}');
|
|
expect(
|
|
session.persistence.timeline(sequence).exportDto().elements,
|
|
hasLength(3),
|
|
);
|
|
await invoke('timeline.undo', 'undo-split-batch', {});
|
|
expect(
|
|
session.persistence
|
|
.timeline(sequence)
|
|
.exportDto()
|
|
.elements
|
|
.map((e) => e.id.value),
|
|
['a', 'b'],
|
|
);
|
|
},
|
|
);
|
|
|
|
test(
|
|
'MCP splits overlapping clips atomically and Agent sees the same tools',
|
|
() async {
|
|
final placed = await invoke('timeline.place', 'batch-setup', {
|
|
'clipId': 'b',
|
|
'at': {'numerator': '1', 'denominator': 1},
|
|
'side': 'above',
|
|
});
|
|
expect(placed.edit, EditOutcome.committed);
|
|
final connection = access.server.connect();
|
|
addTearDown(connection.close);
|
|
final response = await connection.handleJson(
|
|
jsonEncode(
|
|
_request('timeline.splitMany', {
|
|
'workspaceId': access.workspaces.keys.first,
|
|
'operationId': 'mcp-batch',
|
|
'clipIds': ['a', 'b'],
|
|
'at': {'numerator': '5', 'denominator': 1},
|
|
}),
|
|
),
|
|
);
|
|
expect(
|
|
(response!['result'] as Map)['isError'],
|
|
false,
|
|
reason: '$response',
|
|
);
|
|
expect(
|
|
session.persistence.timeline(sequence).exportDto().elements,
|
|
hasLength(4),
|
|
);
|
|
final undo = access.agentTools.singleWhere(
|
|
(tool) => tool.name == 'timeline_undo',
|
|
);
|
|
final result = await undo.execute(
|
|
ToolCall(
|
|
id: 'batch-undo',
|
|
name: undo.name,
|
|
arguments: {'workspaceId': access.workspaces.keys.first},
|
|
),
|
|
ToolContext(
|
|
sessionId: 's',
|
|
runId: 'r',
|
|
operationId: 'agent-batch-undo',
|
|
cancellation: CancellationToken(),
|
|
onProgress: (_) {},
|
|
),
|
|
);
|
|
expect(result.isError, false);
|
|
expect(
|
|
session.persistence.timeline(sequence).exportDto().elements,
|
|
hasLength(2),
|
|
);
|
|
expect(
|
|
access.agentTools.map((t) => t.name),
|
|
containsAll([
|
|
'media_rename',
|
|
'media_remove',
|
|
'timeline_deleteMany',
|
|
'timeline_splitMany',
|
|
'preview_query',
|
|
'preview_play',
|
|
'preview_pause',
|
|
'preview_seek',
|
|
'preview_retry',
|
|
]),
|
|
);
|
|
},
|
|
);
|
|
|
|
test(
|
|
'catalog tools publish changes without removing files or timeline bindings',
|
|
() async {
|
|
final file = File('${root.path}/still.png');
|
|
await file.writeAsBytes([0]);
|
|
await invoke('media.import', 'catalog-import', {'path': file.path});
|
|
final media =
|
|
(await invoke('media.query', 'catalog-query', {})).data['media']
|
|
as List;
|
|
final id = (media.single as Map)['mediaId'];
|
|
final inserted = await invoke('timeline.insert', 'catalog-insert', {
|
|
'mediaId': id,
|
|
'clipId': 'catalog-clip',
|
|
'index': 1,
|
|
'sourceStart': {'numerator': '0', 'denominator': 1},
|
|
'duration': {'numerator': '3', 'denominator': 1},
|
|
});
|
|
expect(
|
|
inserted.edit,
|
|
EditOutcome.committed,
|
|
reason: '${inserted.toJson()}',
|
|
);
|
|
final before = session.commands.version;
|
|
final changes = <ProjectAssetsChanged>[];
|
|
final subscription = workspace.assetChanges.listen(changes.add);
|
|
addTearDown(subscription.cancel);
|
|
final renamed = await invoke('media.rename', 'catalog-rename', {
|
|
'mediaId': id,
|
|
'name': 'Renamed',
|
|
});
|
|
expect(renamed.edit, EditOutcome.committed);
|
|
final replay = await invoke('media.rename', 'catalog-rename', {
|
|
'mediaId': id,
|
|
'name': 'Renamed',
|
|
});
|
|
expect(replay.edit, EditOutcome.committed);
|
|
final noop = await invoke('media.rename', 'catalog-noop', {
|
|
'mediaId': id,
|
|
'name': 'Renamed',
|
|
});
|
|
expect(noop.edit, EditOutcome.notCommitted);
|
|
expect(
|
|
((await invoke('media.query', 'renamed-query', {})).data['media']
|
|
as List)
|
|
.single,
|
|
containsPair('name', 'Renamed'),
|
|
);
|
|
final removed = await invoke('media.remove', 'catalog-remove', {
|
|
'mediaId': id,
|
|
});
|
|
expect(removed.edit, EditOutcome.committed);
|
|
expect(
|
|
(await invoke('media.query', 'removed-query', {})).data['media'],
|
|
isEmpty,
|
|
);
|
|
expect(await file.exists(), isTrue);
|
|
expect(session.commands.version, before);
|
|
expect(
|
|
session.persistence
|
|
.timeline(sequence)
|
|
.exportDto()
|
|
.elements
|
|
.any((e) => e.id.value == 'catalog-clip'),
|
|
isTrue,
|
|
);
|
|
await Future<void>.delayed(Duration.zero);
|
|
expect(changes, hasLength(2));
|
|
expect(
|
|
(await invoke('media.rename', 'missing-rename', {
|
|
'mediaId': 'missing',
|
|
'name': 'New',
|
|
})).status,
|
|
CommandStatus.rejected,
|
|
);
|
|
expect(
|
|
(await invoke('media.rename', 'blank-rename', {
|
|
'mediaId': id,
|
|
'name': ' ',
|
|
})).status,
|
|
CommandStatus.rejected,
|
|
);
|
|
},
|
|
);
|
|
|
|
test('preview tools remain discoverable before a preview attaches', () async {
|
|
expect(
|
|
(await invoke('preview.query', 'preview-query', {})).data['available'],
|
|
false,
|
|
);
|
|
final result = await invoke('preview.play', 'preview-play', {});
|
|
expect(result.status, CommandStatus.rejected);
|
|
expect(result.edit, EditOutcome.notApplicable);
|
|
});
|
|
|
|
test(
|
|
'mask switch preserves geometry and animation even with repeated fields',
|
|
() async {
|
|
await invoke('mask.edit', 'add-toggle-mask', {
|
|
'clipId': 'a',
|
|
'maskId': 'mask',
|
|
'action': 'add',
|
|
'at': {'numerator': '0', 'denominator': 1},
|
|
});
|
|
await invoke('keyframe.editMany', 'animate-toggle-mask', {
|
|
'clipId': 'a',
|
|
'edits': [
|
|
for (final time in [0, 5])
|
|
{
|
|
'parameterId': 'mask.mask.center.x',
|
|
'action': 'set',
|
|
'at': {'numerator': '$time', 'denominator': 1},
|
|
'value': time == 0 ? .4 : .6,
|
|
},
|
|
],
|
|
});
|
|
List<Object?> geometry() => [
|
|
for (final curve
|
|
in session.persistence
|
|
.timeline(sequence)
|
|
.exportDto()
|
|
.elements
|
|
.first
|
|
.parameters)
|
|
if (curve.definition.id != 'mask.mask.enabled')
|
|
[
|
|
curve.definition.id,
|
|
curve.definition.defaultValue,
|
|
for (final key in curve.keyframes)
|
|
[key.sourceTime, key.value, key.interpolation],
|
|
],
|
|
];
|
|
final before = geometry();
|
|
for (final enabled in [false, true]) {
|
|
final result = await invoke('mask.edit', 'switch-$enabled', {
|
|
'clipId': 'a',
|
|
'maskId': 'mask',
|
|
'action': 'setEnabled',
|
|
'enabled': enabled,
|
|
'x': .9,
|
|
'y': .2,
|
|
'width': .3,
|
|
'at': {'numerator': '0', 'denominator': 1},
|
|
});
|
|
expect(result.edit, EditOutcome.committed);
|
|
expect(geometry(), before);
|
|
final stored = await workspace.project!.loadTimeline('project');
|
|
expect(
|
|
stored.sequences.first.elements.first.parameters
|
|
.firstWhere((p) => p.definition.id == 'mask.mask.enabled')
|
|
.definition
|
|
.defaultValue,
|
|
enabled ? 1 : 0,
|
|
);
|
|
}
|
|
},
|
|
);
|
|
|
|
test('shared mask and grouped keyframe use cases interoperate with tools and undo atomically', () async {
|
|
final view = session.view(sequence);
|
|
final clip = ElementId('a');
|
|
session.commands.addMask(
|
|
sequence: sequence,
|
|
clip: clip,
|
|
tick: 0,
|
|
maskId: 'mask',
|
|
shape: ClipMaskShape.rectangle,
|
|
);
|
|
session.commands.editKeyframeChannel(
|
|
sequence: sequence,
|
|
clip: clip,
|
|
tick: 0,
|
|
parameterIds: ['mask.mask.center.x', 'mask.mask.center.y'],
|
|
);
|
|
ElementRecord record() {
|
|
final query = view.version.kernelVersion.query();
|
|
return query.element(query.elementById(clip)!);
|
|
}
|
|
|
|
expect(
|
|
ClipMaskAnimation(
|
|
record(),
|
|
0,
|
|
maskId: 'mask',
|
|
).keyed(maskChannels['position']!),
|
|
isTrue,
|
|
);
|
|
view.undo();
|
|
expect(
|
|
ClipMaskAnimation(
|
|
record(),
|
|
0,
|
|
maskId: 'mask',
|
|
).keyed(maskChannels['position']!),
|
|
isFalse,
|
|
);
|
|
view.redo();
|
|
final edited = await invoke('mask.edit', 'shared-mask', {
|
|
'clipId': 'a',
|
|
'action': 'set',
|
|
'maskId': 'mask',
|
|
'at': {'numerator': '0', 'denominator': 1},
|
|
'x': .75,
|
|
});
|
|
expect(edited.edit, EditOutcome.committed);
|
|
expect(ClipMaskAnimation(record(), 0, maskId: 'mask').value.x, .75);
|
|
final before = view.version;
|
|
expect(
|
|
() => session.commands.editKeyframeChannel(
|
|
sequence: sequence,
|
|
clip: clip,
|
|
tick: 0,
|
|
parameterIds: ['mask.mask.center.x', 'unsupported'],
|
|
),
|
|
throwsA(isA<CommandRejected>()),
|
|
);
|
|
expect(
|
|
view.version,
|
|
same(before),
|
|
reason: 'A bad second channel must not publish the first',
|
|
);
|
|
await invoke('timeline.undo', 'undo-shared-mask', {});
|
|
expect(ClipMaskAnimation(record(), 0, maskId: 'mask').value.x, .5);
|
|
});
|
|
|
|
test(
|
|
'direct typed commands reject incomplete operands without publication',
|
|
() async {
|
|
final view = session.view(sequence);
|
|
final before = view.version;
|
|
for (final command in <EditCommand>[
|
|
EditKeyframe(
|
|
clipId: 'a',
|
|
parameterId: 'canvas.position.x',
|
|
at: CommandTime(0, 1),
|
|
action: KeyframeAction.move,
|
|
),
|
|
EditKeyframe(
|
|
clipId: 'a',
|
|
parameterId: 'canvas.position.x',
|
|
at: CommandTime(0, 1),
|
|
action: KeyframeAction.set,
|
|
interpolation: KeyInterpolation.bezier,
|
|
),
|
|
EditMask(clipId: 'a', at: CommandTime(0, 1), action: MaskAction.add),
|
|
const SetClipAudio(clipId: 'a', db: double.nan),
|
|
const SetProjectCanvas(width: double.infinity, height: 1080),
|
|
]) {
|
|
expect(
|
|
() => session.commands.applyEdit(sequence, command),
|
|
throwsA(isA<CommandRejected>()),
|
|
);
|
|
expect(view.version, same(before));
|
|
}
|
|
expect(view.canUndo, isFalse);
|
|
},
|
|
);
|
|
|
|
test(
|
|
'UI and tools share history, atomic XY, versions, and persistent curves',
|
|
() async {
|
|
session.commands.setTransform(
|
|
sequence: sequence,
|
|
clip: ElementId('a'),
|
|
tick: 0,
|
|
change: (value) => value.copyWith(rotation: 25),
|
|
);
|
|
final before = session.commands.version;
|
|
final result = await invoke(
|
|
'clip.setTransform',
|
|
'position',
|
|
position(192, version: before),
|
|
);
|
|
expect(result.edit, EditOutcome.committed);
|
|
expect(result.version, isNot(before));
|
|
expect(transform().x, closeTo(192 / session.canvas.width, 1e-9));
|
|
expect(transform().y, closeTo(54 / session.canvas.height, 1e-9));
|
|
expect(transform().rotation, 25);
|
|
session.view(sequence).undo();
|
|
expect(transform().x, 0);
|
|
expect(transform().y, 0);
|
|
expect(transform().rotation, 25);
|
|
final undoVersion = session.commands.version;
|
|
final retried = await invoke(
|
|
'clip.setTransform',
|
|
'position',
|
|
position(192, version: before),
|
|
);
|
|
expect(retried, same(result));
|
|
expect(session.commands.version, undoVersion);
|
|
expect(transform().x, 0);
|
|
await invoke('timeline.redo', 'redo', {});
|
|
await session.flush();
|
|
final loaded = await workspace.project!.loadTimeline('project');
|
|
final clip = loaded.sequences.first.elements.first;
|
|
expect(
|
|
clip.parameters
|
|
.firstWhere((curve) => curve.definition.id == 'canvas.position.x')
|
|
.definition
|
|
.defaultValue,
|
|
closeTo(192 / session.canvas.width, 1e-9),
|
|
);
|
|
},
|
|
);
|
|
|
|
test(
|
|
'mask tools preserve identity, animation, undo and reject invalid edits',
|
|
() async {
|
|
Map<String, Object?> args(String action, {String id = 'mask-one'}) => {
|
|
'clipId': 'a',
|
|
'maskId': id,
|
|
'action': action,
|
|
'at': {'numerator': '1', 'denominator': 1},
|
|
};
|
|
final add = await invoke('mask.edit', 'add-mask', {
|
|
...args('add'),
|
|
'shape': 'ellipse',
|
|
});
|
|
expect(add.edit, EditOutcome.committed);
|
|
final version = session.commands.version;
|
|
expect(
|
|
(await invoke('mask.edit', 'add-mask', {
|
|
...args('add'),
|
|
'shape': 'ellipse',
|
|
})).version,
|
|
add.version,
|
|
);
|
|
expect(session.commands.version, version);
|
|
expect(
|
|
(await invoke('mask.edit', 'bad-mask', {
|
|
...args('set'),
|
|
'width': 0,
|
|
})).status,
|
|
CommandStatus.rejected,
|
|
);
|
|
expect(session.commands.version, version);
|
|
final key = await invoke('keyframe.edit', 'mask-key', {
|
|
'clipId': 'a',
|
|
'parameterId': 'mask.mask-one.center.x',
|
|
'action': 'set',
|
|
'at': {'numerator': '1', 'denominator': 1},
|
|
'value': .25,
|
|
});
|
|
expect(key.edit, EditOutcome.committed);
|
|
expect(
|
|
(await invoke('mask.edit', 'set-mask', {
|
|
...args('set'),
|
|
'x': .75,
|
|
'mode': 'subtract',
|
|
})).edit,
|
|
EditOutcome.committed,
|
|
);
|
|
final query = await invoke('timeline.query', 'query-mask', {});
|
|
expect(
|
|
query.status,
|
|
CommandStatus.succeeded,
|
|
reason: '${query.toJson()}',
|
|
);
|
|
expect(
|
|
(await invoke('mask.edit', 'remove-mask', args('remove'))).edit,
|
|
EditOutcome.committed,
|
|
);
|
|
expect(
|
|
(await invoke('timeline.undo', 'undo-mask', {})).edit,
|
|
EditOutcome.committed,
|
|
);
|
|
await session.flush();
|
|
final dto = session.persistence.timeline(sequence).exportDto();
|
|
expect(
|
|
dto.elements.first.parameters.any(
|
|
(p) => p.definition.id == 'mask.mask-one.center.x',
|
|
),
|
|
true,
|
|
);
|
|
},
|
|
);
|
|
|
|
test(
|
|
'keyframe tools set move interpolate and clear without moving playhead',
|
|
() async {
|
|
final view = session.view(sequence);
|
|
final playhead = view.playheadTick;
|
|
final base = {
|
|
'clipId': 'a',
|
|
'parameterId': 'canvas.position.x',
|
|
'at': {'numerator': '2', 'denominator': 1},
|
|
};
|
|
expect(
|
|
(await invoke('keyframe.edit', 'key-set', {
|
|
...base,
|
|
'action': 'set',
|
|
'value': .3,
|
|
'interpolation': 'easeInOut',
|
|
})).edit,
|
|
EditOutcome.committed,
|
|
);
|
|
expect(
|
|
(await invoke('keyframe.edit', 'key-move', {
|
|
...base,
|
|
'action': 'move',
|
|
'to': {'numerator': '3', 'denominator': 1},
|
|
})).edit,
|
|
EditOutcome.committed,
|
|
);
|
|
expect(
|
|
(await invoke('keyframe.edit', 'key-clear', {
|
|
...base,
|
|
'action': 'clear',
|
|
})).edit,
|
|
EditOutcome.committed,
|
|
);
|
|
expect(transform().x, .3);
|
|
expect(view.playheadTick, playhead);
|
|
},
|
|
);
|
|
|
|
test(
|
|
'split leading trim and connected placement preserve shared history',
|
|
() async {
|
|
expect(
|
|
(await invoke('timeline.split', 'split-tool', {
|
|
'clipId': 'a',
|
|
'at': {'numerator': '3', 'denominator': 1},
|
|
})).edit,
|
|
EditOutcome.committed,
|
|
);
|
|
expect(
|
|
session.persistence.timeline(sequence).exportDto().elements.length,
|
|
3,
|
|
);
|
|
await invoke('timeline.undo', 'undo-split-tool', {});
|
|
expect(
|
|
(await invoke('timeline.trim', 'leading-tool', {
|
|
'clipId': 'a',
|
|
'duration': {'numerator': '8', 'denominator': 1},
|
|
'leading': true,
|
|
})).edit,
|
|
EditOutcome.committed,
|
|
);
|
|
await invoke('timeline.undo', 'undo-leading-tool', {});
|
|
final placed = await invoke('timeline.place', 'place-tool', {
|
|
'clipId': 'b',
|
|
'at': {'numerator': '1', 'denominator': 1},
|
|
'side': 'above',
|
|
});
|
|
expect(placed.edit, EditOutcome.committed, reason: '${placed.toJson()}');
|
|
final moved = await invoke('timeline.place', 'move-connected-tool', {
|
|
'clipId': 'b',
|
|
'at': {'numerator': '2', 'denominator': 1},
|
|
'side': 'above',
|
|
});
|
|
expect(moved.edit, EditOutcome.committed, reason: '${moved.toJson()}');
|
|
await invoke('timeline.undo', 'undo-connected-tool', {});
|
|
},
|
|
);
|
|
|
|
test('canvas settings use version checks and persist', () async {
|
|
final old = session.commands.version;
|
|
expect(
|
|
(await invoke('project.setCanvas', 'canvas-tool', {
|
|
'width': 1080,
|
|
'height': 1920,
|
|
})).edit,
|
|
EditOutcome.committed,
|
|
);
|
|
expect(session.canvas.width, 1080);
|
|
expect(
|
|
(await invoke('project.setCanvas', 'stale-canvas-tool', {
|
|
'width': 1920,
|
|
'height': 1080,
|
|
'expectedVersion': old,
|
|
})).status,
|
|
CommandStatus.rejected,
|
|
);
|
|
await session.flush();
|
|
expect(
|
|
(await workspace.loadTimeline(
|
|
projectId,
|
|
'project',
|
|
)).settings['renderSize'],
|
|
{'width': 1080.0, 'height': 1920.0},
|
|
);
|
|
});
|
|
|
|
test('MCP and Agent expose new tools and MCP mask edits reach the shared session', () async {
|
|
expect(
|
|
access.agentTools.map((tool) => tool.name),
|
|
containsAll([
|
|
'mask_edit',
|
|
'keyframe_edit',
|
|
'clip_setAudio',
|
|
'timeline_split',
|
|
'timeline_place',
|
|
'media_import',
|
|
]),
|
|
);
|
|
final connection = access.server.connect();
|
|
addTearDown(connection.close);
|
|
final response = await connection.handleJson(
|
|
jsonEncode(
|
|
_request('mask.edit', {
|
|
'workspaceId': access.workspaces.keys.first,
|
|
'operationId': 'wire-mask',
|
|
'clipId': 'a',
|
|
'maskId': 'wire-mask',
|
|
'action': 'add',
|
|
'at': {'numerator': '0', 'denominator': 1},
|
|
'feather': .2,
|
|
}),
|
|
),
|
|
);
|
|
expect((response!['result'] as Map)['isError'], false, reason: '$response');
|
|
final dto = session.persistence.timeline(sequence).exportDto();
|
|
expect(
|
|
dto.elements.first.parameters
|
|
.firstWhere(
|
|
(curve) => curve.definition.id == 'mask.wire-mask.feather',
|
|
)
|
|
.definition
|
|
.defaultValue,
|
|
.2,
|
|
);
|
|
final before = session.commands.version;
|
|
final canceledFile = File('${root.path}/canceled.png');
|
|
await canceledFile.writeAsBytes([0]);
|
|
final result = await workspace.importExternalMedia(projectId, [
|
|
ExternalMediaFile(path: canceledFile.path),
|
|
], isCancelled: () => true);
|
|
expect(result.added, 0);
|
|
expect(result.failures, hasLength(1));
|
|
expect(session.commands.version, before);
|
|
});
|
|
|
|
test('audio and color tools commit valid media properties and reject non-audio clips', () async {
|
|
expect(
|
|
(await invoke('clip.setAudio', 'invalid-audio', {
|
|
'clipId': 'a',
|
|
'db': -6,
|
|
})).status,
|
|
CommandStatus.rejected,
|
|
);
|
|
final asset = AssetDocument(
|
|
id: 'av',
|
|
name: 'av.mov',
|
|
storage: AssetStorage.external,
|
|
location: 'file:///av.mov',
|
|
);
|
|
await workspace.project!.saveAsset(asset);
|
|
session.insertAsset(
|
|
sequenceId: sequence,
|
|
assetId: asset.id,
|
|
assetName: asset.name,
|
|
uri: Uri.file('/av.mov'),
|
|
duration: RationalTime.seconds(5),
|
|
position: 0,
|
|
kind: 'video',
|
|
hasAudio: true,
|
|
clipId: ElementId('av-clip'),
|
|
);
|
|
expect(
|
|
(await invoke('clip.setAudio', 'audio', {
|
|
'clipId': 'av-clip',
|
|
'db': -6,
|
|
'muted': true,
|
|
})).edit,
|
|
EditOutcome.committed,
|
|
);
|
|
final q = session.view(sequence).version.kernelVersion.query();
|
|
final gain = ClipAudioGain.fromRecord(
|
|
q.element(q.elementById(ElementId('av-clip'))!),
|
|
);
|
|
expect(gain.db, -6);
|
|
expect(gain.muted, true);
|
|
final colors =
|
|
(await invoke('timeline.query', 'colors', {})).data['colorSpaces']
|
|
as List;
|
|
final color = await invoke('media.setColorInterpretation', 'color', {
|
|
'mediaId': 'av',
|
|
'trackIndex': 0,
|
|
'colorSpace': colors[1],
|
|
});
|
|
expect(color.edit, EditOutcome.committed);
|
|
expect(session.mediaColorInterpretation('av', 0)?.name, colors[1]);
|
|
});
|
|
|
|
test(
|
|
'project tools import query and insert explicit IDs with source ranges',
|
|
() async {
|
|
final file = File('${root.path}/still.png');
|
|
await file.writeAsBytes([0]);
|
|
expect(
|
|
(await invoke('media.import', 'import-image', {
|
|
'path': file.path,
|
|
})).data['added'],
|
|
1,
|
|
);
|
|
final media =
|
|
(await invoke('media.query', 'query-media', {})).data['media']
|
|
as List;
|
|
final arguments = {
|
|
'clipId': 'new-image',
|
|
'mediaId': (media.single as Map)['mediaId'],
|
|
'index': 1,
|
|
'sourceStart': {'numerator': '0', 'denominator': 1},
|
|
'duration': {'numerator': '3', 'denominator': 1},
|
|
};
|
|
final inserted = await invoke(
|
|
'timeline.insert',
|
|
'insert-image',
|
|
arguments,
|
|
);
|
|
expect(
|
|
inserted.edit,
|
|
EditOutcome.committed,
|
|
reason: '${inserted.toJson()}',
|
|
);
|
|
expect(
|
|
(await invoke('timeline.insert', 'insert-image', arguments)).version,
|
|
inserted.version,
|
|
);
|
|
expect(
|
|
session.persistence
|
|
.timeline(sequence)
|
|
.exportDto()
|
|
.elements
|
|
.any((e) => e.id.value == 'new-image'),
|
|
true,
|
|
);
|
|
await session.flush();
|
|
},
|
|
);
|
|
|
|
test(
|
|
'review: wrong-sequence parameter timeline cannot publish either kernel',
|
|
() {
|
|
final other = SequenceId('two');
|
|
final before = session.persistence.timeline(sequence).current;
|
|
final otherBefore = session.persistence.timeline(other).current;
|
|
final timeline = session.previewParameters(
|
|
sequence,
|
|
ElementId('a'),
|
|
const ClipTransform(x: .25).parameters,
|
|
);
|
|
expect(() => session.commitParameters(other, timeline), throwsStateError);
|
|
expect(session.persistence.timeline(sequence).current, same(before));
|
|
expect(session.persistence.timeline(other).current, same(otherBefore));
|
|
expect(session.dirty, false);
|
|
timeline.cancel();
|
|
},
|
|
);
|
|
|
|
test(
|
|
'review: publication listeners observe the version of the new state',
|
|
() {
|
|
final before = session.commands.version;
|
|
String? observed;
|
|
session.addListener(() {
|
|
observed = session.commands.version;
|
|
});
|
|
session.commands.setTransform(
|
|
sequence: sequence,
|
|
clip: ElementId('a'),
|
|
tick: 0,
|
|
change: (value) => value.copyWith(x: .25),
|
|
);
|
|
expect(observed, isNot(before));
|
|
expect(observed, session.commands.version);
|
|
},
|
|
);
|
|
|
|
test('session owns versions and rejects edits reentering publication', () {
|
|
final before = session.version;
|
|
Object? rejected;
|
|
void listener() {
|
|
expect(session.commands.version, session.version);
|
|
try {
|
|
session.commands.setTransform(
|
|
sequence: sequence,
|
|
clip: ElementId('a'),
|
|
tick: 0,
|
|
change: (value) => value.copyWith(x: .75),
|
|
);
|
|
} catch (error) {
|
|
rejected = error;
|
|
}
|
|
}
|
|
|
|
session.addListener(listener);
|
|
session.commands.setTransform(
|
|
sequence: sequence,
|
|
clip: ElementId('a'),
|
|
tick: 0,
|
|
change: (value) => value.copyWith(x: .25),
|
|
);
|
|
session.removeListener(listener);
|
|
expect(rejected, isA<StateError>());
|
|
expect(session.version, isNot(before));
|
|
expect(session.commands.version, session.version);
|
|
final committed = session.version;
|
|
session.commands.setTransform(
|
|
sequence: sequence,
|
|
clip: ElementId('a'),
|
|
tick: 0,
|
|
change: (value) => value.copyWith(x: .5),
|
|
);
|
|
expect(session.version, isNot(committed));
|
|
});
|
|
|
|
test('runtime MCP settings start, stop and restart the listener', () async {
|
|
final reserved = await ServerSocket.bind(InternetAddress.loopbackIPv4, 0);
|
|
final port = reserved.port;
|
|
await reserved.close();
|
|
final ids = (projectId, 'project');
|
|
final container = ProviderContainer(
|
|
overrides: [
|
|
editorTimelineProvider(
|
|
ids.$1,
|
|
ids.$2,
|
|
).overrideWith((ref) async => session),
|
|
mcpSettingsRepositoryProvider.overrideWithValue(
|
|
MemoryMcpSettingsRepository(),
|
|
),
|
|
],
|
|
);
|
|
addTearDown(container.dispose);
|
|
final subscription = container.listen(
|
|
editorMcpConnectionProvider(ids.$1, ids.$2),
|
|
(_, _) {},
|
|
);
|
|
addTearDown(subscription.close);
|
|
await container.read(mcpSettingsProvider.future);
|
|
await container
|
|
.read(mcpSettingsProvider.notifier)
|
|
.saveSettings(enabled: true, port: port);
|
|
await container.read(editorMcpConnectionProvider(ids.$1, ids.$2).future);
|
|
final socket = await Socket.connect(InternetAddress.loopbackIPv4, port);
|
|
final disconnected = socket.drain<void>().onError<SocketException>(
|
|
(_, _) {},
|
|
);
|
|
await container
|
|
.read(mcpSettingsProvider.notifier)
|
|
.saveSettings(enabled: false);
|
|
await container.read(editorMcpConnectionProvider(ids.$1, ids.$2).future);
|
|
await disconnected.timeout(const Duration(seconds: 2));
|
|
await expectLater(
|
|
Socket.connect(InternetAddress.loopbackIPv4, port),
|
|
throwsA(isA<SocketException>()),
|
|
);
|
|
await container
|
|
.read(mcpSettingsProvider.notifier)
|
|
.saveSettings(enabled: true);
|
|
await container.read(editorMcpConnectionProvider(ids.$1, ids.$2).future);
|
|
final reconnected = await Socket.connect(
|
|
InternetAddress.loopbackIPv4,
|
|
port,
|
|
);
|
|
reconnected.destroy();
|
|
await container
|
|
.read(mcpSettingsProvider.notifier)
|
|
.saveSettings(enabled: false);
|
|
await container.read(editorMcpConnectionProvider(ids.$1, ids.$2).future);
|
|
});
|
|
|
|
test(
|
|
'review: an occupied MCP port must not disable built-in Agent tools',
|
|
() async {
|
|
final occupied = await ServerSocket.bind(InternetAddress.loopbackIPv4, 0);
|
|
addTearDown(occupied.close);
|
|
final ids = (projectId, 'project');
|
|
final container = ProviderContainer(
|
|
retry: (_, _) => null,
|
|
overrides: [
|
|
applicationToolAccessProvider.overrideWithValue(access),
|
|
editorTimelineProvider(
|
|
ids.$1,
|
|
ids.$2,
|
|
).overrideWith((ref) async => session),
|
|
editorMcpConfigurationProvider.overrideWithValue(
|
|
EditorMcpConfiguration(
|
|
port: occupied.port,
|
|
token: 'review-token-01234567890123456789012345',
|
|
),
|
|
),
|
|
],
|
|
);
|
|
addTearDown(container.dispose);
|
|
final subscription = container.listen(
|
|
editorAgentToolsProvider(ids.$1, ids.$2),
|
|
(_, _) {},
|
|
);
|
|
addTearDown(subscription.close);
|
|
final binding = await container.read(
|
|
editorAgentToolsProvider(ids.$1, ids.$2).future,
|
|
);
|
|
expect(
|
|
binding.tools.any((tool) => tool.name == 'clip_setTransform'),
|
|
true,
|
|
);
|
|
final mcpSubscription = container.listen(
|
|
editorMcpConnectionProvider(ids.$1, ids.$2),
|
|
(_, _) {},
|
|
);
|
|
addTearDown(mcpSubscription.close);
|
|
await expectLater(
|
|
container.read(editorMcpConnectionProvider(ids.$1, ids.$2).future),
|
|
throwsA(anything),
|
|
);
|
|
expect(
|
|
(await container.read(editorAgentToolsProvider(ids.$1, ids.$2).future))
|
|
.owner,
|
|
same(session),
|
|
);
|
|
final tool = binding.tools.singleWhere(
|
|
(tool) => tool.name == 'clip_setTransform',
|
|
);
|
|
final result = await tool.execute(
|
|
ToolCall(
|
|
id: 'offline-mcp',
|
|
name: tool.name,
|
|
arguments: {
|
|
...position(96),
|
|
'workspaceId': access.workspaces.keys.first,
|
|
},
|
|
),
|
|
ToolContext(
|
|
sessionId: 's',
|
|
runId: 'r',
|
|
operationId: 'offline-mcp',
|
|
cancellation: CancellationToken(),
|
|
onProgress: (_) {},
|
|
),
|
|
);
|
|
expect(result.isError, false);
|
|
expect(transform().x, closeTo(96 / session.canvas.width, 1e-9));
|
|
},
|
|
);
|
|
|
|
test('queued tools recheck versions after synchronous UI commit', () async {
|
|
final before = session.commands.version;
|
|
final pending = invoke(
|
|
'clip.setTransform',
|
|
'stale',
|
|
position(100, version: before),
|
|
);
|
|
session.commands.setTransform(
|
|
sequence: sequence,
|
|
clip: ElementId('a'),
|
|
tick: 0,
|
|
change: (value) => value.copyWith(rotation: 10),
|
|
);
|
|
expect((await pending).code, 'staleVersion');
|
|
expect(transform().x, 0);
|
|
expect(transform().rotation, 10);
|
|
});
|
|
|
|
test('explicit tool time edits animated channels without following the UI playhead', () async {
|
|
final view = session.view(sequence);
|
|
final query = view.version.kernelVersion.query();
|
|
final animation = ClipAnimation.at(
|
|
query,
|
|
query.elementById(ElementId('a'))!,
|
|
0,
|
|
TimelineClock.ticksPerSecond ~/ 30,
|
|
);
|
|
session.commitParameters(
|
|
sequence,
|
|
session.previewParameters(
|
|
sequence,
|
|
ElementId('a'),
|
|
animation.toggle(TransformChannel.position),
|
|
),
|
|
parameterTargets: ClipTransform.targets,
|
|
);
|
|
view.seekTo(8 * TimelineClock.ticksPerSecond);
|
|
final result = await invoke('clip.setTransform', 'key', {
|
|
...position(192),
|
|
'at': {'numerator': '5', 'denominator': 1},
|
|
});
|
|
expect(result.edit, EditOutcome.committed);
|
|
final updated = view.version.kernelVersion.query();
|
|
final curve = updated
|
|
.element(updated.elementById(ElementId('a'))!)
|
|
.parameters!['canvas.position.x']!;
|
|
expect(curve.keyframeAt(0), isNotNull);
|
|
expect(
|
|
curve.keyframeAt(5 * TimelineClock.ticksPerSecond)!.value,
|
|
closeTo(192 / session.canvas.width, 1e-9),
|
|
);
|
|
expect(curve.keyframeAt(8 * TimelineClock.ticksPerSecond), isNull);
|
|
expect(view.playheadTick, 8 * TimelineClock.ticksPerSecond);
|
|
});
|
|
|
|
test('toolbar cuts enter the project commit boundary', () async {
|
|
final view = session.view(sequence);
|
|
final query = view.version.kernelVersion.query();
|
|
view.setSelection([query.elementById(ElementId('a'))!]);
|
|
view.seekTo(5 * TimelineClock.ticksPerSecond);
|
|
final version = session.commands.version;
|
|
expect(view.cutSelectionAtPlayhead(), true);
|
|
expect(session.commands.version, isNot(version));
|
|
expect(
|
|
(await invoke('timeline.undo', 'undo-cut', {})).edit,
|
|
EditOutcome.committed,
|
|
);
|
|
final current = view.version.kernelVersion.query();
|
|
expect(current.storylineLength(current.primaryStoryline), 2);
|
|
});
|
|
|
|
test('a prepared UI edit cannot overwrite a tool commit', () async {
|
|
final timeline = session.previewParameters(
|
|
sequence,
|
|
ElementId('a'),
|
|
const ClipTransform(x: .8).parameters,
|
|
);
|
|
await invoke('clip.setTransform', 'remote', position(100));
|
|
expect(
|
|
() => session.commitParameters(sequence, timeline),
|
|
throwsA(anything),
|
|
);
|
|
expect(transform().x, closeTo(100 / session.canvas.width, 1e-9));
|
|
timeline.cancel();
|
|
});
|
|
|
|
test(
|
|
'move, trim and delete share UI undo history and publish views',
|
|
() async {
|
|
final view = session.view(sequence);
|
|
expect(
|
|
(await invoke('timeline.move', 'move', {
|
|
'clipId': 'b',
|
|
'index': 0,
|
|
})).edit,
|
|
EditOutcome.committed,
|
|
);
|
|
var query = view.version.kernelVersion.query();
|
|
expect(
|
|
query.element(query.storylineElements(query.primaryStoryline).first).id,
|
|
ElementId('b'),
|
|
);
|
|
expect(
|
|
(await invoke('timeline.trim', 'trim', {
|
|
'clipId': 'b',
|
|
'duration': {'numerator': '4', 'denominator': 1},
|
|
})).edit,
|
|
EditOutcome.committed,
|
|
);
|
|
expect(
|
|
(await invoke('timeline.delete', 'delete', {'clipId': 'a'})).edit,
|
|
EditOutcome.committed,
|
|
);
|
|
view.undo();
|
|
query = view.version.kernelVersion.query();
|
|
expect(query.elementById(ElementId('a')), isNotNull);
|
|
view.undo();
|
|
view.undo();
|
|
query = view.version.kernelVersion.query();
|
|
expect(
|
|
query.element(query.storylineElements(query.primaryStoryline).first).id,
|
|
ElementId('a'),
|
|
);
|
|
},
|
|
);
|
|
|
|
test('MCP targets a fixed sequence independently of UI selection and deduplicates connections', () async {
|
|
final target = access.workspaces.keys.first;
|
|
session.selectSequence(SequenceId('two'));
|
|
final request = jsonEncode(
|
|
_request('clip.setTransform', {
|
|
...position(250),
|
|
'workspaceId': target,
|
|
'operationId': 'mcp-position',
|
|
}),
|
|
);
|
|
final first = access.server.connect();
|
|
final response = await first.handleJson(request);
|
|
expect((response!['result'] as Map)['isError'], false);
|
|
first.close();
|
|
final version = session.commands.version;
|
|
final second = access.server.connect();
|
|
await second.handleJson(request);
|
|
second.close();
|
|
expect(session.commands.version, version);
|
|
expect(session.activeSequenceId, SequenceId('two'));
|
|
expect(transform().x, closeTo(250 / session.canvas.width, 1e-9));
|
|
final other = session.view(SequenceId('two')).version.kernelVersion.query();
|
|
expect(
|
|
ClipTransform.fromRecord(
|
|
other.element(other.elementById(ElementId('a'))!),
|
|
).x,
|
|
0,
|
|
);
|
|
});
|
|
|
|
test(
|
|
'Agent adapter uses the same dispatcher and recovers original outcomes',
|
|
() async {
|
|
final tool = access.agentTools.singleWhere(
|
|
(tool) => tool.name == 'clip_setTransform',
|
|
);
|
|
final call = ToolCall(
|
|
id: 'call',
|
|
name: tool.name,
|
|
arguments: {
|
|
...position(42),
|
|
'workspaceId': access.workspaces.keys.first,
|
|
},
|
|
);
|
|
final context = ToolContext(
|
|
sessionId: 's',
|
|
runId: 'r',
|
|
operationId: 'agent-edit',
|
|
cancellation: CancellationToken(),
|
|
onProgress: (_) {},
|
|
);
|
|
expect(tool.validate(call.arguments), isNull);
|
|
for (final declaration in access.agentTools) {
|
|
expect(declaration.name, matches(RegExp(r'^[a-zA-Z0-9_-]{1,64}$')));
|
|
}
|
|
expect((await tool.execute(call, context)).isError, false);
|
|
expect(
|
|
(await tool.recover!(call, context)).status,
|
|
RecoveryStatus.completed,
|
|
);
|
|
final conflicting = ToolCall(
|
|
id: call.id,
|
|
name: call.name,
|
|
arguments: {...call.arguments, 'x': 999},
|
|
);
|
|
expect(
|
|
(await tool.recover!(conflicting, context)).status,
|
|
RecoveryStatus.unknown,
|
|
);
|
|
session.view(sequence).undo();
|
|
expect(transform().x, 0);
|
|
},
|
|
);
|
|
|
|
test('invalid time, cancellation, conflicting IDs and closed sessions do not edit', () async {
|
|
final initial = session.commands.version;
|
|
final bad = await invoke('clip.setTransform', 'bad-time', {
|
|
...position(1),
|
|
'at': {'numerator': '20', 'denominator': 1},
|
|
});
|
|
expect(bad.code, 'invalidTime');
|
|
final tools = editorToolsFor(session, sequence);
|
|
final cancelled = await tools.invoke(
|
|
name: 'clip.setTransform',
|
|
arguments: position(1),
|
|
context: CommandContext(
|
|
operationId: 'cancelled',
|
|
isCancelled: () => true,
|
|
),
|
|
);
|
|
expect(cancelled.code, 'cancelled');
|
|
expect(session.commands.version, initial);
|
|
await invoke('clip.setTransform', 'id', position(10));
|
|
expect(
|
|
(await invoke('clip.setTransform', 'id', position(11))).code,
|
|
'operationIdConflict',
|
|
);
|
|
await session.close();
|
|
expect(
|
|
(await tools.invoke(
|
|
name: 'timeline.query',
|
|
arguments: {},
|
|
context: const CommandContext(operationId: 'closed'),
|
|
)).code,
|
|
'closed',
|
|
);
|
|
});
|
|
|
|
test('real stdio launcher edits the open app host through authenticated loopback', () async {
|
|
const token = 'cutdex-test-token-01234567890123456789';
|
|
final bridge = await LocalMcpBridge.start(
|
|
access.server,
|
|
port: 0,
|
|
token: token,
|
|
);
|
|
addTearDown(bridge.close);
|
|
final process = await Process.start(
|
|
flutterTestDartExecutable(),
|
|
['tool/mcp_stdio.dart'],
|
|
environment: {
|
|
'CUTDEX_MCP_PORT': '${bridge.port}',
|
|
'CUTDEX_MCP_TOKEN': token,
|
|
// This standard-library launcher must not need a Dart/Flutter wrapper
|
|
// on PATH, or compete with parallel generators for startup/pub locks.
|
|
'PATH': root.path,
|
|
},
|
|
);
|
|
addTearDown(process.kill);
|
|
final errors = process.stderr.transform(utf8.decoder).join();
|
|
process.stdin.writeln(
|
|
jsonEncode(
|
|
_request('clip.setTransform', {
|
|
...position(320),
|
|
'workspaceId': access.workspaces.keys.first,
|
|
'operationId': 'stdio',
|
|
}),
|
|
),
|
|
);
|
|
final String responseLine;
|
|
try {
|
|
responseLine = await process.stdout
|
|
.transform(utf8.decoder)
|
|
.transform(const LineSplitter())
|
|
.first
|
|
.timeout(const Duration(seconds: 15));
|
|
} on TimeoutException {
|
|
process.kill();
|
|
await process.exitCode.timeout(const Duration(seconds: 5));
|
|
fail('MCP launcher did not respond within 15 seconds.\n${await errors}');
|
|
}
|
|
final response = jsonDecode(responseLine) as Map;
|
|
expect((response['result'] as Map)['isError'], false, reason: '$response');
|
|
expect(transform().x, closeTo(320 / session.canvas.width, 1e-9));
|
|
await process.stdin.close();
|
|
expect(await process.exitCode.timeout(const Duration(seconds: 5)), 0);
|
|
expect(await errors, isNot(contains('Could not connect')));
|
|
});
|
|
|
|
test('wrong bridge credentials cannot reach the editor', () async {
|
|
final bridge = await LocalMcpBridge.start(
|
|
access.server,
|
|
port: 0,
|
|
token: 'cutdex-test-token-01234567890123456789',
|
|
);
|
|
addTearDown(bridge.close);
|
|
final socket = await Socket.connect(
|
|
InternetAddress.loopbackIPv4,
|
|
bridge.port,
|
|
);
|
|
final before = session.commands.version;
|
|
socket.write(
|
|
'wrong\n${jsonEncode(_request('clip.setTransform', {...position(12), 'workspaceId': access.workspaces.keys.first, 'operationId': 'bad'}))}\n',
|
|
);
|
|
expect(
|
|
await socket
|
|
.fold<int>(0, (count, bytes) => count + bytes.length)
|
|
.timeout(const Duration(seconds: 5)),
|
|
0,
|
|
);
|
|
expect(session.commands.version, before);
|
|
socket.destroy();
|
|
});
|
|
|
|
test('endpoint replacement releases the port and ignores old page cleanup', () async {
|
|
const token = 'cutdex-test-token-01234567890123456789';
|
|
final endpoint = EditorMcpEndpoint();
|
|
addTearDown(endpoint.close);
|
|
final first = await endpoint.open(access.server, port: 0, token: token);
|
|
final second = await endpoint.open(
|
|
access.server,
|
|
port: first.port,
|
|
token: token,
|
|
);
|
|
await endpoint.release(first);
|
|
final socket = await Socket.connect(
|
|
InternetAddress.loopbackIPv4,
|
|
second.port,
|
|
);
|
|
socket.write(
|
|
'$token\n${jsonEncode(_request('timeline.query', {'workspaceId': access.workspaces.keys.first}))}\n',
|
|
);
|
|
final response = jsonDecode(
|
|
await socket
|
|
.cast<List<int>>()
|
|
.transform(utf8.decoder)
|
|
.transform(const LineSplitter())
|
|
.first,
|
|
) as Map;
|
|
expect((response['result'] as Map)['isError'], false, reason: '$response');
|
|
socket.destroy();
|
|
});
|
|
|
|
testWidgets(
|
|
'MCP refreshes inspector fields and invalidates an older input timeline',
|
|
(tester) async {
|
|
final query = session.view(sequence).version.kernelVersion.query();
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
editorPreviewProvider(
|
|
projectId,
|
|
'project',
|
|
).overrideWith((ref) async => throw StateError('No preview')),
|
|
],
|
|
child: MaterialApp(
|
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
locale: const Locale('zh'),
|
|
|
|
theme: EditorTheme.penLight,
|
|
home: Scaffold(
|
|
body: Align(
|
|
alignment: Alignment.topLeft,
|
|
child: SizedBox(
|
|
width: 225,
|
|
child: SingleChildScrollView(
|
|
child: PictureProperties(
|
|
projectId: projectId,
|
|
timelineId: 'project',
|
|
session: session,
|
|
sequence: sequence,
|
|
clip: query.element(query.elementById(ElementId('a'))!),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
Finder field(String key) => find.descendant(
|
|
of: find.byKey(ValueKey(key)),
|
|
matching: find.byType(TextField),
|
|
);
|
|
await tester.enterText(field('picture-x'), '999');
|
|
final connection = access.server.connect();
|
|
await tester.runAsync(() async {
|
|
await connection.handleJson(
|
|
jsonEncode(
|
|
_request('clip.setTransform', {
|
|
...position(192),
|
|
'workspaceId': access.workspaces.keys.first,
|
|
'operationId': 'inspector',
|
|
}),
|
|
),
|
|
);
|
|
await session.flush();
|
|
});
|
|
connection.close();
|
|
await tester.pump();
|
|
FocusManager.instance.primaryFocus?.unfocus();
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
double.parse(
|
|
tester.widget<TextField>(field('picture-x')).controller!.text,
|
|
),
|
|
192,
|
|
);
|
|
expect(
|
|
double.parse(
|
|
tester.widget<TextField>(field('picture-y')).controller!.text,
|
|
),
|
|
54,
|
|
);
|
|
expect(transform().x, closeTo(192 / session.canvas.width, 1e-9));
|
|
expect(tester.takeException(), isNull);
|
|
await tester.pumpWidget(const SizedBox());
|
|
},
|
|
);
|
|
}
|