Skip to content

Commit 651c22c

Browse files
committed
refactor(daemon): read each replay lock plan through its own engine helper
Keeping the whole probe inside the advisory guard grew its closure past the fallow complexity threshold. Split the maestro and .ad plan reads into named helpers so the guarded closure only resolves the bundle entry and routes by format; the #1802 tolerance stays in readAdvisoryResolution alone.
1 parent b27e310 commit 651c22c

1 file changed

Lines changed: 31 additions & 19 deletions

File tree

‎src/daemon/replay-device-selection.ts‎

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,41 @@ export async function buildReplayTargetDeviceResolution(
3838
const resolved = bundle.entry;
3939
const source = readReplayScriptSourceFile(bundle, resolved);
4040
if (resolveReplayFormat(resolved, req.flags?.replayBackend) === 'maestro') {
41-
const { inspectMaestroFlow } = await import('@agent-device/maestro');
42-
const flow = inspectMaestroFlow(source, resolved);
43-
return {
44-
flags: req.flags ?? {},
45-
options: buildMaestroReplayTargetDeviceResolutionOptions(
46-
flow.appTarget,
47-
req.flags?.platform,
48-
),
49-
};
41+
return await readMaestroReplayResolution(source, resolved, req.flags);
5042
}
51-
const parsed = parseReplayInput(source, req.flags);
52-
const selection = readScriptReplaySelection(parsed.actions);
53-
if (!selection.appTarget) return undefined;
54-
const scriptFlags = buildReplayScriptPlatformFlags(req.flags, parsed.actions);
55-
const platform = scriptFlags.platform ?? parsed.metadata.platform;
56-
return {
57-
flags:
58-
platform && scriptFlags.platform === undefined ? { ...scriptFlags, platform } : scriptFlags,
59-
options: platform === 'ios' ? appTargetResolutionOptions(selection.appTarget) : undefined,
60-
};
43+
return readAdScriptResolution(source, req.flags);
6144
});
6245
}
6346

47+
async function readMaestroReplayResolution(
48+
source: string,
49+
resolvedPath: string,
50+
flags: DaemonRequest['flags'],
51+
): Promise<ReplayTargetDeviceResolution> {
52+
const { inspectMaestroFlow } = await import('@agent-device/maestro');
53+
const flow = inspectMaestroFlow(source, resolvedPath);
54+
return {
55+
flags: flags ?? {},
56+
options: buildMaestroReplayTargetDeviceResolutionOptions(flow.appTarget, flags?.platform),
57+
};
58+
}
59+
60+
function readAdScriptResolution(
61+
source: string,
62+
flags: DaemonRequest['flags'],
63+
): ReplayTargetDeviceResolution | undefined {
64+
const parsed = parseReplayInput(source, flags);
65+
const selection = readScriptReplaySelection(parsed.actions);
66+
if (!selection.appTarget) return undefined;
67+
const scriptFlags = buildReplayScriptPlatformFlags(flags, parsed.actions);
68+
const platform = scriptFlags.platform ?? parsed.metadata.platform;
69+
return {
70+
flags:
71+
platform && scriptFlags.platform === undefined ? { ...scriptFlags, platform } : scriptFlags,
72+
options: platform === 'ios' ? appTargetResolutionOptions(selection.appTarget) : undefined,
73+
};
74+
}
75+
6476
async function readAdvisoryResolution(
6577
read: () => Promise<ReplayTargetDeviceResolution | undefined>,
6678
): Promise<ReplayTargetDeviceResolution | undefined> {

0 commit comments

Comments
 (0)