Skip to content

Commit 3489c6d

Browse files
committed
fix(work-log): preserve split shell payloads
1 parent 6d10d59 commit 3489c6d

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

‎packages/client-runtime/src/work-log/commandLabel.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,14 @@ describe("commandProgramName", () => {
223223

224224
it.each([
225225
["cmd /c bcdedit /enum", "bcdedit"],
226+
["cmd /c cd C:\\work && npm test", "npm"],
226227
['cmd.exe /d /s /c "cd C:\\work && npm test"', "npm"],
227228
[
228229
'powershell.exe -NoProfile -ExecutionPolicy Bypass -File "C:\\work\\scripts\\doctor.ps1"',
229230
"doctor.ps1",
230231
],
231232
['pwsh -NoProfile -Command "Set-Location C:\\work; pnpm test"', "pnpm"],
233+
["pwsh -Command Set-Location C:\\work; pnpm test", "pnpm"],
232234
])("unwraps Windows shell launchers: %s", (command, program) => {
233235
expect(commandProgramName(command)).toBe(program);
234236
});
@@ -278,6 +280,7 @@ describe("commandProgramName", () => {
278280
"sudo cd /tmp && npm test",
279281
"command CI=1 npm test",
280282
"command false && npm test",
283+
"cmd /c false && npm test",
281284
"cd /tmp <<EOF\nunterminated heredoc",
282285
"cd /tmp && >/tmp/log",
283286
"(xcrun simctl io booted recordVideo /tmp/video.mp4 &) ; wait",

‎packages/client-runtime/src/work-log/commandLabel.ts‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -816,18 +816,25 @@ function windowsShellPayloadProgramName(
816816
tokens: ReadonlyArray<string>,
817817
start: number,
818818
depth: number,
819+
remainingCommand: string | null,
820+
separator: string | null,
819821
segmentsRemaining: number,
820822
): WindowsShellPayload {
823+
const parsePayload = (payload: string | undefined): string | null => {
824+
if (!payload) return null;
825+
const command =
826+
remainingCommand && separator ? `${payload} ${separator} ${remainingCommand}` : payload;
827+
return commandProgramNameInternal(command, depth + 1, "shell", segmentsRemaining);
828+
};
829+
821830
if (shell === "cmd" || shell === "cmd.exe") {
822831
for (let index = start; index < tokens.length; index += 1) {
823832
const option = tokens[index]!.toLowerCase();
824833
if (option !== "/c" && option !== "/k") continue;
825834
const payload = tokens[index + 1];
826835
return {
827836
matched: true,
828-
program: payload
829-
? commandProgramNameInternal(payload, depth + 1, "shell", segmentsRemaining)
830-
: null,
837+
program: parsePayload(payload),
831838
};
832839
}
833840
return { matched: false, program: null };
@@ -839,9 +846,7 @@ function windowsShellPayloadProgramName(
839846
const payload = tokens[index + 1];
840847
return {
841848
matched: true,
842-
program: payload
843-
? commandProgramNameInternal(payload, depth + 1, "shell", segmentsRemaining)
844-
: null,
849+
program: parsePayload(payload),
845850
};
846851
}
847852
if (option === "-file" || option === "-f") {
@@ -1234,6 +1239,8 @@ function parseCommandProgramName(
12341239
tokens,
12351240
index + 1,
12361241
depth,
1242+
commandSplit.remainingCommand,
1243+
commandSplit.separator,
12371244
segmentsRemaining,
12381245
);
12391246
if (payload.matched) return payload.program;

0 commit comments

Comments
 (0)