Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 仅构建时识别私有设备目录,自动选择跳过不可读的 Cindy 目录,测试路径不依赖平台分隔符
Dash96107363aa63
diff --git a/apps/mobile/scripts/lib/sim-whoami.mjs b/apps/mobile/scripts/lib/sim-whoami.mjsindex d08f458b24..507d502101 100644--- a/apps/mobile/scripts/lib/sim-whoami.mjs+++ b/apps/mobile/scripts/lib/sim-whoami.mjs@@ -96,10 +96,19 @@ export function simctlArgs(deviceSet, args) {return deviceSet?.path ? ["simctl", "--set", deviceSet.path, ...args] : ["simctl", ...args];}-/** Use the set holding the exact UDID, otherwise the first set with a booted device. */+/**+ * Use the set holding the exact UDID, otherwise the first set with a booted device.+ * An unreadable fallback candidate is skipped; a pinned (single) set still reports its error.+ */export function selectBootedSimulator(deviceSets, listBooted, simulatorUdid) {for (const deviceSet of deviceSets) {- const lines = listBooted(deviceSet).split("\n");+ let lines;+ try {+ lines = listBooted(deviceSet).split("\n");+ } catch (error) {+ if (deviceSets.length === 1) throw error;+ continue;+ }const booted = bootedSimulatorLinesForTarget(lines, null);const targetBooted = bootedSimulatorLinesForTarget(lines, simulatorUdid);if (simulatorUdid ? targetBooted.length : booted.length) return { deviceSet, booted, targetBooted };@@ -107,6 +116,18 @@ export function selectBootedSimulator(deviceSets, listBooted, simulatorUdid) {return { deviceSet: deviceSets[0], booted: [], targetBooted: [] };}+/** Find the set that knows this UDID in any state (build-only runs need no booted device). */+export function findSimulatorDeviceSet(deviceSets, listDevices, simulatorUdid) {+ for (const deviceSet of deviceSets) {+ try {+ if (listDevices(deviceSet).toUpperCase().includes(`(${simulatorUdid.toUpperCase()})`)) return deviceSet;+ } catch {+ // An unreadable candidate cannot own the device; keep looking.+ }+ }+ return null;+}+/** Probe app installation on the exact Host-owned Simulator without fallback. */export function getSimulatorAppContainer(run, simulatorUdid, bundleId, deviceSet = null) {return run("xcrun", simctlArgs(deviceSet, [diff --git a/apps/mobile/scripts/sim-rebuild.mjs b/apps/mobile/scripts/sim-rebuild.mjsindex 81d373a505..90773883ef 100644--- a/apps/mobile/scripts/sim-rebuild.mjs+++ b/apps/mobile/scripts/sim-rebuild.mjs@@ -79,7 +79,7 @@ import {} from './sim-metro.mjs';import { readSimEnvironment } from './lib/sim-environment.mjs';-import { extractSimWhoamiUdidArgs, resolveMobileSimulatorBundleId, classifySimMetroListener, validateSimMetroIdentity, resolveSimulatorDeviceSets, selectBootedSimulator, simctlArgs } from './lib/sim-whoami.mjs';+import { extractSimWhoamiUdidArgs, resolveMobileSimulatorBundleId, classifySimMetroListener, validateSimMetroIdentity, resolveSimulatorDeviceSets, selectBootedSimulator, findSimulatorDeviceSet, simctlArgs } from './lib/sim-whoami.mjs';const mobileDir = resolve(dirname(fileURLToPath(import.meta.url)), '..');const worktreeRoot = resolve(mobileDir, '../..');@@ -168,6 +168,15 @@ if (!buildOnly) {}deviceSet = selected.deviceSet;console.log(`==> 目标模拟器(${deviceSet.name}):${selected.targetBooted[0].trim()}`);+} else if (simulatorUdid) {+ // 仅构建不要求设备已启动,但 xcodebuild 的精确目标只对系统目录有效:先确认 UDID 属于哪个目录。+ try {+ deviceSet = findSimulatorDeviceSet(resolveSimulatorDeviceSets(), (set) =>+ capture('xcrun', simctlArgs(set, ['list', 'devices'])), simulatorUdid);+ } catch (error) {+ console.error(`✗ ${error.message}`);+ process.exit(1);+ }}async function ensureMetroOwnershipBeforeLaunch(packageName) {diff --git a/apps/mobile/src/__tests__/mobileSimWhoami.test.ts b/apps/mobile/src/__tests__/mobileSimWhoami.test.tsindex 166193e4af..fedd12829a 100644--- a/apps/mobile/src/__tests__/mobileSimWhoami.test.ts+++ b/apps/mobile/src/__tests__/mobileSimWhoami.test.ts@@ -1,4 +1,5 @@// @ts-nocheck —— 被测对象是 .mjs 开发工具模块,vitest 跑其纯函数。+import { join } from 'node:path';import { describe, expect, it, vi } from 'vitest';import {bootedSimulatorLinesForTarget,@@ -12,6 +13,7 @@ import {resolveSimMetroHandoff,resolveSimulatorDeviceSets,selectBootedSimulator,+ findSimulatorDeviceSet,simctlArgs,} from '../../scripts/lib/sim-whoami.mjs';@@ -280,7 +282,7 @@ describe('mobile:sim:whoami exact Simulator target', () => {describe('mobile:sim simulator choice', () => {const root = '/home/test/Library/Application Support/BaguetteCindy';- const cindy = { name: 'cindy', path: `${root}/devices` };+ const cindy = { name: 'cindy', path: join(root, 'devices') };const system = { name: 'system', path: null };const settings = (value?: string) => () => {if (value === undefined) throw Object.assign(new Error('missing'), { code: 'ENOENT' });@@ -327,6 +329,27 @@ describe('mobile:sim simulator choice', () => {.toMatchObject({ deviceSet: system });expect(selectBootedSimulator([cindy, system], () => '', null)).toEqual({ deviceSet: cindy, booted: [], targetBooted: [] });});++ it('skips an unreadable Cindy set in auto mode but still reports a pinned set', () => {+ const line = `iPhone B (${SIMULATOR_UDID}) (Booted)`;+ const listBooted = (set: { name: string }) => {+ if (set.name === 'cindy') throw new Error('cannot read device set');+ return line;+ };+ expect(selectBootedSimulator([cindy, system], listBooted, null)).toMatchObject({ deviceSet: system, targetBooted: [line] });+ expect(() => selectBootedSimulator([cindy], listBooted, null)).toThrow(/cannot read/);+ });++ it('finds the owning device set for a UDID in any state', () => {+ const listing = { cindy: `iPhone A (${SIMULATOR_UDID.toLowerCase()}) (Shutdown)`, system: '' };+ const list = (set: { name: 'cindy' | 'system' }) => listing[set.name];+ expect(findSimulatorDeviceSet([cindy, system], list, SIMULATOR_UDID)).toBe(cindy);+ expect(findSimulatorDeviceSet([cindy, system], list, '11111111-2222-4333-8444-555555555555')).toBeNull();+ expect(findSimulatorDeviceSet([cindy, system], (set: { name: string }) => {+ if (set.name === 'cindy') throw new Error('unreadable');+ return `iPhone B (${SIMULATOR_UDID}) (Shutdown)`;+ }, SIMULATOR_UDID)).toBe(system);+ });});describe('mobile:sim:whoami bundle identity', () => {diff --git a/apps/mobile/src/__tests__/simRebuildScript.test.ts b/apps/mobile/src/__tests__/simRebuildScript.test.tsindex 0ed98bef29..9da9804b53 100644--- a/apps/mobile/src/__tests__/simRebuildScript.test.ts+++ b/apps/mobile/src/__tests__/simRebuildScript.test.ts@@ -5,7 +5,7 @@ import { describe, expect, it, vi } from 'vitest';import { mobileClientBundleEnv } from '../../../../scripts/shared/client-endpoint-build-env.mjs';import { resolvePnpmInvocation, usablePnpmExecPath } from '../../../../scripts/shared/pnpm-invocation.mjs';import { extractMobileDevRegionArgs, withLocalMobileRegionConfig } from '../../scripts/lib/mobile-dev-region.mjs';-import { extractSimWhoamiUdidArgs, resolveMobileSimulatorBundleId, selectBootedSimulator, simctlArgs } from '../../scripts/lib/sim-whoami.mjs';+import { extractSimWhoamiUdidArgs, resolveMobileSimulatorBundleId, selectBootedSimulator, findSimulatorDeviceSet, simctlArgs } from '../../scripts/lib/sim-whoami.mjs';const source = readFileSync(resolve(process.cwd(), 'scripts/sim-rebuild.mjs'), 'utf8');const start = source.indexOf('const iosDir =');@@ -36,7 +36,7 @@ async function rebuild(options: {if (command === 'xcrun' && args.includes('get_app_container')) return '/installed/Cindy.app';if (command === 'xcrun' && args.includes('list')) {const inCindySet = args.includes(cindySet.path);- return inCindySet === Boolean(options.cindyBooted) ? `iPhone (${udid}) (Booted)` : '';+ return inCindySet === Boolean(options.cindyBooted) ? `iPhone (${udid}) (${args.includes('booted') ? 'Booted' : 'Shutdown'})` : '';}if (['pnpm', '/node', 'xcodebuild', 'cmd.exe', '/sdk/adb', 'xcrun'].includes(command)) return '';throw new Error(`unexpected executable ${command}`);@@ -59,7 +59,7 @@ async function rebuild(options: {mobileDir, worktreeRoot: '/repo', join: posix.join, resolve: posix.resolve, homedir: () => '/home/test',process: processStub, console: { log, error: log, warn: log }, execFileSync, spawnSync,mobileClientBundleEnv, extractMobileDevRegionArgs, withLocalMobileRegionConfig,- extractSimWhoamiUdidArgs, selectBootedSimulator, simctlArgs,+ extractSimWhoamiUdidArgs, selectBootedSimulator, findSimulatorDeviceSet, simctlArgs,resolveSimulatorDeviceSets: () => [cindySet, { name: 'system', path: null }],resolveMobileSimulatorBundleId: (region: string) => resolveMobileSimulatorBundleId(region, { execFile: () => JSON.stringify({ ios: { bundleIdentifier: 'com.xd.cindy' } }) }),resolvePnpmInvocation: (args: string[], opts: object) => resolvePnpmInvocation(args, { ...opts, platform: processStub.platform, execPath: '/node' }),@@ -110,7 +110,9 @@ describe('sim-rebuild workflow', () => {expect(result.utimesSync.mock.calls[0][1].getTime()).toBeGreaterThan(0);expect(result.cpSync).not.toHaveBeenCalled();}- expect(result.execFileSync.mock.calls.some(([cmd]) => cmd === 'xcrun')).toBe(false);+ // build-only never touches the device; with --udid it only reads the device list to find the owning set.+ expect(result.execFileSync.mock.calls.some(([cmd, args]) => cmd === 'xcrun'+ && ['install', 'launch', 'uninstall', 'get_app_container'].some((action) => args.includes(action)))).toBe(false);});it.each(['fingerprint-failure', 'cached-architecture-mismatch'])('falls back to a full build for %s', async (reason) => {@@ -131,6 +133,12 @@ describe('sim-rebuild workflow', () => {}});+ it('uses the generic destination for a build-only UDID that lives in Cindy\'s set, even when shut down', async () => {+ const result = await rebuild({ cindyBooted: true, args: ['--build-only', '--force-build', '--udid', udid] });+ expect(result.error).toEqual(new Error('exit:0'));+ expect(result.execFileSync).toHaveBeenCalledWith('xcodebuild', expect.arrayContaining(['-destination', 'generic/platform=iOS Simulator']), expect.any(Object));+ });+it('falls back to the system simulator when Cindy has no booted device', async () => {const result = await rebuild({ args: ['--udid', udid] });expect(result.error).toBeUndefined();