Skip to content

Commit dd4727b

Browse files
committed
fix(simulator): restrict PID parsing to colon pattern on first line
resolveAppPid scanned all output lines with a bracket regex that matched 3+ digit numbers like [404], causing HTTP status codes to be returned as PIDs. Restrict to checking only the first non-empty line using the colon format (e.g. com.example.app: 42567), which is the actual simctl output pattern.
1 parent db7877d commit dd4727b

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

src/utils/__tests__/simulator-steps-pid.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import { launchSimulatorAppWithLogging } from '../simulator-steps.ts';
77
function createMockChild(exitCode: number | null = null): ChildProcess {
88
const emitter = new EventEmitter();
99
const child = emitter as unknown as ChildProcess;
10-
child.exitCode = exitCode;
10+
Object.defineProperty(child, 'exitCode', { value: exitCode, writable: true });
1111
child.unref = vi.fn();
12-
child.pid = 99999;
12+
Object.defineProperty(child, 'pid', { value: 99999, writable: true });
1313
return child;
1414
}
1515

src/utils/simulator-steps.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,9 @@ async function resolveAppPid(logFilePath: string): Promise<number | undefined> {
220220
while (Date.now() - start < PID_POLL_TIMEOUT_MS) {
221221
const content = readLogFileSafe(logFilePath);
222222
if (content) {
223-
for (const line of content.split('\n')) {
224-
const bracketMatch = line.match(/\[(\d{3,})\]/);
225-
if (bracketMatch) {
226-
return parseInt(bracketMatch[1], 10);
227-
}
228-
const colonMatch = line.match(/:\s*(\d+)\s*$/);
223+
const firstLine = content.split('\n').find((l) => l.trim().length > 0);
224+
if (firstLine) {
225+
const colonMatch = firstLine.match(/:\s*(\d+)\s*$/);
229226
if (colonMatch) {
230227
return parseInt(colonMatch[1], 10);
231228
}

0 commit comments

Comments
 (0)