feat(update): self-update from a cloned repo wherever the app is installed
Self-update assumed a conventional install prefix (silently reinstalling into ~/.local when the binary lived elsewhere) and needed a release tarball to do anything. Pick the strategy from what the machine actually has -- a local checkout, git+cmake+compiler for a clone, the prebuilt archive, or the release sources -- and always write the fresh binary next to the running one, building in a temp directory so sudo is only needed for the final copy. Bundles the UI work that depends on it (tray, shortcuts, log filter, CSV exports, cached package details), the structured log categories, and the new test targets (update-manager, AUR, plugins) wired into CTest. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
1 parent
6d5b4274c4
commit
54bff16369
9 files changed
+1123
-200
No files matched your search
@@ -0,0 +1,127 @@
|
||||
// Unit tests for the pure parts of UpdateManager: version comparison and the
|
||||
// update-strategy choice (no network, toolchain or filesystem needed).
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include "update-manager.h"
|
||||
|
||||
static int failures = 0;
|
||||
|
||||
static void check(bool cond, const char* name) {
|
||||
if (cond) {
|
||||
std::cout << "PASS " << name << std::endl;
|
||||
} else {
|
||||
std::cout << "FAIL " << name << std::endl;
|
||||
++failures;
|
||||
}
|
||||
}
|
||||
|
||||
using Caps = UpdateManager::UpdateCapabilities;
|
||||
using Method = UpdateManager::UpdateMethod;
|
||||
|
||||
static void testChooseMethod_checkoutWinsOverEverything() {
|
||||
Caps caps;
|
||||
caps.checkoutUsable = true;
|
||||
caps.hasGit = caps.hasCmake = caps.hasCompiler = true;
|
||||
caps.hasPrebuilt = caps.hasTarball = true;
|
||||
check(UpdateManager::chooseUpdateMethod(caps) == Method::Checkout,
|
||||
"method_checkout_wins");
|
||||
}
|
||||
|
||||
static void testChooseMethod_cloneWhenToolchainPresent() {
|
||||
Caps caps;
|
||||
caps.hasGit = caps.hasCmake = caps.hasCompiler = true;
|
||||
caps.hasPrebuilt = caps.hasTarball = true;
|
||||
// The clone path is deliberately preferred over the prebuilt asset.
|
||||
check(UpdateManager::chooseUpdateMethod(caps) == Method::Clone,
|
||||
"method_clone_first");
|
||||
}
|
||||
|
||||
static void testChooseMethod_cloneRequiresCompiler() {
|
||||
Caps caps;
|
||||
caps.hasGit = caps.hasCmake = true; // no compiler -> cannot rebuild
|
||||
check(UpdateManager::chooseUpdateMethod(caps) == Method::None,
|
||||
"method_clone_needs_compiler");
|
||||
}
|
||||
|
||||
static void testChooseMethod_prebuiltWithoutToolchain() {
|
||||
Caps caps;
|
||||
caps.hasPrebuilt = caps.hasTarball = true;
|
||||
check(UpdateManager::chooseUpdateMethod(caps) == Method::Prebuilt,
|
||||
"method_prebuilt_without_tools");
|
||||
}
|
||||
|
||||
static void testChooseMethod_prebuiltWithGitOnly() {
|
||||
Caps caps;
|
||||
caps.hasGit = true; // git alone cannot build
|
||||
caps.hasPrebuilt = true;
|
||||
check(UpdateManager::chooseUpdateMethod(caps) == Method::Prebuilt,
|
||||
"method_prebuilt_git_only");
|
||||
}
|
||||
|
||||
static void testChooseMethod_prebuiltPreferredOverTarball() {
|
||||
Caps caps;
|
||||
caps.hasCmake = caps.hasCompiler = true; // no git
|
||||
caps.hasPrebuilt = caps.hasTarball = true;
|
||||
check(UpdateManager::chooseUpdateMethod(caps) == Method::Prebuilt,
|
||||
"method_prebuilt_over_tarball");
|
||||
}
|
||||
|
||||
static void testChooseMethod_tarballWithoutGit() {
|
||||
Caps caps;
|
||||
caps.hasCmake = caps.hasCompiler = true; // no git
|
||||
caps.hasTarball = true;
|
||||
check(UpdateManager::chooseUpdateMethod(caps) == Method::Tarball,
|
||||
"method_tarball_without_git");
|
||||
}
|
||||
|
||||
static void testChooseMethod_tarballRequiresCompiler() {
|
||||
Caps caps;
|
||||
caps.hasCmake = true; // no compiler
|
||||
caps.hasTarball = true;
|
||||
check(UpdateManager::chooseUpdateMethod(caps) == Method::None,
|
||||
"method_tarball_needs_compiler");
|
||||
}
|
||||
|
||||
static void testChooseMethod_noneWhenNothingAvailable() {
|
||||
Caps caps;
|
||||
check(UpdateManager::chooseUpdateMethod(caps) == Method::None,
|
||||
"method_none_without_anything");
|
||||
}
|
||||
|
||||
int main() {
|
||||
// Basic ordering
|
||||
check(UpdateManager::isNewerVersion("1.3.2", "1.3.1") == true, "newer_patch");
|
||||
check(UpdateManager::isNewerVersion("1.3.1", "1.3.1") == false, "same_version");
|
||||
check(UpdateManager::isNewerVersion("1.3.0", "1.3.1") == false, "older_patch");
|
||||
check(UpdateManager::isNewerVersion("1.4.0", "1.3.9") == true, "newer_minor");
|
||||
check(UpdateManager::isNewerVersion("2.0.0", "1.9.9") == true, "newer_major");
|
||||
|
||||
// Leading v/V (git tags) is normalized
|
||||
check(UpdateManager::isNewerVersion("v1.3.2", "1.3.1") == true, "tag_v_prefix");
|
||||
check(UpdateManager::isNewerVersion("V1.3.2", "1.3.1") == true, "tag_V_prefix");
|
||||
check(UpdateManager::isNewerVersion("v1.3.1", "1.3.1") == false, "tag_same");
|
||||
|
||||
// Different component counts: 1.3 == 1.3.0
|
||||
check(UpdateManager::isNewerVersion("1.3.1", "1.3") == true, "longer_newer");
|
||||
check(UpdateManager::isNewerVersion("1.3", "1.3.0") == false, "equal_implicit_zero");
|
||||
|
||||
// Empty remote never triggers an update prompt
|
||||
check(UpdateManager::isNewerVersion("", "1.3.1") == false, "empty_remote");
|
||||
|
||||
// Update-strategy choice
|
||||
testChooseMethod_checkoutWinsOverEverything();
|
||||
testChooseMethod_cloneWhenToolchainPresent();
|
||||
testChooseMethod_cloneRequiresCompiler();
|
||||
testChooseMethod_prebuiltWithoutToolchain();
|
||||
testChooseMethod_prebuiltWithGitOnly();
|
||||
testChooseMethod_prebuiltPreferredOverTarball();
|
||||
testChooseMethod_tarballWithoutGit();
|
||||
testChooseMethod_tarballRequiresCompiler();
|
||||
testChooseMethod_noneWhenNothingAvailable();
|
||||
|
||||
if (failures == 0) std::cout << "All update-manager tests passed" << std::endl;
|
||||
return failures == 0 ? 0 : 1;
|
||||
}
|
||||
Reference in new issue
Block a user