From a8828dc94a78b9b353170db82f583f60c0338844 Mon Sep 17 00:00:00 2001 From: rebuildup Date: Fri, 20 Nov 2026 03:29:31 +0900 Subject: [PATCH 1/3] fix(mise): keep the committed lock and align the rustup default A plain `mise install` re-resolves every rolling selector and rewrites the lock it installs from, so the unlocked `mise install gh` bootstrap replaced the committed mise.global.lock (38393 -> 75443 bytes) before `--locked` was ever consulted. Run every mise call under MISE_LOCKED=1 when a committed lock was synced, and restore the caller's value on success. core:rust initializes rustup with `--default-toolchain none` and never sets a default, but cargo: installs build with rustup's default toolchain. A fresh machine therefore has no default at all and a machine with an older default fails MSRV-heavy crates; rust itself still reports as installed. Align the default with the declared rust version and retry the install once so a first bootstrap converges in the same run. Also make the Windows verify able to see the failure instead of trusting the machine copy: compare the rendered config and lock against the repository, and check the rustup default. Report those as failures only for adopted state (main, no uncommitted declared changes) so branch work does not turn a machine report red. Trust the checkout for the bootstrap-status read so a fresh deploy checkout no longer fails verify, and run the renderer test in CI with CRLF-safe matching. --- .github/workflows/ci.yml | 67 +++++++++++ docs/adr/ADR-0010.md | 2 +- docs/adr/ADR-0021.md | 11 ++ platforms/windows-11/verify.ps1 | 167 +++++++++++++++++++++++++++ scripts/apply-global-mise.ps1 | 121 +++++++++++++++++++ scripts/apply-global-mise.sh | 50 ++++++++ scripts/test-windows-mise-config.ps1 | 6 +- 7 files changed, 422 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6ea408f8..f928dbb1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -733,6 +733,73 @@ jobs: Remove-Item -LiteralPath $root -Recurse -Force -ErrorAction SilentlyContinue } + # scripts/test-windows-mise-config.ps1 exercises the renderer + # (scripts/windows-mise-config.ps1) directly instead of going through + # apply-global-mise.ps1 and a fake mise. It was previously absent from CI, + # which is how it went red on every CRLF checkout of this repository + # (core.autocrlf=true, no .gitattributes) while CI stayed green. + - name: Validate Windows mise config renderer + shell: pwsh + run: ./scripts/test-windows-mise-config.ps1 + + - name: Validate the apply keeps the committed lock read-only + shell: pwsh + run: | + Set-StrictMode -Version Latest + $ErrorActionPreference = 'Stop' + + # Regression: apply-global-mise.ps1 runs one unlocked `mise install gh` + # before its auth check, and a plain `mise install` re-resolves every + # rolling selector and rewrites the lock it installs from. Observed on + # a real machine: the committed 38 KB mise.global.lock was replaced by a + # 75 KB re-locked copy before `--locked` was ever consulted, so the + # machine installed a different tool set than the repository pins. + # MISE_LOCKED=1 must be set for the whole apply, and the fake mise below + # records the value each invocation actually saw. + $root = Join-Path ([System.IO.Path]::GetTempPath()) "pc-setup-locked-$([guid]::NewGuid())" + $fakeBin = Join-Path $root 'bin' + $target = Join-Path $root 'config.toml' + $seen = Join-Path $root 'mise-locked-seen.txt' + New-Item -ItemType Directory -Path $fakeBin -Force | Out-Null + $oldPath = $env:PATH + + try { + # A fake mise that records MISE_LOCKED and always succeeds. The + # content is built from an array rather than a here-string: a + # here-string terminator at column 1 would end this YAML block + # scalar and break the workflow file. + $fakeMise = @( + '@echo off', + ('>>"{0}" echo %MISE_LOCKED%' -f $seen), + 'exit /b 0' + ) -join "`r`n" + Set-Content -LiteralPath (Join-Path $fakeBin 'mise.cmd') -Value $fakeMise + $env:PATH = "$fakeBin;$oldPath" + $env:MISE_GLOBAL_CONFIG_FILE = $target + $env:MISE_GITHUB_TOKEN = 'ci-placeholder' + Remove-Item Env:MISE_LOCKED -ErrorAction SilentlyContinue + + & ./scripts/apply-global-mise.ps1 | Out-Null + if ($LASTEXITCODE -ne 0) { throw "apply-global-mise.ps1 exited $LASTEXITCODE" } + + if (-not (Test-Path -LiteralPath $seen)) { throw 'fake mise never ran' } + $values = @(Get-Content -LiteralPath $seen | ForEach-Object { $_.Trim() }) + if ($values.Count -eq 0) { throw 'fake mise recorded no invocations' } + $unlocked = @($values | Where-Object { $_ -ne '1' }) + if ($unlocked.Count -gt 0) { + throw "every mise invocation must run with MISE_LOCKED=1; saw: $($values -join ', ')" + } + + # The caller's environment must not be left mutated. + $leftover = [Environment]::GetEnvironmentVariable('MISE_LOCKED', 'Process') + if ($leftover) { throw "apply left MISE_LOCKED set in the caller: '$leftover'" } + } + finally { + $env:PATH = $oldPath + Remove-Item Env:MISE_GLOBAL_CONFIG_FILE, Env:MISE_GITHUB_TOKEN, Env:MISE_LOCKED -ErrorAction SilentlyContinue + Remove-Item -LiteralPath $root -Recurse -Force -ErrorAction SilentlyContinue + } + - name: Validate global mise config backup before overwrite shell: pwsh run: | diff --git a/docs/adr/ADR-0010.md b/docs/adr/ADR-0010.md index eeef4af1..5d762739 100644 --- a/docs/adr/ADR-0010.md +++ b/docs/adr/ADR-0010.md @@ -55,7 +55,7 @@ This exception does not authorize agents or humans to bypass the release path fo The global mise adapters expose `mise.global.lock` beside the installed global configuration, and the `.mise/locks/` sidecars ship with it so a locked install can resolve dependency graphs. When a committed lockfile exists, the final machine-global install uses mise locked mode so missing or incomplete lock entries fail instead of silently resolving a different upstream version. -The pre-authentication GitHub CLI bootstrap may remain unlocked because it establishes authentication required by later GitHub-backed operations. The final locked install reconciles it to adopted state. +The pre-authentication GitHub CLI bootstrap needs to install `gh` before any lock-backed install can authenticate, but it must not run unlocked. A plain `mise install` re-resolves every rolling selector and rewrites the lock it installs from, so an unlocked bootstrap replaces the adopted `mise.global.lock` with a freshly re-locked copy (observed: a committed 38 KB lock expanded to 75 KB) before the final `--locked` install is ever consulted. The machine then installs a different tool set than the repository pins, which defeats this section. Adapters therefore run the entire apply under mise's locked mode (`MISE_LOCKED=1`), including the bootstrap. ### 6. Notification ownership follows update ownership diff --git a/docs/adr/ADR-0021.md b/docs/adr/ADR-0021.md index 9afc5b32..d508af6d 100644 --- a/docs/adr/ADR-0021.md +++ b/docs/adr/ADR-0021.md @@ -93,6 +93,17 @@ orphan shim は上の「Rust CLI は mise の cargo backend で宣言する」 - Rust CLI の更新は `mise install` 経由になる。`cargo install --force` による個別更新は行わない。 - mise の rust backend が rustup を使い続ける限り、rustup 自体の更新経路は残る。 +## Addendum (2026-11-20): cargo backend の build は rustup default を見る + +`cargo:` tool の install は `cargo install` を実行するが、その `cargo` が使う toolchain は mise が選んだ `RUSTUP_TOOLCHAIN` ではなく rustup の **default toolchain** である。`core:rust` は rustup を `--default-toolchain none` で初期化し、以後 default を設定しない。そのため、既存環境の rustup に古い default (実機では 1.89.0) が残っていると、次の不整合が起きる。 + +- `mise ls rust` は `stable` を installed と報告する。 +- しかし `cargo:tauri-cli` など MSRV の高い crate は `requires rustc 1.90 or newer, while the currently active rustc version is 1.89.0` で失敗し、`apply-global-mise.ps1` 全体が exit 1 になる。 + +したがって `scripts/apply-global-mise.ps1` は、宣言された `rust` の値と rustup default が一致しない場合に `mise exec rust -- rustup default ` で default を宣言値へ揃える。これは「rustup default による暗黙の切り替えを許す」ものではない。mise の宣言が唯一の正本であり、その宣言を rustup 側の default にも反映して両者を一致させる操作である。 + +toolchain の選択そのものは引き続き上の優先順位 (project `mise.toml` / `rust-toolchain.toml` / machine global) に従う。`RUSTUP_TOOLCHAIN` は rustup が `rust-toolchain.toml` より優先するため、project pin はこの default 変更の影響を受けない。 + ## Re-evaluate - mise の rust backend が rustup を前提としない実装 (独自 toolchain 配置) へ変わった場合 diff --git a/platforms/windows-11/verify.ps1 b/platforms/windows-11/verify.ps1 index 5d372409..dcc9ce44 100644 --- a/platforms/windows-11/verify.ps1 +++ b/platforms/windows-11/verify.ps1 @@ -71,15 +71,152 @@ Test-CommandPresent -Name 'mise' if (Get-Command mise -ErrorAction SilentlyContinue) { Push-Location $RepoRoot + # `mise bootstrap status` has to read this checkout's mise.toml, and mise + # refuses an untrusted config. That is fatal here for a reason unrelated to + # machine state: converge.ps1 runs this script from the deployment checkout, + # which is a fresh clone that mise has never trusted, so the call failed with + # "Config files ... are not trusted" on every tick and pcs-setup always + # reported `verify: fail`. Trusting the path for this read keeps the probe + # read-only (nothing is written to mise's trust list) and matches the + # MISE_TRUSTED_CONFIG_PATHS technique the Windows CI job already uses. + $previousTrusted = $env:MISE_TRUSTED_CONFIG_PATHS + if ($previousTrusted) { + if ($previousTrusted -notlike "*$RepoRoot*") { $env:MISE_TRUSTED_CONFIG_PATHS = "$RepoRoot;$previousTrusted" } + } + else { + $env:MISE_TRUSTED_CONFIG_PATHS = [string]$RepoRoot + } try { & mise bootstrap status --missing if ($LASTEXITCODE -eq 0) { Write-Ok 'mise bootstrap desired state' } else { Write-Fail 'mise bootstrap reports missing machine state' } } finally { + if ($null -eq $previousTrusted) { Remove-Item Env:\MISE_TRUSTED_CONFIG_PATHS -ErrorAction SilentlyContinue } + else { $env:MISE_TRUSTED_CONFIG_PATHS = $previousTrusted } Pop-Location } } +# The machine-global config is a rendered copy of this repository's +# mise.global.toml (plus the Windows-only rewrites in +# scripts/windows-mise-config.ps1), and mise reads the copy, not the repository +# file. When the two drift apart, every `mise install` resolves a different tool +# set than the committed desired state while `mise bootstrap status` still only +# reports the tools the *copy* declares -- so a machine can look "converged" +# while installing a version the repository does not specify. Compare the copy +# with a fresh render and report the difference instead of trusting the copy. +function Get-GlobalMiseConfigTarget { + if ($env:MISE_GLOBAL_CONFIG_FILE) { return $env:MISE_GLOBAL_CONFIG_FILE } + return (Join-Path (Join-Path (Join-Path $env:USERPROFILE '.config') 'mise') 'config.toml') +} + +# mise takes the lockfile name from the config file name: `mise..toml` +# becomes `mise..lock` and everything else (including `config.toml`) +# becomes `mise.lock`. Mirrors scripts/apply-global-mise.ps1. +function Get-GlobalMiseLockTarget { + param([string]$ConfigTarget) + $name = Split-Path -Leaf $ConfigTarget + $lockName = if ($name -like 'mise.*.toml') { + [System.IO.Path]::ChangeExtension($name, '.lock') + } + elseif ($name -like '*.local.toml') { + 'mise.local.lock' + } + else { + 'mise.lock' + } + return (Join-Path (Split-Path -Parent $ConfigTarget) $lockName) +} + +function Test-ManagedGlobalMiseConfig { + $renderer = Join-Path (Join-Path $RepoRoot 'scripts') 'windows-mise-config.ps1' + $source = Join-Path $RepoRoot 'mise.global.toml' + if (-not (Test-Path -LiteralPath $source)) { + Write-WarnLocal "no mise.global.toml in $RepoRoot; machine-global config drift not checked" + return + } + if (-not (Test-Path -LiteralPath $renderer)) { + Write-WarnLocal "no scripts/windows-mise-config.ps1 in $RepoRoot; machine-global config drift not checked" + return + } + + # Only adopted state is authoritative. Run from a feature branch, or from a + # checkout with uncommitted edits to the declared state, and the comparison + # says nothing about the machine: the machine is converged to main, not to + # whatever this checkout happens to contain. Report that case as a warning so + # working on a branch does not turn the machine report red. + $isAdopted = $true + if (Get-Command git -CommandType Application -ErrorAction SilentlyContinue) { + $branch = (& git -C $RepoRoot symbolic-ref --quiet --short HEAD 2>$null) + $dirty = @(& git -C $RepoRoot status --porcelain -- mise.global.toml mise.global.lock 2>$null) + if ($LASTEXITCODE -eq 0 -and $branch -and $branch.Trim() -ne 'main') { + $isAdopted = $false + $why = "checkout is on '$($branch.Trim())', not main" + } + elseif ($dirty.Count -gt 0) { + $isAdopted = $false + $why = 'declared mise state has uncommitted changes' + } + } + + $target = Get-GlobalMiseConfigTarget + if (-not (Test-Path -LiteralPath $target)) { + Write-Fail "machine-global mise config missing at $target; run scripts/apply-global-mise.ps1" + return + } + + # Dot-sourcing is safe: windows-mise-config.ps1 only defines functions. + . $renderer + $expected = ConvertTo-WindowsMiseConfig -Text ([System.IO.File]::ReadAllText($source)) + $actual = [System.IO.File]::ReadAllText($target) + if ($actual -cne $expected) { + $expectedLines = @($expected -split "`r?`n") + $actualLines = @($actual -split "`r?`n") + $drift = @(Compare-Object -ReferenceObject $expectedLines -DifferenceObject $actualLines) + $sample = @($drift | Select-Object -First 6 | ForEach-Object { + $side = if ($_.SideIndicator -eq '=>') { 'machine' } else { 'repo' } + "$side $($_.InputObject)" + }) + $detail = "machine-global mise config differs from the rendered repository config ($target). " + + "First differences: " + ($sample -join ' | ') + if ($isAdopted) { + Write-Fail ($detail + ' Run scripts/apply-global-mise.ps1.') + } + else { + Write-WarnLocal ($detail + " Not treated as a failure because $why.") + } + } + else { + Write-Ok 'machine-global mise config matches the rendered repository config' + } + + # The lock is what `mise install --locked` resolves from. A stale copy pins + # versions the repository no longer declares. + $lockSource = Join-Path $RepoRoot 'mise.global.lock' + $lockTarget = Get-GlobalMiseLockTarget -ConfigTarget $target + if (-not (Test-Path -LiteralPath $lockSource)) { return } + if (-not (Test-Path -LiteralPath $lockTarget)) { + Write-Fail "machine-global mise lock missing at $lockTarget; run scripts/apply-global-mise.ps1" + return + } + $lockExpected = [System.IO.File]::ReadAllText($lockSource) + $lockActual = [System.IO.File]::ReadAllText($lockTarget) + if ($lockActual -cne $lockExpected) { + $detail = "machine-global mise lock differs from the repository lock ($lockTarget)." + if ($isAdopted) { + Write-Fail ($detail + ' Run scripts/apply-global-mise.ps1 so `mise install --locked` resolves the committed versions.') + } + else { + Write-WarnLocal ($detail + " Not treated as a failure because $why.") + } + } + else { + Write-Ok 'machine-global mise lock matches the repository lock' + } +} + +Test-ManagedGlobalMiseConfig + if (-not (Get-Command winget -ErrorAction SilentlyContinue)) { Write-Fail 'winget command missing' } @@ -163,6 +300,36 @@ else { } $disabled = (& mise settings get disable_tools 2>$null) -join ' ' if ($disabled -match 'rust') { Write-Fail 'mise disable_tools includes rust; run scripts/apply-global-mise.ps1 (Rust is mise-managed on Windows)' } else { Write-Ok 'mise does not disable the rust tool' } + + # `cargo:` backend tools are built by `cargo install`, which runs the rustup + # proxy for rustup's *default* toolchain -- not the toolchain mise selected. + # core:rust leaves that default unset (or stale), so the cargo: builds can + # fail with "no default toolchain is configured" or "requires rustc N or + # newer" while rust itself still looks installed. scripts/apply-global-mise.ps1 + # repairs this, so a mismatch here means the machine needs a re-apply. + $declaredRust = $null + foreach ($candidate in (Join-Path (Join-Path (Join-Path $env:USERPROFILE '.config') 'mise') 'config.toml'), (Join-Path $RepoRoot 'mise.global.toml')) { + if (-not (Test-Path -LiteralPath $candidate)) { continue } + foreach ($line in [System.IO.File]::ReadAllLines($candidate)) { + $match = [regex]::Match($line, '^\s*rust\s*=\s*"([^"]+)"') + if ($match.Success) { $declaredRust = $match.Groups[1].Value; break } + $inline = [regex]::Match($line, '^\s*rust\s*=\s*\{[^}]*version\s*=\s*"([^"]+)"') + if ($inline.Success) { $declaredRust = $inline.Groups[1].Value; break } + } + if ($declaredRust) { break } + } + if ($declaredRust) { + $defaultOutput = (& mise exec rust -- rustup default 2>&1) -join ' ' + if ($LASTEXITCODE -ne 0) { + Write-Fail "rustup has no usable default toolchain (mise rust = $declaredRust); run scripts/apply-global-mise.ps1 so cargo: installs can build" + } + elseif ($defaultOutput -notmatch "(^|\s)$([regex]::Escape($declaredRust))(-\S+)?(\s|$)") { + Write-Fail "rustup default toolchain is '$($defaultOutput.Trim())', not mise rust = $declaredRust; run scripts/apply-global-mise.ps1 (cargo: installs build with the default toolchain)" + } + else { + Write-Ok "rustup default toolchain matches mise rust = $declaredRust" + } + } } Write-Host "`nTailscale / WSL SSH" diff --git a/scripts/apply-global-mise.ps1 b/scripts/apply-global-mise.ps1 index bda0d7cd..7fff9718 100644 --- a/scripts/apply-global-mise.ps1 +++ b/scripts/apply-global-mise.ps1 @@ -101,6 +101,20 @@ elseif (Test-Path -LiteralPath $TargetLock) { Remove-Item -LiteralPath $TargetLock -Force } +# A plain `mise install` resolves every rolling selector (`latest`, `stable`) +# again and rewrites the lock it installs from. The GitHub-token bootstrap +# below and the main install both run `mise install`, so without this every +# apply would replace the committed lock with a freshly re-locked one before +# `--locked` is ever consulted, and the machine would end up installing a +# different tool set from the one this repository pins. MISE_LOCKED=1 makes +# mise treat the lock as read-only for the rest of the run; converge.ps1 sets +# it for the same reason. Only applied when a lock was actually synced, because +# a machine with no committed lock has to be allowed to create one. +$previousMiseLocked = $env:MISE_LOCKED +if (Test-Path -LiteralPath $TargetLock) { + $env:MISE_LOCKED = '1' +} + function Prepare-MiseGitHubAuth { if ($env:MISE_GITHUB_TOKEN -or $env:GITHUB_API_TOKEN -or $env:GITHUB_TOKEN) { Write-Host 'ok mise GitHub authentication provided by environment' @@ -115,6 +129,12 @@ function Prepare-MiseGitHubAuth { $previousPreference = $ErrorActionPreference $ErrorActionPreference = 'Continue' try { + # `mise install gh` here is only a bootstrap step for the token lookup. + # It must not re-lock: a plain `mise install` resolves every `latest` + # again and rewrites the machine-global lock with all-platform entries, + # so the `--locked` install below would then resolve from the rewritten + # file instead of the committed one. MISE_LOCKED=1 makes this run, and + # the install below, consume the committed lock unchanged. & mise install gh if ($LASTEXITCODE -ne 0) { throw "failed to install gh before GitHub-backed mise tools (exit $LASTEXITCODE)" @@ -146,6 +166,78 @@ function Prepare-MiseGitHubAuth { Prepare-MiseGitHubAuth +# `core:rust` installs toolchains through rustup but never sets rustup's +# *default* toolchain: rustup is initialized with `--default-toolchain none`. +# The cargo: backend tools are built by running `cargo install`, and the cargo +# that runs is the rustup proxy, which selects the *default* toolchain -- not the +# `rust = "stable"` toolchain mise selected and exported as RUSTUP_TOOLCHAIN. +# Two broken states follow from that, and both must be repaired: +# +# * no default at all (a fresh machine): `cargo` fails with +# "rustup could not choose a version of cargo to run" / "no default +# toolchain is configured", so every cargo: install fails; +# * a stale default (this machine had 1.89.0): cargo: installs that need a +# newer compiler fail with "requires rustc 1.90 or newer". +# +# In both cases `mise ls rust` still reports rust as installed, so the failure +# looks unrelated to rust. Point rustup's default at the declared rust version so +# the cargo: builds and mise agree. +function Set-MiseRustDefault { + if (-not (Get-Command mise -CommandType Application -ErrorAction SilentlyContinue)) { return } + # Read the declared rust version from the rendered machine config first, then + # from the repository source. Only the two shapes this repository uses are + # understood: `rust = "stable"` and `rust = { version = "..." }`. + $declared = $null + $candidates = @($TargetConfig, (Join-Path $RepoRoot 'mise.global.toml')) + foreach ($candidate in $candidates) { + if (-not (Test-Path -LiteralPath $candidate)) { continue } + foreach ($line in [System.IO.File]::ReadAllLines($candidate)) { + $match = [regex]::Match($line, '^\s*rust\s*=\s*(.+?)\s*$') + if (-not $match.Success) { continue } + $value = $match.Groups[1].Value + $quoted = [regex]::Match($value, '^"([^"]+)"$') + if ($quoted.Success) { $declared = $quoted.Groups[1].Value; break } + $inline = [regex]::Match($value, 'version\s*=\s*"([^"]+)"') + if ($inline.Success) { $declared = $inline.Groups[1].Value; break } + } + if ($declared) { break } + } + if (-not $declared) { return } + + $previousPreference = $ErrorActionPreference + $ErrorActionPreference = 'Continue' + Push-Location $HOME + try { + # `mise exec rust --` supplies the RUSTUP_HOME/CARGO_HOME and + # RUSTUP_TOOLCHAIN that core:rust manages, so this never touches a + # standalone rustup home that mise does not own. + # + # A non-zero exit here is NOT a reason to skip the repair: on a fresh + # machine `rustup default` exits 1 with "no default toolchain is + # configured", which is exactly the state that has to be fixed. Only the + # subsequent `rustup default ` decides whether the repair + # worked. + $current = (& mise exec rust -- rustup default 2>&1) -join ' ' + if ($LASTEXITCODE -eq 0 -and $current -match "(^|\s)$([regex]::Escape($declared))(-\S+)?(\s|$)") { + Write-Host "ok rustup default toolchain is $declared" + return + } + & mise exec rust -- rustup default $declared *> $null + if ($LASTEXITCODE -eq 0) { + Write-Host "aligned rustup default toolchain with mise rust = $declared" + } + else { + Write-Host "warn could not set the rustup default toolchain to $declared (exit $LASTEXITCODE)" + } + } + finally { + Pop-Location + $ErrorActionPreference = $previousPreference + } +} + +Set-MiseRustDefault + Push-Location $HOME $previousPreference = $ErrorActionPreference $ErrorActionPreference = 'Continue' @@ -158,15 +250,44 @@ try { & mise @installArgs $installExitCode = $LASTEXITCODE + + # On a fresh machine the call above runs while rust is still absent, so + # `mise exec rust -- rustup default ...` cannot resolve the rust tool and the + # first Set-MiseRustDefault call is a no-op. core:rust then installs the + # toolchain but leaves rustup's default unset, so the cargo: builds fail with + # "no default toolchain is configured" and the whole install exits non-zero + # even though rust itself is now installed. Align the default now that the + # toolchain exists and retry once, so a first bootstrap converges in this same + # run instead of requiring a manual re-run. + if ($installExitCode -ne 0) { + Set-MiseRustDefault + Write-Host 'retrying mise install after aligning the rustup default toolchain' + & mise @installArgs + $installExitCode = $LASTEXITCODE + } } finally { $ErrorActionPreference = $previousPreference Pop-Location } +# Keep the default aligned on the success path too: a machine whose cargo: tools +# were already built still has to report a rustup default matching the declared +# rust version, so `cargo install` from an ordinary shell behaves the same way. +Set-MiseRustDefault + if ($installExitCode -ne 0) { exit $installExitCode } Write-Host 'Machine-global mise tools are installed.' Write-Host 'Native Windows dotfiles linking is not canonical yet; apply dotfiles inside WSL until the Windows link adapter is enabled.' + +# Restore the caller's MISE_LOCKED only on a successful run; on failure the +# script exits above and the process ends, so nothing leaks into the caller. +if ($null -eq $previousMiseLocked) { + Remove-Item Env:\MISE_LOCKED -ErrorAction SilentlyContinue +} +else { + $env:MISE_LOCKED = $previousMiseLocked +} diff --git a/scripts/apply-global-mise.sh b/scripts/apply-global-mise.sh index fc35e67e..2b33cf2a 100755 --- a/scripts/apply-global-mise.sh +++ b/scripts/apply-global-mise.sh @@ -124,14 +124,64 @@ if [[ -f "$source_lock" ]]; then printf 'ok using committed mise global lock\n' fi +# `core:rust` installs toolchains through rustup but never sets rustup's +# *default* toolchain (rustup is initialized with `--default-toolchain none`). +# The cargo: tools are built by `cargo install`, and the cargo that runs is the +# rustup proxy, which selects the *default* toolchain -- not the `rust = "stable"` +# toolchain mise selected. A fresh machine therefore has no default at all +# ("rustup could not choose a version of cargo to run"), and a machine with an +# older default fails cargo: builds that need a newer compiler. `mise ls rust` +# still reports rust as installed in both cases, so the failure looks unrelated. +# Align rustup's default with the declared rust version. +declared_rust() { + local candidate value + for candidate in "${target_config}" "${source_config}"; do + [[ -f "$candidate" ]] || continue + value="$(sed -n 's/^[[:space:]]*rust[[:space:]]*=[[:space:]]*"\([^"]*\)".*$/\1/p' "$candidate" | head -n 1)" + if [[ -z "$value" ]]; then + value="$(sed -n 's/^[[:space:]]*rust[[:space:]]*=[[:space:]]*{[^}]*version[[:space:]]*=[[:space:]]*"\([^"]*\)".*$/\1/p' "$candidate" | head -n 1)" + fi + if [[ -n "$value" ]]; then + printf '%s' "$value" + return 0 + fi + done + return 1 +} + +align_rustup_default() { + local declared current + declared="$(declared_rust)" || return 0 + # A non-zero exit here is expected on a fresh machine ("no default toolchain is + # configured") and is exactly the state that has to be repaired, so the result + # of the set command below decides whether this worked. + current="$(mise -C "$HOME" exec rust -- rustup default 2>/dev/null || true)" + if [[ "$current" == "$declared"* ]]; then + printf 'ok rustup default toolchain is %s\n' "$declared" + return 0 + fi + if mise -C "$HOME" exec rust -- rustup default "$declared" >/dev/null 2>&1; then + printf 'aligned rustup default toolchain with mise rust = %s\n' "$declared" + else + printf 'warn could not align the rustup default toolchain with %s\n' "$declared" >&2 + fi +} + +align_rustup_default + last_status=1 for ((attempt = 1; attempt <= install_attempts; attempt++)); do if mise -C "$HOME" "${install_args[@]}"; then + align_rustup_default exit 0 else last_status=$? fi + # The first attempt on a fresh machine installs rust but fails the cargo: + # builds, because rustup had no default yet. Align it and retry. + align_rustup_default + if ((attempt == install_attempts)); then break fi diff --git a/scripts/test-windows-mise-config.ps1 b/scripts/test-windows-mise-config.ps1 index 2113e053..e02787e4 100644 --- a/scripts/test-windows-mise-config.ps1 +++ b/scripts/test-windows-mise-config.ps1 @@ -33,7 +33,11 @@ Write-Host 'ok Windows form uses %MISE_CREDENTIAL_HOST%' # The shared file keeps the Unix form; a Windows-only string here would make the # Unix machines fail instead. Match the assignment, not the prose around it. -$sourceCommand = [regex]::Match($sourceText, '(?m)^credential_command\s*=.*$').Value +# `.*$` stops before `\n` but still captures a trailing `\r`, and Windows +# checkouts of this repository use CRLF (no .gitattributes; core.autocrlf=true in +# Git for Windows). Compare the line without its terminator so the check tests the +# content, not the checkout's line ending. +$sourceCommand = [regex]::Match($sourceText, '(?m)^credential_command\s*=[^\r\n]*').Value if ($sourceCommand -ne 'credential_command = ''gh auth token --hostname "$MISE_CREDENTIAL_HOST"''') { throw "mise.global.toml must carry the portable `$.` form, got: $sourceCommand" } From f8dac5ffea749ac5262be3ce8461eb5567733058 Mon Sep 17 00:00:00 2001 From: rebuildup Date: Fri, 20 Nov 2026 03:35:27 +0900 Subject: [PATCH 2/3] fix(mise): lock the POSIX adapter too, not only the converge caller apply-global-mise.sh has the same unlocked-bootstrap problem as its PowerShell counterpart: it runs `mise install gh` before the locked install, and a plain `mise install` re-resolves every rolling selector and rewrites the lock it installs from. converge.sh happened to set MISE_LOCKED=1 around the script, so the defect was hidden from the only caller that used a lock, while a direct run (and any caller that forgot) still clobbered mise.global.lock. On POSIX the lock is a symlink into the checkout, so that rewrite also dirties the work tree. Set MISE_LOCKED=1 in the script itself when a committed lock exists, so every invocation of every mise command is locked regardless of the caller. A machine with no committed lock stays unlocked so the first bootstrap can create one. --- scripts/apply-global-mise.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/apply-global-mise.sh b/scripts/apply-global-mise.sh index 2b33cf2a..f392cd95 100755 --- a/scripts/apply-global-mise.sh +++ b/scripts/apply-global-mise.sh @@ -58,6 +58,17 @@ fi export MISE_HTTP_TIMEOUT="${MISE_HTTP_TIMEOUT:-120s}" export MISE_HTTP_RETRIES="${MISE_HTTP_RETRIES:-5}" +# A plain `mise install` re-resolves every rolling selector and rewrites the lock +# it installs from, so the unlocked `mise install gh` bootstrap below replaces the +# committed lock before `--locked` is ever consulted (observed: 38393 -> 75443 +# bytes) and the machine installs a different tool set than the repository pins. +# On POSIX the lock is a symlink into the checkout, so that rewrite also dirties +# the work tree. Lock reads for the rest of the run when a committed lock exists; +# a machine with no committed lock must still be able to create one. +if [[ -f "$source_lock" ]]; then + export MISE_LOCKED=1 +fi + prepare_github_auth_for_mise() { if [[ -n "${MISE_GITHUB_TOKEN:-}" || -n "${GITHUB_API_TOKEN:-}" || -n "${GITHUB_TOKEN:-}" ]]; then printf 'ok mise GitHub authentication provided by environment\n' From ea89644fcd2eb72316c424698e04580f768c4e51 Mon Sep 17 00:00:00 2001 From: rebuildup Date: Fri, 20 Nov 2026 03:41:21 +0900 Subject: [PATCH 3/3] test(ci): guard the rustup default alignment like the lock The lock regression was invisible because nothing failed when it broke, so the same failure mode would hide the rustup-default repair too. Add a CI step that models rustup as persistent state and asserts all three machine states a Windows box can be in: no default (fresh), a stale default, and an already matching default. The fake mise exits 1 with rustup's real "no default toolchain is configured" message instead of exiting 0 with empty output: with the earlier fake the early-return bug the step exists to catch passed unnoticed. Verified that re-introducing the old early return makes this step fail. --- .github/workflows/ci.yml | 84 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f928dbb1..365ad243 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -800,6 +800,90 @@ jobs: Remove-Item -LiteralPath $root -Recurse -Force -ErrorAction SilentlyContinue } + - name: Validate the apply aligns the rustup default toolchain + shell: pwsh + run: | + Set-StrictMode -Version Latest + $ErrorActionPreference = 'Stop' + + # Regression: core:rust initializes rustup with `--default-toolchain + # none` and never sets a default, but cargo: backend tools are built by + # `cargo install`, which runs the rustup proxy for the *default* + # toolchain. A fresh machine then has no default at all and a machine + # with an older default fails MSRV-heavy crates ("requires rustc 1.90 + # or newer"), while `mise ls rust` still reports rust as installed. The + # apply must align the default and must not skip the repair just because + # reading the current default fails on a fresh machine. + $root = Join-Path ([System.IO.Path]::GetTempPath()) "pc-setup-rustdefault-$([guid]::NewGuid())" + $fakeBin = Join-Path $root 'bin' + $target = Join-Path $root 'config.toml' + $seen = Join-Path $root 'rustup-seen.txt' + $stateFile = Join-Path $root 'rustup-default.txt' + New-Item -ItemType Directory -Path $fakeBin -Force | Out-Null + $oldPath = $env:PATH + + try { + # The apply refuses to overwrite an unmanaged global config, so seed + # the managed marker the script looks for. + "# Managed by rebuildup/pc-setup.`n[tools]`nrust = `"stable`"" | Set-Content -LiteralPath $target + + # Fake mise that models rustup's default as *persistent* state: a + # `default ` writes it, a bare `default` reads it back. A + # stateless fake would make the apply appear to "fix" the same thing + # twice and hide a genuinely idempotent implementation. + # The read exits 1 when nothing is configured, exactly like real + # rustup on a fresh machine ("no default toolchain is configured"); + # a fake that exits 0 with empty output would hide the early-return + # bug this step exists to catch. + $fake = @( + '@echo off', + ('>>"{0}" echo CALL: %*' -f $seen), + 'echo %* | findstr /C:"rustup default" >nul || exit /b 0', + ('if not "%6"=="" (>"' + $stateFile + '" echo %6 & >>"' + $seen + '" echo SET: %6 & exit /b 0)'), + ('if exist "' + $stateFile + '" (type "' + $stateFile + '" & exit /b 0)'), + 'if defined FAKE_RUST_DEFAULT (echo %FAKE_RUST_DEFAULT% & exit /b 0)', + 'echo error: no default toolchain is configured 1>&2', + 'exit /b 1' + ) -join "`r`n" + Set-Content -LiteralPath (Join-Path $fakeBin 'mise.cmd') -Value $fake + $env:PATH = "$fakeBin;$oldPath" + $env:MISE_GLOBAL_CONFIG_FILE = $target + $env:MISE_GITHUB_TOKEN = 'ci-placeholder' + + function Invoke-Case { + param([string]$Label, [string]$CurrentDefault, [int]$ExpectedSets) + if (Test-Path $seen) { Remove-Item $seen -Force } + # Each case starts from the stated machine state. + if (Test-Path $stateFile) { Remove-Item $stateFile -Force } + if ($CurrentDefault) { + Set-Content -LiteralPath $stateFile -Value $CurrentDefault + Remove-Item Env:FAKE_RUST_DEFAULT -ErrorAction SilentlyContinue + } + else { Remove-Item Env:FAKE_RUST_DEFAULT -ErrorAction SilentlyContinue } + & ./scripts/apply-global-mise.ps1 | Out-Null + if ($LASTEXITCODE -ne 0) { throw "${Label}: apply-global-mise.ps1 exited $LASTEXITCODE" } + $sets = @() + if (Test-Path $seen) { $sets = @(Get-Content -LiteralPath $seen | Where-Object { $_ -match '^SET:' }) } + if ($sets.Count -ne $ExpectedSets) { + $detail = if (Test-Path $seen) { (Get-Content -LiteralPath $seen) -join ' / ' } else { '(no calls)' } + throw "${Label}: expected $ExpectedSets rustup-default set call(s), saw $($sets.Count). calls: $detail" + } + } + + # A fresh machine has no default: `rustup default` (the read) fails + # and that must not stop the repair. + Invoke-Case -Label 'fresh: no default configured' -CurrentDefault '' -ExpectedSets 1 + # A stale default must be moved to the declared value. + Invoke-Case -Label 'stale: 1.89.0 default' -CurrentDefault '1.89.0-x86_64-pc-windows-msvc (default)' -ExpectedSets 1 + # An already-correct default must not be touched. + Invoke-Case -Label 'idempotent: already stable' -CurrentDefault 'stable-x86_64-pc-windows-msvc (default)' -ExpectedSets 0 + } + finally { + $env:PATH = $oldPath + Remove-Item Env:MISE_GLOBAL_CONFIG_FILE, Env:MISE_GITHUB_TOKEN, Env:FAKE_RUST_DEFAULT -ErrorAction SilentlyContinue + Remove-Item -LiteralPath $root -Recurse -Force -ErrorAction SilentlyContinue + } + - name: Validate global mise config backup before overwrite shell: pwsh run: |