Skip to content

Commit 2ef30e8

Browse files
committed
update snapshots
1 parent a9ec947 commit 2ef30e8

8 files changed

Lines changed: 70 additions & 11 deletions

File tree

crates/biome_cli/src/commands/upgrade.rs

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ use biome_diagnostics::{Error, StdError};
44
use biome_fs::normalize_path;
55
use biome_package::node_semver::Version;
66
use camino::{Utf8Path, Utf8PathBuf};
7+
use reqwest::blocking::Client;
78
use self_update::backends::github::Update;
89
use std::env;
910
use std::fmt;
1011
use std::process::{Command, Stdio};
1112
use std::time::Duration;
12-
use reqwest::blocking::Client;
1313

1414
const BREW_BINARY_NAME: &str = "biome";
1515
const GITHUB_REPO_OWNER: &str = "biomejs";
@@ -39,9 +39,17 @@ pub(crate) fn upgrade(session: CliSession) -> Result<(), CliDiagnostic> {
3939
)),
4040
InstallSource::Homebrew => upgrade_with_homebrew(session),
4141
InstallSource::Standalone => upgrade_standalone(session),
42+
InstallSource::Unknown => Err(unknown_install_source_upgrade_error()),
4243
}
4344
}
4445

46+
fn unknown_install_source_upgrade_error() -> CliDiagnostic {
47+
CliDiagnostic::upgrade_error(
48+
"`biome upgrade` couldn't determine how this binary was installed. Upgrade Biome with the same installer or package manager you originally used.",
49+
None,
50+
)
51+
}
52+
4553
fn ensure_upgrade_supported() -> Result<(), CliDiagnostic> {
4654
if env::var_os("BIOME_BINARY").is_some() {
4755
return Err(CliDiagnostic::upgrade_error(
@@ -60,6 +68,7 @@ fn upgrade_with_homebrew(session: CliSession) -> Result<(), CliDiagnostic> {
6068
});
6169

6270
let status = Command::new("brew")
71+
.env("HOMEBREW_NO_AUTO_UPDATE", "1")
6372
.arg("upgrade")
6473
.arg(BREW_BINARY_NAME)
6574
.stdin(Stdio::inherit())
@@ -211,6 +220,7 @@ enum InstallSource {
211220
Homebrew,
212221
Npm,
213222
Standalone,
223+
Unknown,
214224
}
215225

216226
/// Detect the installation source
@@ -219,7 +229,8 @@ enum InstallSource {
219229
///
220230
/// If the `BIOME_DISTRIBUTION` environment variable is set, it will be used to determine the
221231
/// installation source instead of path-based detection. This allows users to override the
222-
/// detected installation source if necessary.
232+
/// detected installation source if necessary. Any unrecognized installation source is treated as
233+
/// unknown so `biome upgrade` does not attempt a cross-channel self-update.
223234
fn detect_install_source(current_exe: &Utf8Path) -> InstallSource {
224235
if let Some(install_source) = install_source_from_env() {
225236
return install_source;
@@ -234,18 +245,21 @@ fn detect_install_source(current_exe: &Utf8Path) -> InstallSource {
234245
} else if is_homebrew_install(&canonical) {
235246
InstallSource::Homebrew
236247
} else {
237-
InstallSource::Standalone
248+
InstallSource::Unknown
238249
}
239250
}
240251

241252
/// Detect the installation source from the environment
242253
fn install_source_from_env() -> Option<InstallSource> {
243-
match env::var_os("BIOME_DISTRIBUTION")?.to_str()? {
244-
"npm" => Some(InstallSource::Npm),
245-
"homebrew" => Some(InstallSource::Homebrew),
246-
"standalone" => Some(InstallSource::Standalone),
247-
_ => None,
248-
}
254+
let install_source = env::var_os("BIOME_DISTRIBUTION")?;
255+
let install_source = match install_source.to_str() {
256+
Some("npm") => InstallSource::Npm,
257+
Some("homebrew") => InstallSource::Homebrew,
258+
Some("standalone") => InstallSource::Standalone,
259+
Some(_) | None => InstallSource::Unknown,
260+
};
261+
262+
Some(install_source)
249263
}
250264

251265
/// Determines whether Biome was installed using a npm-compatible package manager
@@ -394,13 +408,13 @@ mod tests {
394408
}
395409

396410
#[test]
397-
fn defaults_to_standalone_install() {
411+
fn defaults_to_unknown_install_source() {
398412
let _guard = env_lock().lock().unwrap();
399413
let _distribution = ScopedEnvVar::unset("BIOME_DISTRIBUTION");
400414

401415
assert_eq!(
402416
detect_install_source(Utf8Path::new("/usr/local/bin/biome")),
403-
InstallSource::Standalone
417+
InstallSource::Unknown
404418
);
405419
}
406420

@@ -415,6 +429,44 @@ mod tests {
415429
);
416430
}
417431

432+
#[test]
433+
fn standalone_distribution_env_marks_install_as_standalone() {
434+
let _guard = env_lock().lock().unwrap();
435+
let _distribution = ScopedEnvVar::set("BIOME_DISTRIBUTION", "standalone");
436+
437+
assert_eq!(
438+
detect_install_source(Utf8Path::new("/usr/local/bin/biome")),
439+
InstallSource::Standalone
440+
);
441+
}
442+
443+
#[test]
444+
fn invalid_distribution_env_marks_install_as_unknown() {
445+
let _guard = env_lock().lock().unwrap();
446+
let _distribution = ScopedEnvVar::set("BIOME_DISTRIBUTION", "custom-installer");
447+
448+
assert_eq!(
449+
detect_install_source(Utf8Path::new("/opt/homebrew/Cellar/biome/2.4.8/bin/biome")),
450+
InstallSource::Unknown
451+
);
452+
}
453+
454+
#[test]
455+
fn reports_unknown_install_source_upgrade_error() {
456+
let diagnostic = unknown_install_source_upgrade_error();
457+
458+
match diagnostic {
459+
CliDiagnostic::UpgradeError(diagnostic) => {
460+
assert_eq!(
461+
PrintDescription(&diagnostic).to_string(),
462+
"Upgrade has encountered an error: `biome upgrade` couldn't determine how this binary was installed. Upgrade Biome with the same installer or package manager you originally used.",
463+
);
464+
assert!(diagnostic.source.is_none());
465+
}
466+
other => panic!("expected unknown install source upgrade error, got {other:?}"),
467+
}
468+
}
469+
418470
#[test]
419471
fn rejects_upgrade_when_biome_binary_is_set() {
420472
let _guard = env_lock().lock().unwrap();

crates/biome_cli/tests/snapshots/main_commands_rage/rage_ok.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Platform:
1414
OS: **PLACEHOLDER**
1515
1616
Environment:
17+
BIOME_DISTRIBUTION: unset
1718
BIOME_LOG_PATH: **PLACEHOLDER**
1819
BIOME_LOG_PREFIX_NAME: unset
1920
BIOME_LOG_LEVEL: unset

crates/biome_cli/tests/snapshots/main_commands_rage/with_configuration.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Platform:
2424
OS: **PLACEHOLDER**
2525
2626
Environment:
27+
BIOME_DISTRIBUTION: unset
2728
BIOME_LOG_PATH: **PLACEHOLDER**
2829
BIOME_LOG_PREFIX_NAME: unset
2930
BIOME_LOG_LEVEL: unset

crates/biome_cli/tests/snapshots/main_commands_rage/with_formatter_configuration.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Platform:
6161
OS: **PLACEHOLDER**
6262
6363
Environment:
64+
BIOME_DISTRIBUTION: unset
6465
BIOME_LOG_PATH: **PLACEHOLDER**
6566
BIOME_LOG_PREFIX_NAME: unset
6667
BIOME_LOG_LEVEL: unset

crates/biome_cli/tests/snapshots/main_commands_rage/with_jsonc_configuration.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Platform:
2525
OS: **PLACEHOLDER**
2626
2727
Environment:
28+
BIOME_DISTRIBUTION: unset
2829
BIOME_LOG_PATH: **PLACEHOLDER**
2930
BIOME_LOG_PREFIX_NAME: unset
3031
BIOME_LOG_LEVEL: unset

crates/biome_cli/tests/snapshots/main_commands_rage/with_linter_configuration.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Platform:
4242
OS: **PLACEHOLDER**
4343
4444
Environment:
45+
BIOME_DISTRIBUTION: unset
4546
BIOME_LOG_PATH: **PLACEHOLDER**
4647
BIOME_LOG_PREFIX_NAME: unset
4748
BIOME_LOG_LEVEL: unset

crates/biome_cli/tests/snapshots/main_commands_rage/with_malformed_configuration.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Platform:
2424
OS: **PLACEHOLDER**
2525
2626
Environment:
27+
BIOME_DISTRIBUTION: unset
2728
BIOME_LOG_PATH: **PLACEHOLDER**
2829
BIOME_LOG_PREFIX_NAME: unset
2930
BIOME_LOG_LEVEL: unset

crates/biome_cli/tests/snapshots/main_commands_rage/with_no_configuration.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Platform:
1414
OS: **PLACEHOLDER**
1515
1616
Environment:
17+
BIOME_DISTRIBUTION: unset
1718
BIOME_LOG_PATH: **PLACEHOLDER**
1819
BIOME_LOG_PREFIX_NAME: unset
1920
BIOME_LOG_LEVEL: unset

0 commit comments

Comments
 (0)