From b809aaa92e8847fd4e0e19de62482ff7007ab098 Mon Sep 17 00:00:00 2001 From: jkooe <62494645+jkooe@users.noreply.github.com> Date: Wed, 7 Oct 2026 02:23:20 +0800 Subject: [PATCH] =?UTF-8?q?fix(install):=20=E5=8F=8C=E5=87=BB=E5=85=A5?= =?UTF-8?q?=E5=8F=A3=E7=9A=84=E5=AF=86=E9=92=A5=E7=94=9F=E6=88=90=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E6=98=AF=E5=9D=8F=E7=9A=84=20=E2=80=94=E2=80=94=20?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E4=BA=A4=E7=BB=99=20install.ps1=20=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Windows CI 的双击链路冒烟抓到的真 bug**(第四轮 CI 暴露): install.cmd 在「没有 PSK.txt」时自己用 cmd 生成密钥: for /f ... in ('powershell ... -Command "... ($b ^| ForEach-Object ...) ..."') 经 cmd 的 for /f 投递时需要 ^| 转义管道,而 ^ 未被消费、原样漏进 PowerShell → Unexpected token '^' in expression or statement **必炸**:PSK.txt 已不在分发 zip 里(045e3b0),所以「首次双击安装」恰好走到这条路径。 修复:cmd 不再自己生成密钥 —— install.ps1 本来就有完整逻辑 (先复用既有 agent.json 的 key,没有再现场生成,且 PowerShell 引号安全)。 install.cmd 按有无 PSK 决定是否传 -Key。 顺带:本文件的 CRLF 曾被工具写坏,已恢复并复核(ASCII 0 非 ASCII、107 CRLF、无裸 LF); 编码守卫单测 22 项通过,全量 195 单测 / 29 e2e 绿。 --- scripts/install.cmd | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/scripts/install.cmd b/scripts/install.cmd index 5726255..ca133f4 100644 --- a/scripts/install.cmd +++ b/scripts/install.cmd @@ -67,23 +67,16 @@ if exist "%PSKFILE%" ( "if (Test-Path -LiteralPath '%PSKFILE%') { (Get-Content -LiteralPath '%PSKFILE%' -Raw).Trim() }"') do set "PSK=%%K" ) -if not defined PSK ( - echo [*] No usable PSK.txt found - generating a new pre-shared key... - REM 32 random bytes via .NET, hex-encoded to 64 chars. - for /f "delims=" %%K in ('powershell -NoProfile -ExecutionPolicy Bypass -Command ^ - "$b=New-Object byte[] 32; [System.Security.Cryptography.RandomNumberGenerator]::Create().GetBytes($b); ($b ^| ForEach-Object { $_.ToString('x2') }) -join ''"') do set "PSK=%%K" - - if not defined PSK ( - echo [x] Failed to generate a key. Aborting. - if not defined CI pause - exit /b 1 - ) - REM Plain hex, no BOM: the file is read with `set /p` / Get-Content, and a - REM leading U+FEFF would corrupt the first byte of the key. - >"%PSKFILE%" echo %PSK% - echo [+] New key written to "%PSKFILE%" -) else ( +if defined PSK ( echo [+] Using key from PSK.txt +) else ( + REM No PSK.txt -> let install.ps1 handle it: it reuses the key from an existing + REM agent.json when present, otherwise generates one (in PowerShell, where quoting + REM is safe). Do NOT generate here in cmd: routing a PS one-liner with pipes through + REM `for /f` requires ^| escaping that leaks into PowerShell and breaks the parse + REM (real machine 2026-10-07: "Unexpected token '^'" - that is exactly the + REM first-run path, since PSK.txt is no longer shipped in the zip). + echo [*] No usable PSK.txt found - install.ps1 will reuse or generate the key ) REM --- 3) install ------------------------------------------------------------- @@ -91,7 +84,11 @@ echo. echo [*] Installing nodeagent ^(node: %COMPUTERNAME%, port %PORT%, input control ON^)... echo. -powershell -NoProfile -ExecutionPolicy Bypass -File "%PS1%" -NodeId "%COMPUTERNAME%" -Key "%PSK%" -AllowInput -Port %PORT% +if defined PSK ( + powershell -NoProfile -ExecutionPolicy Bypass -File "%PS1%" -NodeId "%COMPUTERNAME%" -Key "%PSK%" -AllowInput -Port %PORT% +) else ( + powershell -NoProfile -ExecutionPolicy Bypass -File "%PS1%" -NodeId "%COMPUTERNAME%" -AllowInput -Port %PORT% +) set "RC=%ERRORLEVEL%" echo.