Skip to content

fix: pass paths to PowerShell via environment instead of -Command args - #189

Merged
yujiezhang-ops merged 1 commit into
mainfrom
fix/windows-powershell-args
Aug 14, 2026
Merged

fix: pass paths to PowerShell via environment instead of -Command args#189
yujiezhang-ops merged 1 commit into
mainfrom
fix/windows-powershell-args

Conversation

@yujiezhang-ops

Copy link
Copy Markdown
Collaborator

问题

powershell.exe -Command <script> <path> 会把脚本字符串之后的所有 token 拼进命令文本,而不是变成 $args。这导致两个连锁错误(见 Windows 端安装日志):

  1. Get-AuthenticodeSignature -LiteralPath $args[0] 收到 $nullParameterArgumentValidationErrorNullNotAllowed
  2. 安装包路径被接到脚本最后一行 ConvertTo-Json -Compress 之后 → InputObjectNotBound

影响面

  • 所有 Windows 桌面应用安装全部失败verifyWindowsInstallerPublisher 是 ChatGPT Desktop、WorkBuddy(国内/国际版)、ZCode 四条 Windows 安装链路共用的验签入口,验签必然报错,安装中断。
  • WorkBuddy 版本探测静默失效workBuddyWindowsVersion 用了相同的错误模式,失败返回 nil,表现为已安装的 WorkBuddy 永远显示不出版本号。
  • 注入隐患workBuddyStartAppsQuery 把应用显示名直接拼进 PowerShell 单引号字符串。
  • 中文 Windows 上报错乱码:PowerShell 按 GBK 输出、BootAgent 按 UTF-8 解码,错误原文全部变成菱形问号。

修复

统一改为通过环境变量传参runWithEnvironment 原生支持),彻底绕开 -Command 的拼接语义与路径引号转义问题:

  • 验签脚本改读 $env:BOOTAGENT_VERIFY_PATH,argv 不再携带路径
  • 版本查询改读 $env:BOOTAGENT_VERSION_PATH
  • StartApps 查询改读 $env:BOOTAGENT_APP_NAME,消除字符串拼接
  • 全部 5 个 PowerShell 脚本开头统一 [Console]::OutputEncoding = [Text.Encoding]::UTF8

macOS 侧(codesign/spctl/plutil/hdiutil/ditto)均为正常 argv 传参,审查后无需改动。

测试

新增 3 个测试,断言路径/名称只通过环境变量到达、不出现在 argv 或脚本文本中(验签测试使用含空格和单引号的路径):

  • TestVerifyWindowsInstallerPassesPathViaEnvironment
  • TestWorkBuddyWindowsVersionPassesPathViaEnvironment
  • TestWorkBuddyStartAppsQueryPassesNameViaEnvironment
go vet ./internal/desktopapp/   # 通过
go test ./internal/desktopapp/  # ok(含 3 个新测试)
go build ./... && go test ./... # 全仓通过

🤖 Generated with Claude Code

powershell.exe -Command treats everything after the script string as
command text, not $args, so the Authenticode verifier received an empty
-LiteralPath and the installer path leaked into ConvertTo-Json. This
broke every Windows desktop-app install (ChatGPT, WorkBuddy, ZCode) and
silently dropped WorkBuddy version detection.

All PowerShell parameters now travel through environment variables,
which also removes the display-name string interpolation in the
StartApps query. Scripts set UTF-8 output encoding so errors stay
readable on CJK Windows.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@yujiezhang-ops
yujiezhang-ops requested a review from a team August 14, 2026 08:59
@yujiezhang-ops
yujiezhang-ops merged commit c7b5912 into main Aug 14, 2026
4 checks passed
@yujiezhang-ops
yujiezhang-ops deleted the fix/windows-powershell-args branch August 14, 2026 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant