Files
sharedinbox/scripts/check_coverage.dart
T
Thomas SharedInboxandClaude Sonnet 4.6 04e65d2fba feat: secure account sharing via public-key encryption (#107)
Replace the insecure plaintext QR export/import flow with an
end-to-end-encrypted account-transfer mechanism:

- Receiver generates an ephemeral X25519 key pair (20-minute lifetime,
  stored in the new share_keys DB table at schema v31) and displays it
  as a QR code (sharedinbox.de:pubkey:v1:…).
- Sender scans the public-key QR, selects accounts (or auto-selects
  when only one exists), encrypts them with ECIES (X25519-ECDH +
  HKDF-SHA256 + AES-256-GCM) and displays an encrypted QR
  (sharedinbox.de:encrypted-accounts:v1:…).
- Receiver scans the encrypted QR, decrypts, verifies the 20-minute
  expiry and MAC authentication tag, then imports the accounts.

New screens: AccountReceiveScreen (/accounts/receive) and
AccountSendScreen (/accounts/send), accessible from the account-list
drawer and per-account popup menu respectively.

Remove the old insecure AccountExportScreen and AccountImportScreen.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-16 01:19:01 +02:00

148 lines
5.3 KiB
Dart

#!/usr/bin/env dart
// Checks that every non-excluded lib/ source file appears in coverage/lcov.info.
// Run after: flutter test test/unit/ --coverage
//
// To exclude a file add its lib-relative path to [_excluded] below.
import 'dart:io';
// Minimum line-hit percentage across all measured (non-excluded) files.
const _minCoveragePercent = 80;
// Pure-abstract interfaces: no executable code, Dart VM never instruments them.
const _noCode = {
'lib/core/repositories/account_repository.dart',
'lib/core/repositories/draft_repository.dart',
'lib/core/repositories/email_repository.dart',
'lib/core/repositories/mailbox_repository.dart',
'lib/core/repositories/share_key_repository.dart',
'lib/core/repositories/sync_log_repository.dart',
'lib/core/repositories/undo_repository.dart',
'lib/core/repositories/search_history_repository.dart',
'lib/core/models/undo_action.dart',
'lib/core/storage/secure_storage.dart',
};
// Files excluded from the unit-coverage gate because they require integration
// or widget tests (covered by `task integration` / `task test-flutter`).
const _excluded = {
'lib/data/db/database.dart',
'lib/data/imap/imap_client_factory.dart',
'lib/data/imap/managesieve_client.dart',
'lib/data/storage/flutter_secure_storage_impl.dart',
'lib/di.dart',
'lib/main.dart',
'lib/ui/router.dart',
'lib/ui/screens/account_list_screen.dart',
'lib/ui/screens/account_receive_screen.dart',
'lib/ui/screens/account_send_screen.dart',
'lib/ui/screens/add_account_screen.dart',
'lib/ui/screens/address_emails_screen.dart',
'lib/ui/screens/changelog_screen.dart',
'lib/ui/screens/compose_screen.dart',
'lib/ui/screens/crash_screen.dart',
'lib/ui/screens/edit_account_screen.dart',
'lib/ui/screens/email_detail_screen.dart',
'lib/ui/screens/email_list_screen.dart',
'lib/ui/screens/mailbox_list_screen.dart',
'lib/ui/screens/search_screen.dart',
'lib/ui/screens/sieve_script_edit_screen.dart',
'lib/ui/screens/sieve_scripts_screen.dart',
'lib/ui/screens/sync_log_screen.dart',
'lib/ui/screens/thread_detail_screen.dart',
'lib/ui/screens/undo_log_screen.dart',
'lib/ui/widgets/folder_drawer.dart',
'lib/ui/widgets/secure_email_webview.dart',
'lib/ui/widgets/snooze_picker.dart',
'lib/ui/widgets/try_connection_button.dart',
'lib/ui/widgets/undo_shell.dart',
'lib/core/sync/account_sync_manager.dart',
'lib/core/sync/background_sync.dart',
'lib/core/sync/reliability_runner.dart',
'lib/data/jmap/jmap_client.dart',
'lib/data/jmap/sieve_repository.dart',
'lib/data/repositories/account_repository_impl.dart',
'lib/data/repositories/email_repository_impl.dart',
'lib/data/repositories/mailbox_repository_impl.dart',
'lib/data/repositories/share_key_repository_impl.dart',
'lib/data/repositories/sync_log_repository_impl.dart',
'lib/data/repositories/undo_repository_impl.dart',
'lib/data/repositories/search_history_repository_impl.dart',
'lib/core/services/update_service.dart',
};
void main() {
// Check for ghost paths in _excluded and _noCode.
final allConfiguredPaths = {..._excluded, ..._noCode};
for (final path in allConfiguredPaths) {
if (!File(path).existsSync()) {
stderr.writeln('ERROR: Ghost path found in check_coverage.dart: $path');
exit(2);
}
}
final lcovFile = File('coverage/lcov.info');
final measuredFiles = lcovFile.existsSync()
? lcovFile
.readAsLinesSync()
.where((l) => l.startsWith('SF:'))
.map((l) => l.substring(3))
.toSet()
: <String>{};
final sourceFiles = Directory('lib')
.listSync(recursive: true)
.whereType<File>()
.where((f) => f.path.endsWith('.dart') && !f.path.endsWith('.g.dart'))
.map((f) => f.path.replaceFirst('./', ''))
.where((p) => !_excluded.contains(p) && !_noCode.contains(p))
.toList()
..sort();
final missing = sourceFiles.where((f) => !measuredFiles.contains(f)).toList();
if (missing.isNotEmpty) {
for (final f in missing) {
stderr.writeln('MISSING from coverage: $f');
}
stderr.writeln(
'ERROR: ${missing.length} file(s) missing from unit coverage.\n'
'Add a test or add to _excluded in scripts/check_coverage.dart.',
);
exit(1);
}
// Compute line-hit percentage, skipping excluded files so their 0% lines
// don't distort the number for genuinely tested code.
String? currentSf;
int total = 0, hits = 0;
for (final line in lcovFile.readAsLinesSync()) {
if (line.startsWith('SF:')) {
currentSf = line.substring(3);
} else if (line.startsWith('DA:') &&
currentSf != null &&
!_excluded.contains(currentSf) &&
!_noCode.contains(currentSf) &&
!currentSf.endsWith('.g.dart')) {
final count = int.parse(line.substring(3).split(',')[1]);
total++;
if (count > 0) hits++;
}
}
final pct = total > 0 ? (hits * 100 ~/ total) : 0;
final measuredCount =
measuredFiles.where((f) => !_excluded.contains(f)).length;
stdout.writeln(
'coverage: $pct% across $measuredCount measured files'
' (${_excluded.length} integration-excluded, ${_noCode.length} no-code'
' — see scripts/check_coverage.dart)',
);
if (pct < _minCoveragePercent) {
stderr.writeln(
'ERROR: coverage $pct% is below the required $_minCoveragePercent%.',
);
exit(1);
}
}