Skip to content

The agent that grows with you

fix(install): a rerun keeps an install on the update channel it chose (#137714)

Tekniumbb35d7a2828c
diff --git a/apps/bootstrap-installer/src-tauri/src/update.rs b/apps/bootstrap-installer/src-tauri/src/update.rs
index 2606b60f584..4a61aa48b2a 100644
--- a/apps/bootstrap-installer/src-tauri/src/update.rs
+++ b/apps/bootstrap-installer/src-tauri/src/update.rs
@@ -152,9 +152,7 @@ async fn run_update(app: AppHandle) -> Result<()> {
}
};
- let update_branch = update_branch_from_args(std::env::args().skip(1))
- .or_else(|| option_env_string("BUILD_PIN_BRANCH"))
- .unwrap_or_else(|| "main".to_string());
+ let update_target = update_target_from_args(std::env::args().skip(1));
let target_app = if cfg!(target_os = "macos") {
target_app_from_args(std::env::args().skip(1))
} else {
@@ -202,27 +200,20 @@ async fn run_update(app: AppHandle) -> Result<()> {
);
// ---- stage 2: hermes update -----------------------------------------
- // Pass --branch so `hermes update` targets the branch this installer was
- // built/pinned against (BUILD_PIN_BRANCH), NOT its built-in default of
- // `main`. The install was a detached-HEAD checkout of a specific commit;
- // without --branch, `hermes update` switches the checkout to `main` (a
- // divergent branch that may not even have the desktop CLI command), then
- // reports "already up to date" against the wrong branch. The desktop
- // detected the update against this same branch, so we must update against
- // it too.
+ // Update against exactly what the desktop checked against (see
+ // update_target_from_args), never `hermes update`'s own default.
emit_log(
&app,
Some("update"),
LogStream::Stdout,
- &format!("[update] updating against branch {update_branch}"),
+ &format!("[update] updating against {}", update_target.join(" ")),
);
let child_env = update_child_env(&install_root);
let mut update_args: Vec<String> =
vec!["update".into(), "--yes".into(), "--gateway".into()];
// Only historical in-place updaters need the old shim bypass.
if legacy_install { update_args.push("--force".into()); }
- update_args.push("--branch".into());
- update_args.push(update_branch);
+ update_args.extend(update_target);
emit_stage(&app, "update", StageState::Running, None, None);
let started = Instant::now();
@@ -777,14 +768,29 @@ fn update_child_env(install_root: &Path) -> Vec<(String, OsString)> {
envs
}
-fn update_branch_from_args<I, S>(args: I) -> Option<String>
+/// `hermes update`'s target flags: the channel the desktop checked against
+/// (`--channel`), else a branch (`--branch`, then the build pin
+/// BUILD_PIN_BRANCH, then `main`). A stable install the desktop checked
+/// against its release must not be updated onto the pinned branch: it would
+/// land on main while its channel still names the release.
+fn update_target_from_args<I, S>(args: I) -> Vec<String>
where
I: IntoIterator<Item = S>,
S: AsRef<str>,
{
- arg_value_from_args(args, "--branch")
- .map(|s| s.trim().to_string())
- .filter(|s| !s.is_empty())
+ let args: Vec<String> = args.into_iter().map(|s| s.as_ref().to_string()).collect();
+ let value = |name: &str| {
+ arg_value_from_args(&args, name)
+ .map(|s| s.trim().to_string())
+ .filter(|s| !s.is_empty())
+ };
+ if let Some(channel) = value("--channel") {
+ return vec!["--channel".into(), channel];
+ }
+ let branch = value("--branch")
+ .or_else(|| option_env_string("BUILD_PIN_BRANCH"))
+ .unwrap_or_else(|| "main".to_string());
+ vec!["--branch".into(), branch]
}
fn target_app_from_args<I, S>(args: I) -> Option<PathBuf>
@@ -1165,16 +1171,24 @@ mod tests {
}
#[test]
- fn parses_update_branch_from_space_or_equals_args() {
+ fn update_targets_the_checked_channel_before_any_branch() {
+ assert_eq!(
+ update_target_from_args(["--update", "--branch", "bb/test"]),
+ ["--branch", "bb/test"]
+ );
+ assert_eq!(
+ update_target_from_args(["--update", "--branch=main"]),
+ ["--branch", "main"]
+ );
assert_eq!(
- update_branch_from_args(["--update", "--branch", "bb/test"]),
- Some("bb/test".to_string())
+ update_target_from_args(["--update", "--channel", "stable", "--target-app", "/A.app"]),
+ ["--channel", "stable"]
);
assert_eq!(
- update_branch_from_args(["--update", "--branch=main"]),
- Some("main".to_string())
+ update_target_from_args(["--update", "--branch", "main", "--channel=stable"]),
+ ["--channel", "stable"]
);
- assert_eq!(update_branch_from_args(["--update"]), None);
+ assert_eq!(update_target_from_args(["--update"])[0], "--branch");
}
#[test]
diff --git a/scripts/install.ps1 b/scripts/install.ps1
index c32295c9226..2f16f42b1b8 100644
--- a/scripts/install.ps1
+++ b/scripts/install.ps1
@@ -844,8 +844,55 @@ function Disable-TreelessGraphWrites([string]$Dir) {
}
}
+# A YAML scalar as Hermes writes it: unquoted, or one pair of matching quotes; trailing comment dropped.
+function ConvertFrom-YamlScalar([string]$Text) {
+ $s = ($Text -replace '\s+#.*$', '').Trim()
+ if ($s.Length -gt 1 -and ($s[0] -eq '"' -or $s[0] -eq "'") -and $s[-1] -eq $s[0]) { $s = $s.Substring(1, $s.Length - 2) }
+ return $s
+}
+
+# The update channel this install chose (config.yaml update.installs.<id>.channel, id = sha16 of
+# the canonical install path, as hermes_cli.update_channel keys it; a record naming this path also
+# counts, since Windows paths can differ only in case). Pre-Python reader of the block YAML Hermes
+# writes; anything it cannot read returns '', which keeps the plain branch behaviour.
+function Get-ChosenChannel {
+ $config = Join-Path $HermesHome 'config.yaml'
+ if (-not (Test-Path -LiteralPath $config)) { return '' }
+ try {
+ $root = (Get-Item -LiteralPath $InstallDir -Force).FullName.TrimEnd('\')
+ $hash = [Security.Cryptography.SHA256]::Create().ComputeHash([Text.Encoding]::UTF8.GetBytes($root))
+ $id = (-join ($hash | ForEach-Object { $_.ToString('x2') })).Substring(0, 16)
+ $lines = [IO.File]::ReadAllLines($config)
+ } catch { return '' }
+ $keys = New-Object System.Collections.Generic.List[object]
+ $records = @{}
+ foreach ($line in $lines) {
+ if ($line -match '^\s*(#|$)') { continue }
+ if ($line -notmatch '^( *)([^:]+):(.*)$') { continue }
+ $indent = $Matches[1].Length
+ $key = ConvertFrom-YamlScalar $Matches[2]
+ $value = ConvertFrom-YamlScalar $Matches[3]
+ while ($keys.Count -and $keys[$keys.Count - 1].Indent -ge $indent) { $keys.RemoveAt($keys.Count - 1) }
+ $keys.Add([pscustomobject]@{ Indent = $indent; Key = $key })
+ if ($keys.Count -eq 4 -and $keys[0].Key -ceq 'update' -and $keys[1].Key -ceq 'installs') {
+ $record = $keys[2].Key
+ if (-not $records.ContainsKey($record)) { $records[$record] = @{} }
+ $records[$record][$key] = $value
+ }
+ }
+ foreach ($record in $records.GetEnumerator()) {
+ $path = "$($record.Value['path'])".TrimEnd('\')
+ if ($record.Key -ceq $id -or ($path -and $path -eq $root)) {
+ $channel = "$($record.Value['channel'])"
+ if ($channel -cmatch '^[a-z0-9]+(-[a-z0-9]+)*$') { return $channel }
+ }
+ }
+ return ''
+}
+
function Stage-Repository {
$pinned = $false
+ $channel = ''
# Refuse an occupied non-checkout before provisioning Git. This check
# needs no tool download and must not overwrite a user's existing files.
if (-not (Test-Path (Join-Path $InstallDir ".git")) -and (Test-Path -LiteralPath $InstallDir)) {
@@ -869,7 +916,14 @@ function Stage-Repository {
}
}
if (Test-Path (Join-Path $InstallDir ".git")) {
- Log "Updating $InstallDir ($Branch)"
+ # A chosen channel (stable, a preview) owns where this checkout sits: `hermes update`
+ # moves it. Switching it to the installer's branch would leave it on main while its
+ # channel still says otherwise, and the next check would offer the release as an update.
+ # Only an explicit -Commit pin outranks the choice.
+ if (-not $Commit) { $channel = Get-ChosenChannel }
+ if ($channel -ceq 'main') { $channel = '' }
+ if ($channel) { Log "Repairing $InstallDir on the $channel update channel it chose" }
+ else { Log "Updating $InstallDir ($Branch)" }
# A checkout cloned before longpaths was set: a deep path past MAX_PATH fails checkout.
Invoke-Native { git -C $InstallDir config core.longpaths true } | Out-Null
# An explicit HERMES_REPO_URL names the source for reruns too, not
@@ -908,6 +962,10 @@ function Stage-Repository {
}
}
}
+ if ($channel) {
+ Log "Keeping its checkout: ``hermes update`` moves it (``hermes update --set-channel main`` follows main)"
+ return
+ }
Invoke-Logged "Fetching origin/$Branch" { git -C $InstallDir fetch origin "+refs/heads/${Branch}:refs/remotes/origin/${Branch}" }
if ($LASTEXITCODE) { Fail "git fetch failed$(Get-NativeDetail)" git_fetch_failed }
$stamp = (Get-Date -Format 'yyyyMMdd-HHmmss')
diff --git a/scripts/install.sh b/scripts/install.sh
index 4cd78a12a7a..433062a274a 100755
--- a/scripts/install.sh
+++ b/scripts/install.sh
@@ -548,8 +548,37 @@ stage_prerequisites() {
log_success "prerequisites ok (git, curl)"
}
+# The update channel this install chose (config.yaml update.installs.<id>.channel,
+# id = sha16 of the canonical install path, as hermes_cli.update_channel keys it).
+# Pre-Python reader of the block YAML Hermes writes; anything it cannot read prints
+# nothing, which keeps the plain branch behaviour.
+chosen_channel() {
+ local config="$HERMES_HOME/config.yaml" root id
+ [ -f "$config" ] || return 0
+ root="$(cd "$INSTALL_DIR" 2>/dev/null && pwd -P)" || return 0
+ if command -v sha256sum >/dev/null 2>&1; then id="$(printf '%s' "$root" | sha256sum)"
+ elif command -v shasum >/dev/null 2>&1; then id="$(printf '%s' "$root" | shasum -a 256)"
+ else return 0; fi
+ awk -v id="${id:0:16}" -v q="'" '
+ function bare(s, f) {
+ sub(/^[ \t]+/, "", s); sub(/[ \t]+#.*$/, "", s); sub(/[ \t\r]+$/, "", s)
+ f = substr(s, 1, 1)
+ if (length(s) > 1 && (f == "\"" || f == q) && substr(s, length(s), 1) == f) s = substr(s, 2, length(s) - 2)
+ return s
+ }
+ /^[ \t]*(#|\r?$)/ { next }
+ {
+ match($0, /^ */); indent = RLENGTH; line = substr($0, indent + 1)
+ colon = index(line, ":"); if (!colon) next
+ while (depth && at[depth] >= indent) depth--
+ at[++depth] = indent; key[depth] = bare(substr(line, 1, colon - 1))
+ if (depth == 4 && key[1] == "update" && key[2] == "installs" && key[3] == id \
+ && key[4] == "channel") { print bare(substr(line, colon + 1)); exit }
+ }' "$config" | grep -E '^[a-z0-9]+(-[a-z0-9]+)*$' || :
+}
+
stage_repository() {
- local pinned=false
+ local pinned=false channel=""
# An interrupted clone from an older installer can leave a .git with no
# initial commit, where stash/checkout abort ("You do not have the
# initial commit yet", #40998). Move it aside -- never delete it, it may
@@ -561,7 +590,17 @@ stage_repository() {
mv "$INSTALL_DIR" "$broken" || fail "cannot move $INSTALL_DIR aside" filesystem_error
fi
if [ -d "$INSTALL_DIR/.git" ]; then
- log "Updating $INSTALL_DIR ($BRANCH)"
+ # A chosen channel (stable, a preview) owns where this checkout sits: `hermes update`
+ # moves it. Switching it to the installer's branch would leave it on main while its
+ # channel still says otherwise, and the next check would offer the release as an update.
+ # Only an explicit --commit pin outranks the choice.
+ [ -n "$INSTALL_COMMIT" ] || channel="$(chosen_channel)"
+ [ "$channel" != main ] || channel=""
+ if [ -n "$channel" ]; then
+ log "Repairing $INSTALL_DIR on the $channel update channel it chose"
+ else
+ log "Updating $INSTALL_DIR ($BRANCH)"
+ fi
# An explicit HERMES_REPO_URL names the source for reruns too, not
# just the first clone.
if [ -n "${HERMES_REPO_URL:-}" ]; then
@@ -601,6 +640,10 @@ stage_repository() {
fi
fi
fi
+ if [ -n "$channel" ]; then
+ log "Keeping its checkout: \`hermes update\` moves it (\`hermes update --set-channel main\` follows main)"
+ return 0
+ fi
run_logged "Fetching origin/$BRANCH" git -C "$INSTALL_DIR" fetch origin "+refs/heads/$BRANCH:refs/remotes/origin/$BRANCH" \
|| fail "git fetch failed$(native_detail)" git_fetch_failed
local stamp