Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(mobile): defer Java discovery until Maestro actually runs

DavidSheneb072c42613a
diff --git a/apps/mobile/scripts/maestro-e2e.mjs b/apps/mobile/scripts/maestro-e2e.mjs
index 31a156ee36..86dcd9a9b9 100644
--- a/apps/mobile/scripts/maestro-e2e.mjs
+++ b/apps/mobile/scripts/maestro-e2e.mjs
@@ -44,7 +44,6 @@ const expoOpenBeforeTest = normalizeBooleanEnv(
process.env.XDT_MOBILE_E2E_EXPO_OPEN_BEFORE_TEST ?? 'true',
'XDT_MOBILE_E2E_EXPO_OPEN_BEFORE_TEST',
);
-const toolEnv = resolveJavaRuntimeEnv(process.env);
const flows = options.flows.length > 0
? options.flows
: splitEnv(process.env.XDT_MOBILE_E2E_FLOWS) ?? ['remote_control_smoke.yaml'];
@@ -75,6 +74,10 @@ if (options.dryRun) {
process.exit(0);
}
+// Dry runs only validate/print the plan; Java discovery can start slow external
+// processes and is needed only when actually running Maestro.
+const toolEnv = resolveJavaRuntimeEnv(process.env);
+
if (includesLogin) {
const metroPort = expoUrl ? new URL(expoUrl).port || '8081' : '8081';
const ownership = probeMetroOwnership(Number(metroPort));
diff --git a/apps/mobile/src/__tests__/nativeE2eEnvironment.test.ts b/apps/mobile/src/__tests__/nativeE2eEnvironment.test.ts
index 61242b0c30..6d92b40d4b 100644
--- a/apps/mobile/src/__tests__/nativeE2eEnvironment.test.ts
+++ b/apps/mobile/src/__tests__/nativeE2eEnvironment.test.ts
@@ -293,12 +293,40 @@ describe('native e2e environment', () => {
expect(missingCredentials.stderr).toContain('isolated test environment');
});
+ it.each([true, false])('probes Java only for real Maestro runs (dryRun=%s)', (dryRun) => {
+ const source = readFileSync(resolve(process.cwd(), 'scripts/maestro-e2e.mjs'), 'utf8');
+ const start = source.indexOf('const options = parseArgs(');
+ expect(start).toBeGreaterThan(0);
+ const resolveJavaRuntimeEnv = vi.fn(() => { throw new Error('java-probe'); });
+ const probeMetroOwnership = vi.fn();
+ const spawn = vi.fn();
+ const log = vi.fn();
+ const execute = () => runInNewContext(source.slice(start), {
+ resolve, existsSync: () => true, readFileSync: () => 'appId: test',
+ resolveJavaRuntimeEnv, probeMetroOwnership, spawnSync: spawn,
+ resolveMobileE2eProfile: () => undefined,
+ mobileRoot: '/mobile', flowRoot: '/mobile/flows', doctorScript: '/mobile/doctor.mjs',
+ defaultAppId: 'com.xd.cindy', loginScenario: 'providers:email-only',
+ console: { log },
+ process: {
+ argv: ['node', 'maestro-e2e.mjs', ...(dryRun ? ['--dry-run'] : [])],
+ env: {}, exit: (code: number) => { throw new Error('exit:' + code); },
+ },
+ });
+ expect(execute).toThrow(dryRun ? 'exit:0' : 'java-probe');
+ expect(resolveJavaRuntimeEnv).toHaveBeenCalledTimes(dryRun ? 0 : 1);
+ expect(probeMetroOwnership).not.toHaveBeenCalled();
+ expect(spawn).not.toHaveBeenCalled();
+ if (dryRun) expect(log).toHaveBeenCalledWith('maestro dry run: APP_ID=com.xd.cindy');
+ });
+
it('keeps Maestro dry runs independent of Metro ownership', () => {
const script = resolve(process.cwd(), 'scripts/maestro-e2e.mjs');
const result = spawnSync(process.execPath, [script, '--dry-run', '--flow', 'login_mock_no_clear.yaml'], {
cwd: process.cwd(), encoding: 'utf8', timeout: 10_000,
env: { ...process.env, EXPO_PUBLIC_LOGIN_SCENARIO: '' },
});
+ expect(result.error).toBeUndefined();
expect(result.status).toBe(0);
expect(result.stdout).toContain('maestro dry run: APP_ID=');
expect(result.stderr).not.toContain('Active Metro');