From 01552ddd986e29500ce13c6869f12d727d9f65ae Mon Sep 17 00:00:00 2001 From: Janghoon Lee <44862514+its-janghoon@users.noreply.github.com> Date: Fri, 13 Nov 2026 05:34:36 +0000 Subject: [PATCH 1/3] feat(install): add install.ps1 for a one-line PowerShell install irm https://raw.githubusercontent.com/redrob-labs/redrob-code/main/install.ps1 | iex installs redrob.exe into %USERPROFILE%\.redrob\bin, verified against the release's SHA256SUMS.txt. redrob upgrade on a Windows curl install now re-runs Console's install.ps1 through PowerShell instead of piping install.sh into a bash that Windows does not have. --- README.ko.md | 22 ++ README.md | 23 ++ install.ps1 | 285 ++++++++++++++++++ packages/redrob/src/installation/index.ts | 52 +++- .../test/installation/install-ps1.test.ts | 83 +++++ .../test/installation/installation.test.ts | 42 +++ 6 files changed, 501 insertions(+), 6 deletions(-) create mode 100644 install.ps1 create mode 100644 packages/redrob/test/installation/install-ps1.test.ts diff --git a/README.ko.md b/README.ko.md index 5d71b6e421..e8399b3fde 100644 --- a/README.ko.md +++ b/README.ko.md @@ -44,6 +44,28 @@ XDG_BIN_DIR=$HOME/.local/bin curl -fsSL https://raw.githubusercontent.com/redrob redrob ``` +#### Windows + +PowerShell(Windows PowerShell 5.1 또는 PowerShell 7)에서 실행합니다. 관리자 권한은 필요 없습니다. + +```powershell +irm https://raw.githubusercontent.com/redrob-labs/redrob-code/main/install.ps1 | iex +``` + +[`install.ps1`](./install.ps1) 은 CPU에 맞는 x64, x64-baseline, arm64 빌드를 골라 릴리스의 +`SHA256SUMS.txt` 로 검증한 뒤 `redrob.exe` 를 `%USERPROFILE%\.redrob\bin` 에 설치하고(Redrob +Desktop 이 찾는 위치이고, `redrob upgrade` 로 업데이트됩니다) 그 폴더를 사용자 PATH 에 추가합니다. +버전이나 설치 폴더를 지정하려면: + +```powershell +& ([scriptblock]::Create((irm https://raw.githubusercontent.com/redrob-labs/redrob-code/main/install.ps1))) -Version 0.18.16 +$env:REDROB_INSTALL_DIR = "D:\tools\redrob"; irm https://raw.githubusercontent.com/redrob-labs/redrob-code/main/install.ps1 | iex +``` + +`REDROB_VERSION`, `REDROB_NO_MODIFY_PATH=1`, `REDROB_CONNECT=rc_...` 는 각각 `-Version`, +`-NoModifyPath`, `-Connect` 와 같습니다. [릴리스 페이지](https://github.com/redrob-labs/redrob-code/releases) +의 서명된 `.msi` 와 `setup.exe` 는 `%LOCALAPPDATA%\Redrob\bin` 에 설치합니다. + ### 인증 레드롭 코드는 의 레드롭 콘솔과 통신하며 워크스페이스 API 키로 diff --git a/README.md b/README.md index 8810e37124..170acee97a 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,29 @@ Then start it in any project: redrob ``` +#### Windows + +In PowerShell (Windows PowerShell 5.1 or PowerShell 7), no administrator rights needed: + +```powershell +irm https://raw.githubusercontent.com/redrob-labs/redrob-code/main/install.ps1 | iex +``` + +[`install.ps1`](./install.ps1) picks the x64, x64-baseline or arm64 build for your CPU, checks it +against the release's `SHA256SUMS.txt`, installs `redrob.exe` into `%USERPROFILE%\.redrob\bin` +(where Redrob Desktop looks, and where `redrob upgrade` can replace it) and adds that folder to +your user PATH. A specific version, or a different folder: + +```powershell +& ([scriptblock]::Create((irm https://raw.githubusercontent.com/redrob-labs/redrob-code/main/install.ps1))) -Version 0.18.16 +$env:REDROB_INSTALL_DIR = "D:\tools\redrob"; irm https://raw.githubusercontent.com/redrob-labs/redrob-code/main/install.ps1 | iex +``` + +`REDROB_VERSION`, `REDROB_NO_MODIFY_PATH=1` and `REDROB_CONNECT=rc_...` do the same as +`-Version`, `-NoModifyPath` and `-Connect`. The signed `.msi` and `setup.exe` on the +[releases page](https://github.com/redrob-labs/redrob-code/releases) install into +`%LOCALAPPDATA%\Redrob\bin` instead. + ### Authentication Redrob Code talks to the Redrob console at and authenticates diff --git a/install.ps1 b/install.ps1 new file mode 100644 index 0000000000..ce232525be --- /dev/null +++ b/install.ps1 @@ -0,0 +1,285 @@ +# Redrob Code installer for Windows (Windows PowerShell 5.1 and PowerShell 7). +# +# irm https://raw.githubusercontent.com/redrob-labs/redrob-code/main/install.ps1 | iex +# & ([scriptblock]::Create((irm https://raw.githubusercontent.com/redrob-labs/redrob-code/main/install.ps1))) -Version 0.18.16 +# +# The Windows counterpart of `install`: it picks the build for this CPU from the GitHub release, +# checks it against the release's SHA256SUMS.txt, and puts redrob.exe (and a redrob-code.exe copy) +# in %USERPROFILE%\.redrob\bin. That is where Redrob Desktop and the engine client look for the +# engine, and where `redrob upgrade` recognises an install it can replace. The folder goes on your +# own PATH. Nothing here needs administrator rights. +# +# There is deliberately no param() block: `irm ... | iex` cannot pass one. Options come from the +# arguments of the scriptblock form above, or from environment variables: +# +# -Version REDROB_VERSION, REDROB_CODE_VERSION Which release. Default: latest +# -InstallDir REDROB_INSTALL_DIR, REDROB_CODE_INSTALL_DIR +# Default: %USERPROFILE%\.redrob\bin +# -Binary REDROB_CODE_BIN Install a redrob.exe you already have +# -NoModifyPath REDROB_NO_MODIFY_PATH=1, REDROB_CODE_NO_PATH=1 +# Leave your PATH alone +# -Connect REDROB_CONNECT Connect this PC to Redrob Chat after +# installing (the code from its connect card) +# REDROB_CODE_DOWNLOAD_BASE Where the releases are (for tests) +# +# Everything runs inside one scriptblock so `iex` leaves no variables behind in your session, and a +# failure throws instead of calling `exit`, which would close the window `iex` was typed into. + +& { + $ErrorActionPreference = 'Stop' + Set-StrictMode -Version 2.0 + # Invoke-WebRequest's progress bar makes a 150 MB download in Windows PowerShell 5.1 many times slower. + $ProgressPreference = 'SilentlyContinue' + + $Repo = 'redrob-labs/redrob-code' + $ReadmeUrl = "https://github.com/$Repo#readme" + + function Get-Setting([string[]] $Names) { + foreach ($name in $Names) { + $value = [Environment]::GetEnvironmentVariable($name) + if ($value) { return $value.Trim() } + } + return '' + } + + $requestedVersion = Get-Setting @('REDROB_VERSION', 'REDROB_CODE_VERSION') + $installDir = Get-Setting @('REDROB_INSTALL_DIR', 'REDROB_CODE_INSTALL_DIR') + $binaryPath = Get-Setting @('REDROB_CODE_BIN') + $connectCode = Get-Setting @('REDROB_CONNECT') + $noModifyPath = (Get-Setting @('REDROB_NO_MODIFY_PATH', 'REDROB_CODE_NO_PATH')) -eq '1' + $downloadBase = Get-Setting @('REDROB_CODE_DOWNLOAD_BASE') + if (-not $downloadBase) { $downloadBase = "https://github.com/$Repo/releases" } + $downloadBase = $downloadBase.TrimEnd('/') + + $rest = @($args) + for ($i = 0; $i -lt $rest.Count; $i++) { + $arg = [string] $rest[$i] + $next = if ($i + 1 -lt $rest.Count) { [string] $rest[$i + 1] } else { '' } + switch -Regex ($arg) { + '^-{1,2}(h|help|\?)$' { + Write-Host 'Redrob Code installer for Windows' + Write-Host '' + Write-Host ' irm https://raw.githubusercontent.com/redrob-labs/redrob-code/main/install.ps1 | iex' + Write-Host ' & ([scriptblock]::Create((irm https://raw.githubusercontent.com/redrob-labs/redrob-code/main/install.ps1))) -Version 0.18.16' + Write-Host '' + Write-Host 'Options: -Version -InstallDir -Binary -NoModifyPath -Connect ' + Write-Host 'Env: REDROB_VERSION REDROB_INSTALL_DIR REDROB_CODE_BIN REDROB_NO_MODIFY_PATH=1 REDROB_CONNECT' + return + } + '^-{1,2}(v|version)$' { + if (-not $next) { throw '-Version needs a version, for example -Version 0.18.16' } + $requestedVersion = $next; $i++; continue + } + '^-{1,2}(installdir|install-dir)$' { + if (-not $next) { throw '-InstallDir needs a folder' } + $installDir = $next; $i++; continue + } + '^-{1,2}(b|binary)$' { + if (-not $next) { throw '-Binary needs the path of a redrob.exe' } + $binaryPath = $next; $i++; continue + } + '^-{1,2}(nomodifypath|no-modify-path)$' { $noModifyPath = $true; continue } + '^-{1,2}connect$' { + if (-not $next) { throw "-Connect needs the rc_... code from Redrob Chat's connect card" } + $connectCode = $next; $i++; continue + } + default { Write-Warning "Unknown option '$arg'" } + } + } + + if ($connectCode -and $connectCode -notmatch '^rc_[A-Za-z0-9_-]{8,128}$') { + throw "-Connect needs the rc_... code from Redrob Chat's connect card" + } + if (-not $installDir) { $installDir = Join-Path $env:USERPROFILE '.redrob\bin' } + $installDir = [IO.Path]::GetFullPath($installDir) + $target = Join-Path $installDir 'redrob.exe' + + # Windows PowerShell 5.1 still defaults to TLS 1.0, which github.com refuses. + try { + [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 + } catch {} + + function Get-Text([string] $Url) { + $response = Invoke-WebRequest -Uri $Url -UseBasicParsing + $content = $response.Content + if ($content -is [byte[]]) { $content = [Text.Encoding]::UTF8.GetString($content) } + return [string] $content + } + + function Get-Arch { + $arch = '' + try { $arch = [string] [Runtime.InteropServices.RuntimeInformation]::OSArchitecture } catch {} + if (-not $arch) { + # A 32-bit PowerShell on 64-bit Windows reports the real CPU in PROCESSOR_ARCHITEW6432. + $arch = if ($env:PROCESSOR_ARCHITEW6432) { $env:PROCESSOR_ARCHITEW6432 } else { $env:PROCESSOR_ARCHITECTURE } + } + switch -Regex ($arch) { + '^(X64|AMD64)$' { return 'x64' } + '^(Arm64|ARM64)$' { return 'arm64' } + default { throw "Redrob Code has no Windows build for $arch. x64 and arm64 are the builds there are." } + } + } + + function Test-Avx2 { + # PF_AVX2_INSTRUCTIONS_AVAILABLE (40). Without AVX2 the regular x64 build crashes on start, + # so such a CPU gets the baseline build, as `install` does. + try { + if (-not ('RedrobInstall.Kernel32' -as [type])) { + Add-Type -Namespace RedrobInstall -Name Kernel32 -MemberDefinition '[DllImport("kernel32.dll")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);' + } + return [RedrobInstall.Kernel32]::IsProcessorFeaturePresent(40) + } catch { + return $false + } + } + + function Install-Binary([string] $From) { + New-Item -ItemType Directory -Force -Path $installDir | Out-Null + foreach ($name in @('redrob.exe', 'redrob-code.exe')) { + $to = Join-Path $installDir $name + $old = "$to.old" + # A running .exe cannot be overwritten or deleted, but it can be renamed, so the one in use + # (`redrob upgrade`, a daemon Redrob Desktop started) moves aside and the .old goes next time. + Remove-Item -LiteralPath $old -Force -ErrorAction SilentlyContinue + if (Test-Path -LiteralPath $to) { Move-Item -LiteralPath $to -Destination $old -Force } + Copy-Item -LiteralPath $From -Destination $to -Force + Remove-Item -LiteralPath $old -Force -ErrorAction SilentlyContinue + } + } + + function Add-UserPath([string] $Dir) { + $key = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey('Environment', $true) + try { + # Read it unexpanded and write it back as REG_EXPAND_SZ, so entries like %USERPROFILE%\bin survive. + $current = [string] $key.GetValue('Path', '', [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames) + $want = $Dir.TrimEnd('\') + $present = $current -split ';' | Where-Object { $_ -and [Environment]::ExpandEnvironmentVariables($_).TrimEnd('\') -ieq $want } + if ($present) { return $false } + $value = if ($current) { $current.TrimEnd(';') + ';' + $Dir } else { $Dir } + $key.SetValue('Path', $value, [Microsoft.Win32.RegistryValueKind]::ExpandString) + } finally { + $key.Close() + } + # Tell Explorer the environment changed, so terminals opened from it see the new PATH. + try { + if (-not ('RedrobInstall.User32' -as [type])) { + Add-Type -Namespace RedrobInstall -Name User32 -MemberDefinition '[DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern System.IntPtr SendMessageTimeout(System.IntPtr hWnd, uint Msg, System.UIntPtr wParam, string lParam, uint fuFlags, uint uTimeout, out System.UIntPtr lpdwResult);' + } + $result = [UIntPtr]::Zero + [RedrobInstall.User32]::SendMessageTimeout([IntPtr] 0xffff, 0x1A, [UIntPtr]::Zero, 'Environment', 2, 5000, [ref] $result) | Out-Null + } catch {} + return $true + } + + if ($binaryPath) { + if (-not (Test-Path -LiteralPath $binaryPath -PathType Leaf)) { throw "Binary not found at $binaryPath" } + Write-Host "Installing redrob from $binaryPath" + Install-Binary ([IO.Path]::GetFullPath($binaryPath)) + } else { + $arch = Get-Arch + $asset = "redrob-windows-$arch" + if ($arch -eq 'x64' -and -not (Test-Avx2)) { $asset = "$asset-baseline" } + $asset = "$asset.zip" + + if ($requestedVersion) { + $version = $requestedVersion -replace '^v', '' + } else { + # The marker the release workflow publishes beside the newest release: a redirect, not the + # GitHub API, so it has no anonymous rate limit. `redrob upgrade` reads the same file. + try { + $version = (Get-Text "$downloadBase/latest/download/VERSION").Trim() -replace '^v', '' + } catch { + throw "Could not read $downloadBase/latest/download/VERSION, so the newest version is unknown. Releases: https://github.com/$Repo/releases" + } + } + if ($version -notmatch '^\d+\.\d+\.\d+([-.][0-9A-Za-z.-]+)?$') { throw "'$version' is not a version" } + + $installed = '' + if (Test-Path -LiteralPath $target) { + try { $installed = ((& $target --version) | Out-String).Trim() } catch {} + if ($installed -eq $version -and -not $connectCode) { + Write-Host "Version $version already installed in $installDir" + return + } + if ($installed) { Write-Host "Installed version: $installed" } + } + + $work = Join-Path ([IO.Path]::GetTempPath()) ("redrob-install-" + [Guid]::NewGuid().ToString('N')) + New-Item -ItemType Directory -Force -Path $work | Out-Null + try { + if (-not ($installed -eq $version)) { + Write-Host '' + Write-Host "Installing redrob version: $version ($asset)" + $releaseUrl = "$downloadBase/download/v$version" + $zip = Join-Path $work $asset + try { + Invoke-WebRequest -Uri "$releaseUrl/$asset" -OutFile $zip -UseBasicParsing + } catch { + throw "Could not download $releaseUrl/$asset. Is v$version a release? https://github.com/$Repo/releases" + } + + # One checksum file per release covers every asset; the line for this asset is picked by + # name. Releases up to v0.6.4 published it as SHA256SUMS. + $sums = $null + foreach ($name in @('SHA256SUMS.txt', 'SHA256SUMS')) { + try { $sums = Get-Text "$releaseUrl/$name"; break } catch {} + } + if (-not $sums) { throw "v$version publishes no SHA256SUMS.txt, so $asset cannot be verified. Nothing was installed." } + $expected = '' + foreach ($line in ($sums -split "`n")) { + $parts = $line.Trim() -split '\s+' + if ($parts.Count -ge 2 -and ($parts[1] -eq $asset -or $parts[1] -eq "*$asset")) { $expected = $parts[0].ToLowerInvariant(); break } + } + if (-not $expected) { throw "SHA256SUMS.txt in v$version has no line for $asset. Nothing was installed." } + $actual = (Get-FileHash -LiteralPath $zip -Algorithm SHA256).Hash.ToLowerInvariant() + if ($actual -ne $expected) { throw "Checksum mismatch for $asset (expected $expected, got $actual). Nothing was installed." } + + $unpacked = Join-Path $work 'x' + Expand-Archive -LiteralPath $zip -DestinationPath $unpacked -Force + $exe = Get-ChildItem -LiteralPath $unpacked -Recurse -Filter 'redrob.exe' | Select-Object -First 1 + if (-not $exe) { throw "$asset holds no redrob.exe" } + Install-Binary $exe.FullName + } + } finally { + Remove-Item -LiteralPath $work -Recurse -Force -ErrorAction SilentlyContinue + } + } + + $onPath = @($env:Path -split ';' | Where-Object { $_ -and $_.TrimEnd('\') -ieq $installDir.TrimEnd('\') }).Count -gt 0 + if (-not $onPath) { + if ($noModifyPath) { + Write-Host '' + Write-Host "$installDir is not on your PATH, and your PATH was left alone. Add it yourself to run redrob by name." + } else { + if (Add-UserPath $installDir) { Write-Host "Added $installDir to your user PATH" } + # This session too, so `redrob` works right away after `irm ... | iex`. + $env:Path = "$env:Path;$installDir" + } + } + + if ($env:GITHUB_ACTIONS -eq 'true' -and $env:GITHUB_PATH) { + Add-Content -LiteralPath $env:GITHUB_PATH -Value $installDir + Write-Host "Added $installDir to `$GITHUB_PATH" + } + + Write-Host '' + Write-Host 'Redrob Code' + Write-Host '' + Write-Host 'To start, open your project and run redrob, then type /connect to sign in:' + # The same line in Korean, kept as UTF-8 bytes so this file stays ASCII: Windows PowerShell 5.1 + # reads a script without a BOM in the ANSI code page, and `irm` text is not always UTF-8 either. + Write-Host ([Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('7Iuc7J6R7ZWY66Ck66m0IO2UhOuhnOygne2KuCDtj7TrjZTsl5DshJwgcmVkcm9i7J2EIOyLpO2Wie2VnCDrkqQgL2Nvbm5lY3Trpbwg7J6F66Cl7ZW0IOuhnOq3uOyduO2VmOyEuOyalDo='))) + Write-Host '' + Write-Host ' cd ' + Write-Host ' redrob' + Write-Host ' /connect' + Write-Host '' + Write-Host "More: $ReadmeUrl" + Write-Host '' + + if ($connectCode) { + Write-Host 'Connecting this PC to Redrob Chat' + & $target desk connect $connectCode + if ($LASTEXITCODE -ne 0) { throw "redrob desk connect failed with code $LASTEXITCODE" } + } +} @args diff --git a/packages/redrob/src/installation/index.ts b/packages/redrob/src/installation/index.ts index 12a6800ada..fb3a89d1b2 100644 --- a/packages/redrob/src/installation/index.ts +++ b/packages/redrob/src/installation/index.ts @@ -90,6 +90,24 @@ export class UpgradeFailedError extends Schema.TaggedErrorClass fs.writeFile(file, "\uFEFF" + body, "utf8")) + const result = yield* appProcess + .run( + ChildProcess.make( + "powershell.exe", + ["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-File", file], + { env, extendEnv: true }, + ), + ) + .pipe(Effect.ensuring(Effect.promise(() => fs.rm(file, { force: true })))) + return { + code: result.exitCode, + stdout: result.stdout.toString("utf8"), + stderr: result.stderr.toString("utf8"), + } + } const bodyBytes = new TextEncoder().encode(body) const shell = yield* upgradeScriptShell() const result = yield* appProcess.run( ChildProcess.make(shell, [], { stdin: Stream.make(bodyBytes), - // The directory rather than the default, so the binary that is running is the one - // replaced when it was installed somewhere other than `$HOME/.redrob/bin`. Anything else - // the user set, `REDROB_CODE_DOWNLOAD_BASE` included, arrives through the inherited env. - env: { REDROB_CODE_VERSION: target, REDROB_CODE_INSTALL_DIR: path.dirname(process.execPath) }, + env, extendEnv: true, }), ) @@ -292,7 +332,7 @@ const layer: Layer.Layer !line.trimStart().startsWith("#")) + .join("\n") + +describe("install.ps1", () => { + test("runs through iex: no param block, no exit", () => { + // `irm ... | iex` cannot bind a param() block, so options come from $args and the environment. + expect(code).not.toMatch(/^\s*param\s*\(/im) + // `exit` inside `iex` closes the PowerShell window the person typed the command into. + expect(code).not.toMatch(/\bexit\b/i) + // One scriptblock, so `iex` leaves no variables in the person's session. + expect(code.trimStart().startsWith("& {")).toBe(true) + expect(code.trimEnd().endsWith("} @args")).toBe(true) + }) + + test("is ASCII, which Windows PowerShell 5.1 reads the same in every code page", () => { + expect([...script].every((ch) => ch.charCodeAt(0) < 128)).toBe(true) + }) + + test("installs where Redrob Desktop and `redrob upgrade` look", () => { + // redrob-desktop's enginesetup.rs: `~/.redrob/bin/redrob.exe`; isCurlInstall: a `.redrob\bin` dir. + expect(code).toContain("Join-Path $env:USERPROFILE '.redrob\\bin'") + expect(code).toContain("'redrob.exe', 'redrob-code.exe'") + }) + + test("reads its options from the environment, under the names both installers use", () => { + for (const name of [ + "REDROB_VERSION", + "REDROB_CODE_VERSION", + "REDROB_INSTALL_DIR", + "REDROB_CODE_INSTALL_DIR", + "REDROB_CODE_DOWNLOAD_BASE", + "REDROB_NO_MODIFY_PATH", + "REDROB_CONNECT", + ]) { + expect(code).toContain(`'${name}'`) + } + }) + + test("downloads assets the release publishes and verifies them", () => { + // The release workflow zips `dist/redrob-windows-*` (x64, x64-baseline, arm64) and publishes + // SHA256SUMS.txt covering every asset. + expect(code).toContain('"redrob-windows-$arch"') + expect(code).toContain('"$asset-baseline"') + expect(code).toContain("'SHA256SUMS.txt'") + expect(code).toContain("Get-FileHash") + expect(code).toContain("/latest/download/VERSION") + }) + + test("changes only the user's PATH", () => { + expect(code).toContain("[Microsoft.Win32.Registry]::CurrentUser.OpenSubKey('Environment', $true)") + expect(code).not.toContain("LocalMachine") + expect(code).not.toMatch(/HKLM/i) + }) + + const pwsh = Bun.which("pwsh") + test.skipIf(!pwsh)("parses in PowerShell", () => { + const result = Bun.spawnSync([ + pwsh!, + "-NoProfile", + "-NonInteractive", + "-Command", + `$e = $null; [void][System.Management.Automation.Language.Parser]::ParseFile('${file.replace(/'/g, "''")}', [ref]$null, [ref]$e); if ($e) { $e | ForEach-Object { $_.ToString() }; exit 1 }`, + ]) + expect(result.stdout.toString() + result.stderr.toString()).toBe("") + expect(result.exitCode).toBe(0) + }) +}) diff --git a/packages/redrob/test/installation/installation.test.ts b/packages/redrob/test/installation/installation.test.ts index bd0246c06f..ac9b9388a2 100644 --- a/packages/redrob/test/installation/installation.test.ts +++ b/packages/redrob/test/installation/installation.test.ts @@ -9,6 +9,7 @@ import { Installation } from "../../src/installation" import { CrossSpawnSpawner } from "@redrob-code/core/cross-spawn-spawner" import { testEffect } from "../lib/effect" import path from "path" +import fs from "fs" const encoder = new TextEncoder() @@ -212,6 +213,47 @@ describe("installation", () => { yield* Installation.use.upgrade("curl", "9.9.9") }), ) + + test("picks the installer for the platform", () => { + expect(Installation.upgradeScriptUrl("linux")).toBe(Installation.CONSOLE_INSTALL_SCRIPT_URL) + expect(Installation.upgradeScriptUrl("darwin")).toBe(Installation.CONSOLE_INSTALL_SCRIPT_URL) + expect(Installation.upgradeScriptUrl("win32")).toBe("https://console.redrob.ai/code/install.ps1") + expect(Installation.reinstallCommand("win32")).toBe("irm https://console.redrob.ai/code/install.ps1 | iex") + expect(Installation.reinstallCommand("linux")).toBe(`curl -fsSL ${Installation.CONSOLE_INSTALL_SCRIPT_URL} | sh`) + }) + + const winCalls: string[] = [] + const winRuns: Array<{ cmd: string; args: readonly string[]; env: Record }> = [] + testEffect( + testLayer( + (request) => { + winCalls.push(request.url) + return new Response("Write-Host install", { status: 200 }) + }, + (cmd, args, env) => { + winRuns.push({ cmd, args, env }) + return "installed" + }, + ), + ).effect("upgrades a Windows curl install through install.ps1, not sh", () => + Effect.gen(function* () { + const platform = process.platform + Object.defineProperty(process, "platform", { value: "win32" }) + yield* Installation.use + .upgrade("curl", "9.9.9") + .pipe(Effect.ensuring(Effect.sync(() => Object.defineProperty(process, "platform", { value: platform })))) + expect(winCalls).toEqual([Installation.CONSOLE_INSTALL_PS1_URL]) + // Windows has no bash or sh to pipe install.sh into, and install.sh refuses Windows anyway. + expect(winRuns.some((run) => run.cmd === "bash" || run.cmd === "sh")).toBe(false) + const run = winRuns.find((r) => r.cmd === "powershell.exe") + expect(run?.args.slice(0, 5)).toEqual(["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-File"]) + expect(run?.args[5]).toEndWith(".ps1") + expect(run?.env["REDROB_CODE_VERSION"]).toBe("9.9.9") + expect(run?.env["REDROB_CODE_INSTALL_DIR"]).toBe(path.dirname(process.execPath)) + // The script file is removed once it has run. + expect(fs.existsSync(run!.args[5]!)).toBe(false) + }), + ) }) describe("method", () => { From 694e7ade900eb5993134014a238e52e41a3ca50a Mon Sep 17 00:00:00 2001 From: Janghoon Lee <44862514+its-janghoon@users.noreply.github.com> Date: Fri, 13 Nov 2026 05:37:45 +0000 Subject: [PATCH 2/3] fix(install): put the install folder first on PATH, as install does --- install.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/install.ps1 b/install.ps1 index ce232525be..b998b3837e 100644 --- a/install.ps1 +++ b/install.ps1 @@ -155,7 +155,8 @@ $want = $Dir.TrimEnd('\') $present = $current -split ';' | Where-Object { $_ -and [Environment]::ExpandEnvironmentVariables($_).TrimEnd('\') -ieq $want } if ($present) { return $false } - $value = if ($current) { $current.TrimEnd(';') + ';' + $Dir } else { $Dir } + # First, as `install` does, so this copy wins over an older one (an .msi install appends). + $value = if ($current) { $Dir + ';' + $current.TrimStart(';') } else { $Dir } $key.SetValue('Path', $value, [Microsoft.Win32.RegistryValueKind]::ExpandString) } finally { $key.Close() @@ -253,7 +254,7 @@ } else { if (Add-UserPath $installDir) { Write-Host "Added $installDir to your user PATH" } # This session too, so `redrob` works right away after `irm ... | iex`. - $env:Path = "$env:Path;$installDir" + $env:Path = "$installDir;$env:Path" } } From 4fd9f9b9f83b592e16509ec3a99e9715cd9fa14a Mon Sep 17 00:00:00 2001 From: Janghoon Lee <44862514+its-janghoon@users.noreply.github.com> Date: Fri, 13 Nov 2026 05:48:28 +0000 Subject: [PATCH 3/3] fix(upgrade): re-run this repository's install.ps1 on Windows Console's /code/install.ps1 calls Invoke-WebRequest without -UseBasicParsing, so under Windows PowerShell 5.1 with -NonInteractive it cannot read SHA256SUMS.txt and refuses every upgrade. --- packages/redrob/src/installation/index.ts | 13 ++++++++----- .../redrob/test/installation/installation.test.ts | 8 +++++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/redrob/src/installation/index.ts b/packages/redrob/src/installation/index.ts index fb3a89d1b2..8ed83b627c 100644 --- a/packages/redrob/src/installation/index.ts +++ b/packages/redrob/src/installation/index.ts @@ -91,21 +91,24 @@ export class UpgradeFailedError extends Schema.TaggedErrorClass { test("picks the installer for the platform", () => { expect(Installation.upgradeScriptUrl("linux")).toBe(Installation.CONSOLE_INSTALL_SCRIPT_URL) expect(Installation.upgradeScriptUrl("darwin")).toBe(Installation.CONSOLE_INSTALL_SCRIPT_URL) - expect(Installation.upgradeScriptUrl("win32")).toBe("https://console.redrob.ai/code/install.ps1") - expect(Installation.reinstallCommand("win32")).toBe("irm https://console.redrob.ai/code/install.ps1 | iex") + expect(Installation.upgradeScriptUrl("win32")).toBe( + "https://raw.githubusercontent.com/redrob-labs/redrob-code/main/install.ps1", + ) + expect(Installation.reinstallCommand("win32")).toBe(`irm ${Installation.INSTALL_PS1_URL} | iex`) expect(Installation.reinstallCommand("linux")).toBe(`curl -fsSL ${Installation.CONSOLE_INSTALL_SCRIPT_URL} | sh`) }) @@ -242,7 +244,7 @@ describe("installation", () => { yield* Installation.use .upgrade("curl", "9.9.9") .pipe(Effect.ensuring(Effect.sync(() => Object.defineProperty(process, "platform", { value: platform })))) - expect(winCalls).toEqual([Installation.CONSOLE_INSTALL_PS1_URL]) + expect(winCalls).toEqual([Installation.INSTALL_PS1_URL]) // Windows has no bash or sh to pipe install.sh into, and install.sh refuses Windows anyway. expect(winRuns.some((run) => run.cmd === "bash" || run.cmd === "sh")).toBe(false) const run = winRuns.find((r) => r.cmd === "powershell.exe")