2 Commits
Author SHA1 Message Date
BlackAngelTV 6224a94df6 test(flatpak): add end-to-end CLI integration test
Drives the real FlatpakManager against the live flatpak CLI: install a small
app through the provider's own fallback logic, verify it is listed and
flagged as installed in search, run update and refresh, then uninstall. The
test is non-destructive for pre-existing installs and skips when flatpak is
absent.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-08-29 15:05:14 +02:00
BlackAngelTV 1b3f11aad8 fix(flatpak): show honest search status and harden install
Search results now report whether each app is already installed or has a
pending update, like pacman does with its [installed] marker, so the UI no
longer shows "Disponible" for apps that are already managed. Install is also
idempotent (already-deployed apps short-circuit) and skips the doomed bare
retry when both a system and a user flathub remote make the ref ambiguous.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-08-29 15:05:14 +02:00
3 changed files with 148 additions and 16 deletions

No files matched your search

+6
View File
@@ -52,6 +52,12 @@ add_executable(flatpak-manager-test tests/flatpak-manager.test.cpp src/flatpak-m
target_include_directories(flatpak-manager-test PRIVATE include) target_include_directories(flatpak-manager-test PRIVATE include)
add_test(NAME flatpak-manager-test COMMAND flatpak-manager-test) add_test(NAME flatpak-manager-test COMMAND flatpak-manager-test)
# Real end-to-end test of the Flatpak provider against the live flatpak CLI
# (installs and uninstalls a small app). Skipped when flatpak is missing.
add_executable(flatpak-integration-test tests/flatpak-integration.test.cpp src/flatpak-manager.cpp)
target_include_directories(flatpak-integration-test PRIVATE include)
add_test(NAME flatpak-integration-test COMMAND flatpak-integration-test)
add_executable(package-utils-test tests/package-utils.test.cpp) add_executable(package-utils-test tests/package-utils.test.cpp)
target_include_directories(package-utils-test PRIVATE include) target_include_directories(package-utils-test PRIVATE include)
add_test(NAME package-utils-test COMMAND package-utils-test) add_test(NAME package-utils-test COMMAND package-utils-test)
+48 -16
View File
@@ -5,6 +5,7 @@
#include <sstream> #include <sstream>
#include <cctype> #include <cctype>
#include <algorithm> #include <algorithm>
#include <set>
#include <vector> #include <vector>
// Helper to run shell commands and capture output. // Helper to run shell commands and capture output.
@@ -182,7 +183,24 @@ std::vector<PackageInfo> FlatpakManager::parseUpdatesOutput(const std::string& o
std::vector<PackageInfo> FlatpakManager::search(const std::string& query) { std::vector<PackageInfo> FlatpakManager::search(const std::string& query) {
std::string cmd = "flatpak search " + query + " 2>&1"; std::string cmd = "flatpak search " + query + " 2>&1";
return parseSearchOutput(exec(cmd.c_str())); std::vector<PackageInfo> results = parseSearchOutput(exec(cmd.c_str()));
// Report the honest status of each hit (already installed / pending
// update) so the search page does not keep showing "Disponible" for apps
// that are already managed, like pacman does with its [installed] marker.
if (!results.empty()) {
std::set<std::string> installed;
for (const auto& pkg : listInstalled()) installed.insert(pkg.name);
std::set<std::string> outdated;
for (const auto& pkg : listUpdates()) outdated.insert(pkg.name);
for (auto& pkg : results) {
pkg.installed = installed.count(pkg.name) > 0;
pkg.updateAvailable = outdated.count(pkg.name) > 0;
}
}
return results;
} }
std::vector<PackageInfo> FlatpakManager::listInstalled() { std::vector<PackageInfo> FlatpakManager::listInstalled() {
@@ -203,35 +221,49 @@ bool FlatpakManager::isInstalled(const std::string& appId) {
bool FlatpakManager::install(const std::string& packageName, bool FlatpakManager::install(const std::string& packageName,
std::function<void(const std::string&)> progressCallback) { std::function<void(const std::string&)> progressCallback) {
m_lastError.clear(); m_lastError.clear();
if (progressCallback) progressCallback("Installation de " + packageName + "...");
// A fresh flatpak setup has no remote configured: add the default flathub // Idempotent: an app already deployed (in either installation) is reported
// one (idempotent, per-user) so the install can resolve the app. // as installed without re-running the installer.
streamOutput( if (isInstalled(packageName)) {
exec("flatpak remote-add --if-not-exists --user flathub " if (progressCallback) progressCallback(packageName + " est déjà installé.");
"https://flathub.org/repo/flathub.flatpakrepo 2>&1"), return true;
progressCallback); }
if (progressCallback) progressCallback("Installation de " + packageName + "...");
auto tryInstall = [&](const std::string& extra) { auto tryInstall = [&](const std::string& extra) {
return exec(("flatpak install --noninteractive --assumeyes " + extra + " " return exec(("flatpak install --noninteractive --assumeyes " + extra + " "
+ packageName + " 2>&1").c_str()); + packageName + " 2>&1").c_str());
}; };
// A fresh flatpak setup has no remote configured: add the default flathub
// one (idempotent, per-user) so the install can resolve the app.
exec("flatpak remote-add --if-not-exists --user flathub "
"https://flathub.org/repo/flathub.flatpakrepo 2>&1");
std::string output = tryInstall(""); std::string output = tryInstall("");
auto ambiguous = [&]() {
return output.find("Multiple remotes") != std::string::npos;
};
auto noRefs = [&]() {
return output.find("No refs found") != std::string::npos
|| output.find("No remote refs") != std::string::npos;
};
// Stale remote metadata makes flatpak report "No refs found": refresh the // Stale remote metadata makes flatpak report "No refs found": refresh the
// appstream cache and retry once before giving up. // appstream cache and retry once before giving up. When both a system and
// a user flathub remote exist, flatpak refuses to pick one in non-
// interactive mode, so go straight to the per-user installation instead of
// repeating a doomed attempt.
if (output.find("error:") != std::string::npos && !isInstalled(packageName) if (output.find("error:") != std::string::npos && !isInstalled(packageName)
&& (output.find("No refs found") != std::string::npos && (noRefs() || ambiguous())) {
|| output.find("No remote refs") != std::string::npos)) {
if (progressCallback) progressCallback("Mise à jour des métadonnées des dépôts..."); if (progressCallback) progressCallback("Mise à jour des métadonnées des dépôts...");
streamOutput(exec("flatpak update --appstream 2>&1"), progressCallback); exec("flatpak update --appstream 2>&1");
output = tryInstall(""); output = tryInstall(ambiguous() ? "--user flathub" : "");
} }
// Failures worth a second attempt in the per-user installation (no polkit, // Remaining failures get one per-user attempt (no polkit, no ambiguity).
// no ambiguity): "Multiple remotes have refs matching", system-wide
// remotes requiring authentication, or missing user metadata.
if (output.find("error:") != std::string::npos && !isInstalled(packageName)) { if (output.find("error:") != std::string::npos && !isInstalled(packageName)) {
if (progressCallback) progressCallback("Nouvel essai en mode utilisateur..."); if (progressCallback) progressCallback("Nouvel essai en mode utilisateur...");
output = tryInstall("--user flathub"); output = tryInstall("--user flathub");
+94
View File
@@ -0,0 +1,94 @@
#include "flatpak-manager.h"
#include <cstdlib>
#include <iostream>
// Real end-to-end exercise of the Flatpak provider against the live `flatpak`
// CLI: install a small app, verify it is listed and marked as installed in
// search, run update/refresh, then uninstall. It validates the exact commands
// the application runs (install fallbacks included) instead of only parsing.
//
// Skipped (with a message) when the flatpak binary is not available so the
// suite stays green on systems without it.
//
// The test is non-destructive for pre-existing installs: if the app is already
// present when the test starts it is left in place, only verified and updated.
namespace {
const std::string kApp = "org.gnome.Calculator";
bool isInstalled(FlatpakManager& fm) {
for (const auto& pkg : fm.listInstalled()) {
if (pkg.name == kApp) return true;
}
return false;
}
} // namespace
int main() {
if (system("which flatpak > /dev/null 2>&1") != 0) {
std::cout << "flatpak not installed, skipping integration test" << std::endl;
return 0;
}
FlatpakManager fm;
const bool preinstalled = isInstalled(fm);
// 1. Install through the provider's own logic (remote-add + fallbacks).
if (!fm.install(kApp, nullptr)) {
std::cout << "FAIL install: " << fm.lastError() << std::endl;
return 1;
}
if (!isInstalled(fm)) {
std::cout << "FAIL install: app not listed as installed" << std::endl;
return 1;
}
// 2. Updating the single app and all apps must complete without error.
if (!fm.update(kApp, nullptr)) {
std::cout << "FAIL update(app): " << fm.lastError() << std::endl;
return 1;
}
if (!fm.update("", nullptr)) {
std::cout << "FAIL update(all): " << fm.lastError() << std::endl;
return 1;
}
// 3. Refreshing the appstream metadata must complete without error.
if (!fm.refresh(nullptr)) {
std::cout << "FAIL refresh: " << fm.lastError() << std::endl;
return 1;
}
// 4. Search must find the app and report it as installed (not "Disponible").
bool searchFound = false;
for (const auto& pkg : fm.search("calculator")) {
if (pkg.name == kApp) {
searchFound = true;
if (!pkg.installed) {
std::cout << "FAIL search: app not flagged as installed" << std::endl;
return 1;
}
}
}
if (!searchFound) {
std::cout << "FAIL search: app not found in results" << std::endl;
return 1;
}
// 5. Uninstall, unless the app was already there before the test started.
if (!preinstalled) {
if (!fm.remove(kApp, nullptr)) {
std::cout << "FAIL remove: " << fm.lastError() << std::endl;
return 1;
}
if (isInstalled(fm)) {
std::cout << "FAIL remove: app still listed as installed" << std::endl;
return 1;
}
}
std::cout << "All flatpak integration tests passed." << std::endl;
return 0;
}