Files
SpotiFLAC-Mobile/test/platform_bridge_post_processing_test.dart
zarzet aa99726439 feat(backend): migrate production backend to Rust
Replace the Go backend with the Rust workspace and route Android/iOS through
UniFFI bindings. Include the migrated extension runtime, network, providers,
media metadata, downloads and library operations, with version 5.0.0+147.

Remove Go sources, adapters, native build selection and CI dependencies.
Build Rust unconditionally and lock the iOS Rust pod using a relative path.
Retain legacy source and migration evidence in a local ignored archive.

Validation: Android Kotlin compile and 53 native tests; Swift Rust-branch
equivalence and syntax; CocoaPods install; workflow, shell, Ruby, plist and
diff checks. Reuse the preceding 100 Rust tests, fmt/Clippy and five-ABI
build checkpoint; no new APK or iOS application build for this cleanup.

Known follow-up: URL/URLSearchParams globals are missing from the Rust JS
runtime. A controlled extension replay confirms a URL-resolution regression;
this commit does not fix that runtime gap.
2026-09-14 22:58:27 +07:00

94 lines
3.1 KiB
Dart

import 'dart:convert';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:spotiflac_android/services/platform_bridge.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
const channel = MethodChannel('com.zarz.spotiflac/backend');
tearDown(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, null);
});
test(
'native replacement is exposed to the download queue as file_path',
() async {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (call) async {
expect(call.method, 'runPostProcessingV2');
expect(call.arguments, {
'input': jsonEncode({
'item_id': 'queue-item',
'path': '/music/original.flac',
}),
'metadata': jsonEncode({'title': 'Example'}),
});
return jsonEncode({
'success': true,
'new_file_path': '/music/converted.m4a',
});
});
final result = await PlatformBridge.runPostProcessingV2(
'/music/original.flac',
metadata: {'title': 'Example'},
itemId: 'queue-item',
);
expect(result['file_path'], '/music/converted.m4a');
expect(result['new_file_path'], '/music/converted.m4a');
},
);
test(
'SAF keeps the destination URI instead of exposing a staging path',
() async {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (call) async {
expect(call.arguments, {
'input': jsonEncode({'uri': 'content://example/document/track'}),
'metadata': '',
});
return jsonEncode({
'success': true,
'new_file_path': '/cache/processed.flac',
'new_file_uri': 'content://example/document/track',
});
});
final result = await PlatformBridge.runPostProcessingV2(
'content://example/document/track',
);
expect(result['file_path'], 'content://example/document/track');
},
);
test(
'legacy results, no-op hooks and failures retain their contracts',
() async {
for (final response in <Map<String, dynamic>>[
{'success': true, 'file_path': '/music/legacy.flac'},
{'success': true, 'new_file_path': ''},
{'success': false, 'error': 'processing failed'},
]) {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(
channel,
(_) async => jsonEncode(response),
);
final result = await PlatformBridge.runPostProcessingV2(
'/music/original.flac',
);
if (response['success'] == true) {
expect(
result['file_path'],
response['file_path'] ?? '/music/original.flac',
);
} else {
expect(result, response);
}
}
},
);
}