Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Trim device health tests

Neeraj Guptafded92bc003b
diff --git a/mobile/apps/photos/integration_test/device_health_test.dart b/mobile/apps/photos/integration_test/device_health_test.dart
deleted file mode 100644
index b84b7e4b7f..0000000000
--- a/mobile/apps/photos/integration_test/device_health_test.dart
+++ /dev/null
@@ -1,28 +0,0 @@
-import 'dart:io';
-
-import 'package:ente_photos_platform/ente_photos_platform.dart';
-import 'package:flutter_test/flutter_test.dart';
-import 'package:integration_test/integration_test.dart';
-
-void main() {
- IntegrationTestWidgetsFlutterBinding.ensureInitialized();
-
- testWidgets('native device health snapshot is current and usable', (
- tester,
- ) async {
- final snapshot = await DeviceHealthClient.instance.getSnapshot();
- final memory = await DeviceHealthClient.instance.getMemorySnapshot();
- final now = DateTime.now();
-
- expect(snapshot.isFreshAt(now, const Duration(seconds: 10)), isTrue);
- expect(memory.status, DeviceSignalStatus.available);
- expect(memory.totalBytes, greaterThan(0));
- expect(snapshot.thermal.status, isNot(DeviceSignalStatus.unavailable));
- if (Platform.isAndroid) {
- expect(snapshot.platform, DeviceHealthPlatform.android);
- expect(snapshot.battery.status, DeviceSignalStatus.available);
- } else if (Platform.isIOS) {
- expect(snapshot.platform, DeviceHealthPlatform.ios);
- }
- });
-}
diff --git a/mobile/apps/photos/plugins/ente_photos_platform/test/device_health_test.dart b/mobile/apps/photos/plugins/ente_photos_platform/test/device_health_test.dart
index 01d38d611f..dd0a428831 100644
--- a/mobile/apps/photos/plugins/ente_photos_platform/test/device_health_test.dart
+++ b/mobile/apps/photos/plugins/ente_photos_platform/test/device_health_test.dart
@@ -1,118 +1,33 @@
import 'package:ente_photos_platform/ente_photos_platform.dart';
-import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
- TestWidgetsFlutterBinding.ensureInitialized();
-
- test('parses a complete Android observation', () {
- final snapshot = DeviceHealthSnapshot.fromMap(
- _snapshotMap(platform: 'android'),
- );
-
- expect(snapshot.platform, DeviceHealthPlatform.android);
- expect(snapshot.battery.levelPercent, 64);
- expect(snapshot.battery.temperatureCelsius, 31.5);
- expect(snapshot.battery.health, DeviceBatteryHealth.good);
- expect(snapshot.thermal.state, DeviceThermalState.moderate);
- });
-
- test('accepts iOS battery observations without private metrics', () {
- final snapshot = DeviceHealthSnapshot.fromMap(
- _snapshotMap(
- platform: 'ios',
- battery: {'status': 'available', 'levelPercent': 80},
- ),
- );
-
- expect(snapshot.battery.temperatureCelsius, isNull);
- expect(snapshot.battery.health, isNull);
- });
-
- test('rejects available battery observations without a valid level', () {
- expect(
- () => DeviceHealthSnapshot.fromMap(
- _snapshotMap(battery: {'status': 'available'}),
- ),
- throwsFormatException,
- );
- expect(
- () => DeviceHealthSnapshot.fromMap(
- _snapshotMap(battery: {'status': 'available', 'levelPercent': 101}),
- ),
- throwsFormatException,
- );
- });
-
- test('rejects values attached to unavailable signals', () {
- expect(
- () => DeviceHealthSnapshot.fromMap(
- _snapshotMap(thermal: {'status': 'unsupported', 'state': 'nominal'}),
- ),
- throwsFormatException,
- );
- });
-
- test('requires errors only for unavailable signals', () {
- expect(
- () => DeviceHealthSnapshot.fromMap(
- _snapshotMap(battery: {'status': 'unavailable'}),
- ),
- throwsFormatException,
- );
+ test('validates native signal payloads', () {
expect(
- () => DeviceHealthSnapshot.fromMap(
- _snapshotMap(
- thermal: {
- 'status': 'available',
- 'state': 'nominal',
- 'errorCode': 'unexpected',
- },
- ),
- ),
- throwsFormatException,
- );
- });
-
- test('source requests typed health and memory snapshots', () async {
- const channel = MethodChannel('device-health-source-test');
- final methods = <String>[];
- TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
- .setMockMethodCallHandler(channel, (call) async {
- methods.add(call.method);
- return switch (call.method) {
- 'deviceHealth.getSnapshot' => _snapshotMap(),
- 'deviceHealth.getMemorySnapshot' => {
- 'status': 'available',
- 'totalBytes': 8 * 1024 * 1024 * 1024,
- },
- _ => throw MissingPluginException(),
- };
- });
- addTearDown(
- () => TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
- .setMockMethodCallHandler(channel, null),
- );
-
- final source = DeviceHealthClient(methodChannel: channel);
- expect((await source.getSnapshot()).battery.levelPercent, 64);
- expect(
- (await source.getMemorySnapshot()).totalBytes,
- 8 * 1024 * 1024 * 1024,
- );
- expect(methods, [
- 'deviceHealth.getSnapshot',
- 'deviceHealth.getMemorySnapshot',
- ]);
+ DeviceHealthSnapshot.fromMap(_snapshotMap()).battery.levelPercent,
+ 64,
+ );
+
+ final invalidSnapshots = [
+ _snapshotMap(battery: {'status': 'available'}),
+ _snapshotMap(battery: {'status': 'unavailable'}),
+ _snapshotMap(thermal: {'status': 'unsupported', 'state': 'nominal'}),
+ ];
+
+ for (final snapshot in invalidSnapshots) {
+ expect(
+ () => DeviceHealthSnapshot.fromMap(snapshot),
+ throwsFormatException,
+ );
+ }
});
}
Map<String, Object?> _snapshotMap({
- String platform = 'android',
Map<String, Object?>? battery,
Map<String, Object?>? thermal,
}) => {
- 'platform': platform,
+ 'platform': 'android',
'observedAtMs': 1800000000000,
'battery':
battery ??
diff --git a/mobile/apps/photos/test/services/machine_learning/device_health_policy_test.dart b/mobile/apps/photos/test/services/machine_learning/device_health_policy_test.dart
index b1d6920549..ec74dbce37 100644
--- a/mobile/apps/photos/test/services/machine_learning/device_health_policy_test.dart
+++ b/mobile/apps/photos/test/services/machine_learning/device_health_policy_test.dart
@@ -8,72 +8,33 @@ void main() {
Set<DeviceHealthIssue> issues(DeviceHealthSnapshot snapshot) =>
policy.evaluate(snapshot, now: now).issues;
- test('accepts fresh healthy Android evidence', () {
- expect(issues(_snapshot(now)), isEmpty);
- });
-
- test('rejects stale and future observations', () {
- for (final observedAt in [
- now.subtract(const Duration(minutes: 3)),
- now.add(const Duration(milliseconds: 1)),
- ]) {
- expect(issues(_snapshot(observedAt)), {
- DeviceHealthIssue.staleObservation,
- });
- }
- });
-
- test('rejects unavailable or low battery evidence', () {
- expect(
- issues(
- _snapshot(
- now,
- battery: const DeviceBatterySnapshot(
- status: DeviceSignalStatus.unavailable,
- errorCode: 'battery_read_failed',
- ),
- ),
+ test('fails closed without current required evidence', () {
+ final unavailableBattery = _snapshot(
+ now,
+ battery: const DeviceBatterySnapshot(
+ status: DeviceSignalStatus.unavailable,
+ errorCode: 'battery_read_failed',
),
- contains(DeviceHealthIssue.batteryUnavailable),
);
+
+ expect(issues(_snapshot(now.subtract(const Duration(minutes: 3)))), {
+ DeviceHealthIssue.staleObservation,
+ });
expect(
- issues(_snapshot(now, battery: _androidBattery(level: 19))),
- contains(DeviceHealthIssue.lowBattery),
+ issues(unavailableBattery),
+ contains(DeviceHealthIssue.batteryUnavailable),
);
});
- test('accepts unsupported iOS battery evidence', () {
+ test('enforces the compute safety limits', () {
expect(
- issues(
- _snapshot(
- now,
- platform: DeviceHealthPlatform.ios,
- battery: const DeviceBatterySnapshot(
- status: DeviceSignalStatus.unsupported,
- ),
- ),
- ),
- isEmpty,
+ issues(_snapshot(now, battery: _androidBattery(level: 19))),
+ contains(DeviceHealthIssue.lowBattery),
);
- });
-
- test('rejects hot or unknown Android battery evidence', () {
expect(
issues(_snapshot(now, battery: _androidBattery(temperature: 42.1))),
contains(DeviceHealthIssue.batteryTooHot),
);
- expect(
- issues(
- _snapshot(
- now,
- battery: _androidBattery(health: DeviceBatteryHealth.unknown),
- ),
- ),
- contains(DeviceHealthIssue.batteryHealthUnavailable),
- );
- });
-
- test('rejects serious thermal state', () {
expect(
issues(
_snapshot(
@@ -88,51 +49,47 @@ void main() {
);
});
- test('uses Android battery evidence when thermal APIs are unsupported', () {
+ test('uses battery evidence when Android thermal APIs are unsupported', () {
+ const unsupportedThermal = DeviceThermalSnapshot(
+ status: DeviceSignalStatus.unsupported,
+ );
+
+ expect(issues(_snapshot(now, thermal: unsupportedThermal)), isEmpty);
expect(
issues(
_snapshot(
now,
- thermal: const DeviceThermalSnapshot(
- status: DeviceSignalStatus.unsupported,
- ),
+ battery: _androidBattery(health: DeviceBatteryHealth.unknown),
+ thermal: unsupportedThermal,
),
),
- isEmpty,
+ contains(DeviceHealthIssue.thermalUnavailable),
);
});
- test('accepts iOS without Android-only battery metrics', () {
- expect(
- issues(
- _snapshot(
- now,
- platform: DeviceHealthPlatform.ios,
- battery: const DeviceBatterySnapshot(
- status: DeviceSignalStatus.available,
- levelPercent: 80,
- ),
- ),
+ test('requires only signals available on iOS devices', () {
+ final unsupportedBattery = _snapshot(
+ now,
+ platform: DeviceHealthPlatform.ios,
+ battery: const DeviceBatterySnapshot(
+ status: DeviceSignalStatus.unsupported,
+ ),
+ );
+ final unsupportedThermal = _snapshot(
+ now,
+ platform: DeviceHealthPlatform.ios,
+ battery: const DeviceBatterySnapshot(
+ status: DeviceSignalStatus.available,
+ levelPercent: 80,
+ ),
+ thermal: const DeviceThermalSnapshot(
+ status: DeviceSignalStatus.unsupported,
),
- isEmpty,
);
- });
- test('does not treat unsupported iOS thermal evidence as healthy', () {
+ expect(issues(unsupportedBattery), isEmpty);
expect(
- issues(
- _snapshot(
- now,
- platform: DeviceHealthPlatform.ios,
- battery: const DeviceBatterySnapshot(
- status: DeviceSignalStatus.available,
- levelPercent: 80,
- ),
- thermal: const DeviceThermalSnapshot(
- status: DeviceSignalStatus.unsupported,
- ),
- ),
- ),
+ issues(unsupportedThermal),
contains(DeviceHealthIssue.thermalUnavailable),
);
});