fix(android): require --device when several devices are connected

With no serial requested and more than one device online, pickDevice silently returned connected[0], but that serial is never threaded into the per-step adb calls, so every later bare adb command failed with "more than one device". Error instead and ask for --device, mirroring pickAVD; a single device stays unambiguous.
This commit is contained in:
pj committed 2026-06-11 09:26:01 +05:30
1 parent 194866511f
commit 600fb71c5b
2 files changed
+23 -6

No files matched your search

+12 -2
View File
@@ -47,13 +47,23 @@ func TestPickDevice_RequestedNotConnected(t *testing.T) {
}
}
func TestPickDevice_NoRequestUsesFirst(t *testing.T) {
serial, found, err := pickDevice("", []string{"emulator-5554", "physical-abc"})
func TestPickDevice_NoRequestSingleDeviceUsesIt(t *testing.T) {
serial, found, err := pickDevice("", []string{"emulator-5554"})
if err != nil || !found || serial != "emulator-5554" {
t.Fatalf("got (%q, %v, %v), want (emulator-5554, true, nil)", serial, found, err)
}
}
func TestPickDevice_NoRequestMultipleDevicesErrors(t *testing.T) {
serial, found, err := pickDevice("", []string{"emulator-5554", "physical-abc"})
if err == nil {
t.Fatal("expected an error asking for --device when several devices are connected")
}
if found || serial != "" {
t.Fatalf("ambiguous selection must not pick a device, got (%q, %v)", serial, found)
}
}
func TestPickDevice_NoneConnectedFallsBackToAVD(t *testing.T) {
serial, found, err := pickDevice("", nil)
if err != nil || found || serial != "" {