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
86 lines
2.9 KiB
Dart
86 lines
2.9 KiB
Dart
import 'dart:io';
|
|
import 'dart:convert';
|
|
|
|
import 'package:crypto/crypto.dart';
|
|
import 'package:cutdex/integrations/runtime/export_publication.dart';
|
|
import 'package:cutdex_core/editor.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
void main() {
|
|
late Directory root;
|
|
setUp(
|
|
() async =>
|
|
root = await Directory.systemTemp.createTemp('export-recovery-'),
|
|
);
|
|
tearDown(() => root.delete(recursive: true));
|
|
test(
|
|
'published output is recovered repeatedly without encoding again',
|
|
() async {
|
|
final destination = File('${root.path}/result.mp4').uri;
|
|
var calls = 0;
|
|
Future<Uri> encode(Uri uri) async {
|
|
calls++;
|
|
await File.fromUri(uri).writeAsString('encoded movie');
|
|
return uri;
|
|
}
|
|
|
|
await ExportPublication(destination, 'op').run('snapshot', encode);
|
|
for (var i = 0; i < 3; i++) {
|
|
expect(
|
|
await ExportPublication(destination, 'op').run('snapshot', encode),
|
|
destination,
|
|
);
|
|
}
|
|
expect(calls, 1);
|
|
await expectLater(
|
|
ExportPublication(destination, 'op').run('other', encode),
|
|
throwsA(isA<CommandRejected>()),
|
|
);
|
|
},
|
|
);
|
|
test('ready staging receipt recovers the publication crash window', () async {
|
|
final destination = File('${root.path}/result.mp4').uri;
|
|
final job = ExportPublication(destination, 'op');
|
|
await job.directory.create();
|
|
final bytes = utf8.encode('complete movie');
|
|
await job.staged.writeAsBytes(bytes);
|
|
await job.receipt.writeAsString(
|
|
jsonEncode({
|
|
'operationId': 'op',
|
|
'destination': destination.toString(),
|
|
'fingerprint': 'snapshot',
|
|
'bytes': bytes.length,
|
|
'sha256': sha256.convert(bytes).toString(),
|
|
}),
|
|
);
|
|
expect(await ExportPublication(destination, 'op').recover(), destination);
|
|
expect(await job.staged.exists(), false);
|
|
expect(await File.fromUri(destination).readAsBytes(), bytes);
|
|
});
|
|
test(
|
|
'incomplete and externally changed output never silently overwrites',
|
|
() async {
|
|
final destination = File('${root.path}/result.mp4').uri;
|
|
final job = ExportPublication(destination, 'op');
|
|
await expectLater(
|
|
job.run('snapshot', (_) async => throw StateError('killed encoder')),
|
|
throwsStateError,
|
|
);
|
|
expect(await job.recover(), null);
|
|
await expectLater(
|
|
job.run('snapshot', (_) async => destination),
|
|
throwsA(isA<CommandRejected>()),
|
|
);
|
|
expect(await File.fromUri(destination).exists(), false);
|
|
final next = ExportPublication(destination, 'explicit-retry');
|
|
await next.run('snapshot', (uri) async {
|
|
await File.fromUri(uri).writeAsString('complete');
|
|
return uri;
|
|
});
|
|
await File.fromUri(destination).writeAsString('changed');
|
|
await expectLater(next.recover(), throwsA(isA<CommandRejected>()));
|
|
expect(await File.fromUri(destination).readAsString(), 'changed');
|
|
},
|
|
);
|
|
}
|