Skip to content

Commit 66608a0

Browse files
cameroncookecodex
andcommitted
ref(test): Share result bundle argument parsing
Move result bundle path parsing into a shared helper so single-phase and two-phase test execution paths use the same validation and precedence rules. Refs #397 Co-Authored-By: Codex <noreply@openai.com>
1 parent 899b5b7 commit 66608a0

3 files changed

Lines changed: 69 additions & 59 deletions

File tree

src/utils/result-bundle-args.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
function isResultBundlePathValue(value: string | undefined): value is string {
2+
return value !== undefined && value.length > 0 && !value.startsWith('-');
3+
}
4+
5+
export function parseResultBundlePathArgs(extraArgs?: readonly string[]): {
6+
remainingArgs: string[];
7+
resultBundlePath?: string;
8+
} {
9+
if (!extraArgs) {
10+
return { remainingArgs: [] };
11+
}
12+
13+
const remainingArgs: string[] = [];
14+
let resultBundlePath: string | undefined;
15+
16+
for (let index = 0; index < extraArgs.length; index += 1) {
17+
const argument = extraArgs[index];
18+
if (argument === '-resultBundlePath') {
19+
const value = extraArgs[index + 1];
20+
if (isResultBundlePathValue(value)) {
21+
resultBundlePath = value;
22+
index += 1;
23+
}
24+
continue;
25+
}
26+
27+
if (argument?.startsWith('-resultBundlePath=')) {
28+
const value = argument.slice('-resultBundlePath='.length);
29+
if (isResultBundlePathValue(value)) {
30+
resultBundlePath = value;
31+
}
32+
continue;
33+
}
34+
35+
if (argument !== undefined) {
36+
remainingArgs.push(argument);
37+
}
38+
}
39+
40+
return {
41+
remainingArgs,
42+
...(resultBundlePath ? { resultBundlePath } : {}),
43+
};
44+
}
45+
46+
export function findResultBundlePathArg(extraArgs?: readonly string[]): string | undefined {
47+
return parseResultBundlePathArgs(extraArgs).resultBundlePath;
48+
}

src/utils/simulator-test-execution.ts

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,37 @@
1+
import { parseResultBundlePathArgs } from './result-bundle-args.ts';
12
import type { TestPreflightResult } from './test-preflight.ts';
23

3-
function isResultBundlePathValue(value: string | undefined): value is string {
4-
return value !== undefined && value.length > 0 && !value.startsWith('-');
5-
}
6-
74
function parseTestSelectorArgs(extraArgs: string[] | undefined): {
85
remainingArgs: string[];
96
selectorArgs: string[];
107
resultBundlePath?: string;
118
} {
12-
if (!extraArgs || extraArgs.length === 0) {
13-
return { remainingArgs: [], selectorArgs: [] };
9+
const parsedResultBundleArgs = parseResultBundlePathArgs(extraArgs);
10+
if (parsedResultBundleArgs.remainingArgs.length === 0) {
11+
return {
12+
remainingArgs: [],
13+
selectorArgs: [],
14+
...(parsedResultBundleArgs.resultBundlePath
15+
? { resultBundlePath: parsedResultBundleArgs.resultBundlePath }
16+
: {}),
17+
};
1418
}
1519

1620
const remainingArgs: string[] = [];
1721
const selectorArgs: string[] = [];
18-
let resultBundlePath: string | undefined;
1922

20-
for (let index = 0; index < extraArgs.length; index += 1) {
21-
const argument = extraArgs[index]!;
23+
for (let index = 0; index < parsedResultBundleArgs.remainingArgs.length; index += 1) {
24+
const argument = parsedResultBundleArgs.remainingArgs[index]!;
2225

2326
if (argument === '-only-testing' || argument === '-skip-testing') {
24-
const value = extraArgs[index + 1];
27+
const value = parsedResultBundleArgs.remainingArgs[index + 1];
2528
if (value) {
2629
selectorArgs.push(argument, value);
2730
index += 1;
2831
}
2932
continue;
3033
}
3134

32-
if (argument === '-resultBundlePath') {
33-
const value = extraArgs[index + 1];
34-
if (isResultBundlePathValue(value)) {
35-
resultBundlePath = value;
36-
index += 1;
37-
}
38-
continue;
39-
}
40-
41-
if (argument.startsWith('-resultBundlePath=')) {
42-
const value = argument.slice('-resultBundlePath='.length);
43-
if (isResultBundlePathValue(value)) {
44-
resultBundlePath = value;
45-
}
46-
continue;
47-
}
48-
4935
if (argument.startsWith('-only-testing:') || argument.startsWith('-skip-testing:')) {
5036
selectorArgs.push(argument);
5137
continue;
@@ -54,7 +40,13 @@ function parseTestSelectorArgs(extraArgs: string[] | undefined): {
5440
remainingArgs.push(argument);
5541
}
5642

57-
return { remainingArgs, selectorArgs, resultBundlePath };
43+
return {
44+
remainingArgs,
45+
selectorArgs,
46+
...(parsedResultBundleArgs.resultBundlePath
47+
? { resultBundlePath: parsedResultBundleArgs.resultBundlePath }
48+
: {}),
49+
};
5850
}
5951

6052
export function createSimulatorTwoPhaseExecutionPlan(params: {

src/utils/test-common.ts

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { getDefaultCommandExecutor } from './command.ts';
1616
import { type TestPreflightResult } from './test-preflight.ts';
1717

1818
import { createSimulatorTwoPhaseExecutionPlan } from './simulator-test-execution.ts';
19+
import { findResultBundlePathArg } from './result-bundle-args.ts';
1920

2021
import type {
2122
BuildTarget,
@@ -59,37 +60,6 @@ function getFallbackErrorMessages(
5960
return [...streamedLines, ...(responseContent ?? []).map((item) => item.text)];
6061
}
6162

62-
function isResultBundlePathValue(value: string | undefined): value is string {
63-
return value !== undefined && value.length > 0 && !value.startsWith('-');
64-
}
65-
66-
function findResultBundlePathArg(extraArgs?: readonly string[]): string | undefined {
67-
if (!extraArgs) {
68-
return undefined;
69-
}
70-
71-
let resultBundlePath: string | undefined;
72-
for (let index = 0; index < extraArgs.length; index += 1) {
73-
const argument = extraArgs[index];
74-
if (argument === '-resultBundlePath') {
75-
const value = extraArgs[index + 1];
76-
if (isResultBundlePathValue(value)) {
77-
resultBundlePath = value;
78-
index += 1;
79-
}
80-
continue;
81-
}
82-
if (argument?.startsWith('-resultBundlePath=')) {
83-
const value = argument.slice('-resultBundlePath='.length);
84-
if (isResultBundlePathValue(value)) {
85-
resultBundlePath = value;
86-
}
87-
}
88-
}
89-
90-
return resultBundlePath;
91-
}
92-
9363
function createXcodebuildTestArtifacts(
9464
params: Pick<SharedTestExecutorParams, 'deviceId'>,
9565
started: ReturnType<typeof createDomainStreamingPipeline>,

0 commit comments

Comments
 (0)