feat(workspace): add workflow navigation and resizable desktop panels
This commit is contained in:
1 parent
02413383d8
commit
1acfe4a005
17 files changed
+2008
-277
No files matched your search
@@ -0,0 +1,264 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:cutdex/app/app.dart';
|
||||
import 'package:cutdex/integrations/agent/conversation_repository.dart';
|
||||
import 'package:cutdex/integrations/platform/device_experience.dart';
|
||||
import 'package:cutdex/persistence/app_database.dart';
|
||||
import 'package:cutdex/persistence/settings/view_settings_repositories.dart';
|
||||
import 'package:cutdex/workspace/projects.dart';
|
||||
import 'package:cutdex/workspace/view_settings.dart';
|
||||
import 'package:cutdex/workspace/workspace_mode.dart';
|
||||
import 'package:cutdex_sdk/project.dart';
|
||||
import 'package:cutdex_sdk/timeline/model.dart';
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:integration_test/integration_test.dart';
|
||||
|
||||
import '../test/support/empty_conversation_repository.dart';
|
||||
import '../test/support/preview_fixture.dart';
|
||||
|
||||
/// Run with flutter drive --profile on macOS and test_driver/integration_test.dart.
|
||||
/// Define CUTDEX_RESIZE_SOURCE (an image) and CUTDEX_RESIZE_REPORT (JSON output).
|
||||
/// Widget-test timings are not comparable to these real-engine measurements.
|
||||
void main() {
|
||||
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
||||
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive;
|
||||
const source = String.fromEnvironment('CUTDEX_RESIZE_SOURCE');
|
||||
const output = String.fromEnvironment('CUTDEX_RESIZE_REPORT');
|
||||
const rounds = int.fromEnvironment('CUTDEX_RESIZE_ROUNDS', defaultValue: 3);
|
||||
const inputHz = 120;
|
||||
const inputCount = 240;
|
||||
const clipCount = 64;
|
||||
const assetCount = 100;
|
||||
|
||||
testWidgets('profile full desktop workspace split and junction dragging', (
|
||||
tester,
|
||||
) async {
|
||||
expect(kProfileMode, isTrue, reason: 'Use flutter drive --profile');
|
||||
expect(Platform.isMacOS, isTrue);
|
||||
expect(await File(source).exists(), isTrue);
|
||||
final ids = List.generate(clipCount, (i) => ElementId('clip-$i'));
|
||||
final fixture = await createPreviewFixture(
|
||||
File(source).uri,
|
||||
mediaType: 'image',
|
||||
renderSize: {'width': 1280, 'height': 720},
|
||||
timelineOverride: TimelineDto(
|
||||
id: SequenceId('one'),
|
||||
name: 'Resize profiling',
|
||||
format: TimelineFormat.fps30,
|
||||
primaryStorylineId: StorylineId('primary'),
|
||||
storylines: [StorylineDto(id: StorylineId('primary'), elementIds: ids)],
|
||||
elements: [
|
||||
for (final (i, id) in ids.indexed)
|
||||
ElementDto(
|
||||
id: id,
|
||||
name: 'Clip $i',
|
||||
structure: ElementStructure.content,
|
||||
payloadRef: PayloadRef('source'),
|
||||
duration: RationalTime.seconds(2),
|
||||
sourceRange: TimeRange(
|
||||
start: RationalTime.zero,
|
||||
duration: RationalTime.seconds(2),
|
||||
),
|
||||
mediaRange: TimeRange(
|
||||
start: RationalTime.zero,
|
||||
duration: RationalTime.seconds(2),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
for (var i = 0; i < assetCount; i++) {
|
||||
await fixture.workspace.project!.saveAsset(
|
||||
AssetDocument(
|
||||
id: i == 0 ? 'media' : 'media-$i',
|
||||
name: 'Image $i',
|
||||
storage: AssetStorage.external,
|
||||
location: File(source).uri.toString(),
|
||||
metadata: {'kind': 'image'},
|
||||
),
|
||||
);
|
||||
}
|
||||
final projectPath = '${fixture.directory.path}/Preview.cutdex';
|
||||
await fixture.workspace.close();
|
||||
final database = AppDatabase(
|
||||
NativeDatabase(File('${fixture.directory.path}/settings.sqlite')),
|
||||
);
|
||||
final workspaceWrites = _CountWorkspaceWrites(
|
||||
DriftWorkspaceViewSettingsRepository(database),
|
||||
);
|
||||
final projectWrites = _CountProjectWrites(
|
||||
DriftProjectViewSettingsRepository(database),
|
||||
);
|
||||
final container = ProviderContainer(
|
||||
overrides: [
|
||||
appDatabaseProvider.overrideWithValue(database),
|
||||
deviceExperienceProvider.overrideWithValue(DeviceExperience.desktop),
|
||||
workspaceViewSettingsRepositoryProvider.overrideWithValue(
|
||||
workspaceWrites,
|
||||
),
|
||||
projectViewSettingsRepositoryProvider.overrideWithValue(projectWrites),
|
||||
conversationRepositoryProvider.overrideWith(
|
||||
(ref) async => EmptyConversationRepository(),
|
||||
),
|
||||
],
|
||||
);
|
||||
addTearDown(() async {
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
await container.read(projectsProvider.notifier).prepareToQuit();
|
||||
container.dispose();
|
||||
await database.close();
|
||||
await fixture.directory.delete(recursive: true);
|
||||
});
|
||||
await container.read(workspaceViewSettingsProvider.future);
|
||||
container
|
||||
.read(workspaceViewSettingsProvider.notifier)
|
||||
.setMode(WorkspaceMode.cut);
|
||||
expect(
|
||||
await container.read(projectsProvider.notifier).open(projectPath),
|
||||
isTrue,
|
||||
);
|
||||
// This is the normal app/router/editor, with only isolated storage and chat.
|
||||
// ignore: riverpod_lint/provider_scope_placement
|
||||
await tester.pumpWidget(
|
||||
UncontrolledProviderScope(container: container, child: const CutdexApp()),
|
||||
);
|
||||
await const MethodChannel('cutdex_native/window')
|
||||
.invokeMethod<void>('toggleMaximize');
|
||||
final readyClock = Stopwatch()..start();
|
||||
final junction = find.byKey(const Key('desktop-chat-timeline-junction'));
|
||||
while (junction.evaluate().isEmpty) {
|
||||
if (readyClock.elapsed.inSeconds > 60) {
|
||||
throw TimeoutException('Desktop editor did not open');
|
||||
}
|
||||
await tester.pump();
|
||||
await Future<void>.delayed(const Duration(milliseconds: 16));
|
||||
}
|
||||
await Future<void>.delayed(const Duration(seconds: 3));
|
||||
final size = tester.view.physicalSize / tester.view.devicePixelRatio;
|
||||
expect(size.width, greaterThan(1100));
|
||||
final results = <String, dynamic>{
|
||||
'mode': 'profile',
|
||||
'platform': Platform.operatingSystemVersion,
|
||||
'logicalSize': [size.width, size.height],
|
||||
'pixelRatio': tester.view.devicePixelRatio,
|
||||
'displayRefreshHz': tester.view.display.refreshRate,
|
||||
'inputHz': inputHz,
|
||||
'inputsPerDrag': inputCount,
|
||||
'clips': clipCount,
|
||||
'assets': assetCount,
|
||||
'scope': 'Full app, native still-image preview, file-backed SQLite; synthetic mouse input',
|
||||
'runs': <Map<String, dynamic>>[],
|
||||
};
|
||||
final report = File(output);
|
||||
await report.parent.create(recursive: true);
|
||||
Future<void> save() => report.writeAsString(
|
||||
const JsonEncoder.withIndent(' ').convert(results),
|
||||
);
|
||||
await save();
|
||||
const scenarios = {
|
||||
'sidebar': ('project-sidebar-resize', Offset(55, 0)),
|
||||
'media': ('editor-media-resize', Offset(65, 0)),
|
||||
'timeline': ('editor-timeline-resize', Offset(0, 80)),
|
||||
'mediaJunction': ('editor-media-timeline-junction', Offset(65, 80)),
|
||||
'chatJunction': ('desktop-chat-timeline-junction', Offset(55, 80)),
|
||||
};
|
||||
for (var round = 0; round < rounds; round++) {
|
||||
for (final entry in scenarios.entries) {
|
||||
final (key, amplitude) = entry.value;
|
||||
final reportKey = '${entry.key}-$round';
|
||||
final start = tester.getCenter(find.byKey(Key(key)));
|
||||
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
await mouse.addPointer(location: start);
|
||||
await Future<void>.delayed(const Duration(milliseconds: 250));
|
||||
final writesBefore = workspaceWrites.count;
|
||||
final projectWritesBefore = projectWrites.count;
|
||||
final dispatchTimes = <int>[];
|
||||
await binding.watchPerformance(() async {
|
||||
await mouse.down(start);
|
||||
final clock = Stopwatch()..start();
|
||||
for (var i = 1; i <= inputCount; i++) {
|
||||
final dueUs = (i * 1000000 / inputHz).round();
|
||||
final waitUs = dueUs - clock.elapsedMicroseconds;
|
||||
if (waitUs > 0) {
|
||||
await Future<void>.delayed(Duration(microseconds: waitUs));
|
||||
}
|
||||
final dispatch = Stopwatch()..start();
|
||||
await mouse.moveTo(
|
||||
start + amplitude * math.sin(2 * math.pi * i / inputCount),
|
||||
);
|
||||
dispatchTimes.add(dispatch.elapsedMicroseconds);
|
||||
}
|
||||
await mouse.up();
|
||||
await mouse.removePointer();
|
||||
}, reportKey: reportKey);
|
||||
// Allow queued persistence writes and batched engine timings to arrive.
|
||||
await Future<void>.delayed(const Duration(seconds: 1));
|
||||
final timings = Map<String, dynamic>.from(
|
||||
binding.reportData![reportKey] as Map,
|
||||
);
|
||||
final build = List<int>.from(timings['frame_build_times'] as List);
|
||||
final raster = List<int>.from(
|
||||
timings['frame_rasterizer_times'] as List,
|
||||
);
|
||||
int overBudget(int budgetUs) => List.generate(
|
||||
build.length,
|
||||
(i) => i,
|
||||
).where((i) => build[i] > budgetUs || raster[i] > budgetUs).length;
|
||||
final row = <String, dynamic>{
|
||||
'scenario': entry.key,
|
||||
'round': round,
|
||||
'workspaceWrites': workspaceWrites.count - writesBefore,
|
||||
'projectWrites': projectWrites.count - projectWritesBefore,
|
||||
'over16ms': overBudget(16667),
|
||||
'over8ms': overBudget(8333),
|
||||
'dispatchUs': dispatchTimes,
|
||||
'timings': timings,
|
||||
};
|
||||
(results['runs'] as List).add(row);
|
||||
await save();
|
||||
debugPrint(
|
||||
'RESIZE_PROFILE ${entry.key} $round frames=${build.length} '
|
||||
'over16ms=${row['over16ms']} writes=${row['workspaceWrites']}',
|
||||
);
|
||||
}
|
||||
}
|
||||
results['status'] = 'passed';
|
||||
await save();
|
||||
expect(tester.takeException(), isNull);
|
||||
}, skip: !Platform.isMacOS || source.isEmpty || output.isEmpty);
|
||||
}
|
||||
|
||||
class _CountWorkspaceWrites implements WorkspaceViewSettingsRepository {
|
||||
_CountWorkspaceWrites(this.delegate);
|
||||
final WorkspaceViewSettingsRepository delegate;
|
||||
int count = 0;
|
||||
@override
|
||||
Future<WorkspaceViewSettingsData> load() => delegate.load();
|
||||
@override
|
||||
Future<void> save(WorkspaceViewSettingsData settings) {
|
||||
count++;
|
||||
return delegate.save(settings);
|
||||
}
|
||||
}
|
||||
|
||||
class _CountProjectWrites implements ProjectViewSettingsRepository {
|
||||
_CountProjectWrites(this.delegate);
|
||||
final ProjectViewSettingsRepository delegate;
|
||||
int count = 0;
|
||||
@override
|
||||
Future<ProjectViewSettingsData> load(String id) => delegate.load(id);
|
||||
@override
|
||||
Future<void> save(String id, ProjectViewSettingsData settings) {
|
||||
count++;
|
||||
return delegate.save(id, settings);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user