Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(ios-simulator): gate startup marker recovery
JiangJiahaoe2c93c0475f9
diff --git a/apps/desktop/src/main/mcp-integrations/__tests__/ios-simulator.test.ts b/apps/desktop/src/main/mcp-integrations/__tests__/ios-simulator.test.tsindex 5b137de520..e3fff26dde 100644--- a/apps/desktop/src/main/mcp-integrations/__tests__/ios-simulator.test.ts+++ b/apps/desktop/src/main/mcp-integrations/__tests__/ios-simulator.test.ts@@ -191,6 +191,72 @@ describe('iOS Simulator host', () => {},);+ it('gates an already-created Host on one startup pending-create recovery', async () => {+ let finishRecovery: (value: readonly string[]) => void = () => undefined;+ const recoverPendingCreatesAtStartup = vi.fn(+ (_owned: readonly { udid: string; name: string }[], _signal?: AbortSignal) =>+ new Promise<readonly string[]>((resolve) => {+ finishRecovery = resolve;+ }),+ );+ const lifecycle: IOSSimulatorSimctlLifecycle = {+ findExact: vi.fn(),+ bootExact: vi.fn(),+ shutdownExact: vi.fn(),+ createExact: vi.fn(),+ recoverPendingCreatesAtStartup,+ deleteExact: vi.fn(),+ };+ const inspect = vi.fn(async () => READY_REPORT);+ const host = createIOSSimulatorHost({+ lifecycle,+ runtime: { inspect },+ getSession: vi.fn(async (id) => localSession(id)),+ });++ const firstCall = host.callTool('list_devices', {}, { sessionId: 'session-a' });+ await vi.waitFor(() => expect(recoverPendingCreatesAtStartup).toHaveBeenCalledOnce());+ expect(recoverPendingCreatesAtStartup).toHaveBeenCalledWith([], expect.any(AbortSignal));+ expect(inspect).not.toHaveBeenCalled();++ finishRecovery([]);+ await expect(firstCall).resolves.toMatchObject({ ok: true });+ await expect(+ host.callTool('list_devices', {}, { sessionId: 'session-a' }),+ ).resolves.toMatchObject({ ok: true });+ expect(recoverPendingCreatesAtStartup).toHaveBeenCalledOnce();+ });++ it('retries startup pending-create recovery after the ownership gate becomes available', async () => {+ let recoveryAllowed = false;+ const recoverPendingCreatesAtStartup = vi.fn(async () => [] as readonly string[]);+ const lifecycle: IOSSimulatorSimctlLifecycle = {+ findExact: vi.fn(),+ bootExact: vi.fn(),+ shutdownExact: vi.fn(),+ createExact: vi.fn(),+ recoverPendingCreatesAtStartup,+ deleteExact: vi.fn(),+ };+ const host = createIOSSimulatorHost({+ lifecycle,+ runtime: { inspect: vi.fn(async () => READY_REPORT) },+ getSession: vi.fn(async (id) => localSession(id)),+ canReconcilePendingCreates: () => recoveryAllowed,+ });++ await expect(+ host.callTool('list_devices', {}, { sessionId: 'session-a' }),+ ).resolves.toMatchObject({ ok: true });+ expect(recoverPendingCreatesAtStartup).not.toHaveBeenCalled();++ recoveryAllowed = true;+ await expect(+ host.callTool('list_devices', {}, { sessionId: 'session-a' }),+ ).resolves.toMatchObject({ ok: true });+ expect(recoverPendingCreatesAtStartup).toHaveBeenCalledOnce();+ });+it('does not reconcile Simulator ownership during generic IPC bootstrap', () => {const source = readFileSync(new URL('../../maker-ipc/register.ts', import.meta.url), 'utf8');expect(source).not.toContain('reconcileIOSSimulatorOwnership');diff --git a/apps/desktop/src/main/mcp-integrations/ios-simulator.ts b/apps/desktop/src/main/mcp-integrations/ios-simulator.tsindex bfcc07aad8..7054fad247 100644--- a/apps/desktop/src/main/mcp-integrations/ios-simulator.ts+++ b/apps/desktop/src/main/mcp-integrations/ios-simulator.ts@@ -390,9 +390,13 @@ const STARTUP_PENDING_CREATE_RECOVERY_TIMEOUT_MS = 6_000;async function recoverProfilePendingCreatesAtStartup(lifecycle: IOSSimulatorSimctlLifecycle,persistedInstances: readonly IOSSimulatorInstance[],+ signal?: AbortSignal,): Promise<void> {if (!lifecycle.recoverPendingCreatesAtStartup) return;const controller = new AbortController();+ const abortFromParent = (): void => controller.abort(signal?.reason);+ if (signal?.aborted) abortFromParent();+ else signal?.addEventListener('abort', abortFromParent, { once: true });const timer = setTimeout(() => controller.abort(new Error('Simulator pending-create startup recovery timed out')),STARTUP_PENDING_CREATE_RECOVERY_TIMEOUT_MS,@@ -415,6 +419,7 @@ async function recoverProfilePendingCreatesAtStartup(});} finally {clearTimeout(timer);+ signal?.removeEventListener('abort', abortFromParent);}}@@ -980,7 +985,8 @@ export function createIOSSimulatorHost(options: IOSSimulatorHostOptions = {}): Ilet ownershipReconciled = false;let ownershipReconcilePromise: Promise<void> | null = null;let pendingCreateReconcileController: AbortController | null = null;- let pendingCreateReconcilePromise: Promise<readonly string[]> | null = null;+ let pendingCreateReconcilePromise: Promise<unknown> | null = null;+ let startupPendingCreateRecoveryAttempted = false;let disposePromise: Promise<void> | null = null;const canReconcilePendingCreates = options.canReconcilePendingCreates ?? (() => true);@@ -2334,6 +2340,30 @@ export function createIOSSimulatorHost(options: IOSSimulatorHostOptions = {}): Iif (ownershipReconcilePromise) return ownershipReconcilePromise;ownershipReconcilePromise = (async () => {let complete = true;+ if (!startupPendingCreateRecoveryAttempted && lifecycle.recoverPendingCreatesAtStartup) {+ if (!canReconcilePendingCreates()) {+ complete = false;+ } else {+ startupPendingCreateRecoveryAttempted = true;+ const controller = new AbortController();+ const recovery = recoverProfilePendingCreatesAtStartup(+ lifecycle,+ actor.listAll(),+ controller.signal,+ );+ pendingCreateReconcileController = controller;+ pendingCreateReconcilePromise = recovery;+ try {+ await recovery;+ } finally {+ if (pendingCreateReconcileController === controller) {+ pendingCreateReconcileController = null;+ pendingCreateReconcilePromise = null;+ }+ }+ }+ }+ if (disposePromise) return;const persistedInstances = actor.listAll();if (lifecycle.reconcilePendingCreates && persistedInstances.length > 0) {if (!canReconcilePendingCreates()) {@@ -6155,8 +6185,8 @@ export async function reconcilePersistedIOSSimulatorOwnership(const persistedInstances = registry.loadSync();const lifecycle =options.createLifecycle?.(registry) ?? createProfileScopedIOSSimulatorLifecycle(registry);- await recoverProfilePendingCreatesAtStartup(lifecycle, persistedInstances);if (persistedInstances.length === 0) {+ await recoverProfilePendingCreatesAtStartup(lifecycle, persistedInstances);registry.releaseWriterSync();return;}