LifeMate — Personal, Family & Learning Companion
ci: verify Android persistence before building private test APK
Codex committed
Oct 8, 2026 at 05:24 UTC
53084534263aa713edf553113d5c2ef0d6717b3a
6 files changed
+262
-1
.github/workflows/local-persistence.yml
new
+105
@@ -0,0 +1,105 @@
1
+name: Verify local device persistence
2
+
3
+on:
4
+ push:
5
+ branches: [fix/local-task-persistence]
6
+ paths:
7
+ - 'apps/lifemate/**'
8
+ - '.github/workflows/local-persistence.yml'
9
+
10
+permissions:
11
+ contents: read
12
+
13
+jobs:
14
+ flutter-checks:
15
+ runs-on: ubuntu-latest
16
+ timeout-minutes: 25
17
+ defaults:
18
+ run:
19
+ working-directory: apps/lifemate
20
+ steps:
21
+ - uses: actions/checkout@v4
22
+ with:
23
+ persist-credentials: false
24
+ - uses: subosito/flutter-action@v2
25
+ with:
26
+ channel: stable
27
+ flutter-version: '3.47.6'
28
+ cache: true
29
+ - run: flutter pub get
30
+ - name: Check formatting in persistence change files
31
+ run: |
32
+ dart format --output=none --set-exit-if-changed \
33
+ lib/main.dart lib/phase3_ui.dart lib/role_entry_main.dart \
34
+ lib/local_data_store.dart lib/local_only_api.dart \
35
+ test/app_test.dart test/local_persistence_test.dart \
36
+ test/local_persistence_ui_test.dart integration_test
37
+ - run: flutter analyze --no-pub
38
+ - run: flutter test --no-pub --reporter expanded
39
+
40
+ android-persistence:
41
+ needs: flutter-checks
42
+ runs-on: ubuntu-latest
43
+ timeout-minutes: 60
44
+ defaults:
45
+ run:
46
+ working-directory: apps/lifemate
47
+ steps:
48
+ - uses: actions/checkout@v4
49
+ with:
50
+ persist-credentials: false
51
+ - uses: actions/setup-java@v4
52
+ with:
53
+ distribution: temurin
54
+ java-version: '17'
55
+ - uses: subosito/flutter-action@v2
56
+ with:
57
+ channel: stable
58
+ flutter-version: '3.47.6'
59
+ cache: true
60
+ - run: flutter pub get
61
+ - name: Enable KVM
62
+ run: |
63
+ echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
64
+ sudo udevadm control --reload-rules
65
+ sudo udevadm trigger --name-match=kvm
66
+ - name: Verify real Android storage across four app processes
67
+ uses: reactivecircus/android-emulator-runner@v2
68
+ with:
69
+ api-level: 35
70
+ target: google_apis
71
+ arch: x86_64
72
+ emulator-port: 5554
73
+ force-avd-creation: true
74
+ disable-animations: true
75
+ emulator-options: -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim
76
+ working-directory: apps/lifemate
77
+ # Each command runs in its own shell. Keep pipefail with each test.
78
+ # --no-uninstall retains SharedPreferences during Flutter test teardown.
79
+ script: |
80
+ bash -eo pipefail -c 'flutter test integration_test/local_persistence_device_test.dart -d emulator-5554 --no-pub --no-uninstall --dart-define=PERSISTENCE_PHASE=create --reporter expanded 2>&1 | tee "$RUNNER_TEMP/local-persistence-create.log"'
81
+ adb -s emulator-5554 shell am force-stop com.example.lifemate
82
+ bash -eo pipefail -c 'flutter test integration_test/local_persistence_device_test.dart -d emulator-5554 --no-pub --no-uninstall --dart-define=PERSISTENCE_PHASE=update --reporter expanded 2>&1 | tee "$RUNNER_TEMP/local-persistence-update.log"'
83
+ adb -s emulator-5554 shell am force-stop com.example.lifemate
84
+ bash -eo pipefail -c 'flutter test integration_test/local_persistence_device_test.dart -d emulator-5554 --no-pub --no-uninstall --dart-define=PERSISTENCE_PHASE=archive --reporter expanded 2>&1 | tee "$RUNNER_TEMP/local-persistence-archive.log"'
85
+ adb -s emulator-5554 shell am force-stop com.example.lifemate
86
+ bash -eo pipefail -c 'flutter test integration_test/local_persistence_device_test.dart -d emulator-5554 --no-pub --no-uninstall --dart-define=PERSISTENCE_PHASE=verify --reporter expanded 2>&1 | tee "$RUNNER_TEMP/local-persistence-verify.log"'
87
+ adb -s emulator-5554 shell am force-stop com.example.lifemate
88
+ bash -e -c 'if grep -E "Uninstalling old version|Package install error" "$RUNNER_TEMP"/local-persistence-*.log; then echo "An installation reset invalidated the persistence test."; exit 1; fi'
89
+ - name: Build local role-entry APK after persistence gates
90
+ run: flutter build apk --release --no-pub --target=lib/role_entry_main.dart
91
+ - name: Upload local test APK
92
+ uses: actions/upload-artifact@v4
93
+ with:
94
+ name: LifeGuide-local-persistence-test-apk
95
+ path: apps/lifemate/build/app/outputs/flutter-apk/app-release.apk
96
+ if-no-files-found: error
97
+ retention-days: 14
98
+ - name: Upload persistence phase logs
99
+ if: always()
100
+ uses: actions/upload-artifact@v4
101
+ with:
102
+ name: local-persistence-device-logs
103
+ path: ${{ runner.temp }}/local-persistence-*.log
104
+ if-no-files-found: warn
105
+ retention-days: 14
apps/lifemate/android/app/src/main/AndroidManifest.xml
+2
@@ -2,6 +2,8 @@
2
<application
3
android:label="LifeMate"
4
android:name="${applicationName}"
5
+ android:fullBackupContent="@xml/local_data_backup_rules"
6
+ android:dataExtractionRules="@xml/local_data_extraction_rules"
7
android:icon="@drawable/lifemate_logo">
8
<activity
9
android:name=".MainActivity"
apps/lifemate/android/app/src/main/res/xml/local_data_backup_rules.xml
new
+6
@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<full-backup-content>
3
+ <!-- The local record/profile document is intentionally device-only. -->
4
+ <exclude domain="file" path="datastore/FlutterSharedPreferences.preferences_pb" />
5
+ <exclude domain="file" path="datastore/FlutterSharedPreferences.preferences_pb.tmp" />
6
+</full-backup-content>
apps/lifemate/android/app/src/main/res/xml/local_data_extraction_rules.xml
new
+11
@@ -0,0 +1,11 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<data-extraction-rules>
3
+ <cloud-backup>
4
+ <exclude domain="file" path="datastore/FlutterSharedPreferences.preferences_pb" />
5
+ <exclude domain="file" path="datastore/FlutterSharedPreferences.preferences_pb.tmp" />
6
+ </cloud-backup>
7
+ <device-transfer>
8
+ <exclude domain="file" path="datastore/FlutterSharedPreferences.preferences_pb" />
9
+ <exclude domain="file" path="datastore/FlutterSharedPreferences.preferences_pb.tmp" />
10
+ </device-transfer>
11
+</data-extraction-rules>
apps/lifemate/integration_test/local_persistence_device_test.dart
new
+137
@@ -0,0 +1,137 @@
1
+import 'dart:convert';
2
+
3
+import 'package:flutter/foundation.dart';
4
+import 'package:flutter_test/flutter_test.dart';
5
+import 'package:integration_test/integration_test.dart';
6
+import 'package:lifemate/local_data_store.dart';
7
+import 'package:lifemate/local_only_api.dart';
8
+import 'package:shared_preferences/shared_preferences.dart';
9
+
10
+const _phase = String.fromEnvironment('PERSISTENCE_PHASE');
11
+const _originalTitle = 'آزمون پایداری تکلیف روی دستگاه';
12
+const _editedTitle = 'آزمون پایداری تکلیف روی دستگاه - ویرایش';
13
+const _dueAt = '2030-10-15T12:00:00.000Z';
14
+const _editedNotes = 'این تغییر باید پس از توقف اجباری باقی بماند.';
15
+
16
+Map<String, dynamic> _record(
17
+ Iterable<Map<String, dynamic>> items,
18
+ String title,
19
+) {
20
+ final matches = items.where((item) => item['title'] == title).toList();
21
+ expect(matches, hasLength(1),
22
+ reason: 'Expected one durable test assignment.');
23
+ expect(matches.single['id'], isA<String>());
24
+ expect(matches.single['id'], isNotEmpty);
25
+ return matches.single;
26
+}
27
+
28
+Future<Map<String, dynamic>> _readDisk() async {
29
+ final preferences = SharedPreferencesAsync();
30
+ final raw = await preferences.getString(LocalDataStore.key);
31
+ expect(raw, isNotNull,
32
+ reason: 'The Android preference must survive restart.');
33
+ final data = jsonDecode(raw!) as Map<String, dynamic>;
34
+ expect(data['version'], 1);
35
+ expect(data['items'], hasLength(1));
36
+ return data;
37
+}
38
+
39
+Iterable<Map<String, dynamic>> _savedItems(Map<String, dynamic> data) =>
40
+ (data['items'] as List).map(
41
+ (item) => Map<String, dynamic>.from(item as Map),
42
+ );
43
+
44
+Future<void> _expectEditedProfile(LocalOnlyApi api) async {
45
+ final profile = await api.getProfile();
46
+ expect(profile['display_name'], 'سارا');
47
+ expect(profile['theme_preference'], 'boy_blue');
48
+ expect(profile['profile_category'], 'girl_minor');
49
+ expect(api.accessToken, isNull);
50
+}
51
+
52
+void main() {
53
+ IntegrationTestWidgetsFlutterBinding.ensureInitialized();
54
+
55
+ testWidgets('Android persistence phase: $_phase', (tester) async {
56
+ expect(defaultTargetPlatform, TargetPlatform.android);
57
+ expect(_phase, isIn(['create', 'update', 'archive', 'verify']));
58
+ final api = LocalOnlyApi(category: 'girl_minor', displayName: 'آرام');
59
+ expect(api.accessToken, isNull,
60
+ reason: 'Local entry has no server session.');
61
+
62
+ switch (_phase) {
63
+ case 'create':
64
+ final preferences = SharedPreferencesAsync();
65
+ expect(
66
+ await preferences.containsKey(LocalDataStore.key),
67
+ isFalse,
68
+ reason:
69
+ 'Create must start on a fresh emulator, without clearing data.',
70
+ );
71
+ expect(await api.listPlanItems(), isEmpty);
72
+ final created = await api.createPlanItem({
73
+ 'kind': 'assignment',
74
+ 'title': _originalTitle,
75
+ 'dueAt': _dueAt,
76
+ 'visibility': 'private',
77
+ });
78
+ final visible = _record(await api.listPlanItems(), _originalTitle);
79
+ final saved = _record(_savedItems(await _readDisk()), _originalTitle);
80
+ expect(visible['id'], created['id']);
81
+ expect(saved['id'], created['id']);
82
+ expect(saved['kind'], 'assignment');
83
+ expect(saved['due_at'], _dueAt);
84
+ expect(saved['visibility'], 'private');
85
+ expect(saved['status'], 'planned');
86
+ expect((await api.getProfile())['display_name'], 'آرام');
87
+
88
+ case 'update':
89
+ final restored = _record(await api.listPlanItems(), _originalTitle);
90
+ final id = restored['id'] as String;
91
+ expect(restored['due_at'], _dueAt);
92
+ expect(restored['status'], 'planned');
93
+ await api.updatePlanItem(id, {
94
+ 'title': _editedTitle,
95
+ 'notes': _editedNotes,
96
+ 'status': 'in_progress',
97
+ });
98
+ await api.updateProfile(
99
+ displayName: 'سارا', themePreference: 'boy_blue');
100
+ final updated = _record(await api.listPlanItems(), _editedTitle);
101
+ expect(updated['id'], id);
102
+ expect(updated['notes'], _editedNotes);
103
+ expect(updated['status'], 'in_progress');
104
+ expect(updated['due_at'], _dueAt);
105
+ await _expectEditedProfile(api);
106
+
107
+ case 'archive':
108
+ await _expectEditedProfile(api);
109
+ final restored = _record(await api.listPlanItems(), _editedTitle);
110
+ final id = restored['id'] as String;
111
+ expect(restored['notes'], _editedNotes);
112
+ expect(restored['status'], 'in_progress');
113
+ await api.updatePlanItem(id, {'status': 'cancelled'});
114
+ expect(await api.listPlanItems(), isEmpty);
115
+ final archived = _record(_savedItems(await _readDisk()), _editedTitle);
116
+ expect(archived['id'], id);
117
+ expect(archived['status'], 'cancelled');
118
+
119
+ case 'verify':
120
+ await _expectEditedProfile(api);
121
+ expect(await api.listPlanItems(), isEmpty);
122
+ final data = await _readDisk();
123
+ final archived = _record(_savedItems(data), _editedTitle);
124
+ expect(archived['status'], 'cancelled');
125
+ expect(archived['kind'], 'assignment');
126
+ expect(archived['notes'], _editedNotes);
127
+ expect(archived['due_at'], _dueAt);
128
+ expect(archived['visibility'], 'private');
129
+ final profile = data['profile'] as Map;
130
+ expect(profile['display_name'], 'سارا');
131
+ expect(profile['theme_preference'], 'boy_blue');
132
+ expect(archived['owner_user_id'], profile['user_id']);
133
+ }
134
+
135
+ expect(api.accessToken, isNull);
136
+ });
137
+}
apps/lifemate/pubspec.yaml
+1
-1
@@ -1,5 +1,5 @@
1
name: lifemate
2
-version: 0.1.0+1
2
+version: 0.1.1+2
3
publish_to: none
4
description: LifeMate personal, family and learning companion.
5
environment: