Files
cutdex/test/export_publication_test.dart
T
lingjhf 38ca180cf7
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
refactor(core): own editor UI and pin verified native releases
2026-10-12 03:20:29 +08:00

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');
},
);
}