Files
OrcaSlicer/tests/libslic3r/update_channel_tests.cpp
T
Lam Wei Lun ab003cdeba Make app updates opt-in: notify when verified, install only from the dialog
The updater installed a prefetched build when the application quit, so an
update happened with no click and no visible moment. Now the startup check
only prefetches, a persistent notification opens the dialog once the helper
has verified the artifact, and the dialog's install button is the only path
to the helper. Install-at-quit and the helper's --install-only mode are gone.

Readiness is the helper's verified marker bound to the artifact digest, not
the file name: the helper renames before verifying, and a nightly reuses one
asset name. Skip deletes the cached artifact under a per-download lock.
2026-11-16 19:26:31 +08:00

986 lines
43 KiB
C++

#include <catch2/catch_all.hpp>
#include <string>
#include "catch2/catch_test_macros.hpp"
#include "libslic3r/UpdateChannel.hpp"
using namespace Slic3r;
namespace {
// Two stable releases plus the rolling nightly one, in the order the service
// returns them: the picker must not simply take the first entry.
const char* stable_releases_json()
{
return R"JSON([
{
"tag_name": "v2.4.0",
"prerelease": false,
"html_url": "https://example.invalid/releases/v2.4.0",
"body": "older release",
"updated_at": "2026-06-01T10:00:00Z",
"assets": [
{
"name": "OrcaSlicer_Windows_Installer_V2.4.0_x64.exe",
"browser_download_url": "https://example.invalid/OrcaSlicer_Windows_Installer_V2.4.0_x64.exe",
"digest": "sha256:1111",
"size": 100
}
]
},
{
"tag_name": "v2.5.0",
"prerelease": false,
"html_url": "https://example.invalid/releases/v2.5.0",
"body": "newer release",
"updated_at": "2026-10-01T10:00:00Z",
"assets": [
{
"name": "OrcaSlicer_Windows_Installer_V2.5.0_x64.exe",
"browser_download_url": "https://example.invalid/OrcaSlicer_Windows_Installer_V2.5.0_x64.exe",
"digest": "sha256:2222",
"size": 200
}
]
},
{
"tag_name": "nightly-builds",
"prerelease": true,
"html_url": "https://example.invalid/releases/nightly-builds",
"body": "nightly release",
"updated_at": "2026-11-10T08:31:54Z",
"assets": [
{
"name": "OrcaSlicer_Windows_Installer_x64_nightly.exe",
"browser_download_url": "https://example.invalid/OrcaSlicer_Windows_Installer_x64_nightly.exe",
"digest": "sha256:nightly2",
"size": 300
}
]
}
])JSON";
}
const char* nightly_releases_json()
{
return R"JSON([
{
"tag_name": "nightly-builds",
"prerelease": true,
"html_url": "https://example.invalid/releases/nightly-builds",
"body": "nightly release",
"updated_at": "2026-11-10T08:31:54Z",
"assets": [
{
"name": "OrcaSlicer_Windows_Installer_x64_nightly.exe",
"browser_download_url": "https://example.invalid/OrcaSlicer_Windows_Installer_x64_nightly.exe",
"digest": "sha256:nightly2",
"size": 300
}
]
}
])JSON";
}
// The nightly release lists the discontinued _belt AppImage before the main one.
const char* nightly_belt_first_releases_json()
{
return R"JSON([
{
"tag_name": "nightly-builds",
"prerelease": true,
"html_url": "https://example.invalid/releases/nightly-builds",
"body": "nightly release",
"updated_at": "2026-11-10T08:31:54Z",
"assets": [
{
"name": "OrcaSlicer_Linux_AppImage_Ubuntu2404_nightly_belt.AppImage",
"browser_download_url": "https://example.invalid/OrcaSlicer_Linux_AppImage_Ubuntu2404_nightly_belt.AppImage",
"digest": "sha256:belt",
"size": 310
},
{
"name": "OrcaSlicer_Linux_AppImage_Ubuntu2404_nightly.AppImage",
"browser_download_url": "https://example.invalid/OrcaSlicer_Linux_AppImage_Ubuntu2404_nightly.AppImage",
"digest": "sha256:nightly2",
"size": 300
}
]
}
])JSON";
}
const char* nightly_belt_only_releases_json()
{
return R"JSON([
{
"tag_name": "nightly-builds",
"prerelease": true,
"html_url": "https://example.invalid/releases/nightly-builds",
"body": "nightly release",
"updated_at": "2026-11-10T08:31:54Z",
"assets": [
{
"name": "OrcaSlicer_Linux_AppImage_Ubuntu2404_nightly_belt.AppImage",
"browser_download_url": "https://example.invalid/OrcaSlicer_Linux_AppImage_Ubuntu2404_nightly_belt.AppImage",
"digest": "sha256:belt",
"size": 310
}
]
}
])JSON";
}
// The nightly release with its only asset carrying no digest.
const char* nightly_release_without_digest_json()
{
return R"JSON([
{
"tag_name": "nightly-builds",
"prerelease": true,
"html_url": "https://example.invalid/releases/nightly-builds",
"body": "nightly release",
"updated_at": "2026-11-10T08:31:54Z",
"assets": [
{
"name": "OrcaSlicer_Windows_Installer_x64_nightly.exe",
"browser_download_url": "https://example.invalid/OrcaSlicer_Windows_Installer_x64_nightly.exe",
"size": 300
}
]
}
])JSON";
}
// A stable release whose only asset carries no digest.
const char* stable_release_without_digest_json()
{
return R"JSON([
{
"tag_name": "v2.5.0",
"prerelease": false,
"html_url": "https://example.invalid/releases/v2.5.0",
"body": "newer release",
"updated_at": "2026-10-01T10:00:00Z",
"assets": [
{
"name": "OrcaSlicer_Windows_Installer_V2.5.0_x64.exe",
"browser_download_url": "https://example.invalid/OrcaSlicer_Windows_Installer_V2.5.0_x64.exe",
"size": 200
}
]
}
])JSON";
}
// The shape the service returns while 2.6.0 is in flight: the final release, the
// rolling nightly and the three prereleases, deliberately not in version order. The
// final release sorts above every prerelease, so both Stable and Pre-Release offer it.
const char* prerelease_releases_json()
{
return R"JSON([
{
"tag_name": "v2.6.0",
"prerelease": false,
"html_url": "https://example.invalid/releases/v2.6.0",
"body": "2.6.0",
"updated_at": "2026-11-20T10:00:00Z",
"assets": [
{
"name": "OrcaSlicer_Windows_Installer_V2.6.0_x64.exe",
"browser_download_url": "https://example.invalid/OrcaSlicer_Windows_Installer_V2.6.0_x64.exe",
"digest": "sha256:2600",
"size": 400
}
]
},
{
"tag_name": "nightly-builds",
"prerelease": true,
"html_url": "https://example.invalid/releases/nightly-builds",
"body": "nightly release",
"updated_at": "2026-11-10T08:31:54Z",
"assets": [
{
"name": "OrcaSlicer_Windows_Installer_x64_nightly.exe",
"browser_download_url": "https://example.invalid/OrcaSlicer_Windows_Installer_x64_nightly.exe",
"digest": "sha256:nightly2",
"size": 350
}
]
},
{
"tag_name": "v2.6.0-beta",
"prerelease": true,
"html_url": "https://example.invalid/releases/v2.6.0-beta",
"body": "2.6.0 beta",
"updated_at": "2026-10-27T17:22:32Z",
"assets": [
{
"name": "OrcaSlicer_Windows_Installer_V2.6.0-beta_x64.exe",
"browser_download_url": "https://example.invalid/OrcaSlicer_Windows_Installer_V2.6.0-beta_x64.exe",
"digest": "sha256:2600beta",
"size": 390
}
]
},
{
"tag_name": "v2.6.0-rc",
"prerelease": true,
"html_url": "https://example.invalid/releases/v2.6.0-rc",
"body": "2.6.0 release candidate",
"updated_at": "2026-11-01T10:36:26Z",
"assets": [
{
"name": "OrcaSlicer_Windows_Installer_V2.6.0-rc_x64.exe",
"browser_download_url": "https://example.invalid/OrcaSlicer_Windows_Installer_V2.6.0-rc_x64.exe",
"digest": "sha256:2600rc",
"size": 395
}
]
},
{
"tag_name": "v2.6.0-alpha",
"prerelease": true,
"html_url": "https://example.invalid/releases/v2.6.0-alpha",
"body": "2.6.0 alpha",
"updated_at": "2026-10-16T14:28:11Z",
"assets": [
{
"name": "OrcaSlicer_Windows_Installer_V2.6.0-alpha_x64.exe",
"browser_download_url": "https://example.invalid/OrcaSlicer_Windows_Installer_V2.6.0-alpha_x64.exe",
"digest": "sha256:2600alpha",
"size": 380
}
]
}
])JSON";
}
// The state right after a final ships, before the next cycle opens: a stable build and a
// prerelease of the next version.
const char* newer_prerelease_release_json()
{
return R"JSON([
{
"tag_name": "v2.6.0",
"prerelease": false,
"html_url": "https://example.invalid/releases/v2.6.0",
"body": "2.6.0",
"updated_at": "2026-11-20T10:00:00Z",
"assets": [
{
"name": "OrcaSlicer_Windows_Installer_V2.6.0_x64.exe",
"browser_download_url": "https://example.invalid/OrcaSlicer_Windows_Installer_V2.6.0_x64.exe",
"digest": "sha256:2600",
"size": 400
}
]
},
{
"tag_name": "v2.7.0-alpha",
"prerelease": true,
"html_url": "https://example.invalid/releases/v2.7.0-alpha",
"body": "2.7.0 alpha",
"updated_at": "2026-12-02T09:00:00Z",
"assets": [
{
"name": "OrcaSlicer_Windows_Installer_V2.7.0-alpha_x64.exe",
"browser_download_url": "https://example.invalid/OrcaSlicer_Windows_Installer_V2.7.0-alpha_x64.exe",
"digest": "sha256:2700alpha",
"size": 410
}
]
}
])JSON";
}
// v2.3.2-rc shipped its assets with the suffix spelled in upper case.
const char* mixed_case_asset_release_json()
{
return R"JSON([
{
"tag_name": "v2.3.2-rc",
"prerelease": true,
"html_url": "https://example.invalid/releases/v2.3.2-rc",
"body": "2.3.2 rc",
"updated_at": "2026-03-01T13:59:35Z",
"assets": [
{
"name": "OrcaSlicer_Windows_Installer_V2.3.2-RC_x64.exe",
"browser_download_url": "https://example.invalid/OrcaSlicer_Windows_Installer_V2.3.2-RC_x64.exe",
"digest": "sha256:232rc",
"size": 300
}
]
}
])JSON";
}
// A stable release shipping both the Windows installer and the portable zip.
const char* stable_portable_release_json()
{
return R"JSON([
{
"tag_name": "v2.5.0",
"prerelease": false,
"html_url": "https://example.invalid/releases/v2.5.0",
"body": "newer release",
"updated_at": "2026-10-01T10:00:00Z",
"assets": [
{
"name": "OrcaSlicer_Windows_Installer_V2.5.0_x64.exe",
"browser_download_url": "https://example.invalid/OrcaSlicer_Windows_Installer_V2.5.0_x64.exe",
"digest": "sha256:2222",
"size": 200
},
{
"name": "OrcaSlicer_Windows_portable_V2.5.0_x64.zip",
"browser_download_url": "https://example.invalid/OrcaSlicer_Windows_portable_V2.5.0_x64.zip",
"digest": "sha256:2222portable",
"size": 210
}
]
}
])JSON";
}
// A stable release newer than the -dev version a nightly build reports.
const char* stable_after_dev_release_json()
{
return R"JSON([
{
"tag_name": "v2.6.1",
"prerelease": false,
"html_url": "https://example.invalid/releases/v2.6.1",
"body": "2.6.1",
"updated_at": "2026-11-25T10:00:00Z",
"assets": [
{
"name": "OrcaSlicer_Windows_Installer_V2.6.1_x64.exe",
"browser_download_url": "https://example.invalid/OrcaSlicer_Windows_Installer_V2.6.1_x64.exe",
"digest": "sha256:2610",
"size": 420
}
]
}
])JSON";
}
} // namespace
TEST_CASE("A stable release newer than the running version is offered", "[UpdateChannel]")
{
const UpdateCandidate candidate = resolve_update(stable_releases_json(), UpdateChannel::Stable, "", "",
"2.4.9", "", InstallFlavour::WindowsInstaller, "x86_64");
CHECK(candidate.available);
CHECK(candidate.reason.empty());
CHECK(candidate.channel == UpdateChannel::Stable);
CHECK(candidate.version == "2.5.0");
CHECK(candidate.version_label == "2.5.0");
CHECK(candidate.release_url == "https://example.invalid/releases/v2.5.0");
CHECK(candidate.release_notes == "newer release");
CHECK(candidate.asset.name == "OrcaSlicer_Windows_Installer_V2.5.0_x64.exe");
CHECK(candidate.asset.digest == "sha256:2222");
CHECK(candidate.asset.size == 200);
}
TEST_CASE("A stable release equal to the running version is not offered", "[UpdateChannel]")
{
const UpdateCandidate candidate = resolve_update(stable_releases_json(), UpdateChannel::Stable, "", "",
"2.5.0", "", InstallFlavour::WindowsInstaller, "x86_64");
CHECK_FALSE(candidate.available);
CHECK(candidate.reason == "up_to_date");
CHECK(candidate.version == "2.5.0");
}
TEST_CASE("A nightly with a different digest than the installed build is offered", "[UpdateChannel]")
{
const UpdateCandidate candidate = resolve_update(nightly_releases_json(), UpdateChannel::Nightly,
"sha256:nightly1", "nightly", "2.6.0-dev",
"2026-11-01T00:00:00Z", InstallFlavour::WindowsInstaller,
"x86_64");
CHECK(candidate.available);
CHECK(candidate.reason.empty());
CHECK(candidate.channel == UpdateChannel::Nightly);
CHECK(candidate.version == "2026-11-10T08:31:54Z");
CHECK(candidate.version_label == "Nightly, 10 Nov 2026 08:31 UTC");
CHECK(candidate.asset.digest == "sha256:nightly2");
}
TEST_CASE("A nightly with the same digest as the installed build is up to date", "[UpdateChannel]")
{
const UpdateCandidate candidate = resolve_update(nightly_releases_json(), UpdateChannel::Nightly,
"sha256:nightly2", "nightly", "2.6.0-dev",
"2026-11-01T00:00:00Z", InstallFlavour::WindowsInstaller,
"x86_64");
CHECK_FALSE(candidate.available);
CHECK(candidate.reason == "up_to_date");
}
TEST_CASE("Switching from nightly to stable offers the stable release", "[UpdateChannel]")
{
const UpdateCandidate candidate = resolve_update(stable_releases_json(), UpdateChannel::Stable,
"sha256:nightly2", "nightly", "2.5.0", "",
InstallFlavour::WindowsInstaller, "x86_64");
CHECK(candidate.available);
CHECK(candidate.reason == "channel_switch");
CHECK(candidate.version == "2.5.0");
}
TEST_CASE("Switching from stable to nightly offers the nightly release", "[UpdateChannel]")
{
const UpdateCandidate candidate = resolve_update(nightly_releases_json(), UpdateChannel::Nightly,
"sha256:2222", "stable", "2.5.0",
"2026-11-01T00:00:00Z", InstallFlavour::WindowsInstaller,
"x86_64");
CHECK(candidate.available);
CHECK(candidate.reason == "channel_switch");
}
TEST_CASE("A hand-installed nightly is not downgraded by the channel it infers", "[UpdateChannel]")
{
// Nothing recorded its channel, so Stable reads the running dev build as nightly and treats
// the check as a channel switch. 2.5.0 sorts below the running build, so it is not offered.
const UpdateCandidate candidate = resolve_update(stable_releases_json(), UpdateChannel::Stable, "", "",
"2.6.0-dev", "2026-11-01T00:00:00Z",
InstallFlavour::WindowsInstaller, "x86_64");
CHECK_FALSE(candidate.available);
CHECK(candidate.reason == "up_to_date");
CHECK(candidate.version == "2.5.0");
}
TEST_CASE("A hand-installed prerelease is not downgraded by the channel it infers", "[UpdateChannel]")
{
// No recorded channel, so Stable reads the running 2.6.0-rc1 as a prerelease and treats the
// check as a channel switch: 2.5.0 sorts below the running build, so it is not offered.
const UpdateCandidate candidate = resolve_update(stable_releases_json(), UpdateChannel::Stable, "", "",
"2.6.0-rc1", "", InstallFlavour::WindowsInstaller, "x86_64");
CHECK_FALSE(candidate.available);
CHECK(candidate.reason == "up_to_date");
CHECK(candidate.version == "2.5.0");
}
TEST_CASE("A hand-installed prerelease is offered the stable release of its own version", "[UpdateChannel]")
{
const UpdateCandidate candidate = resolve_update(newer_prerelease_release_json(), UpdateChannel::Stable, "", "",
"2.6.0-rc1", "", InstallFlavour::WindowsInstaller, "x86_64");
CHECK(candidate.available);
CHECK(candidate.reason == "channel_switch");
CHECK(candidate.version == "2.6.0");
}
TEST_CASE("A hand-installed dev build is offered a newer stable release", "[UpdateChannel]")
{
const UpdateCandidate candidate = resolve_update(stable_after_dev_release_json(), UpdateChannel::Stable, "", "",
"2.6.0-dev", "", InstallFlavour::WindowsInstaller, "x86_64");
CHECK(candidate.available);
CHECK(candidate.reason == "channel_switch");
CHECK(candidate.version == "2.6.1");
}
TEST_CASE("A hand-installed build whose version cannot be compared is not switched", "[UpdateChannel]")
{
// Nothing recorded the channel and the version does not parse, so it belongs to no channel
// an ordering could be checked against: the stable release is not offered, even though
// Stable is what the user selected.
const UpdateCandidate candidate = resolve_update(stable_releases_json(), UpdateChannel::Stable, "", "",
"dev build", "", InstallFlavour::WindowsInstaller, "x86_64");
CHECK_FALSE(candidate.available);
CHECK(candidate.reason == "up_to_date");
}
TEST_CASE("A recorded prerelease channel still switches to the stable channel", "[UpdateChannel]")
{
// The switch comes from the setting, not from the version: the stable artifact is offered
// even though it sorts below the running prerelease.
const UpdateCandidate candidate = resolve_update(stable_releases_json(), UpdateChannel::Stable,
"sha256:2600rc", "prerelease", "2.6.0-rc1", "",
InstallFlavour::WindowsInstaller, "x86_64");
CHECK(candidate.available);
CHECK(candidate.reason == "channel_switch");
CHECK(candidate.version == "2.5.0");
}
TEST_CASE("The channel of a version follows its suffix", "[UpdateChannel]")
{
// 2.6.0-dev parses as a semver prerelease but is the nightly version, so it is checked first.
CHECK(channel_of_version("2.6.0-dev") == UpdateChannel::Nightly);
CHECK(channel_of_version("2.6.0-rc1") == UpdateChannel::PreRelease);
CHECK(channel_of_version("2.6.0-beta") == UpdateChannel::PreRelease);
CHECK(channel_of_version("2.6.0-alpha") == UpdateChannel::PreRelease);
CHECK(channel_of_version("2.6.0") == UpdateChannel::Stable);
CHECK(channel_of_version("") == UpdateChannel::Nightly);
CHECK(channel_of_version("garbage") == UpdateChannel::Nightly);
}
TEST_CASE("The pre-release channel offers the final release when it is newer than every prerelease", "[UpdateChannel]")
{
const UpdateCandidate candidate = resolve_update(prerelease_releases_json(), UpdateChannel::PreRelease, "",
"", "2.5.0", "", InstallFlavour::WindowsInstaller, "x86_64");
CHECK(candidate.available);
CHECK(candidate.channel == UpdateChannel::PreRelease);
CHECK(candidate.version == "2.6.0");
CHECK(candidate.asset.name == "OrcaSlicer_Windows_Installer_V2.6.0_x64.exe");
CHECK(candidate.asset.digest == "sha256:2600");
}
TEST_CASE("The pre-release channel offers a prerelease newer than the newest final release", "[UpdateChannel]")
{
const UpdateCandidate candidate = resolve_update(newer_prerelease_release_json(), UpdateChannel::PreRelease, "",
"", "2.5.0", "", InstallFlavour::WindowsInstaller, "x86_64");
CHECK(candidate.available);
CHECK(candidate.version == "2.7.0-alpha");
}
TEST_CASE("The pre-release channel offers the newest final release when no prerelease exists", "[UpdateChannel]")
{
const UpdateCandidate candidate = resolve_update(stable_releases_json(), UpdateChannel::PreRelease, "", "",
"2.4.9", "", InstallFlavour::WindowsInstaller, "x86_64");
CHECK(candidate.available);
CHECK(candidate.version == "2.5.0");
}
TEST_CASE("Stable never offers a prerelease that outranks every final release", "[UpdateChannel]")
{
// 2.7.0-alpha sorts above the newest final, so a Stable check that saw it would offer it.
const UpdateCandidate candidate = resolve_update(newer_prerelease_release_json(), UpdateChannel::Stable, "",
"", "2.5.0", "", InstallFlavour::WindowsInstaller, "x86_64");
CHECK(candidate.available);
CHECK(candidate.version == "2.6.0");
}
TEST_CASE("The pre-release channel offers nothing when the running build is the final release", "[UpdateChannel]")
{
// The newest release is the 2.6.0 final itself, so nothing is newer than the running build.
const UpdateCandidate candidate = resolve_update(prerelease_releases_json(), UpdateChannel::PreRelease, "",
"", "2.6.0", "", InstallFlavour::WindowsInstaller, "x86_64");
CHECK_FALSE(candidate.available);
CHECK(candidate.reason == "up_to_date");
CHECK(candidate.version == "2.6.0");
}
TEST_CASE("A beta is offered the final release of its version", "[UpdateChannel]")
{
const UpdateCandidate candidate = resolve_update(prerelease_releases_json(), UpdateChannel::PreRelease, "",
"", "2.6.0-beta", "", InstallFlavour::WindowsInstaller, "x86_64");
CHECK(candidate.available);
CHECK(candidate.version == "2.6.0");
}
TEST_CASE("A dev build is offered the final release of its own version", "[UpdateChannel]")
{
// Semver ranks the final release above the -dev build of the same version.
const UpdateCandidate candidate = resolve_update(prerelease_releases_json(), UpdateChannel::PreRelease, "",
"", "2.6.0-dev", "", InstallFlavour::WindowsInstaller, "x86_64");
CHECK(candidate.available);
CHECK(candidate.version == "2.6.0");
}
TEST_CASE("Switching to pre-release does not offer a prerelease older than the running build", "[UpdateChannel]")
{
const UpdateCandidate candidate = resolve_update(prerelease_releases_json(), UpdateChannel::PreRelease,
"sha256:2600", "stable", "2.6.0", "",
InstallFlavour::WindowsInstaller, "x86_64");
CHECK_FALSE(candidate.available);
CHECK(candidate.reason == "up_to_date");
}
TEST_CASE("Switching to pre-release offers a prerelease newer than the running build", "[UpdateChannel]")
{
const UpdateCandidate candidate = resolve_update(newer_prerelease_release_json(), UpdateChannel::PreRelease,
"sha256:2600", "stable", "2.6.0", "",
InstallFlavour::WindowsInstaller, "x86_64");
CHECK(candidate.available);
CHECK(candidate.version == "2.7.0-alpha");
}
TEST_CASE("A skipped pre-release stays skipped until a newer one appears", "[UpdateChannel]")
{
const UpdateCandidate candidate = resolve_update(newer_prerelease_release_json(), UpdateChannel::PreRelease, "",
"", "2.6.0", "", InstallFlavour::WindowsInstaller, "x86_64");
REQUIRE(candidate.available);
CHECK(update_is_skipped(candidate, "2.7.0-alpha", ""));
CHECK(update_is_skipped(candidate, "2.7.0", ""));
CHECK_FALSE(update_is_skipped(candidate, "2.6.0", ""));
std::string skip_version = "2.6.0";
std::string skip_artifact = "sha256:nightly2";
update_skip_values(candidate, skip_version, skip_artifact);
CHECK(skip_version == "2.7.0-alpha");
CHECK(skip_artifact == "sha256:nightly2");
}
TEST_CASE("An asset version matches regardless of case", "[UpdateChannel]")
{
const UpdateCandidate candidate = resolve_update(mixed_case_asset_release_json(), UpdateChannel::PreRelease, "",
"", "2.3.1", "", InstallFlavour::WindowsInstaller, "x86_64");
CHECK(candidate.available);
CHECK(candidate.version == "2.3.2-rc");
CHECK(candidate.asset.name == "OrcaSlicer_Windows_Installer_V2.3.2-RC_x64.exe");
}
TEST_CASE("A release asset without a digest is offered but cannot be installed in-app", "[UpdateChannel]")
{
const UpdateCandidate candidate = resolve_update(stable_release_without_digest_json(), UpdateChannel::Stable,
"", "", "2.4.9", "", InstallFlavour::WindowsInstaller,
"x86_64");
CHECK(candidate.available);
CHECK(candidate.reason == "no_digest");
CHECK(candidate.asset.name == "OrcaSlicer_Windows_Installer_V2.5.0_x64.exe");
CHECK_FALSE(can_install_in_app(candidate, InstallFlavour::WindowsInstaller));
}
TEST_CASE("A supported flavour with no matching asset is offered so the release page can open", "[UpdateChannel]")
{
// A macOS bundle has nothing to download from a release that only ships a Windows
// installer, so the caller falls back to the release page.
const UpdateCandidate candidate = resolve_update(stable_releases_json(), UpdateChannel::Stable, "", "",
"2.4.9", "", InstallFlavour::MacOSBundle, "x86_64");
CHECK(candidate.available);
CHECK(candidate.reason == "no_asset_for_platform");
CHECK(candidate.asset.name.empty());
CHECK(candidate.version == "2.5.0");
CHECK(candidate.release_url == "https://example.invalid/releases/v2.5.0");
CHECK_FALSE(can_install_in_app(candidate, InstallFlavour::MacOSBundle));
}
TEST_CASE("Only a candidate with an asset, URL, digest and size is installed in-app", "[UpdateChannel]")
{
const UpdateCandidate candidate = resolve_update(stable_releases_json(), UpdateChannel::Stable, "", "",
"2.4.9", "", InstallFlavour::WindowsInstaller, "x86_64");
CHECK(can_install_in_app(candidate, InstallFlavour::WindowsInstaller));
CHECK_FALSE(can_install_in_app(candidate, InstallFlavour::Msix));
}
TEST_CASE("An asset without a size is not installed in-app", "[UpdateChannel]")
{
// prepare_download_dir can never call a zero-sized download complete, so it would be
// fetched again on every start and the quit-time install would never run.
UpdateCandidate candidate;
candidate.asset.name = "OrcaSlicer_Windows_Installer_V2.5.0_x64.exe";
candidate.asset.url = "https://example.invalid/OrcaSlicer_Windows_Installer_V2.5.0_x64.exe";
candidate.asset.digest = "sha256:2222";
candidate.asset.size = 0;
CHECK_FALSE(can_install_in_app(candidate, InstallFlavour::WindowsInstaller));
candidate.asset.size = 200;
CHECK(can_install_in_app(candidate, InstallFlavour::WindowsInstaller));
}
TEST_CASE("A portable Windows build is offered the portable zip directly", "[UpdateChannel]")
{
const UpdateCandidate candidate = resolve_update(stable_portable_release_json(), UpdateChannel::Stable, "", "",
"2.4.9", "", InstallFlavour::WindowsPortable, "x86_64");
CHECK(candidate.available);
CHECK(candidate.reason.empty());
CHECK(candidate.asset.name == "OrcaSlicer_Windows_portable_V2.5.0_x64.zip");
CHECK(candidate.asset.url == "https://example.invalid/OrcaSlicer_Windows_portable_V2.5.0_x64.zip");
CHECK(candidate.asset.digest == "sha256:2222portable");
CHECK_FALSE(can_install_in_app(candidate, InstallFlavour::WindowsPortable));
CHECK(is_download_only(InstallFlavour::WindowsPortable));
}
TEST_CASE("The Store offers only the stable channel", "[UpdateChannel]")
{
const UpdateCandidate nightly = resolve_update(nightly_releases_json(), UpdateChannel::Nightly,
"sha256:nightly1", "nightly", "2.6.0-dev",
"2026-11-01T00:00:00Z", InstallFlavour::Msix, "x86_64");
const UpdateCandidate prerelease = resolve_update(prerelease_releases_json(), UpdateChannel::PreRelease, "",
"", "2.5.0", "", InstallFlavour::Msix, "x86_64");
CHECK_FALSE(nightly.available);
CHECK(nightly.reason == "store_channel");
CHECK_FALSE(prerelease.available);
CHECK(prerelease.reason == "store_channel");
}
TEST_CASE("An AppImage update takes the main build over a discontinued _belt build", "[UpdateChannel]")
{
// The _belt asset is listed first, as it is on the nightly release.
const UpdateCandidate candidate = resolve_update(nightly_belt_first_releases_json(), UpdateChannel::Nightly,
"sha256:nightly1", "nightly", "2.6.0-dev",
"2026-11-01T00:00:00Z", InstallFlavour::LinuxAppImage, "x86_64");
CHECK(candidate.available);
CHECK(candidate.asset.name == "OrcaSlicer_Linux_AppImage_Ubuntu2404_nightly.AppImage");
CHECK(candidate.asset.digest == "sha256:nightly2");
CHECK_FALSE(can_install_in_app(candidate, InstallFlavour::LinuxAppImage));
CHECK(is_download_only(InstallFlavour::LinuxAppImage));
}
TEST_CASE("A _belt AppImage alone leaves the release offered without an asset", "[UpdateChannel]")
{
const UpdateCandidate candidate = resolve_update(nightly_belt_only_releases_json(), UpdateChannel::Nightly,
"sha256:nightly1", "nightly", "2.6.0-dev",
"2026-11-01T00:00:00Z", InstallFlavour::LinuxAppImage, "x86_64");
CHECK(candidate.available);
CHECK(candidate.reason == "no_asset_for_platform");
CHECK(candidate.asset.name.empty());
}
TEST_CASE("A Store flavour with no matching asset is offered so the Store or release page can open", "[UpdateChannel]")
{
const UpdateCandidate candidate = resolve_update(stable_releases_json(), UpdateChannel::Stable, "", "",
"2.4.9", "", InstallFlavour::Msix, "x86_64");
CHECK(candidate.available);
CHECK(candidate.reason == "no_asset_for_platform");
CHECK(candidate.asset.name.empty());
CHECK(candidate.version == "2.5.0");
CHECK(candidate.release_url == "https://example.invalid/releases/v2.5.0");
CHECK(candidate.release_notes == "newer release");
}
TEST_CASE("A stable release that is not newer is not offered even with a stale installed digest", "[UpdateChannel]")
{
const UpdateCandidate candidate = resolve_update(stable_releases_json(), UpdateChannel::Stable,
"sha256:9999", "stable", "2.5.0", "",
InstallFlavour::WindowsInstaller, "x86_64");
CHECK_FALSE(candidate.available);
CHECK(candidate.reason == "up_to_date");
CHECK(candidate.version == "2.5.0");
}
TEST_CASE("A release that is not newer is not offered when its flavour has no asset either", "[UpdateChannel]")
{
const UpdateCandidate candidate = resolve_update(stable_releases_json(), UpdateChannel::Stable, "", "",
"2.5.0", "", InstallFlavour::Msix, "x86_64");
CHECK_FALSE(candidate.available);
}
TEST_CASE("A source build has no nightly identity to compare against", "[UpdateChannel]")
{
const UpdateCandidate candidate = resolve_update(nightly_releases_json(), UpdateChannel::Nightly, "", "",
"2.6.0-dev", "", InstallFlavour::WindowsInstaller, "x86_64");
CHECK_FALSE(candidate.available);
CHECK(candidate.reason == "source_build");
}
TEST_CASE("A nightly built shortly before its release's last asset upload is not offered to itself", "[UpdateChannel]")
{
// The release is updated_at 2026-11-10T08:31:54Z; the build started an hour earlier.
const UpdateCandidate candidate = resolve_update(nightly_releases_json(), UpdateChannel::Nightly, "", "",
"2.6.0-dev", "2026-11-10T07:31:54Z",
InstallFlavour::WindowsInstaller, "x86_64");
CHECK_FALSE(candidate.available);
CHECK(candidate.reason == "up_to_date");
}
TEST_CASE("A nightly released well after the build is offered to a manually installed build", "[UpdateChannel]")
{
// Twelve hours before the release, which is past the upload margin.
const UpdateCandidate candidate = resolve_update(nightly_releases_json(), UpdateChannel::Nightly, "", "",
"2.6.0-dev", "2026-11-09T20:31:54Z",
InstallFlavour::WindowsInstaller, "x86_64");
CHECK(candidate.available);
CHECK(candidate.reason.empty());
CHECK(candidate.asset.digest == "sha256:nightly2");
}
TEST_CASE("A nightly built after its release is not offered to a manually installed build", "[UpdateChannel]")
{
const UpdateCandidate candidate = resolve_update(nightly_releases_json(), UpdateChannel::Nightly, "", "",
"2.6.0-dev", "2026-11-10T09:00:00Z",
InstallFlavour::WindowsInstaller, "x86_64");
CHECK_FALSE(candidate.available);
CHECK(candidate.reason == "up_to_date");
}
TEST_CASE("A nightly with an unparsable build timestamp is not offered to a manually installed build", "[UpdateChannel]")
{
const UpdateCandidate candidate = resolve_update(nightly_releases_json(), UpdateChannel::Nightly, "", "",
"2.6.0-dev", "not-a-timestamp",
InstallFlavour::WindowsInstaller, "x86_64");
CHECK_FALSE(candidate.available);
CHECK(candidate.reason == "up_to_date");
}
TEST_CASE("A skipped stable version stays skipped until a newer one appears", "[UpdateChannel]")
{
const UpdateCandidate candidate = resolve_update(stable_releases_json(), UpdateChannel::Stable, "", "",
"2.4.9", "", InstallFlavour::WindowsInstaller, "x86_64");
CHECK(update_is_skipped(candidate, "2.5.0", ""));
CHECK_FALSE(update_is_skipped(candidate, "2.4.0", ""));
CHECK_FALSE(update_is_skipped(candidate, "", ""));
}
TEST_CASE("A skipped nightly digest stays skipped until the build changes", "[UpdateChannel]")
{
const UpdateCandidate candidate = resolve_update(nightly_releases_json(), UpdateChannel::Nightly,
"sha256:nightly1", "nightly", "2.6.0-dev",
"2026-11-01T00:00:00Z", InstallFlavour::WindowsInstaller,
"x86_64");
CHECK(update_is_skipped(candidate, "", "sha256:nightly2"));
CHECK_FALSE(update_is_skipped(candidate, "", "sha256:nightly1"));
CHECK_FALSE(update_is_skipped(candidate, "", ""));
}
TEST_CASE("A nightly without a digest is skipped by its build time", "[UpdateChannel]")
{
const UpdateCandidate candidate = resolve_update(nightly_release_without_digest_json(), UpdateChannel::Nightly,
"sha256:nightly1", "nightly", "2.6.0-dev",
"2026-11-01T00:00:00Z", InstallFlavour::WindowsInstaller,
"x86_64");
REQUIRE(candidate.available);
std::string skip_version;
std::string skip_artifact;
update_skip_values(candidate, skip_version, skip_artifact);
CHECK(skip_artifact == "2026-11-10T08:31:54Z");
CHECK(update_is_skipped(candidate, "", skip_artifact));
}
TEST_CASE("Skipping records the version for stable and the digest for nightly", "[UpdateChannel]")
{
const UpdateCandidate stable = resolve_update(stable_releases_json(), UpdateChannel::Stable, "", "",
"2.4.9", "", InstallFlavour::WindowsInstaller, "x86_64");
std::string skip_version;
std::string skip_artifact = "keep";
update_skip_values(stable, skip_version, skip_artifact);
CHECK(skip_version == "2.5.0");
CHECK(skip_artifact == "keep");
const UpdateCandidate nightly = resolve_update(nightly_releases_json(), UpdateChannel::Nightly,
"sha256:nightly1", "nightly", "2.6.0-dev",
"2026-11-01T00:00:00Z", InstallFlavour::WindowsInstaller,
"x86_64");
skip_version = "keep";
skip_artifact = "";
update_skip_values(nightly, skip_version, skip_artifact);
CHECK(skip_version == "keep");
CHECK(skip_artifact == "sha256:nightly2");
}
TEST_CASE("Channel and flavour keys round-trip through their strings", "[UpdateChannel]")
{
CHECK(update_channel_key(UpdateChannel::Stable) == "stable");
CHECK(update_channel_key(UpdateChannel::Nightly) == "nightly");
CHECK(update_channel_key(UpdateChannel::PreRelease) == "prerelease");
CHECK(update_channel_from_key("nightly") == UpdateChannel::Nightly);
CHECK(update_channel_from_key("prerelease") == UpdateChannel::PreRelease);
CHECK(update_channel_from_key("stable") == UpdateChannel::Stable);
CHECK(update_channel_from_key("") == UpdateChannel::Stable);
CHECK(update_channel_from_key("unknown") == UpdateChannel::Stable);
CHECK(install_flavour_key(InstallFlavour::WindowsInstaller) == "windows_installer");
CHECK(install_flavour_key(InstallFlavour::WindowsPortable) == "windows_portable");
CHECK(install_flavour_key(InstallFlavour::MacOSBundle) == "macos_bundle");
CHECK(install_flavour_key(InstallFlavour::LinuxAppImage) == "linux_appimage");
CHECK(install_flavour_key(InstallFlavour::Msix) == "msix");
CHECK(install_flavour_key(InstallFlavour::Flatpak) == "flatpak");
CHECK(install_flavour_key(InstallFlavour::Other) == "other");
CHECK(in_app_install_supported(InstallFlavour::WindowsInstaller));
CHECK(in_app_install_supported(InstallFlavour::MacOSBundle));
CHECK_FALSE(in_app_install_supported(InstallFlavour::WindowsPortable));
CHECK_FALSE(in_app_install_supported(InstallFlavour::LinuxAppImage));
CHECK_FALSE(in_app_install_supported(InstallFlavour::Msix));
CHECK_FALSE(in_app_install_supported(InstallFlavour::Flatpak));
CHECK_FALSE(in_app_install_supported(InstallFlavour::Other));
}
TEST_CASE("Only the portable and AppImage flavours are download-only", "[UpdateChannel]")
{
CHECK(is_download_only(InstallFlavour::WindowsPortable));
CHECK(is_download_only(InstallFlavour::LinuxAppImage));
CHECK_FALSE(is_download_only(InstallFlavour::WindowsInstaller));
CHECK_FALSE(is_download_only(InstallFlavour::MacOSBundle));
CHECK_FALSE(is_download_only(InstallFlavour::Msix));
CHECK_FALSE(is_download_only(InstallFlavour::Flatpak));
CHECK_FALSE(is_download_only(InstallFlavour::Other));
}
TEST_CASE("A check with nothing to offer has nothing to do", "[UpdateChannel]")
{
UpdateRequest request;
request.available = false;
CHECK(update_action(request) == UpdateAction::None);
// Unavailable wins over every other field, a manual check included.
request.user_initiated = true;
request.download_ready = true;
CHECK(update_action(request) == UpdateAction::None);
}
TEST_CASE("An automatic check ignores a skipped update", "[UpdateChannel]")
{
UpdateRequest request;
request.available = true;
request.skipped = true;
CHECK(update_action(request) == UpdateAction::None);
// A skipped build is not reported either, even when its artifact is already verified.
request.download_ready = true;
CHECK(update_action(request) == UpdateAction::None);
}
TEST_CASE("A manual check still offers a skipped update", "[UpdateChannel]")
{
UpdateRequest request;
request.available = true;
request.skipped = true;
request.user_initiated = true;
CHECK(update_action(request) == UpdateAction::Prefetch);
// The verified artifact opens the dialog at once rather than being fetched again.
request.download_ready = true;
CHECK(update_action(request) == UpdateAction::NotifyReady);
}
TEST_CASE("A verified download is reported ready instead of prefetched", "[UpdateChannel]")
{
const UpdateRequest request{true, false, false, true};
CHECK(update_action(request) == UpdateAction::NotifyReady);
}
TEST_CASE("An available update without a verified download is prefetched", "[UpdateChannel]")
{
const UpdateRequest request{true, false, false, false};
CHECK(update_action(request) == UpdateAction::Prefetch);
}