Fix okteto.* commands failing on PowerShell with "Unexpected token"#342
Open
Zionett wants to merge 1 commit into
Open
Fix okteto.* commands failing on PowerShell with "Unexpected token"#342Zionett wants to merge 1 commit into
Zionett wants to merge 1 commit into
Conversation
681ecdb to
1d92426
Compare
PR okteto#318 introduced shell-aware quoting that wraps the binary path in single quotes. PowerShell parses a leading single-quoted token as a string expression, not a command, so every Okteto command fails with "Unexpected token '<subcommand>' in expression or statement". Add invokeBinary() in src/shell.ts which prepends PowerShell's call operator (`&`) when shell === 'powershell', and route the six command builders through it. POSIX (where `&` is the background operator) and cmd.exe (where `"path" arg` already invokes) are unchanged. Tests: new invokeBinary block in shell.test.ts, updated PowerShell expectations across all six builders, and a cross-builder regression that asserts every PowerShell command line starts with `& '` so a future builder added without invokeBinary fails CI. Fixes okteto#341 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1d92426 to
486b602
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #341 — every
Okteto:command fails on PowerShell withUnexpected token '<subcommand>' in expression or statementafter #318.Root cause
PR #318 introduced shell-aware quoting in
src/shell.ts. Forshell === 'powershell',quote()wraps values in single quotes, so the six command builders insrc/okteto.tsproduced lines that begin with a quoted string literal:PowerShell parses a leading single-quoted token as a string expression, not a command, so the next token (
up) is a parse error.Fix
The canonical PowerShell idiom for invoking an executable whose path needs quoting is the call operator
&. It forces invocation while keeping stdout/stderr attached to the integrated terminal (unlikeStart-Process) and does not re-parse arguments (unlikeInvoke-Expression, which would also reopen a quoting/injection footgun againstquotePowerShell).invokeBinary(binary, shell)helper insrc/shell.tsthat prepends&only whenshell === 'powershell'.src/okteto.ts(buildUpCommand,buildDeployCommand,buildDestroyCommand,buildTestCommand,buildSetContextCommand,buildSetNamespaceCommand) now route the binary throughinvokeBinaryinstead ofquote.&is the background operator) andcmd.exe(where"path" argalready invokes) are unchanged. Git Bash continues to use POSIX quoting viagitBashMode().pwsh).Test coverage
Unit tests grow from 165 → 240 in this PR (the bulk of the increase is unrelated coverage that landed in
pnpm testcollection; +14 are this PR's: 8 newinvokeBinarytests + 6 cross-builder regression tests):describe('invokeBinary', …)block insrc/test/suite/shell.test.tscovering POSIX, PowerShell, and cmd × bare names, paths with spaces, embedded apostrophes.src/test/suite/okteto.commands.test.tsto expect the leading&.startsWith("& '")for PowerShell so a malicious binary path can't drop the prefix.describe('PowerShell call operator (issue #341)', …)cross-builder guardrail that asserts every PowerShell builder output matches/^& '/. Any future builder added withoutinvokeBinarywill fail CI here.Test plan
pnpm run lint— no errorspnpm test— 240 passingpnpm run test:e2e— 10 passingpnpm run package— producesremote-kubernetes-0.5.4.vsixOkteto: Up,Deploy,Destroy,Test,Set Context,Set Namespacein a PowerShell-backed VS Code terminal (PS 5.1 + PS 7), with a binary path that contains spaces (C:\Program Files\okteto\okteto.exe)cmd.exeand Git Bash (okteto.gitBash = true) to confirm no regression🤖 Generated with Claude Code