The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 09:15 UTC
perf(server): check Android SDK locations before PATH (#19960)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 15, 2026 at 15:59 UTC
a175e06cdc8cd08e892c04f38615200638cf3a78
2 files changed
+89
-31
apps/server/src/device/LocalDeviceHost.test.ts
+60
@@ -255,6 +255,66 @@ const diagnose = (
255
);
256
257
describe("Android SDK availability", () => {
258
+ it.effect("uses the standard Windows SDK without probing PATH", () =>
259
+ Effect.gen(function* () {
260
+ const root = "C:\\Users\\test\\AppData\\Local\\Android\\Sdk";
261
+ const probes: string[] = [];
262
+ const sdk = yield* LocalDeviceHost.__testing.androidSdk.pipe(
263
+ Effect.provideService(HostProcess.Environment, {
264
+ USERPROFILE: "C:\\Users\\test",
265
+ LOCALAPPDATA: "C:\\Users\\test\\AppData\\Local",
266
+ PATH: "\\\\slow-share\\tools;C:\\other-tools",
267
+ }),
268
+ Effect.provideService(HostProcess.Platform, "win32"),
269
+ Effect.provideService(
270
+ FileSystem.FileSystem,
271
+ FileSystem.makeNoop({
272
+ exists: (file) =>
273
+ Effect.sync(() => {
274
+ probes.push(file);
275
+ return file === `${root}\\platform-tools\\adb.exe`;
276
+ }),
277
+ realPath: () => Effect.die("Standard SDK must not resolve PATH executables"),
278
+ }),
279
+ ),
280
+ Effect.provide(NodePath.layerWin32),
281
+ );
282
+ expect(sdk).toMatchObject({ root, adb: true });
283
+ expect(probes.filter((file) => !file.startsWith("C:\\Users\\test\\"))).toEqual([]);
284
+ }),
285
+ );
286
+
287
+ it.effect("falls back to adb on the Windows Path without resolving missing entries", () =>
288
+ Effect.gen(function* () {
289
+ const root = "D:\\Android\\Sdk";
290
+ const resolved: string[] = [];
291
+ const sdk = yield* LocalDeviceHost.__testing.androidSdk.pipe(
292
+ Effect.provideService(HostProcess.Environment, {
293
+ USERPROFILE: "C:\\Users\\test",
294
+ Path: "C:\\missing;C:\\shims",
295
+ }),
296
+ Effect.provideService(HostProcess.Platform, "win32"),
297
+ Effect.provideService(
298
+ FileSystem.FileSystem,
299
+ FileSystem.makeNoop({
300
+ exists: (file) =>
301
+ Effect.succeed(
302
+ file === "C:\\shims\\adb.exe" || file === `${root}\\platform-tools\\adb.exe`,
303
+ ),
304
+ realPath: (file) =>
305
+ Effect.sync(() => {
306
+ resolved.push(file);
307
+ return `${root}\\platform-tools\\adb.exe`;
308
+ }),
309
+ }),
310
+ ),
311
+ Effect.provide(NodePath.layerWin32),
312
+ );
313
+ expect(sdk).toMatchObject({ root, adb: true });
314
+ expect(resolved).toEqual(["C:\\shims\\adb.exe"]);
315
+ }),
316
+ );
317
+
318
it.effect("explains that adb alone is insufficient to launch an emulator", () =>
319
Effect.gen(function* () {
320
const reason = yield* diagnose(["/sdk/platform-tools/adb"], { ANDROID_HOME: "/sdk" });
apps/server/src/device/LocalDeviceHost.ts
+29
-31
@@ -143,8 +143,25 @@ const androidSdk = Effect.gen(function* () {
143
const path = yield* Path.Path;
144
const environment = yield* HostProcess.Environment;
145
const platform = yield* HostProcess.Platform;
146
+ const windows = platform === "win32";
147
const home = environment.HOME ?? environment.USERPROFILE ?? "";
148
const explicit = environment.ANDROID_HOME?.trim() || environment.ANDROID_SDK_ROOT?.trim();
149
+ const exists = (file: string) => fs.exists(file).pipe(Effect.orElseSucceed(() => false));
150
+ const adbBinary = windows ? "adb.exe" : "adb";
151
+ const avdmanagerBinary = windows ? "avdmanager.bat" : "avdmanager";
152
+ const inspect = Effect.fnUntraced(function* (root: string) {
153
+ const adb = yield* exists(path.join(root, "platform-tools", adbBinary));
154
+ const emulator = yield* exists(
155
+ path.join(root, "emulator", windows ? "emulator.exe" : "emulator"),
156
+ );
157
+ if (!explicit && !adb && !emulator) return null;
158
+ const avdmanager = yield* exists(
159
+ path.join(root, "cmdline-tools", "latest", "bin", avdmanagerBinary),
160
+ );
161
+ const legacyAvdmanager =
162
+ !avdmanager && (yield* exists(path.join(root, "tools", "bin", avdmanagerBinary)));
163
+ return { root, adb, emulator, avdmanager, legacyAvdmanager };
164
+ });
165
const candidates = explicit
166
? [explicit]
167
: [
@@ -156,39 +173,20 @@ const androidSdk = Effect.gen(function* () {
173
"Sdk",
174
),
175
];
176
+ for (const root of candidates) {
177
+ const sdk = yield* inspect(root);
178
+ if (sdk) return sdk;
179
+ }
180
+ // PATH entries can be slow to stat (network shares), so only consult them after the standard locations miss.
181
if (!explicit) {
160
- for (const directory of (environment.PATH ?? "").split(platform === "win32" ? ";" : ":")) {
182
+ const searchPath = environment.PATH ?? environment.Path ?? "";
183
+ for (const directory of searchPath.split(windows ? ";" : ":")) {
184
if (!directory) continue;
162
- const resolved = yield* fs
163
- .realPath(path.join(directory, platform === "win32" ? "adb.exe" : "adb"))
164
- .pipe(Effect.option);
165
- if (resolved._tag === "Some") candidates.push(path.dirname(path.dirname(resolved.value)));
166
- }
167
- }
168
- const exists = (file: string) => fs.exists(file).pipe(Effect.orElseSucceed(() => false));
169
- for (const root of candidates) {
170
- const adb = yield* exists(
171
- path.join(root, "platform-tools", platform === "win32" ? "adb.exe" : "adb"),
172
- );
173
- const emulator = yield* exists(
174
- path.join(root, "emulator", platform === "win32" ? "emulator.exe" : "emulator"),
175
- );
176
- if (explicit || adb || emulator) {
177
- const avdmanager = yield* exists(
178
- path.join(
179
- root,
180
- "cmdline-tools",
181
- "latest",
182
- "bin",
183
- platform === "win32" ? "avdmanager.bat" : "avdmanager",
184
- ),
185
- );
186
- const legacyAvdmanager =
187
- !avdmanager &&
188
- (yield* exists(
189
- path.join(root, "tools", "bin", platform === "win32" ? "avdmanager.bat" : "avdmanager"),
190
- ));
191
- return { root, adb, emulator, avdmanager, legacyAvdmanager };
185
+ const adb = path.join(directory, adbBinary);
186
+ if (!(yield* exists(adb))) continue;
187
+ const resolved = yield* fs.realPath(adb).pipe(Effect.orElseSucceed(() => adb));
188
+ const sdk = yield* inspect(path.dirname(path.dirname(resolved)));
189
+ if (sdk) return sdk;
190
}
191
}
192
return { root: null, adb: false, emulator: false, avdmanager: false, legacyAvdmanager: false };