@davoodmehraban89 / LifeMate / commits / 00bb8ee
Fork 0

LifeMate — Personal, Family & Learning Companion

test: accept only stable empty WAL caches after synthetic app exit

Quinn White committed Oct 22, 2026 at 20:13 UTC 00bb8eec1898757ad9c197eb9327135fb1e69dfd
3 files changed +142 -7
apps/lifemate/tool/test_personal_recovery_android.py
+17 -7
@@ -248,10 +248,17 @@ class Harness:
248
249 def _cold(self, package):
250 require(self.process_state(package) == 'ABSENT', 'database_process_must_be_absent')
251 - query = ' && '.join('test ! -e ' + DATABASE + suffix for suffix in ('-wal', '-shm', '-journal'))
252 - output = self.adb.shell('run-as', package, 'sh', '-c',
253 - f'if {query}; then printf CLEAN; else printf SIDECAR; fi').strip()
254 - require(output == 'CLEAN', 'database_sidecar_present')
251 + # A terminated read-only Android WAL connection can leave a zero-byte
252 + # WAL plus SHM cache. Only a strictly empty WAL has no frames to replay.
253 + wal, shm, journal = (DATABASE + suffix for suffix in ('-wal', '-shm', '-journal'))
254 + query = (f'if [ -e {journal} ]; then printf SIDECAR; '
255 + f'elif [ ! -e {wal} ] && [ ! -e {shm} ]; then printf CLEAN; '
256 + f'elif [ -f {wal} ] && [ ! -s {wal} ]; then '
257 + f'if [ -e {shm} ]; then printf EMPTY_WAL_SHM; else printf EMPTY_WAL; fi; '
258 + 'else printf SIDECAR; fi')
259 + output = self.adb.shell('run-as', package, 'sh', '-c', query).strip()
260 + require(output in ('CLEAN', 'EMPTY_WAL', 'EMPTY_WAL_SHM'), 'database_sidecar_present')
261 + return output
262
263 def _remote(self, package, script):
264 self._owned(package)
@@ -271,9 +278,10 @@ class Harness:
278 require(self.capture(package) == raw, 'seed_bytes_not_confirmed')
279
280 def capture(self, package):
274 - self._cold(package)
281 + before = self._cold(package)
282 raw = self.binary(self._remote(package, 'cat ' + DATABASE))
276 - self._cold(package)
283 + require(self._cold(package) == before, 'database_cache_shape_changed')
284 + self.receipt.setdefault('coldCaptureStates', {})[package] = before
285 require(100 <= len(raw) <= MAX_PAYLOAD_BYTES and raw[:16] == b'SQLite format 3\0'
286 and int.from_bytes(raw[68:72], 'big') == FIXTURE_APPLICATION_ID,
287 'captured_database_invalid')
@@ -355,7 +363,7 @@ class Harness:
363
364 def screenshot(self, kind='ordinary'):
365 require(self.gated and bool(self.seeded & self.launched) and
358 - kind in ('ordinary', 'ui-failure-original', 'ui-failure-qa'),
366 + kind in ('ordinary', 'qa-restored', 'ui-failure-original', 'ui-failure-qa'),
367 'synthetic_screenshot_boundary_required')
368 raw = self.binary('screencap -p')
369 require(24 <= len(raw) <= MAX_PAYLOAD_BYTES and raw[:8] == b'\x89PNG\r\n\x1a\n'
@@ -404,6 +412,8 @@ class Harness:
412 self.receipt['currentPhase'] = phase
413 for package, role in ((ORIGINAL, 'original'), (QA, 'qa')):
414 self.launch(package)
415 + if phase == 'both_apps_after_first_close' and package == QA:
416 + self.screenshot('qa-restored')
417 self.close(package)
418 raw = self.capture(package)
419 captured = private / (phase + '-' + role + '.sqlite')
apps/lifemate/tool/test_personal_recovery_android_test.py
+44
@@ -126,6 +126,50 @@ class RecoveryBoundaryTest(unittest.TestCase):
126 with self.assertRaises(subject.AcceptanceError):
127 h.capture(subject.ORIGINAL)
128
129 + def test_capture_accepts_only_stable_empty_wal_cache_shapes(self):
130 + h = self.make()
131 + h.preflight()
132 + h.install(subject.ORIGINAL)
133 + raw = subject.create_sample_database()
134 + h.binary = lambda command, data=None: raw
135 + for shape in ('CLEAN', 'EMPTY_WAL', 'EMPTY_WAL_SHM'):
136 + self.adb.sidecars = shape
137 + self.assertEqual(h.capture(subject.ORIGINAL), raw)
138 + self.adb.sidecars = 'EMPTY_WAL_SHM'
139 + def changing_read(command, data=None):
140 + self.adb.sidecars = 'EMPTY_WAL'
141 + return raw
142 + h.binary = changing_read
143 + with self.assertRaisesRegex(subject.AcceptanceError, 'database_cache_shape_changed'):
144 + h.capture(subject.ORIGINAL)
145 + for state in ('NONEMPTY_WAL', 'ORPHAN_SHM', 'JOURNAL', 'SIDECAR'):
146 + self.adb.sidecars = state
147 + with self.assertRaisesRegex(subject.AcceptanceError, 'database_sidecar_present'):
148 + h.capture(subject.ORIGINAL)
149 +
150 + def test_actual_exited_sqlite_reader_leaves_empty_wal_cache_only(self):
151 + source = self.directory / 'real-closed-reader.sqlite'
152 + fixture = subject.create_sample_database()
153 + source.write_bytes(fixture)
154 + script = ("import os,sqlite3,sys; d=sqlite3.connect(sys.argv[1]); "
155 + "d.execute('PRAGMA journal_mode=WAL'); "
156 + "d.execute('SELECT * FROM local_profiles').fetchall(); os._exit(0)")
157 + subprocess.run(['python3', '-c', script, str(source)], check=True)
158 + wal, shm = Path(str(source) + '-wal'), Path(str(source) + '-shm')
159 + self.assertEqual(wal.stat().st_size, 0)
160 + self.assertGreater(shm.stat().st_size, 0)
161 + before = {p: p.read_bytes() for p in (source, wal, shm)}
162 + # The AVD harness captures the main bytes only AFTER its cold zero-WAL gate.
163 + captured = self.directory / 'captured-main.sqlite'
164 + captured.write_bytes(source.read_bytes())
165 + reference = self.directory / 'reference.sqlite'
166 + reference.write_bytes(fixture)
167 + normalized = subject.normalized_snapshot(captured, self.directory / 'normalized.sqlite')
168 + self.assertEqual(normalized, subject.export_fixture(reference))
169 + self.assertEqual(subject.independent_sql(reference),
170 + subject.independent_sql(self.directory / 'normalized.sqlite'))
171 + self.assertEqual({p: p.read_bytes() for p in before}, before)
172 +
173 def test_private_normalization_preserves_wal_header_source_and_full_fields(self):
174 raw = bytearray(subject.create_sample_database())
175 raw[18:20] = b'\x02\x02'
docs/audits/evidence/personal-recovery-sidecar-failed-2026-10-22.json new
+81
@@ -0,0 +1,81 @@
1 +{
2 + "schemaVersion": 1,
3 + "status": "FAILED_ACTUAL_ANDROID_ACCEPTANCE",
4 + "sourceCommit": "7eb413d92ec6b83c02326dd28b4e2446c1d6c321",
5 + "runId": 39845355974,
6 + "artifactId": 12455128173,
7 + "artifactZipSha256": "35fb3a29b5f72404b2dbde16a49db036d81591d7acb0d028f3f4b80c0b45644c",
8 + "rootVerifiedArtifactDigest": true,
9 + "rootViewedFictionalOriginalScreenshot": true,
10 + "receipt": {
11 + "apks": {
12 + "original": {
13 + "package": "ir.lifeguide.app.device",
14 + "sha256": "c24ff6e75a987945399b0d96129f5d1a72525fa0270f31b0c481f9780f84db8e",
15 + "versionCode": 9,
16 + "versionName": "0.7.2-personal.1"
17 + },
18 + "qaNeverDistribute": {
19 + "package": "ir.lifeguide.app.personal",
20 + "sha256": "8db3d32f4070c60cd41588c5d54a96f2233654765da2606c707a31e26a0d9ebe",
21 + "versionCode": 10,
22 + "versionName": "0.7.2-recovery-qa.10"
23 + },
24 + "upgradeNeverDistribute": {
25 + "package": "ir.lifeguide.app.personal",
26 + "sha256": "c04721407c164c32c79353a5e5bf20547f8f8eec82b473d6e77f704f34716920",
27 + "versionCode": 11,
28 + "versionName": "0.7.2-recovery-qa.11"
29 + }
30 + },
31 + "canonicalSnapshotSha256": "f64bf8f30e41dc4eddca18629f2ca950839fdb11f489c85889a40500739c06f9",
32 + "certificatesSha256": [
33 + "4ef990d647fc98ac41113d5dbe7ee476ba80bf95b71b5f219b7863fa95263391",
34 + "901ddfcf2804a43d8efcd51aeabad7889c0db703d4c3f2cd69be127bdf8708b5",
35 + "901ddfcf2804a43d8efcd51aeabad7889c0db703d4c3f2cd69be127bdf8708b5"
36 + ],
37 + "checks": {
38 + "allApksAndFreshEmulatorGatedBeforeInstall": "PASS"
39 + },
40 + "counts": {
41 + "local_occurrences": 4,
42 + "local_plans": 4,
43 + "local_profiles": 1,
44 + "local_weekly_slots": 3
45 + },
46 + "currentPhase": "original_seed_and_ordinary_ui",
47 + "errorCode": "database_sidecar_present",
48 + "fictionalScreenshotsSha256": {
49 + "personal-recovery-android.png": "c8633f0e08645142e9212571a108b515ebc093ec2b512e4c51ffe5c5ff047b2a"
50 + },
51 + "lastUiObservation": {
52 + "exactContentDescriptionMatch": true,
53 + "exactTextMatch": false,
54 + "nodeCount": 30,
55 + "ownedPackageNodeCount": 30,
56 + "package": "ir.lifeguide.app.device"
57 + },
58 + "limitations": {
59 + "Doze": "UNVERIFIED",
60 + "USB": "UNVERIFIED",
61 + "Windows": "UNVERIFIED",
62 + "distributionApk": "UNVERIFIED",
63 + "originalNotificationsEnabled": "UNVERIFIED",
64 + "ownerData": "UNVERIFIED",
65 + "ownerSigningKey": "UNVERIFIED",
66 + "physicalDevice": "UNVERIFIED",
67 + "powerLossOrFullDisk": "UNVERIFIED",
68 + "reboot": "UNVERIFIED",
69 + "soundOrVibration": "UNVERIFIED"
70 + },
71 + "result": "FAIL",
72 + "schemaVersion": 1,
73 + "syntheticDataOnly": true
74 + },
75 + "diagnosis": {
76 + "uiHypothesis": "VERIFIED: exact owned content-desc true, text false; original fictional greeting visible in actual PNG",
77 + "sidecarCause": "Android sidecar presence observed; exact sizes UNVERIFIED in this run",
78 + "localReproduction": "real Python SQLite WAL reader followed by process exit leaves zero-byte WAL plus32768byte SHM; private main copy preserves all logical data",
79 + "fixScope": "accept only cold stable zero-byte WAL/cache shape; nonempty WAL/orphan SHM/journal still refused; no source deletion or checkpoint"
80 + }
81 +}