55 HostProcessExecutablePath ,
66 HostProcessPlatform ,
77} from "@t3tools/shared/hostProcess" ;
8+ import { isCommandAvailable , resolveSpawnCommand } from "@t3tools/shared/shell" ;
89import * as Console from "effect/Console" ;
910import * as Crypto from "effect/Crypto" ;
1011import * as Effect from "effect/Effect" ;
@@ -48,7 +49,7 @@ export function clientStatus(
4849 return record . fingerprint === fingerprint ? "compatible" : "stale" ;
4950}
5051
51- /** Record only a successful installation built from unchanged native inputs . */
52+ /** Keep native sources stable during ensure, as with a normal build; endpoint checks reject detected edits . */
5253export const ensureClient = Effect . fn ( "ensureClient" ) ( function * < E , R , E2 , R2 > ( operations : {
5354 fingerprint : Effect . Effect < string , E , R > ;
5455 installedBinary : Effect . Effect < string | null , E , R > ;
@@ -62,19 +63,25 @@ export const ensureClient = Effect.fn("ensureClient")(function* <E, R, E2, R2>(o
6263 yield * operations . installedBinary ,
6364 yield * operations . readRecord ,
6465 ) ;
65- if ( status === "compatible" ) return { status, rebuilt : false , fingerprint } ;
66- yield * operations . build ;
67- if ( ( yield * operations . fingerprint ) !== fingerprint ) {
68- return yield * new NativeClientError ( {
69- message :
70- "Native inputs changed during the build. Run ensure again; this build was not recorded." ,
71- } ) ;
66+ const verifyInputs = Effect . gen ( function * ( ) {
67+ if ( ( yield * operations . fingerprint ) !== fingerprint ) {
68+ return yield * new NativeClientError ( {
69+ message :
70+ "Native inputs changed during verification. Run ensure again; this build was not recorded." ,
71+ } ) ;
72+ }
73+ } ) ;
74+ if ( status === "compatible" ) {
75+ yield * verifyInputs ;
76+ return { status, rebuilt : false , fingerprint } ;
7277 }
78+ yield * operations . build ;
7379 const binary = yield * operations . installedBinary ;
7480 if ( binary === null )
7581 return yield * new NativeClientError ( {
7682 message : "Build finished but the development client is not installed." ,
7783 } ) ;
84+ yield * verifyInputs ;
7885 yield * operations . saveRecord ( { fingerprint, binary } ) ;
7986 return { status : "compatible" as const , rebuilt : true , fingerprint } ;
8087} ) ;
@@ -146,6 +153,22 @@ const collect = <E>(stream: Stream.Stream<Uint8Array, E>) =>
146153 ( a , b ) => a + b ,
147154 ) ,
148155 ) ;
156+ export const resolveAdb = Effect . gen ( function * ( ) {
157+ if ( yield * isCommandAvailable ( "adb" ) ) return "adb" ;
158+ const environment = yield * HostProcessEnvironment ;
159+ const path = yield * Path . Path ;
160+ const executable = ( yield * HostProcessPlatform ) === "win32" ? "adb.exe" : "adb" ;
161+ for ( const sdk of [ environment . ANDROID_SDK_ROOT , environment . ANDROID_HOME ] ) {
162+ if ( ! sdk ) continue ;
163+ const candidate = path . join ( sdk , "platform-tools" , executable ) ;
164+ if ( yield * isCommandAvailable ( candidate ) ) return candidate ;
165+ }
166+ return yield * new NativeClientError ( {
167+ message :
168+ "adb was not found on PATH or in ANDROID_SDK_ROOT/ANDROID_HOME. Install Android SDK platform-tools." ,
169+ } ) ;
170+ } ) ;
171+
149172const command = Effect . fn ( "nativeClient.command" ) ( function * (
150173 program : string ,
151174 args : string [ ] ,
@@ -154,8 +177,10 @@ const command = Effect.fn("nativeClient.command")(function* (
154177) {
155178 const spawner = yield * ChildProcessSpawner . ChildProcessSpawner ;
156179 const environment = yield * HostProcessEnvironment ;
180+ const spawn = yield * resolveSpawnCommand ( program === "adb" ? yield * resolveAdb : program , args ) ;
157181 const child = yield * spawner . spawn (
158- ChildProcess . make ( program , args , {
182+ ChildProcess . make ( spawn . command , spawn . args , {
183+ shell : spawn . shell ,
159184 cwd : cwd ?? ( yield * roots ) . mobile ,
160185 env : {
161186 ...environment ,
0 commit comments