fix(cua-driver): make install.ps1 survive the piped invocation it documents - #3153
Conversation
install.ps1 documents itself as an `irm ... | iex` install, and that invocation
failed outright with:
The attribute cannot be added because variable Channel with value
would no longer be valid.
Piped into Invoke-Expression, param() is not a parameter block: it becomes a set
of attributed variable declarations. [string]$Channel is initialised to '', and
its own [ValidateSet("stable","nightly")] rejects that default before the body
runs. The parameter has no default in the set, so this happened for every iex
caller whether or not they passed -Channel. Run as a script file the same code
is fine, because an unbound parameter is never assigned and validation never
fires — which is why the asymmetry survived review.
Validate at the point of use instead, keeping the accepted values and the error
wording aligned with the saved-channel check below it.
Reproduced and fixed against the real script under pwsh: the unmodified script
fails at the param block; the patched one proceeds into real work. The guard was
driven directly — stable and nightly return, bogus reports
"invalid -Channel 'bogus'; expected stable or nightly".
This is what breaks the Windows workspace image build at its
"install cua-driver" step, which blocks rebuilding that image at all.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Update on verification, now that CI has run — with one thing a green check does not show.
But those jobs invoke the script as a file — The That leaves a genuine gap: the documented install invocation is not tested anywhere in CI, on any platform. The cheapest close is to switch one matrix entry from the file invocation to |
install.ps1documents itself as anirm ... | iexinstall, and that invocation has been failing outright:Cause
Piped into
Invoke-Expression, aparam()block is not a parameter block — it becomes a set of attributed variable declarations.[string]$Channelis therefore initialised to'', and its own[ValidateSet("stable", "nightly")]rejects that default before the body ever runs. The parameter has no default in the set, so the failure is unconditional: it happens for everyiexcaller, whether or not they pass-Channel.Run as a real script file the same code is fine, because an unbound parameter is never assigned and validation never fires. That asymmetry is why it survived review.
Fix
Drop the attribute and validate at the point of use, keeping the same accepted values and the same wording as the saved-channel check immediately below it.
Verification
All against
mcr.microsoft.com/powershellwith the real script, not a reduction:install.ps1intoInvoke-Expressiongives exactly the error above.cua.ai:443, where before it died at the param block immediately.Resolve-SelectedChanneldirectly:nightly→nightly,stable→stable,bogus→invalid -Channel 'bogus'; expected stable or nightly. Case-insensitivity is unchanged, since both-notinandValidateSetare case-insensitive.Not verified, and worth a reviewer's attention: I could not run the whole script through on Windows — on Linux it stops on Windows-only environment assumptions well before channel resolution — so the end-to-end install is unproven from here, as is the image build below.
Why it matters beyond the one-liner
The Windows workspace image installs the driver by piping this script into
Invoke-Expression, so its build fails at theinstall cua-driverstep. That blocks rebuilding the Windows image at all, which in turn blocks anything that needs a newer driver in the image — including #3132, whose tool-listing fix cannot reach users until the image is rebuilt.Co-Authored-By: Claude Opus 5 (1M context) noreply@anthropic.com
🤖 Generated with Claude Code