Repository navigation
Description
Part of #1259.
Scope
After this PR, device-table.ts is a part of the Android driver (ADR 0063 §4). It owns the device states (keyed by AVD folder) and the per-device locks, and does a device's state, the per-device lock (also under seed:<spec key> for a seed make), the devices listManaged reports with their serials and marks, pre-root devices, and reattaching running emulators after a restart. AndroidDriver builds it in its constructor, passes it the options it needs, and delegates to it. Behaviour, messages, timeouts and files on disk do not change. The root and later parts write device states only through this part (set, get, delete). No test serializes two calls on one device today; this task adds one: a second call under the same lock starts only after the first ends, and a call on another device does not wait.
In short
About 259 lines of code move out of the 3,573-line driver into a file an agent reads whole. Nothing a user or a caller sees changes. A part is a file that owns its own state and takes its collaborators in an options object; it never imports index.ts.
flowchart LR
R["index.ts: AndroidDriver"] --> P["device-table.ts (new part)"]
R --> O[parts moved earlier]
P --> O
What a user would notice if this goes wrong: a running device is missed after a restart, or two calls on one device run at once.
Technical spec
Facts
Commit 059a270. Line numbers are on that commit; earlier tasks of #1259 move code, so the implementer finds each name by search.
| # | Fact | Source |
|---|---|---|
| F1 | every name this task moves, at its line on 059a270 (the exact assignment of every name of the file, made from its syntax tree) | DeviceEntry at src/drivers/android/index.ts:280; #devices at src/drivers/android/index.ts:618; #locks at src/drivers/android/index.ts:626; findLegacy at src/drivers/android/index.ts:859; destroyLegacy at src/drivers/android/index.ts:889; #reattachRunningEmulators at src/drivers/android/index.ts:1066; listManaged at src/drivers/android/index.ts:1919; #observedDevice at src/drivers/android/index.ts:1935; #listDeviceEntries at src/drivers/android/index.ts:1962; #holdsAvd at src/drivers/android/index.ts:1980; #attributeSerial at src/drivers/android/index.ts:2015; #resolveRunningAvds at src/drivers/android/index.ts:2057; #stateFor at src/drivers/android/index.ts:3043; #withDeviceLock at src/drivers/android/index.ts:3064; observedAndroidDevice at src/drivers/android/index.ts:3325; buildObservedMark at src/drivers/android/index.ts:3362 |
| F2 | a part in this folder takes an options object and is built by the driver | src/drivers/android/adb-registrar.ts:22-25, src/drivers/android/index.ts:675 |
| F3 | such a part has its own test file that builds it directly | src/drivers/android/adb-registrar.test.ts:9 |
| F4 | the folder's testing.ts is imported by index.test.ts, and the test file's shared helpers sit outside any describe |
src/drivers/android/index.test.ts:46, src/drivers/android/index.test.ts:5117-5410, src/drivers/android/index.test.ts:7306-8212 |
| F5 | Fallow fails CI on an import loop between files (circular-dependencies, default error) and on any dead-code finding |
node_modules/fallow/schema.json RulesConfig at pnpm-lock.yaml:2180; docs/internal/agent-rules/toolchain.md:51-53 |
| F6 | test-lint flags an added sibling import in a test unless a why: sits above the first describe |
.agents/scripts/test-lint.mjs:141-148 |
| F7 | the module manual is 141 lines, and manuals may have at most 150 | src/drivers/android/AGENTS.md:1-141, src/docs-manuals.test.ts:9 |
| F8 | the root tests that prove the root still reaches this part | src/drivers/android/index.test.ts:3937 "gates running state, processes and erasable marks on path proof" |
| F9 | the lock map is keyed by AVD folder, and by seed:<spec key> for a seed make |
src/drivers/android/index.ts:626, src/drivers/android/index.ts:1445 |
| F10 | no test in index.test.ts serializes two calls on one device |
`grep -nE 'lock |
Modules touched
Searches: grep -rn of each F1 name under src/ (hits only in src/drivers/android/index.ts, src/drivers/android/index.test.ts and, for the exports index.ts keeps, their importers); ls src/drivers/android/device-table.ts (absent on 059a270).
flowchart LR
R["index.ts (changed)"] --> P["device-table.ts (new)"]
P --> E["earlier parts, data.ts"]
src/drivers/android/device-table.ts: new; the part. It imports onlydata.ts, files that exist on 059a270 and the parts of earlier tasks; anything else reaches it as an option or a callback.src/drivers/android/index.ts: builds the part, delegates, and loses the F1 names.src/drivers/android/index.test.ts: loses the tests named under Tests.src/drivers/android/device-table.test.ts: new; its tests.src/drivers/android/data.ts: takes a type two parts share, when this task moves one.src/drivers/android/testing.ts: takes any helper two test files now use.src/drivers/android/AGENTS.md: the one Files row for the parts (ADR 0063), which Android driver: adb-tools.ts, the leaf part for env, commands and device folders #1264 adds, gainsdevice-table.tsand a few words; no new row (F7).src/source-hygiene.test.ts: the two Android entries of the shrink-only list take their new lengths; an entry whose file is now within its limit is removed.
Contract and event changes
none: the task moves code inside the Android driver; no file under src/contract/ and no event changes (search: git grep -n "drivers/android" src/contract gives 0 hits).
Other code on the same state
The state this part owns: the device states (keyed by AVD folder) and the per-device locks. Searches: grep -n of each owned name in src/drivers/android/index.ts and under src/ outside the Android folder (0 hits outside). After this task the root and later tasks (#1272) reach that state only through this part's interface; none keeps a copy.
Failure modes
none: the task crosses no new boundary and writes no new state. Every call to adb, emulator, avdmanager or sdkmanager it moves keeps its arguments, environment and time limit (F1).
Rules in play
- ADR 0063 §1, "A part never calls the root": the part takes collaborators and callbacks in its options and imports no
index.ts(F5 fails a loop). - ADR 0063 §2, tests sit with the part: a test moves only when everything it asserts is made by this part; a test across parts stays in the root's tests. A part test file has one
why:above its firstdescribenaming "a part of a decomposed module" (F6). - ADR 0063 §3: a listed file that is now within its limit leaves the shrink-only list in this PR.
- Architecture rule 14, "nothing outside the directory imports a file inside it": only files in
src/drivers/android/import the part. - Architecture rule 17, "A comment starts with
why:": a moved comment that is not awhy:, or that no longer holds, is deleted. - Documentation rule 7 and
src/docs-manuals.test.ts: the manual stays within 150 lines (F7).
Tests
The seam is src/drivers/android/device-table.test.ts, a new file modelled on src/drivers/android/adb-registrar.test.ts. These 16 tests move there, each keeping its claim and cases, because everything each asserts is made by this part: src/drivers/android/index.test.ts:1474 "reports one running root AVD, one stopped root AVD and the running AVD's process"; src/drivers/android/index.test.ts:1507 "listManaged settles after the timeout when one serial's mark read never answers, reports that …"; src/drivers/android/index.test.ts:1558 "reads the erasable mark with head -c 4096, and a mark cut at that cap is read as no mark"; src/drivers/android/index.test.ts:1617 "listManaged passes a 30-second timeout to adb devices"; src/drivers/android/index.test.ts:1631 "treats an otherwise-stopped AVD as transitioning when an unattributable transitional serial is…"; src/drivers/android/index.test.ts:1653 "still resolves a stopped AVD as stopped when adb reports no serials at all"; src/drivers/android/index.test.ts:1728 "listManaged reports matching durable and erasable marks for a running device"; src/drivers/android/index.test.ts:1758 "listManaged reports an erased running device when the erasable mark file is gone"; src/drivers/android/index.test.ts:1788 "keeps listManaged alive when a serial dies between the scan and the read"; src/drivers/android/index.test.ts:1825 "listManaged reports erasableReadable: false for a stopped, marked device"; src/drivers/android/index.test.ts:1844 "listManaged reports no mark for a stopped, pre-existing AVD with no durable key (upgrade path)…"; src/drivers/android/index.test.ts:4025 "does not attribute an outside-root emulator to a root AVD with the same name (#261)"; src/drivers/android/index.test.ts:4074 "manages every AVD in its root, whatever the AVD is called"; src/drivers/android/index.test.ts:4138 "ignores a running emulator whose AVD does not live in its root"; src/drivers/android/index.test.ts:4699 "finds an AVD stranded in the pre-root AVD home"; src/drivers/android/index.test.ts:4711 "deletes a stranded AVD against the legacy AVD home, not Simlock's root". Every other test stays where it is; F8's tests stay in src/drivers/android/index.test.ts and keep proving the root reaches the part.
- The driver lists devices and locks each one through
device-table.ts, and sees the same devices, serials and order of calls as before; cases: "reports one running root AVD, one stopped root AVD and the running AVD's process"; "listManaged settles after the timeout when one serial's mark read never answers, reports that …"; "reads the erasable mark with head -c 4096, and a mark cut at that cap is read as no mark"; "listManaged passes a 30-second timeout to adb devices"; "treats an otherwise-stopped AVD as transitioning when an unattributable transitional serial is…"; "still resolves a stopped AVD as stopped when adb reports no serials at all"; and the other tests named in its task; a second call under one device's lock waits for the first, a call on another device does not (new).
Done when
pnpm exec vitest run --project unit src/drivers/androidpasses, and its number of tests is the base's plus the tests this task adds.src/drivers/android/device-table.tsexists, and only files insrc/drivers/android/import it: dependency-cruiser'spast-indexrule (.dependency-cruiser.mjs:36-37), run bypnpm check, fails any import of it from outside the folder.src/drivers/android/index.tsdefines none of the F1 names, except eachDrivermethod (and otherAndroidDrivermember the core or the daemon calls), which stays and delegates; the root's field that holds the part takes a name that is not an F1 name; an F1 constant the root still uses is imported from the part.- In
src/source-hygiene.test.ts, each Android entry equals its file's new line count, or is gone when the file is within its limit. pnpm checkpasses.
Out of scope
- Any change of behaviour, message, timeout or file on disk.
- The parts of the other tasks of Split the source and test files too big for agents to read whole #1259.
- New tests for code moved unchanged that no test pinned on the base: the
legacyAvdHome === deviceRootguard infindLegacy, theexists(deviceRoot)early return in#listDeviceEntries,porton a recovered process'sdriverData, and the lock-map cleanup. Tests: no new test for these; the root test that proves which options the root hands the part stays, since ADR 0063 §2 makes the root's wiring its own claim (decided in delivery, pending the maintainer; the same call as Android driver: system-images.ts owns system images and components #1270 and Android driver: catalog.ts owns device profiles, fit and the resolved-spec cache #1273)
Depends on
Written by an agent.
Activity
chore(stack): merge task/1273 into the Android device table split (#1271
refactor(android): device-table.ts owns the device states, locks, lis…