Gitea CI / Check code and tests (pull_request) Failing after 8s
Gitea CI / Build Android APK (pull_request) Skipped
Gitea CI / Build Windows x64 app (pull_request) Skipped
Gitea CI / Audit and package Windows x64 (pull_request) Skipped
Gitea CI / Assemble and validate CI artifacts (pull_request) Skipped
Gitea CI / Gitea CI passed (pull_request) Failing after 1s
393 lines
14 KiB
Dart
393 lines
14 KiB
Dart
import '../test/support/creation_names.dart';
|
|
|
|
import 'dart:io';
|
|
import 'dart:convert';
|
|
|
|
import 'package:cutdex/integrations/runtime/processing_configuration.dart';
|
|
import 'package:cutdex/workspace/persistence/project_workspace.dart';
|
|
import 'package:cutdex/workspace/timeline_session.dart';
|
|
import 'package:cutdex_core/editor.dart';
|
|
import 'package:cutdex_preview/cutdex_preview.dart';
|
|
import 'package:cutdex_native_flutter/cutdex_native_flutter.dart';
|
|
import 'package:cutdex_core/timeline/model.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:integration_test/integration_test.dart';
|
|
|
|
const source = String.fromEnvironment('CUTDEX_ASR_FIXTURE');
|
|
const packageRoot = String.fromEnvironment('CUTDEX_PROCESSING_ROOT');
|
|
Future<void> until(
|
|
bool Function() done, {
|
|
Duration timeout = const Duration(minutes: 4),
|
|
}) async {
|
|
final watch = Stopwatch()..start();
|
|
while (!done()) {
|
|
if (watch.elapsed > timeout) {
|
|
throw StateError('Timed out waiting for processing');
|
|
}
|
|
await Future<void>.delayed(const Duration(milliseconds: 30));
|
|
}
|
|
}
|
|
|
|
Future<List<String>> workers() async {
|
|
final List<String> processes;
|
|
if (Platform.isWindows) {
|
|
final result = await Process.run('powershell.exe', [
|
|
'-NoProfile',
|
|
'-Command',
|
|
r"Get-CimInstance Win32_Process | Where-Object { $_.Name -match '^(cutdex-(processing|asr|audio|m2m100)-worker|ffmpeg)\.exe$' } | Select-Object -ExpandProperty ExecutablePath | ConvertTo-Json -Compress",
|
|
]);
|
|
if (result.exitCode != 0) throw StateError('${result.stderr}');
|
|
final output = (result.stdout as String).trim();
|
|
final decoded = output.isEmpty ? null : jsonDecode(output);
|
|
processes = switch (decoded) {
|
|
null => [],
|
|
String path => [path],
|
|
List<Object?> paths => paths.cast<String>(),
|
|
_ => throw StateError('Unexpected Windows process inventory'),
|
|
};
|
|
} else {
|
|
final result = await Process.run('/bin/ps', ['-axo', 'pid=,command=']);
|
|
if (result.exitCode != 0) throw StateError('${result.stderr}');
|
|
processes = (result.stdout as String).split('\n');
|
|
}
|
|
final normalizedRoot = packageRoot.replaceAll(r'\', '/').toLowerCase();
|
|
return processes.where((line) {
|
|
final normalized = line.replaceAll(r'\', '/').toLowerCase();
|
|
return normalized.contains('$normalizedRoot/') &&
|
|
RegExp(r'(cutdex-(processing|asr|audio|m2m100)-worker|/ffmpeg)')
|
|
.hasMatch(normalized);
|
|
}).toList();
|
|
}
|
|
|
|
Future<void> workerStarted(bool Function() terminal, String worker) async {
|
|
final watch = Stopwatch()..start();
|
|
while (!(await workers()).any((line) => line.contains(worker))) {
|
|
if (terminal() || watch.elapsed > const Duration(seconds: 30)) {
|
|
throw StateError('No live worker observed');
|
|
}
|
|
await Future<void>.delayed(const Duration(milliseconds: 20));
|
|
}
|
|
}
|
|
|
|
Future<
|
|
({
|
|
ProjectWorkspace workspace,
|
|
EditorTimelineSession session,
|
|
Directory root,
|
|
String projectId,
|
|
String assetId,
|
|
})
|
|
>
|
|
fixture() async {
|
|
final config = ProcessingConfiguration.configured()!;
|
|
expect(config.transcriptionModel, isNotNull);
|
|
expect(config.translationModel, isNotNull);
|
|
expect(config.vocalSeparationModel, isNotNull);
|
|
final root = await Directory.systemTemp.createTemp('cutdex-real-processing-');
|
|
final workspace = ProjectWorkspace(
|
|
creationNames: testCreationNames,
|
|
processing: config,
|
|
);
|
|
await workspace.open('${root.path}/Test.cutdex', name: 'Real processing');
|
|
final timelines = await workspace.createTimeline('Speech');
|
|
final project = workspace.project!;
|
|
final imported = await project.importFile(File(source), name: 'Speech');
|
|
final document = await workspace.loadTimeline(
|
|
project.info.id,
|
|
timelines.single.id,
|
|
);
|
|
final session = await workspace.openTimelineSession(
|
|
project.info.id,
|
|
document,
|
|
);
|
|
final media = await workspace.prepareMedia(project.info.id, imported.id);
|
|
session.insertAsset(
|
|
sequenceId: session.activeSequenceId!,
|
|
assetId: imported.id,
|
|
assetName: 'Speech',
|
|
uri: media.uri,
|
|
duration: media.duration,
|
|
position: 0,
|
|
kind: 'audio',
|
|
hasAudio: true,
|
|
clipId: ElementId('speech'),
|
|
);
|
|
return (
|
|
workspace: workspace,
|
|
session: session,
|
|
root: root,
|
|
projectId: project.info.id,
|
|
assetId: imported.id,
|
|
);
|
|
}
|
|
|
|
Future<void> play(EditorTimelineSession session) async {
|
|
session.view(session.activeSequenceId!).seekTo(0);
|
|
final preview = PreviewController(
|
|
timeline: session,
|
|
activeSequence: () => session.activeSequenceId,
|
|
viewForSequence: session.view,
|
|
runtime: CutdexRuntime(),
|
|
);
|
|
try {
|
|
await preview.initialize();
|
|
expect(preview.error, isNull);
|
|
expect(preview.ready, isTrue);
|
|
await preview.controlPreview(session.activeSequenceId!, PreviewAction.play);
|
|
await until(
|
|
() =>
|
|
preview.positionTick > TimelineClock.ticksPerSecond ~/ 5 ||
|
|
preview.error != null,
|
|
timeout: const Duration(seconds: 15),
|
|
);
|
|
expect(preview.error, isNull);
|
|
expect(preview.positionTick, greaterThan(0));
|
|
await preview.controlPreview(
|
|
session.activeSequenceId!,
|
|
PreviewAction.pause,
|
|
);
|
|
} finally {
|
|
await preview.close();
|
|
}
|
|
}
|
|
|
|
void main() {
|
|
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
|
testWidgets(
|
|
'real recognition, independent translation, stems and native playback',
|
|
(tester) async {
|
|
final f = await fixture();
|
|
try {
|
|
final session = f.session;
|
|
final sequence = session.activeSequenceId!;
|
|
final service = session.transcriptions!;
|
|
final recognition = await service.start(
|
|
StartTranscription(mediaId: f.assetId, language: 'en', threads: 2),
|
|
);
|
|
await until(() => recognition.terminal);
|
|
expect(
|
|
recognition.status,
|
|
TranscriptionStatus.succeeded,
|
|
reason: recognition.error,
|
|
);
|
|
expect(recognition.result!.cues, isNotEmpty);
|
|
final recognized = await session.applyTranscription(
|
|
sequence,
|
|
ApplyTranscription(taskId: recognition.id, clipId: 'speech'),
|
|
);
|
|
final recognizedIds = (recognized['captionIds'] as List).cast<String>();
|
|
expect(recognizedIds, hasLength(recognition.result!.cues.length));
|
|
expect(
|
|
session.caption(sequence, recognizedIds.first).text,
|
|
recognition.result!.cues.first.text,
|
|
);
|
|
service.configure(
|
|
backend: null,
|
|
modelDirectory: null,
|
|
translationBackend: service.translationBackend,
|
|
translationModel: service.translationModel,
|
|
);
|
|
expect(service.recognitionAvailable, isFalse);
|
|
final translation = await service.startTranslation(
|
|
StartSubtitleTranslation(
|
|
source: recognition.result!.subtitles.toFilePath(),
|
|
sourceLanguage: 'en',
|
|
targetLanguage: 'zh',
|
|
threads: 2,
|
|
),
|
|
);
|
|
await until(() => translation.terminal);
|
|
expect(
|
|
translation.status,
|
|
TranscriptionStatus.succeeded,
|
|
reason: translation.error,
|
|
);
|
|
expect(translation.result!.document.cues, isNotEmpty);
|
|
final translated = await session.applySubtitleTranslation(
|
|
sequence,
|
|
ApplySubtitleTranslation(
|
|
taskId: translation.id,
|
|
clipId: 'speech',
|
|
source: recognition.source!.toFilePath(),
|
|
sourceStartMs: recognition.sourceStartMs,
|
|
),
|
|
);
|
|
final translatedIds = (translated['captionIds'] as List).cast<String>();
|
|
expect(
|
|
translatedIds,
|
|
hasLength(translation.result!.document.cues.length),
|
|
);
|
|
expect(
|
|
session.caption(sequence, translatedIds.first).text,
|
|
translation.result!.document.cues.first.text,
|
|
);
|
|
await play(session);
|
|
final separated = await session.vocalSeparations!.start(
|
|
StartVocalSeparation(mediaId: f.assetId, threads: 2),
|
|
);
|
|
await until(() => separated.terminal);
|
|
expect(
|
|
separated.status,
|
|
VocalSeparationStatus.succeeded,
|
|
reason: separated.error,
|
|
);
|
|
for (final uri in [
|
|
separated.result!.vocals,
|
|
separated.result!.instrumental,
|
|
]) {
|
|
expect(await File.fromUri(uri).length(), greaterThan(44));
|
|
final info = await CutdexRuntime().probe(
|
|
MediaReference(id: 'stem', uri: uri),
|
|
);
|
|
expect(info.audioTrackCount, greaterThan(0));
|
|
expect(
|
|
info.duration.seconds,
|
|
closeTo(recognition.result!.durationMs / 1000, 0.1),
|
|
);
|
|
}
|
|
await session.applyVocalSeparation(
|
|
sequence,
|
|
ApplyVocalSeparation(
|
|
taskId: separated.id,
|
|
clipId: 'speech',
|
|
stems: VocalStem.values,
|
|
insertIntoTimeline: true,
|
|
),
|
|
);
|
|
expect(await f.workspace.listAssets(f.projectId), hasLength(3));
|
|
await play(session);
|
|
await session.flush();
|
|
expect(await workers(), isEmpty);
|
|
} finally {
|
|
await f.workspace.close();
|
|
await f.root.delete(recursive: true);
|
|
}
|
|
},
|
|
skip: !(Platform.isMacOS || Platform.isWindows) || source.isEmpty,
|
|
timeout: const Timeout(Duration(minutes: 12)),
|
|
);
|
|
for (final capability in ['asr', 'translation', 'audio']) {
|
|
for (final action in [
|
|
'cancel',
|
|
'closeTimeline',
|
|
'switchProjectThenClose',
|
|
]) {
|
|
testWidgets(
|
|
'real $capability $action reaps processes and avoids partial publication',
|
|
(tester) async {
|
|
final f = await fixture();
|
|
try {
|
|
final destination = '${f.root.path}/cancel-output';
|
|
late bool Function() terminal;
|
|
late void Function() cancel;
|
|
late String Function() status;
|
|
late String worker;
|
|
switch (capability) {
|
|
case 'asr':
|
|
final task = await f.session.transcriptions!.start(
|
|
StartTranscription(
|
|
mediaId: f.assetId,
|
|
language: 'en',
|
|
threads: 2,
|
|
destination: destination,
|
|
),
|
|
);
|
|
terminal = () => task.terminal;
|
|
cancel = () => f.session.transcriptions!.cancel(task.id);
|
|
status = () => task.status.name;
|
|
worker = 'cutdex-asr-worker';
|
|
case 'translation':
|
|
final input = File('${f.root.path}/input.json');
|
|
await input.writeAsString(
|
|
jsonEncode({
|
|
'schemaVersion': 1,
|
|
'language': 'en',
|
|
'cues': [
|
|
{
|
|
'startMs': 0,
|
|
'endMs': 1000,
|
|
'text': 'This is a short translation test.',
|
|
},
|
|
],
|
|
}),
|
|
);
|
|
final task = await f.session.transcriptions!.startTranslation(
|
|
StartSubtitleTranslation(
|
|
source: input.path,
|
|
sourceLanguage: 'en',
|
|
targetLanguage: 'zh',
|
|
threads: 2,
|
|
destination: destination,
|
|
),
|
|
);
|
|
terminal = () => task.terminal;
|
|
cancel = () =>
|
|
f.session.transcriptions!.cancelTranslation(task.id);
|
|
status = () => task.status.name;
|
|
worker = 'cutdex-m2m100-worker';
|
|
case 'audio':
|
|
final task = await f.session.vocalSeparations!.start(
|
|
StartVocalSeparation(
|
|
mediaId: f.assetId,
|
|
threads: 2,
|
|
destination: destination,
|
|
),
|
|
);
|
|
terminal = () => task.terminal;
|
|
cancel = () => f.session.vocalSeparations!.cancel(task.id);
|
|
status = () => task.status.name;
|
|
worker = 'cutdex-audio-worker';
|
|
}
|
|
await workerStarted(terminal, worker);
|
|
switch (action) {
|
|
case 'cancel':
|
|
cancel();
|
|
await until(terminal);
|
|
case 'closeTimeline':
|
|
await f.session.close();
|
|
case 'switchProjectThenClose':
|
|
await f.workspace.open(
|
|
'${f.root.path}/Other.cutdex',
|
|
name: 'Other',
|
|
);
|
|
expect(f.session.acceptsEdits, isTrue);
|
|
await f.session.close();
|
|
}
|
|
expect(status(), action == 'cancel' ? 'cancelled' : 'interrupted');
|
|
expect(await workers(), isEmpty);
|
|
expect(await Directory(destination).exists(), isFalse);
|
|
final staging = await f.root
|
|
.list()
|
|
.where(
|
|
(entry) => entry.uri.pathSegments
|
|
.where((segment) => segment.isNotEmpty)
|
|
.last
|
|
.startsWith('.cutdex-'),
|
|
)
|
|
.toList();
|
|
if (action == 'cancel' || capability == 'translation') {
|
|
expect(
|
|
staging,
|
|
isEmpty,
|
|
reason: 'Disposable staging must be removed',
|
|
);
|
|
} else {
|
|
// Host interruption preserves a resumable ASR/audio checkpoint, not a published result.
|
|
expect(staging, hasLength(1));
|
|
expect(
|
|
await File('${staging.single.path}/checkpoint.json').exists(),
|
|
isTrue,
|
|
);
|
|
}
|
|
} finally {
|
|
await f.workspace.close();
|
|
await f.root.delete(recursive: true);
|
|
}
|
|
},
|
|
skip: !(Platform.isMacOS || Platform.isWindows) || source.isEmpty,
|
|
timeout: const Timeout(Duration(minutes: 2)),
|
|
);
|
|
}
|
|
}
|
|
}
|