Skip to content

Commit 37b1eca

Browse files
committed
refactor(shell-quote): one implementation, reached through the runner host port
Closes #2525. The Android perf copy is a direct import swap to @agent-device/host-kit/command, which platform-android already uses for shellQuoteIfNeeded. The apple runner copy goes through AppleRunnerHost because R77 (apple-runner-host-port) forbids a value import of host-kit from runner/**, and runner/ sits in the eager closure of seven Apple facades.
1 parent 730b201 commit 37b1eca

5 files changed

Lines changed: 8 additions & 9 deletions

File tree

‎packages/platform-android/src/perf-native-artifacts.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from 'node:path';
22
import type { DeviceInfo } from '@agent-device/kernel/device';
33
import { AppError } from '@agent-device/kernel/errors';
4+
import { shellQuote } from '@agent-device/host-kit/command';
45
import { sleep } from '@agent-device/host-kit/retry';
56
import { resolveAndroidAdbExecutor, type AndroidAdbExecutor } from './adb-executor.ts';
67
import { annotateAndroidNativePerfError } from './perf-native-errors.ts';
@@ -121,10 +122,6 @@ export async function readFileSize(
121122
}
122123
}
123124

124-
export function shellQuote(value: string): string {
125-
return `'${value.replaceAll("'", `'\\''`)}'`;
126-
}
127-
128125
async function stopAndroidBackgroundTool(
129126
adb: AndroidAdbExecutor,
130127
session: AndroidNativePerfSession,

‎packages/platform-android/src/perf-native-simpleperf.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type { DeviceInfo } from '@agent-device/kernel/device';
22
import { AppError } from '@agent-device/kernel/errors';
3+
import { shellQuote } from '@agent-device/host-kit/command';
34
import { resolveAndroidAdbExecutor, type AndroidAdbExecutor } from './adb-executor.ts';
45
import {
56
buildAndroidNativeRemotePath,
67
cleanupAndroidRemotePath,
78
readFileSize,
8-
shellQuote,
99
stopAndroidNativePerfSession,
1010
writeJsonArtifact,
1111
} from './perf-native-artifacts.ts';

‎packages/platform-apple/src/core/runner-host.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
runCmdBackground,
99
runCmdStreaming,
1010
runCmdSync,
11+
shellQuote,
1112
} from '@agent-device/host-kit/command';
1213
import { emitDiagnostic, withDiagnosticTimer } from '@agent-device/host-kit/diagnostics';
1314
import {
@@ -57,6 +58,7 @@ export const appleRunnerHost: AppleRunnerHost = {
5758
runCmdBackground,
5859
requireExecSuccess,
5960
isCommandTimeoutError,
61+
shellQuote,
6062
emitDiagnostic,
6163
withDiagnosticTimer,
6264
retryWithPolicy,

‎packages/platform-apple/src/runner/host.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ export type AppleRunnerHost = {
167167
): ExecResult;
168168
/** True only for the error the exec layer raises when it killed a command at `timeoutMs`. */
169169
isCommandTimeoutError(error: unknown): boolean;
170+
/** Single-quote one value for a POSIX shell fragment (hints and remote commands). */
171+
shellQuote(value: string): string;
170172
// Diagnostics (@agent-device/host-kit/diagnostics)
171173
emitDiagnostic(event: DiagnosticEventInput): void;
172174
withDiagnosticTimer<T>(
@@ -297,6 +299,7 @@ export const requireExecSuccess: AppleRunnerHost['requireExecSuccess'] = (result
297299
requireHost().requireExecSuccess(result, message, extra);
298300
export const isCommandTimeoutError: AppleRunnerHost['isCommandTimeoutError'] = (error) =>
299301
requireHost().isCommandTimeoutError(error);
302+
export const shellQuote: AppleRunnerHost['shellQuote'] = (value) => requireHost().shellQuote(value);
300303
export const emitDiagnostic: AppleRunnerHost['emitDiagnostic'] = (event) =>
301304
requireHost().emitDiagnostic(event);
302305
export const withDiagnosticTimer = <T>(

‎packages/platform-apple/src/runner/runner-lease.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
readProcessStartTime,
1313
classifyOwnerLiveness,
1414
leaseOwnerStateDir,
15+
shellQuote,
1516
} from './host.ts';
1617
import { AppError } from '@agent-device/kernel/errors';
1718
import type { DeviceInfo } from '@agent-device/kernel/device';
@@ -289,10 +290,6 @@ function formatEnvAssignment(name: string, value: string): string {
289290
return `${name}=${shellQuote(value)}`;
290291
}
291292

292-
function shellQuote(value: string): string {
293-
return `'${value.replaceAll("'", String.raw`'\''`)}'`;
294-
}
295-
296293
// A lease whose owner process is gone but whose runner may still be running:
297294
// the adoption path probes it instead of killing it. Detached leases (graceful
298295
// daemon shutdown rewrote the token) classify as stale too once the owner pid

0 commit comments

Comments
 (0)