From 934f85c3ef5552f50a5de66af469760e49ae1353 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 3 Mar 2026 15:33:58 +0100 Subject: [PATCH 1/3] fix: clean daemon metadata in integration teardown --- test/integration/android.test.ts | 3 ++- test/integration/ios.test.ts | 3 ++- test/integration/test-helpers.ts | 13 ++++++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/test/integration/android.test.ts b/test/integration/android.test.ts index 0352469bbc..82c74572c1 100644 --- a/test/integration/android.test.ts +++ b/test/integration/android.test.ts @@ -1,5 +1,5 @@ import test from 'node:test'; -import { createIntegrationTestContext, runCliJson } from './test-helpers.ts'; +import { cleanupDefaultDaemonMetadata, createIntegrationTestContext, runCliJson } from './test-helpers.ts'; const session = ['--session', 'android-test']; const settingsSectionLabels = [ @@ -24,6 +24,7 @@ const settingsCrashDialogSelector = settingsCrashDialogLabels test.after(() => { runCliJson(['close', '--platform', 'android', ...session]); + cleanupDefaultDaemonMetadata(); }); test('android settings commands', () => { diff --git a/test/integration/ios.test.ts b/test/integration/ios.test.ts index da35894c4c..f8ef4e8721 100644 --- a/test/integration/ios.test.ts +++ b/test/integration/ios.test.ts @@ -1,7 +1,7 @@ import test from 'node:test'; import { existsSync } from 'node:fs'; import path from 'node:path'; -import { createIntegrationTestContext, runCliJson } from './test-helpers.ts'; +import { cleanupDefaultDaemonMetadata, createIntegrationTestContext, runCliJson } from './test-helpers.ts'; const session = ['--session', 'ios-test']; const iosTarget = ['--platform', 'ios']; @@ -13,6 +13,7 @@ test.after(() => { if (iosPhysicalUdid && didRunIosPhysicalSession) { runCliJson(['close', '--platform', 'ios', '--udid', iosPhysicalUdid, '--json', '--session', 'ios-device-test']); } + cleanupDefaultDaemonMetadata(); }); test('ios settings commands', { skip: shouldSkipIos() }, async () => { diff --git a/test/integration/test-helpers.ts b/test/integration/test-helpers.ts index 34cb2e5360..f43990f4e2 100644 --- a/test/integration/test-helpers.ts +++ b/test/integration/test-helpers.ts @@ -1,6 +1,7 @@ import assert from 'node:assert/strict'; -import { mkdirSync, writeFileSync } from 'node:fs'; +import { existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs'; import path from 'node:path'; +import { resolveDaemonPaths } from '../../src/daemon/config.ts'; import { runCmdSync } from '../../src/utils/exec.ts'; export type CliJsonResult = { @@ -73,6 +74,16 @@ export function formatResultDebug(step: string, args: string[], result: CliJsonR ].join('\n'); } +export function cleanupDefaultDaemonMetadata(): void { + const { infoPath, lockPath } = resolveDaemonPaths(process.env.AGENT_DEVICE_STATE_DIR); + if (existsSync(infoPath)) { + rmSync(infoPath, { force: true }); + } + if (existsSync(lockPath)) { + rmSync(lockPath, { force: true }); + } +} + export function createIntegrationTestContext(options: IntegrationTestContextOptions) { const { platform, testName } = options; const stepHistory: StepRecord[] = []; From 17f200fff387a45b511ddb3c98d30dbd2cc878e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 3 Mar 2026 16:02:27 +0100 Subject: [PATCH 2/3] fix: isolate integration daemon state dirs --- test/integration/android.test.ts | 12 +++++++++--- test/integration/ios.test.ts | 26 +++++++++++++++++++++----- test/integration/test-helpers.ts | 6 +++++- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/test/integration/android.test.ts b/test/integration/android.test.ts index 82c74572c1..5095ab7c7e 100644 --- a/test/integration/android.test.ts +++ b/test/integration/android.test.ts @@ -1,7 +1,9 @@ import test from 'node:test'; -import { cleanupDefaultDaemonMetadata, createIntegrationTestContext, runCliJson } from './test-helpers.ts'; +import path from 'node:path'; +import { cleanupDaemonMetadata, createIntegrationTestContext, runCliJson } from './test-helpers.ts'; -const session = ['--session', 'android-test']; +const stateDir = path.resolve('test/.state/android-integration'); +const session = ['--session', 'android-test', '--state-dir', stateDir]; const settingsSectionLabels = [ 'Apps', 'Apps & notifications', @@ -22,9 +24,13 @@ const settingsCrashDialogSelector = settingsCrashDialogLabels .map((label) => (label.includes(' ') ? `label="${label}"` : `label=${label}`)) .join(' || '); +test.before(() => { + cleanupDaemonMetadata(stateDir); +}); + test.after(() => { runCliJson(['close', '--platform', 'android', ...session]); - cleanupDefaultDaemonMetadata(); + cleanupDaemonMetadata(stateDir); }); test('android settings commands', () => { diff --git a/test/integration/ios.test.ts b/test/integration/ios.test.ts index f8ef4e8721..19a842b281 100644 --- a/test/integration/ios.test.ts +++ b/test/integration/ios.test.ts @@ -1,19 +1,35 @@ import test from 'node:test'; import { existsSync } from 'node:fs'; import path from 'node:path'; -import { cleanupDefaultDaemonMetadata, createIntegrationTestContext, runCliJson } from './test-helpers.ts'; +import { cleanupDaemonMetadata, createIntegrationTestContext, runCliJson } from './test-helpers.ts'; -const session = ['--session', 'ios-test']; +const stateDir = path.resolve('test/.state/ios-integration'); +const daemonState = ['--state-dir', stateDir]; +const session = ['--session', 'ios-test', ...daemonState]; const iosTarget = ['--platform', 'ios']; const iosPhysicalUdid = process.env.IOS_UDID?.trim(); let didRunIosPhysicalSession = false; +test.before(() => { + cleanupDaemonMetadata(stateDir); +}); + test.after(() => { runCliJson(['close', ...iosTarget, '--json', ...session]); if (iosPhysicalUdid && didRunIosPhysicalSession) { - runCliJson(['close', '--platform', 'ios', '--udid', iosPhysicalUdid, '--json', '--session', 'ios-device-test']); + runCliJson([ + 'close', + '--platform', + 'ios', + '--udid', + iosPhysicalUdid, + '--json', + '--session', + 'ios-device-test', + ...daemonState, + ]); } - cleanupDefaultDaemonMetadata(); + cleanupDaemonMetadata(stateDir); }); test('ios settings commands', { skip: shouldSkipIos() }, async () => { @@ -100,7 +116,7 @@ test('ios physical device core lifecycle', { skip: shouldSkipIosPhysicalDevice() platform: 'ios', testName: 'ios physical device core lifecycle', }); - const deviceSession = ['--session', 'ios-device-test']; + const deviceSession = ['--session', 'ios-device-test', ...daemonState]; const target = ['--platform', 'ios', '--udid', iosPhysicalUdid as string]; didRunIosPhysicalSession = true; diff --git a/test/integration/test-helpers.ts b/test/integration/test-helpers.ts index f43990f4e2..6a2440cd27 100644 --- a/test/integration/test-helpers.ts +++ b/test/integration/test-helpers.ts @@ -75,7 +75,11 @@ export function formatResultDebug(step: string, args: string[], result: CliJsonR } export function cleanupDefaultDaemonMetadata(): void { - const { infoPath, lockPath } = resolveDaemonPaths(process.env.AGENT_DEVICE_STATE_DIR); + cleanupDaemonMetadata(process.env.AGENT_DEVICE_STATE_DIR); +} + +export function cleanupDaemonMetadata(stateDir?: string): void { + const { infoPath, lockPath } = resolveDaemonPaths(stateDir); if (existsSync(infoPath)) { rmSync(infoPath, { force: true }); } From d4a6c0981cf51d2fb1f1972694a2eceb900b66a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 3 Mar 2026 16:58:56 +0100 Subject: [PATCH 3/3] fix: raise configurable daemon startup timeout --- src/daemon-client.ts | 11 ++++++++++- src/utils/__tests__/daemon-client.test.ts | 17 ++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/daemon-client.ts b/src/daemon-client.ts index 055a29df44..f84403852f 100644 --- a/src/daemon-client.ts +++ b/src/daemon-client.ts @@ -52,7 +52,7 @@ type DaemonClientSettings = { }; const REQUEST_TIMEOUT_MS = resolveDaemonRequestTimeoutMs(); -const DAEMON_STARTUP_TIMEOUT_MS = 5000; +const DAEMON_STARTUP_TIMEOUT_MS = resolveDaemonStartupTimeoutMs(); const DAEMON_TAKEOVER_TERM_TIMEOUT_MS = 3000; const DAEMON_TAKEOVER_KILL_TIMEOUT_MS = 1000; const IOS_RUNNER_XCODEBUILD_KILL_PATTERNS = [ @@ -650,6 +650,15 @@ export function resolveDaemonRequestTimeoutMs(raw: string | undefined = process. return Math.max(1000, Math.floor(parsed)); } +export function resolveDaemonStartupTimeoutMs( + raw: string | undefined = process.env.AGENT_DEVICE_DAEMON_STARTUP_TIMEOUT_MS, +): number { + if (!raw) return 15000; + const parsed = Number(raw); + if (!Number.isFinite(parsed)) return 15000; + return Math.max(1000, Math.floor(parsed)); +} + export function resolveDaemonStartupHint( state: { hasInfo: boolean; hasLock: boolean }, paths: Pick = resolveDaemonPaths(process.env.AGENT_DEVICE_STATE_DIR), diff --git a/src/utils/__tests__/daemon-client.test.ts b/src/utils/__tests__/daemon-client.test.ts index 0d2890ec4b..cf7511ae90 100644 --- a/src/utils/__tests__/daemon-client.test.ts +++ b/src/utils/__tests__/daemon-client.test.ts @@ -4,7 +4,12 @@ import { spawn } from 'node:child_process'; import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; -import { computeDaemonCodeSignature, resolveDaemonRequestTimeoutMs, resolveDaemonStartupHint } from '../../daemon-client.ts'; +import { + computeDaemonCodeSignature, + resolveDaemonRequestTimeoutMs, + resolveDaemonStartupHint, + resolveDaemonStartupTimeoutMs, +} from '../../daemon-client.ts'; import { resolveDaemonPaths } from '../../daemon/config.ts'; import { isProcessAlive, @@ -23,6 +28,16 @@ test('resolveDaemonRequestTimeoutMs enforces minimum timeout', () => { assert.equal(resolveDaemonRequestTimeoutMs('invalid'), 90000); }); +test('resolveDaemonStartupTimeoutMs defaults to 15000', () => { + assert.equal(resolveDaemonStartupTimeoutMs(undefined), 15000); +}); + +test('resolveDaemonStartupTimeoutMs enforces minimum timeout', () => { + assert.equal(resolveDaemonStartupTimeoutMs('100'), 1000); + assert.equal(resolveDaemonStartupTimeoutMs('20000'), 20000); + assert.equal(resolveDaemonStartupTimeoutMs('invalid'), 15000); +}); + test('resolveDaemonStartupHint prefers stale lock guidance when lock exists without info', () => { const hint = resolveDaemonStartupHint({ hasInfo: false, hasLock: true }); assert.match(hint, /daemon\.lock/i);