Repository navigation
Description
Part of #754.
Scope
A worker with real drivers stores each simulator's and emulator's driver data in the driver's own table, ios_device_data or android_device_data, so its devices survive a restart field for field. Each driver package owns its table and its migrations, and the composition root passes both tables whatever the host's platform, so a device whose driver was refused still loads.
In short
Today a device's driverData rides inside state.json. After task 1 the registry stores it through a device-data table per platform. This task adds the two real ones, so a real worker can store its devices again.
flowchart LR
R[Registry commit] --> D[(devices)]
R --> I["ios_device_data (new)"]
R --> A["android_device_data (new)"]
driverData today |
Row after |
|---|---|
iOS {"udid":"9F2C…","name":"simlock-ios-1","deviceTypeId":"com.apple.CoreSimulator.SimDeviceType.iPhone-16","runtimeId":"com.apple.CoreSimulator.SimRuntime.iOS-18-4"} |
ios_device_data: udid, name, device_type_id, runtime_id, slim_signature NULL, slim_mark_token NULL |
iOS slimmed, with slimSignature and slimMarkToken |
the same, with both slim columns set |
Android {"avdName":"simlock_1","configHash":"ab12","imageIdentity":"system-images;android-35;google_apis;arm64-v8a@3","port":5554,"serial":"emulator-5554"} |
android_device_data: avd_name, config_hash, image_identity, port, serial |
Android with no imageIdentity |
image_identity NULL, read back with no key |
If this goes wrong, a user would notice a device that comes back after a restart with a changed udid, AVD, port or slim state, so the driver cannot reach it or slims it again.
Technical spec
Facts
Commit 8db8112b.
| # | Fact | Source |
|---|---|---|
| F1 | IosDriverData: deviceTypeId, name, runtimeId, udid required; slimSignature?, slimMarkToken? |
src/drivers/ios/index.ts:171-178 |
| F2 | iOS sets slimSignature, and slimMarkToken only when a token exists; it reads both with typeof === "string" |
src/drivers/ios/index.ts:970-976, :2120-2143 |
| F3 | AndroidDriverData: avdName, configHash, port, serial required; imageIdentity?; isAndroidDriverData does not check imageIdentity |
src/drivers/android/data.ts:1-19 |
| F4 | Android restores imageIdentity ?? "" |
src/drivers/android/index.ts:2185 |
| F5 | Observed, stranded and recovered device shapes (listManaged, findLegacy) are never committed to the registry | src/drivers/ios/index.ts:1097-1137; src/drivers/android/index.ts:647-652, :1283-1289, :2466-2472; only registry commits store driverData (rg driverData src/core) |
| F6 | iOS is discovered only on darwin, and a refused root is a rejection, not a throw |
src/daemon/main.ts:1085-1097, :1189-1198, :1238-1250 |
| F7 | Drivers may import core and ports | src/drivers/AGENTS.md:5 "Uses: core, ports" |
| F8 | No core or leasing file reads a key inside driverData |
rg driverData src --type ts -g '!*.test.ts' -g '!src/drivers/**': registry pass-through only (src/core/registry.ts:1340-1361) |
| F9 | Task 1 adds DeviceDataTable, describeDeviceDataTable (src/core/testing.ts), resolveDeviceDataTables and the empty productionDeviceDataTables(), and owner names ios-device-data, android-device-data |
#754 Shared values; #761 |
| F10 | Android's verbs refuse data that fails isAndroidDriverData with Android device <id> has invalid driver data |
src/drivers/android/index.ts:2165-2167 |
Modules touched
Searches: IosDriverData, AndroidDriverData, driverData, deviceData (task 1's map) over src/.
src/drivers/ios/device-data.ts(new),src/drivers/ios/index.ts(export).src/drivers/android/device-data.ts(new),src/drivers/android/index.ts(export).src/daemon/main.ts:productionDeviceDataTables()returnsnew Map([["ios", iosDeviceDataTable], ["android", androidDeviceDataTable]]), without readingprocess.platform.src/drivers/ios/device-data.test.ts,src/drivers/android/device-data.test.ts(new): each runs task 1'sdescribeDeviceDataTable. No core file changes.- Manuals:
src/drivers/AGENTS.md,src/drivers/ios/AGENTS.md,src/drivers/android/AGENTS.md(each driver's table and its version).
flowchart LR
main["daemon/main.ts *"] --> ios["drivers/ios device-data *"]
main --> android["drivers/android device-data *"]
main --> reg[core Registry]
ios --> core["core DeviceDataTable"]
android --> core
Surface and extension points
Each driver's index.ts exports one DeviceDataTable (iosDeviceDataTable, androidDeviceDataTable), built with no driver instance and no host tool, so it loads where the driver itself is refused (F6). It implements task 1's definition and joins its conformance suite (architecture rule 20).
| Owner, version 1 | Table, key | Columns |
|---|---|---|
ios-device-data |
ios_device_data, device_id |
udid, name, device_type_id, runtime_id, slim_signature (NULL when absent), slim_mark_token (NULL when absent) |
android-device-data |
android_device_data, device_id |
avd_name, config_hash, image_identity (NULL when absent), port, serial |
Both tables are STRICT; a required field is NOT NULL (port an INTEGER, the rest TEXT), an optional one nullable. write throws Invalid <platform> driver data for device <id> (<platform> is ios or android) when a required key is missing or not its type, an optional key is present but not a string, or the value has a key not in the shape. So a value write accepts always passes the driver's own read check (F2, F3, F10). read returns the shape with absent keys left out, not set to undefined.
Contract and event changes
None (searched src/contract for IosDriverData, AndroidDriverData: none).
Other code on the same state
Searched driverData writes outside drivers: the registry only (F8). The drivers keep reading driverData from the record the registry hands them, unchanged. Task 1's commit is the one caller of write and its load the one caller of read.
Failure modes
| Call | Outcome | What happens | Limit, counted from |
|---|---|---|---|
write |
ok | row inserted or replaced in the commit's transaction | — |
| not the driver's shape | throws; the commit rolls back (task 1) | — | |
read |
ok | the shape | — |
| no row | throws; load refuses (task 1) | — |
No state of its own outside the commit transaction.
Rules in play
- ADR 0036 §2, "one row in that driver's own table, keyed by
device_id" and "Each owner creates its own tables and keeps its own schema version". - ADR 0036 §3, "a separate export of its driver package … works when the driver's tools are missing".
- Architecture rule 2, iOS and Android encapsulated: the shapes stay in the driver packages.
- Architecture rule 3, a driver adds no core change: only
main.tsand the drivers change. - Architecture rule 20, one conformance suite: each driver runs
describeDeviceDataTablefrom core'stesting.tson its own table with its own examples, since the shapes are the driver's (rule 2). This is the one deviation fromdescribe.eachover the registry, which would put driver shapes into a host test.
Tests
Seam: describeDeviceDataTable (#761, src/core/testing.ts) in each driver's new device-data.test.ts, and Registry.load over openMemoryStateDatabase (model: src/core/registry.test.ts).
describeDeviceDataTablepasses foriosDeviceDataTableandandroidDeviceDataTablewith every example of the In short table (both slim keys, neither,imageIdentityabsent).- Each table's
writerefuses, naming the platform and the device: a missing required key, a required key of the wrong type (port: "5554"), an optional key of the wrong type (slimSignature: 5,imageIdentity: 5), and an extra key. - A registry restarted on one temp
state.db, holding an iOS and an Android device with the real tables, returns both devices'driverDataunchanged. resolveDeviceDataTables({}), with noSIMLOCK_DRIVERS_MODULE, answers the iOS table underiosand the Android table underandroid(extends state.db opens and checks at start, and the worker's registry lives in it #761's resolver test). That is the mapstartDaemonpasses to both the open andRegistry.load(state.db opens and checks at start, and the worker's registry lives in it #761's test of the shared path).
Done when
pnpm test:changedpasses.rg -n "productionDeviceDataTables" src/daemon/main.tsshows it passed where task 1 passed the empty map.
Out of scope
- A Vega table.
- Physical devices' driver data (none today).
Depends on
Written by an agent.
Activity
[-]state.db opens and checks at start, and the worker's registry lives in it[/-][+]iOS and Android device data in their own state.db tables[/+]test: resolveDeviceDataTables answers the iOS and Android tables with…
feat(daemon): production device-data tables hold the iOS and Android …
test: a registry restarted on one state.db returns an iOS and an Andr…
docs(drivers): the manuals name each driver's device-data table and i…
fix(android): androidDeviceDataTable refuses a port that is not an in…
docs(ios): the iOS driver manual fits in 150 lines (#757)
feat(drivers): iOS and Android device-data tables (#783)