From 2cd8e3a0bc64d7c70750838042216e94185d86f0 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 13 Oct 2026 21:59:02 +0200 Subject: [PATCH 1/4] test: doctor reports a devices.xml profile hidden by a library profile (#491) --- src/cli/index.test.ts | 26 ++++++ src/drivers/android/index.test.ts | 127 ++++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+) diff --git a/src/cli/index.test.ts b/src/cli/index.test.ts index dc00f8bbd..fbe677287 100644 --- a/src/cli/index.test.ts +++ b/src/cli/index.test.ts @@ -1369,6 +1369,32 @@ describe("CLI: daemon status (ADR 0003 §11)", () => { expect(JSON.parse(output.stdout)).toEqual({ findings }); }); + it("simlock doctor prints a driver-advisory finding to stderr as `Warning [] : `", async () => { + const output = outputCapture(); + const findings = [ + { + code: "device-profile-hidden", + kind: "driver-advisory" as const, + message: '"Pixel 9" in devices.xml is not used', + platform: "android" as const, + }, + ]; + + await expect( + runCli( + ["doctor"], + output.environmentWith({ + connectAdmin: async () => + fakeClient({ runDoctor: () => Promise.resolve({ findings } as never) }), + }), + ), + ).resolves.toBe(0); + + expect(output.stderr.split("\n")).toContain( + 'Warning [android] device-profile-hidden: "Pixel 9" in devices.xml is not used', + ); + }); + it("simlock doctor writes agent-device fail ; on stderr, one line of at most 500 characters per part, after the advisory, prerequisite and warm-pool lines, prints the report on stdout unchanged, and exits 0", async () => { const output = outputCapture(); const findings = [ diff --git a/src/drivers/android/index.test.ts b/src/drivers/android/index.test.ts index c9373b537..94e6970c0 100644 --- a/src/drivers/android/index.test.ts +++ b/src/drivers/android/index.test.ts @@ -1982,6 +1982,133 @@ describe("AndroidDriver", () => { expect(device?.mark).toBeUndefined(); }); + describe("device-profile-hidden advisories", () => { + const hiddenMessage = (xmlName: string, libraryName: string) => + `"${xmlName}" in devices.xml is not used: Simlock's own ${libraryName} profile answers to that name`; + + // why: the fake adb server answers no version, so the physical handler adds its own advisory. + async function hiddenProfileAdvisories(driver: AndroidDriver) { + return (await driver.advisories()).filter( + (advisory) => advisory.code === "device-profile-hidden", + ); + } + + async function advisoriesFor(devicesXml: string | undefined, listing = pixelDevices) { + const filesystem = await androidFilesystem(); + if (devicesXml !== undefined) await writeDevicesXml(filesystem, devicesXml); + const runner = new ScriptedProcessRunner([ + processResult(binaries.avdmanager, ["list", "device"], listing), + ]); + const driver = await createDriver(filesystem, runner); + return { advisories: await hiddenProfileAdvisories(driver), runner }; + } + + it("reports `device-profile-hidden` for a `devices.xml` profile named like a library profile, with the message naming both", async () => { + const { advisories } = await advisoriesFor(customDeviceXml("Pixel 9", 4096)); + + expect(advisories).toEqual([ + { code: "device-profile-hidden", message: hiddenMessage("Pixel 9", "Pixel 9") }, + ]); + }); + + it("reports one matching a library profile's other name, in any letter case, naming the library profile's display name", async () => { + const { advisories } = await advisoriesFor( + customDeviceXml("pixel_9", 4096) + customDeviceXml("PIXEL 9", 4096), + ); + + expect(advisories).toEqual([ + { code: "device-profile-hidden", message: hiddenMessage("pixel_9", "Pixel 9") }, + { code: "device-profile-hidden", message: hiddenMessage("PIXEL 9", "Pixel 9") }, + ]); + }); + + it("reports two hidden profiles as two advisories, in `devices.xml` order", async () => { + const { advisories } = await advisoriesFor( + customDeviceXml("Pixel 9", 4096) + customDeviceXml("Pixel 8", 4096), + ); + + expect(advisories.map((advisory) => advisory.message)).toEqual([ + hiddenMessage("Pixel 9", "Pixel 9"), + hiddenMessage("Pixel 8", "Pixel 8"), + ]); + }); + + it("reports nothing for a `devices.xml` profile no library profile answers to", async () => { + const { advisories } = await advisoriesFor(customDeviceXml("My Tablet", 4096)); + + expect(advisories).toEqual([]); + }); + + it("reports nothing for a library name the SDK also lists", async () => { + const sdkListing = `Available devices:\nid: 0 or "pixel_9"\n Name: Pixel 9\n OEM : Google\n`; + + const { advisories } = await advisoriesFor(undefined, sdkListing); + + expect(advisories).toEqual([]); + }); + + it("reports one advisory per profile when `avdmanager list device` also lists it with `OEM : User`, and runs no `avdmanager`", async () => { + const userListing = `Available devices:\nid: 0 or "Pixel 9"\n Name: Pixel 9\n OEM : User\n`; + + const { advisories, runner } = await advisoriesFor( + customDeviceXml("Pixel 9", 4096), + userListing, + ); + + expect(advisories).toEqual([ + { code: "device-profile-hidden", message: hiddenMessage("Pixel 9", "Pixel 9") }, + ]); + expect(runner.calls.map((call) => call.command)).not.toContain(binaries.avdmanager); + }); + + it("reports nothing when `devices.xml` is missing or unreadable", async () => { + const missing = await advisoriesFor(undefined); + const filesystem = await androidFilesystem(); + await filesystem.mkdirp(`${home}/.android`); + await filesystem.writeFileAtomic(`${home}/.android/devices.xml`, "not xml at all {{{"); + const driver = await createDriver(filesystem, new ScriptedProcessRunner([])); + + expect(missing.advisories).toEqual([]); + expect(await hiddenProfileAdvisories(driver)).toEqual([]); + }); + + it("keeps the physical handler's advisories, before the new ones", async () => { + const base = await androidFilesystem(); + await writeDevicesXml(base, customDeviceXml("Pixel 9", 4096)); + let broken = false; + const filesystem = new Proxy(base, { + get(target, property) { + if (property === "stat" && broken) { + return async () => { + throw new Error("EACCES"); + }; + } + const value = Reflect.get(target, property) as unknown; + return typeof value === "function" ? (value as () => unknown).bind(target) : value; + }, + }); + const driver = await createDriver(filesystem, new ScriptedProcessRunner([])); + broken = true; + + const advisories = await driver.advisories(); + + expect(advisories.map((advisory) => advisory.code)).toEqual([ + "adb-protocol-mismatch", + "device-profile-hidden", + ]); + }); + + it("reports no hidden profiles for a driver built with injected `deviceProfileSources`", async () => { + const filesystem = await androidFilesystem(); + await writeDevicesXml(filesystem, customDeviceXml("Pixel 9", 4096)); + const driver = await createDriver(filesystem, new ScriptedProcessRunner([]), { + deviceProfileSources: [], + }); + + expect(await hiddenProfileAdvisories(driver)).toEqual([]); + }); + }); + describe("device-profile sources", () => { it("resolves a devices.xml-only model and applies its properties to config.ini before the config hash is captured", async () => { const filesystem = await androidFilesystem(); From 40d96f56183609b98089f49f29ec6d6a83a7af4e Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 13 Oct 2026 22:00:20 +0200 Subject: [PATCH 2/4] feat(android): doctor reports a devices.xml profile the library hides (#491) 5 failing -> 0 failing --- docs/CLI.md | 9 +++++ src/drivers/android/device-profile-source.ts | 23 +++++++++++- src/drivers/android/index.ts | 39 ++++++++++++++++---- 3 files changed, 62 insertions(+), 9 deletions(-) diff --git a/docs/CLI.md b/docs/CLI.md index 9bbe1690f..542f52fa9 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -2129,6 +2129,15 @@ protocol version, for example the one in the SDK's `platform-tools`. Nothing is reported when no server is listening on that port. Advisory only, like the findings above — there is no `--fix` for it. +`doctor` also reports a `driver-advisory` finding (code +`device-profile-hidden`) for each profile in your Android `devices.xml` whose +name one of Simlock's own Android profiles answers to, in the file's order. The +message names the `devices.xml` profile and the Simlock profile that is used +instead; Simlock reads its own profile first, so the one in `devices.xml` is +never used. A name that Simlock's profile shares with the SDK is not reported, +because the two agree. Rename the profile in `devices.xml` to use it. Advisory +only — there is no `--fix` for it. + `doctor` also checks the [prerequisites](#prerequisites) of each platform this host can run (iOS only on macOS), every time it runs. Each one missing is a `prerequisite-missing` finding with `platform`, `prerequisite` (for example diff --git a/src/drivers/android/device-profile-source.ts b/src/drivers/android/device-profile-source.ts index 066998555..64650d6b5 100644 --- a/src/drivers/android/device-profile-source.ts +++ b/src/drivers/android/device-profile-source.ts @@ -214,6 +214,28 @@ function matchProfile( ); } +interface HiddenUserProfile { + readonly userName: string; + readonly libraryName: string; +} + +export async function hiddenUserProfiles( + library: DeviceProfileSource, + user: DeviceProfileSource, +): Promise { + const libraryProfiles = await library.profiles(); + const hidden: HiddenUserProfile[] = []; + for (const profile of await user.profiles()) { + const shadow = profile.names + .map((name) => matchProfile(libraryProfiles, name)) + .find((match) => match !== undefined); + if (shadow !== undefined) { + hidden.push({ libraryName: shadow.name, userName: profile.name }); + } + } + return hidden; +} + /** Today's behavior, refactored behind `DeviceProfileSource`: resolves against `avdmanager list device`. */ export class BuiltinDeviceProfileSource implements DeviceProfileSource { readonly #avdmanager: string; @@ -240,7 +262,6 @@ export class BuiltinDeviceProfileSource implements DeviceProfileSource { * profiles come before custom ones, so a real SDK profile wins a name clash with a * devices.xml one whatever order `avdmanager` prints them in. */ - // fallow-ignore-next-line unused-class-member -- reached through the DeviceProfileSource port by DeviceProfileRegistry. async profiles(): Promise { const profiles = (await this.#avdmanagerProfiles()).map( (profile): DeviceProfile => ({ diff --git a/src/drivers/android/index.ts b/src/drivers/android/index.ts index e40144fb1..9f1cf3bbe 100644 --- a/src/drivers/android/index.ts +++ b/src/drivers/android/index.ts @@ -61,6 +61,7 @@ import { isAndroidDriverData, type AndroidDriverData } from "./data.js"; import { AndroidPhysicalHandler, PHYSICAL_RECLAIM_ESTIMATE_MS } from "./physical-handler.js"; import { BuiltinDeviceProfileSource, + hiddenUserProfiles, containsForbiddenCharacter, DeviceProfileRegistry, parseAvdmanagerDeviceProfiles, @@ -462,6 +463,7 @@ export class AndroidDriver implements Driver { readonly #acceptAndroidLicenses: boolean; readonly #clock: Clock; readonly #deviceProfiles: DeviceProfileRegistry; + readonly #profileSources: ReturnType | undefined; readonly #devices = new Map(); readonly #deviceRoot: string; readonly #filesystem: Filesystem; @@ -529,9 +531,14 @@ export class AndroidDriver implements Driver { this.#legacyAvdHome = options.env.ANDROID_AVD_HOME ?? join(options.homeDirectory, ".android", "avd"); this.#portAllocator = portAllocatorFor(options.processRunner, sdk.adb); + const defaults = + options.deviceProfileSources === undefined + ? defaultDeviceProfileSources(options, sdk, this.#onDiagnostic, () => this.#env()) + : undefined; + this.#profileSources = defaults; this.#deviceProfiles = new DeviceProfileRegistry( options.deviceProfileSources ?? - defaultDeviceProfileSources(options, sdk, this.#onDiagnostic, () => this.#env()), + (defaults === undefined ? [] : [defaults.library, defaults.builtin, defaults.user]), ); } @@ -1069,7 +1076,19 @@ export class AndroidDriver implements Driver { } async advisories(): Promise { - return this.#physical.advisories(); + const physical = await this.#physical.advisories(); + if (this.#profileSources === undefined) return physical; + const hidden = await hiddenUserProfiles( + this.#profileSources.library, + this.#profileSources.user, + ); + return [ + ...physical, + ...hidden.map(({ libraryName, userName }) => ({ + code: "device-profile-hidden", + message: `"${userName}" in devices.xml is not used: Simlock's own ${libraryName} profile answers to that name`, + })), + ]; } async listManaged(): Promise { @@ -2566,18 +2585,22 @@ function defaultDeviceProfileSources( sdk: AndroidSdkPaths, onDiagnostic: ((diagnostic: AndroidDriverDiagnostic) => void) | undefined, env: () => NodeJS.ProcessEnv, -): readonly DeviceProfileSource[] { +): { + readonly library: DeviceProfileSource; + readonly builtin: DeviceProfileSource; + readonly user: DeviceProfileSource; +} { const { ANDROID_PREFS_ROOT, ANDROID_SDK_HOME, ANDROID_USER_HOME } = options.env; const devicesXmlPath = ANDROID_USER_HOME !== undefined ? `${ANDROID_USER_HOME}/devices.xml` : `${ANDROID_PREFS_ROOT ?? ANDROID_SDK_HOME ?? options.homeDirectory}/.android/devices.xml`; - return [ - new LibraryDeviceProfileSource(), + return { + library: new LibraryDeviceProfileSource(), // Scoped like every other call: an unscoped `avdmanager` would read the user's `~/.android`. - new BuiltinDeviceProfileSource(sdk.avdmanager, options.processRunner, env), - new UserDeviceProfileSource(devicesXmlPath, options.filesystem, onDiagnostic), - ]; + builtin: new BuiltinDeviceProfileSource(sdk.avdmanager, options.processRunner, env), + user: new UserDeviceProfileSource(devicesXmlPath, options.filesystem, onDiagnostic), + }; } function portAllocatorFor(processRunner: ProcessRunner, adb: string): PortAllocator { From 32e5dbecd3039f17d18627122257f9ffe2df804d Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 13 Oct 2026 22:06:25 +0200 Subject: [PATCH 3/4] test(android): drop the SDK-name advisory test and the claim it made (#491) --- docs/CLI.md | 3 +-- src/drivers/android/index.test.ts | 8 -------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/docs/CLI.md b/docs/CLI.md index 542f52fa9..9789a6544 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -2134,8 +2134,7 @@ findings above — there is no `--fix` for it. name one of Simlock's own Android profiles answers to, in the file's order. The message names the `devices.xml` profile and the Simlock profile that is used instead; Simlock reads its own profile first, so the one in `devices.xml` is -never used. A name that Simlock's profile shares with the SDK is not reported, -because the two agree. Rename the profile in `devices.xml` to use it. Advisory +never used. Rename the profile in `devices.xml` to use it. Advisory only — there is no `--fix` for it. `doctor` also checks the [prerequisites](#prerequisites) of each platform diff --git a/src/drivers/android/index.test.ts b/src/drivers/android/index.test.ts index 94e6970c0..f1dbe3257 100644 --- a/src/drivers/android/index.test.ts +++ b/src/drivers/android/index.test.ts @@ -2039,14 +2039,6 @@ describe("AndroidDriver", () => { expect(advisories).toEqual([]); }); - it("reports nothing for a library name the SDK also lists", async () => { - const sdkListing = `Available devices:\nid: 0 or "pixel_9"\n Name: Pixel 9\n OEM : Google\n`; - - const { advisories } = await advisoriesFor(undefined, sdkListing); - - expect(advisories).toEqual([]); - }); - it("reports one advisory per profile when `avdmanager list device` also lists it with `OEM : User`, and runs no `avdmanager`", async () => { const userListing = `Available devices:\nid: 0 or "Pixel 9"\n Name: Pixel 9\n OEM : User\n`; From 71c57ad470f1d7624e85c868972cfeb285ce7cde Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 13 Oct 2026 22:07:27 +0200 Subject: [PATCH 4/4] test(android): restore the SDK-name advisory test and its CLI.md sentence (#491) --- docs/CLI.md | 3 ++- src/drivers/android/index.test.ts | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/CLI.md b/docs/CLI.md index 9789a6544..14f948689 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -2134,7 +2134,8 @@ findings above — there is no `--fix` for it. name one of Simlock's own Android profiles answers to, in the file's order. The message names the `devices.xml` profile and the Simlock profile that is used instead; Simlock reads its own profile first, so the one in `devices.xml` is -never used. Rename the profile in `devices.xml` to use it. Advisory +never used. An SDK profile that a Simlock profile hides is not reported, only +a `devices.xml` one. Rename the profile in `devices.xml` to use it. Advisory only — there is no `--fix` for it. `doctor` also checks the [prerequisites](#prerequisites) of each platform diff --git a/src/drivers/android/index.test.ts b/src/drivers/android/index.test.ts index f1dbe3257..94e6970c0 100644 --- a/src/drivers/android/index.test.ts +++ b/src/drivers/android/index.test.ts @@ -2039,6 +2039,14 @@ describe("AndroidDriver", () => { expect(advisories).toEqual([]); }); + it("reports nothing for a library name the SDK also lists", async () => { + const sdkListing = `Available devices:\nid: 0 or "pixel_9"\n Name: Pixel 9\n OEM : Google\n`; + + const { advisories } = await advisoriesFor(undefined, sdkListing); + + expect(advisories).toEqual([]); + }); + it("reports one advisory per profile when `avdmanager list device` also lists it with `OEM : User`, and runs no `avdmanager`", async () => { const userListing = `Available devices:\nid: 0 or "Pixel 9"\n Name: Pixel 9\n OEM : User\n`;