Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 151 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,157 @@ 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 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 <value>` 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: |
Expand Down
2 changes: 1 addition & 1 deletion docs/adr/ADR-0010.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions docs/adr/ADR-0021.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <declared>` で 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 配置) へ変わった場合
Expand Down
Loading