Automatically reconnect single ADB head unit

This commit is contained in:
2026-07-31 19:25:32 +02:00
parent 3e3e0010d6
commit 0a0dae144c
12 changed files with 103 additions and 29 deletions
+36
View File
@@ -80,6 +80,42 @@ describe("read-only ADB collector", () => {
});
});
it("automatically discovers exactly one device and refuses ambiguous connections", async () => {
const calls: string[][] = [];
const execute: AdbExecutor = async (_executable, arguments_) => {
calls.push([...arguments_]);
if (arguments_[0] === "devices") {
return { stdout: "List of devices attached\nAUTO-MG4\tdevice product:saic model:autus\n", stderr: "" };
}
if (arguments_.at(-1) === "get-state") return { stdout: "device\n", stderr: "" };
return { stdout: "value\n", stderr: "" };
};
const status = await collectAdbStatus({ ...enabledConfig, serial: null }, execute);
expect(status).toMatchObject({ available: true, value: { state: "connected" } });
expect(calls[0]).toEqual(["devices"]);
for (const arguments_ of calls.slice(1)) expect(arguments_.slice(0, 2)).toEqual(["-s", "AUTO-MG4"]);
const multiple: AdbExecutor = async () => ({
stdout: "List of devices attached\nMG4\tdevice\nPHONE\tdevice\n",
stderr: ""
});
await expect(collectAdbStatus({ ...enabledConfig, serial: null }, multiple)).resolves.toMatchObject({
available: false,
state: "ambiguous"
});
});
it("reports an automatically discovered device awaiting authorization", async () => {
const execute: AdbExecutor = async () => ({
stdout: "List of devices attached\nAUTO-MG4\tunauthorized\n",
stderr: ""
});
await expect(collectAdbStatus({ ...enabledConfig, serial: null }, execute)).resolves.toMatchObject({
available: false,
state: "unauthorized"
});
});
it("keeps individual fields unavailable when a connected device only partially responds", async () => {
const execute: AdbExecutor = async (_executable, arguments_) => {
if (arguments_.at(-1) === "get-state") return { stdout: "device\n", stderr: "" };
+2 -2
View File
@@ -11,8 +11,8 @@ describe("ADB configuration", () => {
});
});
it("requires a constrained serial when enabled", () => {
expect(() => loadConfig({ NODE_ENV: "test", ADB_ENABLED: "true" })).toThrow("ADB_SERIAL is required");
it("supports automatic discovery or a constrained pinned serial when enabled", () => {
expect(loadConfig({ NODE_ENV: "test", ADB_ENABLED: "true" }).adb).toMatchObject({ enabled: true, serial: null });
expect(() =>
loadConfig({ NODE_ENV: "test", ADB_ENABLED: "true", ADB_SERIAL: "serial; shell command" })
).toThrow();