2026-10-17 12:08:30 -05:00
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn a_cargo_install_is_told_to_use_cargo() {
|
|
|
|
|
for path in [
|
|
|
|
|
"/home/dev/.cargo/bin/luxe",
|
|
|
|
|
"C:/Users/dev/.cargo/bin/luxe.exe",
|
|
|
|
|
"/home/dev/.rustup/toolchains/stable/bin/luxe",
|
|
|
|
|
] {
|
|
|
|
|
assert_eq!(InstallSource::from_path(Path::new(path)), InstallSource::Cargo, "{path}");
|
|
|
|
|
}
|
luxe update and /update, editable question answers, and a version bump owed once per release
- luxe update and /update update Luxe with the command for however it was installed (cargo or
Homebrew), run one program at a time with the terminal attached, then check that the luxe on
PATH is the new version. Luxe never downloads or replaces its own binary. The start screen says
"Update available · /update".
- A question's typed answer edits at its caret: arrows, word jumps, Home, End and Delete work,
and up and down move through a wrapped answer before leaving it.
- The version check owes a bump once per release: the version on main is the next release, and
only a released one (a v-tag) has to move.
- Dependency updates arrive through the sync, so Dependabot and the weekly jobs no longer run here.
2026-10-17 14:14:27 -05:00
|
|
|
assert_eq!(
|
|
|
|
|
InstallSource::Cargo.update_command().as_deref(),
|
|
|
|
|
Some("cargo install --locked --force luxe-cli")
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The steps are what runs, one program at a time with no shell between, so they are pinned as
|
|
|
|
|
/// argument lists: a flag moved into the wrong step, or a shell operator turned into an argument,
|
|
|
|
|
/// would read the same in the joined line and run very differently.
|
|
|
|
|
#[test]
|
|
|
|
|
fn the_update_steps_are_the_owners_own_commands() {
|
|
|
|
|
let cargo: &[&[&str]] = &[&["cargo", "install", "--locked", "--force", "luxe-cli"]];
|
|
|
|
|
let brew: &[&[&str]] = &[&["brew", "update"], &["brew", "upgrade", "luxe"]];
|
|
|
|
|
assert_eq!(InstallSource::Cargo.update_steps(), Some(cargo));
|
|
|
|
|
assert_eq!(InstallSource::Homebrew.update_steps(), Some(brew));
|
|
|
|
|
assert_eq!(
|
|
|
|
|
InstallSource::Homebrew.update_command().as_deref(),
|
|
|
|
|
Some("brew update && brew upgrade luxe")
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(InstallSource::Archive.update_steps(), None, "a download has no owner to ask");
|
2026-10-17 12:08:30 -05:00
|
|
|
}
|
|
|
|
|
|
luxe 0.1.5: a provider picker, model ids, and a guided review that says less
The dock's provider row opens a list of providers, and the model picker opens on the provider in use, with tab to widen it; signing in opens it on the provider just signed in to. Models go by their id unless config names them, and the model row wears its maker's mark.
The guided review's guide prompt is shorter, the pull request brief shows the start of the description with the rest behind p, its commits drop the Luxe-review and Luxe-revision lines, and the weakened-gates signal is gone.
luxe update reruns the installer it was installed with, in place of luxe-cli-update. The preview's FILE tab reads files the session changed outside the project, and only those. Smaller fixes: bash headers are highlighted, the preview loses a blank row, the launcher divider sits inside its frame, and the phone app's top bar is clear of iOS's blur.
rustls-webpki 0.103.16 and webpki-roots 1.0.10 fix RUSTSEC-2026-0381 and RUSTSEC-2026-0382, and vite 8.3.4 fixes GHSA-587h-7wmj-h5pm, GHSA-698v-4r3x-3vcv and GHSA-r825-w8mm-5pxw.
2026-10-22 13:25:32 -05:00
|
|
|
/// A stand-in `luxe` in `.cargo/bin` under a temp dir, where the path alone says Cargo.
|
|
|
|
|
fn luxe_in_cargo_bin() -> (tempfile::TempDir, PathBuf) {
|
A v-tag releases Luxe with installers, Homebrew and crates.io, SECURITY.md says how to report a hole, and luxe update runs the installer's updater
- release.yml, generated by dist from dist-workspace.toml, builds macOS, Linux and Windows,
attests every artifact, and publishes shell and PowerShell installers with their updater,
a luxe formula in evanwhittaker/homebrew-tap, and the crates through Trusted Publishing
(publish-crates.yml, which skips versions crates.io already has).
- luxe update recognizes an installer copy by luxe-cli-update beside it and runs that.
- The README, the install guide and the site lead with the installer, Homebrew and Windows.
- SECURITY.md: report privately through a GitHub advisory or contact@luxe.dev.
2026-10-17 15:37:45 -05:00
|
|
|
let dir = tempfile::tempdir().expect("tempdir");
|
|
|
|
|
let bin = dir.path().join(".cargo/bin");
|
|
|
|
|
std::fs::create_dir_all(&bin).expect("bin dir");
|
|
|
|
|
let luxe = bin.join(format!("luxe{}", std::env::consts::EXE_SUFFIX));
|
|
|
|
|
std::fs::write(&luxe, b"").expect("a stand-in luxe");
|
luxe 0.1.5: a provider picker, model ids, and a guided review that says less
The dock's provider row opens a list of providers, and the model picker opens on the provider in use, with tab to widen it; signing in opens it on the provider just signed in to. Models go by their id unless config names them, and the model row wears its maker's mark.
The guided review's guide prompt is shorter, the pull request brief shows the start of the description with the rest behind p, its commits drop the Luxe-review and Luxe-revision lines, and the weakened-gates signal is gone.
luxe update reruns the installer it was installed with, in place of luxe-cli-update. The preview's FILE tab reads files the session changed outside the project, and only those. Smaller fixes: bash headers are highlighted, the preview loses a blank row, the launcher divider sits inside its frame, and the phone app's top bar is clear of iOS's blur.
rustls-webpki 0.103.16 and webpki-roots 1.0.10 fix RUSTSEC-2026-0381 and RUSTSEC-2026-0382, and vite 8.3.4 fixes GHSA-587h-7wmj-h5pm, GHSA-698v-4r3x-3vcv and GHSA-r825-w8mm-5pxw.
2026-10-22 13:25:32 -05:00
|
|
|
(dir, luxe)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// A receipt that names the binary's directory marks an installer copy wherever it lives, a
|
|
|
|
|
/// `~/.cargo/bin` it was told to use included. One for another directory does not.
|
|
|
|
|
#[test]
|
|
|
|
|
fn the_installers_receipt_marks_an_installer_copy() {
|
|
|
|
|
let (_dir, luxe) = luxe_in_cargo_bin();
|
|
|
|
|
let receipt =
|
|
|
|
|
|prefix: &Path| InstallReceipt { install_prefix: prefix.into(), modify_path: true };
|
|
|
|
|
let here = receipt(luxe.parent().unwrap());
|
|
|
|
|
let elsewhere = receipt(Path::new("/somewhere/else"));
|
|
|
|
|
assert_eq!(InstallSource::from_install_with(&luxe, None), InstallSource::Cargo, "the path");
|
|
|
|
|
assert_eq!(InstallSource::from_install_with(&luxe, Some(&elsewhere)), InstallSource::Cargo);
|
|
|
|
|
assert_eq!(InstallSource::from_install_with(&luxe, Some(&here)), InstallSource::Installer);
|
|
|
|
|
}
|
A v-tag releases Luxe with installers, Homebrew and crates.io, SECURITY.md says how to report a hole, and luxe update runs the installer's updater
- release.yml, generated by dist from dist-workspace.toml, builds macOS, Linux and Windows,
attests every artifact, and publishes shell and PowerShell installers with their updater,
a luxe formula in evanwhittaker/homebrew-tap, and the crates through Trusted Publishing
(publish-crates.yml, which skips versions crates.io already has).
- luxe update recognizes an installer copy by luxe-cli-update beside it and runs that.
- The README, the install guide and the site lead with the installer, Homebrew and Windows.
- SECURITY.md: report privately through a GitHub advisory or contact@luxe.dev.
2026-10-17 15:37:45 -05:00
|
|
|
|
luxe 0.1.5: a provider picker, model ids, and a guided review that says less
The dock's provider row opens a list of providers, and the model picker opens on the provider in use, with tab to widen it; signing in opens it on the provider just signed in to. Models go by their id unless config names them, and the model row wears its maker's mark.
The guided review's guide prompt is shorter, the pull request brief shows the start of the description with the rest behind p, its commits drop the Luxe-review and Luxe-revision lines, and the weakened-gates signal is gone.
luxe update reruns the installer it was installed with, in place of luxe-cli-update. The preview's FILE tab reads files the session changed outside the project, and only those. Smaller fixes: bash headers are highlighted, the preview loses a blank row, the launcher divider sits inside its frame, and the phone app's top bar is clear of iOS's blur.
rustls-webpki 0.103.16 and webpki-roots 1.0.10 fix RUSTSEC-2026-0381 and RUSTSEC-2026-0382, and vite 8.3.4 fixes GHSA-587h-7wmj-h5pm, GHSA-698v-4r3x-3vcv and GHSA-r825-w8mm-5pxw.
2026-10-22 13:25:32 -05:00
|
|
|
/// A copy installed with the legacy updater beside it is an installer copy without a receipt too,
|
|
|
|
|
/// and its update is `luxe update` rather than the updater.
|
|
|
|
|
#[test]
|
|
|
|
|
fn the_legacy_updater_beside_the_binary_marks_an_installer_copy() {
|
|
|
|
|
let (_dir, luxe) = luxe_in_cargo_bin();
|
|
|
|
|
let updater = luxe.with_file_name(format!("{LEGACY_UPDATER}{}", std::env::consts::EXE_SUFFIX));
|
A v-tag releases Luxe with installers, Homebrew and crates.io, SECURITY.md says how to report a hole, and luxe update runs the installer's updater
- release.yml, generated by dist from dist-workspace.toml, builds macOS, Linux and Windows,
attests every artifact, and publishes shell and PowerShell installers with their updater,
a luxe formula in evanwhittaker/homebrew-tap, and the crates through Trusted Publishing
(publish-crates.yml, which skips versions crates.io already has).
- luxe update recognizes an installer copy by luxe-cli-update beside it and runs that.
- The README, the install guide and the site lead with the installer, Homebrew and Windows.
- SECURITY.md: report privately through a GitHub advisory or contact@luxe.dev.
2026-10-17 15:37:45 -05:00
|
|
|
std::fs::write(&updater, b"").expect("a stand-in updater");
|
luxe 0.1.5: a provider picker, model ids, and a guided review that says less
The dock's provider row opens a list of providers, and the model picker opens on the provider in use, with tab to widen it; signing in opens it on the provider just signed in to. Models go by their id unless config names them, and the model row wears its maker's mark.
The guided review's guide prompt is shorter, the pull request brief shows the start of the description with the rest behind p, its commits drop the Luxe-review and Luxe-revision lines, and the weakened-gates signal is gone.
luxe update reruns the installer it was installed with, in place of luxe-cli-update. The preview's FILE tab reads files the session changed outside the project, and only those. Smaller fixes: bash headers are highlighted, the preview loses a blank row, the launcher divider sits inside its frame, and the phone app's top bar is clear of iOS's blur.
rustls-webpki 0.103.16 and webpki-roots 1.0.10 fix RUSTSEC-2026-0381 and RUSTSEC-2026-0382, and vite 8.3.4 fixes GHSA-587h-7wmj-h5pm, GHSA-698v-4r3x-3vcv and GHSA-r825-w8mm-5pxw.
2026-10-22 13:25:32 -05:00
|
|
|
assert_eq!(InstallSource::from_install_with(&luxe, None), InstallSource::Installer);
|
|
|
|
|
assert_eq!(InstallSource::Installer.update_steps(), None, "no command, luxe runs the script");
|
|
|
|
|
assert_eq!(InstallSource::Installer.advice(), "`luxe update`");
|
A v-tag releases Luxe with installers, Homebrew and crates.io, SECURITY.md says how to report a hole, and luxe update runs the installer's updater
- release.yml, generated by dist from dist-workspace.toml, builds macOS, Linux and Windows,
attests every artifact, and publishes shell and PowerShell installers with their updater,
a luxe formula in evanwhittaker/homebrew-tap, and the crates through Trusted Publishing
(publish-crates.yml, which skips versions crates.io already has).
- luxe update recognizes an installer copy by luxe-cli-update beside it and runs that.
- The README, the install guide and the site lead with the installer, Homebrew and Windows.
- SECURITY.md: report privately through a GitHub advisory or contact@luxe.dev.
2026-10-17 15:37:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// A directory named like the updater is not the updater.
|
|
|
|
|
#[test]
|
|
|
|
|
fn a_directory_named_like_the_updater_does_not_count() {
|
|
|
|
|
let dir = tempfile::tempdir().expect("tempdir");
|
|
|
|
|
let luxe = dir.path().join("luxe");
|
|
|
|
|
std::fs::write(&luxe, b"").expect("a stand-in luxe");
|
luxe 0.1.5: a provider picker, model ids, and a guided review that says less
The dock's provider row opens a list of providers, and the model picker opens on the provider in use, with tab to widen it; signing in opens it on the provider just signed in to. Models go by their id unless config names them, and the model row wears its maker's mark.
The guided review's guide prompt is shorter, the pull request brief shows the start of the description with the rest behind p, its commits drop the Luxe-review and Luxe-revision lines, and the weakened-gates signal is gone.
luxe update reruns the installer it was installed with, in place of luxe-cli-update. The preview's FILE tab reads files the session changed outside the project, and only those. Smaller fixes: bash headers are highlighted, the preview loses a blank row, the launcher divider sits inside its frame, and the phone app's top bar is clear of iOS's blur.
rustls-webpki 0.103.16 and webpki-roots 1.0.10 fix RUSTSEC-2026-0381 and RUSTSEC-2026-0382, and vite 8.3.4 fixes GHSA-587h-7wmj-h5pm, GHSA-698v-4r3x-3vcv and GHSA-r825-w8mm-5pxw.
2026-10-22 13:25:32 -05:00
|
|
|
let name = format!("{LEGACY_UPDATER}{}", std::env::consts::EXE_SUFFIX);
|
A v-tag releases Luxe with installers, Homebrew and crates.io, SECURITY.md says how to report a hole, and luxe update runs the installer's updater
- release.yml, generated by dist from dist-workspace.toml, builds macOS, Linux and Windows,
attests every artifact, and publishes shell and PowerShell installers with their updater,
a luxe formula in evanwhittaker/homebrew-tap, and the crates through Trusted Publishing
(publish-crates.yml, which skips versions crates.io already has).
- luxe update recognizes an installer copy by luxe-cli-update beside it and runs that.
- The README, the install guide and the site lead with the installer, Homebrew and Windows.
- SECURITY.md: report privately through a GitHub advisory or contact@luxe.dev.
2026-10-17 15:37:45 -05:00
|
|
|
std::fs::create_dir(dir.path().join(name)).expect("a directory");
|
luxe 0.1.5: a provider picker, model ids, and a guided review that says less
The dock's provider row opens a list of providers, and the model picker opens on the provider in use, with tab to widen it; signing in opens it on the provider just signed in to. Models go by their id unless config names them, and the model row wears its maker's mark.
The guided review's guide prompt is shorter, the pull request brief shows the start of the description with the rest behind p, its commits drop the Luxe-review and Luxe-revision lines, and the weakened-gates signal is gone.
luxe update reruns the installer it was installed with, in place of luxe-cli-update. The preview's FILE tab reads files the session changed outside the project, and only those. Smaller fixes: bash headers are highlighted, the preview loses a blank row, the launcher divider sits inside its frame, and the phone app's top bar is clear of iOS's blur.
rustls-webpki 0.103.16 and webpki-roots 1.0.10 fix RUSTSEC-2026-0381 and RUSTSEC-2026-0382, and vite 8.3.4 fixes GHSA-587h-7wmj-h5pm, GHSA-698v-4r3x-3vcv and GHSA-r825-w8mm-5pxw.
2026-10-22 13:25:32 -05:00
|
|
|
assert_ne!(InstallSource::from_install_with(&luxe, None), InstallSource::Installer);
|
A v-tag releases Luxe with installers, Homebrew and crates.io, SECURITY.md says how to report a hole, and luxe update runs the installer's updater
- release.yml, generated by dist from dist-workspace.toml, builds macOS, Linux and Windows,
attests every artifact, and publishes shell and PowerShell installers with their updater,
a luxe formula in evanwhittaker/homebrew-tap, and the crates through Trusted Publishing
(publish-crates.yml, which skips versions crates.io already has).
- luxe update recognizes an installer copy by luxe-cli-update beside it and runs that.
- The README, the install guide and the site lead with the installer, Homebrew and Windows.
- SECURITY.md: report privately through a GitHub advisory or contact@luxe.dev.
2026-10-17 15:37:45 -05:00
|
|
|
}
|
|
|
|
|
|
2026-10-17 12:08:30 -05:00
|
|
|
/// Homebrew is checked first because its Linux and Intel-macOS prefixes sit *inside* paths the
|
|
|
|
|
/// other arms would otherwise claim.
|
|
|
|
|
#[test]
|
|
|
|
|
fn a_homebrew_install_is_not_mistaken_for_a_system_package() {
|
|
|
|
|
for path in [
|
|
|
|
|
"/opt/homebrew/bin/luxe",
|
|
|
|
|
"/usr/local/Cellar/luxe/0.1.0/bin/luxe",
|
|
|
|
|
"/home/linuxbrew/.linuxbrew/bin/luxe",
|
|
|
|
|
] {
|
|
|
|
|
assert_eq!(InstallSource::from_path(Path::new(path)), InstallSource::Homebrew, "{path}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// `/usr/local/bin` is where you put things a package manager did *not* install, so advising a
|
|
|
|
|
/// package manager there would be wrong.
|
|
|
|
|
#[test]
|
|
|
|
|
fn only_package_manager_prefixes_count_as_a_system_package() {
|
|
|
|
|
assert_eq!(InstallSource::from_path(Path::new("/usr/bin/luxe")), InstallSource::SystemPackage);
|
|
|
|
|
assert_eq!(InstallSource::from_path(Path::new("/usr/local/bin/luxe")), InstallSource::Archive);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
InstallSource::from_path(Path::new("/home/dev/luxe/target/release/luxe")),
|
|
|
|
|
InstallSource::Archive
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Every source says something actionable, and none of them name a command they cannot know is
|
|
|
|
|
/// right.
|
|
|
|
|
#[test]
|
|
|
|
|
fn every_source_gives_advice_and_none_of_it_is_a_guess() {
|
|
|
|
|
for source in [
|
|
|
|
|
InstallSource::Cargo,
|
|
|
|
|
InstallSource::Homebrew,
|
|
|
|
|
InstallSource::SystemPackage,
|
|
|
|
|
InstallSource::Archive,
|
|
|
|
|
] {
|
|
|
|
|
assert!(!source.advice().is_empty(), "{source:?}");
|
|
|
|
|
}
|
|
|
|
|
assert!(
|
|
|
|
|
InstallSource::SystemPackage.update_command().is_none(),
|
|
|
|
|
"naming apt on an Arch box is the failure this exists to avoid"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The two orderings a string compare gets wrong, and which is the whole reason `semver` is a
|
|
|
|
|
/// dependency here.
|
|
|
|
|
#[test]
|
|
|
|
|
fn version_comparison_follows_semver_rather_than_the_alphabet() {
|
|
|
|
|
assert!(is_newer("0.10.0", "0.9.0"), "0.10 is newer than 0.9 despite sorting before it");
|
|
|
|
|
assert!(!is_newer("0.9.0", "0.10.0"));
|
|
|
|
|
assert!(is_newer("0.2.0", "0.2.0-rc.1"), "a release beats its own pre-release");
|
|
|
|
|
assert!(!is_newer("0.2.0-rc.1", "0.2.0"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn a_release_tag_may_carry_a_v() {
|
|
|
|
|
assert!(is_newer("v0.2.0", "0.1.0"));
|
|
|
|
|
assert_eq!(normalize_version(" v1.2.3 "), "1.2.3");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn the_same_version_is_not_an_update() {
|
|
|
|
|
assert!(!is_newer("0.1.0", "0.1.0"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Garbage on either side must produce silence, not a notice about a version nobody can parse.
|
|
|
|
|
#[test]
|
|
|
|
|
fn an_unparseable_version_says_nothing() {
|
|
|
|
|
assert!(!is_newer("not-a-version", "0.1.0"));
|
|
|
|
|
assert!(!is_newer("0.2.0", "also-not-a-version"));
|
|
|
|
|
assert!(!is_newer("", "0.1.0"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn a_notice_names_both_versions_and_the_command() {
|
|
|
|
|
let state = UpdateState { latest: Some("v0.2.0".into()), checked_at: 0 };
|
|
|
|
|
let notice = notice(&state, "0.1.0", InstallSource::Cargo).expect("behind by a minor");
|
|
|
|
|
let line = notice.line();
|
|
|
|
|
assert!(line.contains("0.2.0"), "{line}");
|
|
|
|
|
assert!(line.contains("you have 0.1.0"), "{line}");
|
luxe update and /update, editable question answers, and a version bump owed once per release
- luxe update and /update update Luxe with the command for however it was installed (cargo or
Homebrew), run one program at a time with the terminal attached, then check that the luxe on
PATH is the new version. Luxe never downloads or replaces its own binary. The start screen says
"Update available · /update".
- A question's typed answer edits at its caret: arrows, word jumps, Home, End and Delete work,
and up and down move through a wrapped answer before leaving it.
- The version check owes a bump once per release: the version on main is the next release, and
only a released one (a v-tag) has to move.
- Dependency updates arrive through the sync, so Dependabot and the weekly jobs no longer run here.
2026-10-17 14:14:27 -05:00
|
|
|
assert!(line.contains("cargo install --locked --force luxe-cli"), "{line}");
|
2026-10-17 12:08:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn there_is_no_notice_when_current_or_unchecked() {
|
|
|
|
|
let fresh = UpdateState { latest: Some("0.1.0".into()), checked_at: 0 };
|
|
|
|
|
assert_eq!(notice(&fresh, "0.1.0", InstallSource::Cargo), None, "not behind");
|
|
|
|
|
assert_eq!(
|
|
|
|
|
notice(&UpdateState::default(), "0.1.0", InstallSource::Cargo),
|
|
|
|
|
None,
|
|
|
|
|
"never checked"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn a_never_checked_state_is_stale_and_a_just_checked_one_is_not() {
|
|
|
|
|
assert!(UpdateState::default().is_stale(CHECK_TTL));
|
|
|
|
|
let now = SystemTime::now().duration_since(UNIX_EPOCH).expect("clock").as_secs();
|
|
|
|
|
assert!(!UpdateState { latest: None, checked_at: now }.is_stale(CHECK_TTL));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// A clock that jumped backwards must not make every launch re-check.
|
|
|
|
|
#[test]
|
|
|
|
|
fn a_future_timestamp_reads_as_fresh() {
|
|
|
|
|
let now = SystemTime::now().duration_since(UNIX_EPOCH).expect("clock").as_secs();
|
|
|
|
|
assert!(!UpdateState { latest: None, checked_at: now + 86_400 }.is_stale(CHECK_TTL));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn state_round_trips_through_a_file() {
|
|
|
|
|
let dir = tempfile::tempdir().expect("tempdir");
|
|
|
|
|
let path = dir.path().join("nested").join("update.json");
|
|
|
|
|
let state = UpdateState { latest: Some("0.3.0".into()), checked_at: 42 };
|
|
|
|
|
state.store(&path).expect("stores, creating the directory");
|
|
|
|
|
let loaded = UpdateState::load(&path);
|
|
|
|
|
assert_eq!(loaded.latest.as_deref(), Some("0.3.0"));
|
|
|
|
|
assert_eq!(loaded.checked_at, 42);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Losing the cache costs one request, so a corrupt file is a default rather than an error.
|
|
|
|
|
#[test]
|
|
|
|
|
fn a_corrupt_cache_reads_as_never_checked() {
|
|
|
|
|
let dir = tempfile::tempdir().expect("tempdir");
|
|
|
|
|
let path = dir.path().join("update.json");
|
|
|
|
|
std::fs::write(&path, b"{not json").expect("write");
|
|
|
|
|
assert!(UpdateState::load(&path).latest.is_none());
|
|
|
|
|
}
|