Skip to content

Commit a9c289b

Browse files
committed
addressing codex review
1 parent 44cb6c4 commit a9c289b

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

src/infra/shell-inline-command.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ export function resolvePowerShellInlineCommandMatch(argv: string[]): {
217217
});
218218
}
219219

220+
export function isPowerShellInlineRestCommandFlag(token: string): boolean {
221+
return POWERSHELL_INLINE_REST_COMMAND_FLAGS.has(normalizeLowercaseStringOrEmpty(token));
222+
}
223+
220224
export function hasPosixInteractiveStartupBeforeInlineCommand(
221225
argv: string[],
222226
flags: ReadonlySet<string>,

src/infra/system-run-command.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,18 @@ describe("system run command helpers", () => {
187187
expect(res.previewText).toBe("echo hi");
188188
});
189189

190+
test("validateSystemRunCommandConsistency accepts PowerShell command-with-args payload text", () => {
191+
const res = expectValidResult(
192+
validateSystemRunCommandConsistency({
193+
argv: ["pwsh", "-cwa", "Write-Output", "hi"],
194+
rawCommand: "Write-Output hi",
195+
allowLegacyShellText: true,
196+
}),
197+
);
198+
expect(res.shellPayload).toBe("Write-Output hi");
199+
expect(res.previewText).toBe("Write-Output hi");
200+
});
201+
190202
test("validateSystemRunCommandConsistency rejects shell-only rawCommand for env assignment prelude", () => {
191203
expectRawCommandMismatch({
192204
argv: ["/usr/bin/env", "BASH_ENV=/tmp/payload.sh", "bash", "-lc", "echo hi"],

src/infra/system-run-command.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import {
77
} from "./exec-wrapper-resolution.js";
88
import {
99
POSIX_INLINE_COMMAND_FLAGS,
10-
POWERSHELL_INLINE_COMMAND_FLAGS,
10+
isPowerShellInlineRestCommandFlag,
1111
resolveInlineCommandMatch,
12+
resolvePowerShellInlineCommandMatch,
1213
} from "./shell-inline-command.js";
1314

1415
type SystemRunCommandValidation =
@@ -95,13 +96,19 @@ function hasTrailingPositionalArgvAfterInlineCommand(argv: string[]): boolean {
9596

9697
const inlineCommandIndex =
9798
wrapper === "powershell" || wrapper === "pwsh"
98-
? resolveInlineCommandMatch(wrapperArgv, POWERSHELL_INLINE_COMMAND_FLAGS).valueTokenIndex
99+
? resolvePowerShellInlineCommandMatch(wrapperArgv).valueTokenIndex
99100
: resolveInlineCommandMatch(wrapperArgv, POSIX_INLINE_COMMAND_FLAGS, {
100101
allowCombinedC: true,
101102
}).valueTokenIndex;
102103
if (inlineCommandIndex === null) {
103104
return false;
104105
}
106+
if (
107+
(wrapper === "powershell" || wrapper === "pwsh") &&
108+
isPowerShellInlineRestCommandFlag(wrapperArgv[inlineCommandIndex - 1] ?? "")
109+
) {
110+
return false;
111+
}
105112
return wrapperArgv.slice(inlineCommandIndex + 1).some((entry) => entry.trim().length > 0);
106113
}
107114

0 commit comments

Comments
 (0)