Files
sharedinbox/scripts/check_coverage.dart
T
87244de7da feat: group email headers in full-screen dialog (#374)
Closes #372

## What changed

- **New widget** `lib/ui/widgets/email_headers_dialog.dart`: full-screen header browser that organises headers into collapsible groups:
  - **Headers** — all standard headers (expanded by default)
  - **List- Headers** — all `List-*` headers grouped together (expanded)
  - **Received** — all `Received` headers, **collapsed by default**; shows the inter-hop duration between consecutive entries and highlights delays in colour (green < 30 s, orange < 5 min, red >= 5 min)
  - **ARC- Headers** — all `ARC-*` headers (above X-, expanded)
  - **X-Prefix Headers** — X- headers split by their second component (e.g. `X-Google-*` → "X-Google Headers"), sorted alphabetically, at the very bottom

- **`email_detail_screen.dart`**: `_showHeaders` now uses `EmailHeadersDialog`; `_showStructure` converted from `AlertDialog` to `Dialog.fullscreen()` — satisfying "Make popup windows full screen."

- **`scripts/check_coverage.dart`**: new widget file added to the `_excluded` set (UI widgets are covered by integration tests, not unit tests).

## Verified

`task check` passes (analyze: no issues, 491 unit tests pass, coverage >= 80 %).

Co-authored-by: Thomas SharedInbox <sharedinbox@thomas-guettler.de>
Reviewed-on: https://codeberg.org/guettli/sharedinbox/pulls/374
2026-06-03 22:14:14 +02:00

158 lines
5.7 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/db_schema_version.dart',
'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/repositories/user_preferences_repository.dart',
'lib/core/models/undo_action.dart',
'lib/core/models/user_preferences.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/ui/screens/about_screen.dart',
'lib/ui/screens/email_action_helpers.dart',
'lib/ui/utils/about_markdown.dart',
'lib/ui/widgets/email_headers_dialog.dart',
'lib/ui/widgets/email_tile.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/data/repositories/user_preferences_repository_impl.dart',
'lib/ui/screens/user_preferences_screen.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);
}
}