Skip to content

Commit 61cf615

Browse files
PierrunoYTclaude
andcommitted
fix(prompt): correct PowerShell status guidance and assert dialect syntax
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent cc9bb5c commit 61cf615

2 files changed

Lines changed: 25 additions & 8 deletions

File tree

‎src/utils/__tests__/shellDialect.spec.ts‎

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
11
import { describeShellDialect } from "../shellDialect"
22

33
describe("describeShellDialect", () => {
4+
const cmdSyntax = ["`&`", "`&&`", "`%VAR%`", "`set X=Y`", "`%ERRORLEVEL%`"]
5+
const powershellSyntax = ["`;`", "`$env:VAR`", "`$?`", "`$LASTEXITCODE`"]
6+
47
it.each([
5-
{ shell: "C:\\Windows\\System32\\cmd.exe", expected: "cmd.exe" },
6-
{ shell: "C:\\Windows\\System32\\CMD.EXE", expected: "cmd.exe" },
7-
{ shell: "C:\\Program Files\\PowerShell\\7\\pwsh.exe", expected: "PowerShell" },
8-
{ shell: "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", expected: "PowerShell" },
9-
])("names the dialect for $shell", ({ shell, expected }) => {
10-
expect(describeShellDialect(shell)).toContain(expected)
8+
{ shell: "C:\\Windows\\System32\\cmd.exe", expected: "cmd.exe", syntax: cmdSyntax },
9+
{ shell: "C:\\Windows\\System32\\CMD.EXE", expected: "cmd.exe", syntax: cmdSyntax },
10+
{ shell: "C:\\Program Files\\PowerShell\\7\\pwsh.exe", expected: "PowerShell", syntax: powershellSyntax },
11+
{
12+
shell: "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
13+
expected: "PowerShell",
14+
syntax: powershellSyntax,
15+
},
16+
])("names the dialect and its syntax for $shell", ({ shell, expected, syntax }) => {
17+
const description = describeShellDialect(shell)
18+
19+
expect(description).toContain(expected)
20+
for (const token of syntax) {
21+
expect(description).toContain(token)
22+
}
23+
})
24+
25+
it("tells PowerShell users that a failed cmdlet does not change $LASTEXITCODE", () => {
26+
expect(describeShellDialect("pwsh.exe")).toContain("does not change when a cmdlet fails")
1127
})
1228

1329
it("warns that ';' does not chain commands in cmd.exe", () => {

‎src/utils/shellDialect.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ export function describeShellDialect(shellPath: string): string | undefined {
2121
if (name === "powershell.exe" || name === "pwsh.exe" || name === "powershell" || name === "pwsh") {
2222
return (
2323
"Commands run through PowerShell, not bash. Use PowerShell syntax: `;` to chain commands, " +
24-
"`$env:VAR` for environment variables, `$LASTEXITCODE` for exit codes, and cmdlets such as " +
25-
"`Get-ChildItem` and `Select-String`."
24+
"`$env:VAR` for environment variables, `$?` for whether the last command succeeded " +
25+
"(`$LASTEXITCODE` only holds the exit code of native programs and does not change when a cmdlet fails), " +
26+
"and cmdlets such as `Get-ChildItem` and `Select-String`."
2627
)
2728
}
2829

0 commit comments

Comments
 (0)