Files
lemonade/test/cpp/test_latest_version_fallback.cpp
e97d68cb3c fix(server): fall back to installed llama.cpp binary when "latest" lookup fails (#2279)
When a backend's *_bin is pinned to "latest", loading a model resolves the
newest release tag from GitHub. If that lookup fails (e.g. HTTP 504) or is
otherwise unreachable, resolution threw and the model refused to load — even
though a perfectly usable binary was already installed (lemonade-sdk#2265).

Mirror the existing offline behavior for the live-failure case: when the
"latest" lookup cannot be satisfied, fall back to the version recorded in the
installed binary's version.txt and load with a warning, instead of throwing.
Only error when neither a live tag nor an installed binary is available. This
applies to every backend resolved through resolve_user_version() (llamacpp,
whisper, sd, kokoro, …) pinned to "latest", not just llamacpp:vulkan.

The fallback decision is extracted into a pure, I/O-free helper
(lemon::resolve_latest_pin) so the policy can be unit-tested in isolation;
resolve_user_version() now gathers the inputs (live lookup + installed
version.txt) and applies the result. Adds a standalone C++ unit test covering
the full decision table (online ok / online failed / offline, with and without
an installed binary), wired into CMake + CI alongside the existing watcher test.
The test uses explicit pass/fail accounting (not assert(), which the Release
build's -DNDEBUG would compile away) so it remains effective in CI.

Scoped to the "latest" resolution path only: pinned/builtin/path/bare-tag
values and unrelated load errors are unchanged.

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Co-authored-by: glm-5.2 <[email protected]>
Co-authored-by: GPT-5.5 <[email protected]>
2026-06-21 22:50:15 +00:00

110 lines
4.8 KiB
C++

// Standalone unit tests for lemon::resolve_latest_pin() — the pure policy that
// decides how a "latest" *_bin config pin resolves to a concrete release tag
// when the live GitHub lookup succeeds, fails (e.g. HTTP 504), or is skipped
// (offline). Regression coverage for lemonade-sdk/lemonade#2265: a transient
// GitHub failure must fall back to the installed binary instead of refusing to
// load a model that is otherwise ready.
//
// Checks use an explicit pass/fail counter (not assert()) so the test stays
// effective under the Release build the CI `default` preset uses, where
// -DNDEBUG would compile assert() to a no-op.
//
// Compile with:
// g++ -std=c++17 -I src/cpp/include \
// test/cpp/test_latest_version_fallback.cpp -o latest_version_fallback_test
//
// Run with:
// ./latest_version_fallback_test
#include <cstdio>
#include <string>
#include <lemon/backend_version_policy.h>
using lemon::LatestPinResolution;
using lemon::resolve_latest_pin;
struct TestResult {
int passed = 0;
int failed = 0;
void check(bool cond, const std::string& name) {
if (cond) {
printf("[PASS] %s\n", name.c_str());
++passed;
} else {
printf("[FAIL] %s\n", name.c_str());
++failed;
}
}
};
int main() {
TestResult r;
const std::string recipe = "llamacpp";
const std::string backend = "vulkan";
printf("=== resolve_latest_pin() Unit Tests ===\n\n");
// Online, GitHub lookup succeeds → use the freshly-fetched tag (no fallback).
{
LatestPinResolution res = resolve_latest_pin(recipe, backend, /*offline=*/false,
/*fetched_latest=*/"b9700",
/*installed_version=*/"b9632");
r.check(res.version == "b9700", "online ok: uses fetched tag");
r.check(res.error.empty(), "online ok: no error");
r.check(!res.used_installed_fallback, "online ok: not a fallback");
}
// Online, GitHub lookup FAILS, a binary is installed → fall back to the
// installed version (the #2265 fix). Must not produce an error.
{
LatestPinResolution res = resolve_latest_pin(recipe, backend, /*offline=*/false,
/*fetched_latest=*/"",
/*installed_version=*/"b9632");
r.check(res.version == "b9632", "online failed + installed: falls back to installed (#2265)");
r.check(res.error.empty(), "online failed + installed: no error");
r.check(res.used_installed_fallback, "online failed + installed: flagged as fallback");
}
// Online, GitHub lookup FAILS, nothing installed → unresolvable, with a
// message that names the GitHub failure (not offline).
{
LatestPinResolution res = resolve_latest_pin(recipe, backend, /*offline=*/false,
/*fetched_latest=*/"",
/*installed_version=*/"");
r.check(res.version.empty(), "online failed + none: no version");
r.check(res.error.find("GitHub lookup failed") != std::string::npos,
"online failed + none: error names GitHub failure");
r.check(res.error.find("llamacpp:vulkan") != std::string::npos,
"online failed + none: error names recipe:backend");
r.check(!res.used_installed_fallback, "online failed + none: not a fallback");
}
// Offline, a binary is installed → reuse it (the live result is ignored even
// if somehow non-empty).
{
LatestPinResolution res = resolve_latest_pin(recipe, backend, /*offline=*/true,
/*fetched_latest=*/"b9700",
/*installed_version=*/"b9632");
r.check(res.version == "b9632", "offline + installed: reuses installed, ignores fetched");
r.check(res.error.empty(), "offline + installed: no error");
r.check(res.used_installed_fallback, "offline + installed: flagged as fallback");
}
// Offline, nothing installed → unresolvable, with the offline-specific
// message.
{
LatestPinResolution res = resolve_latest_pin(recipe, backend, /*offline=*/true,
/*fetched_latest=*/"",
/*installed_version=*/"");
r.check(res.version.empty(), "offline + none: no version");
r.check(res.error.find("offline mode") != std::string::npos,
"offline + none: error names offline mode");
r.check(!res.used_installed_fallback, "offline + none: not a fallback");
}
printf("\n%d/%d checks passed\n", r.passed, r.passed + r.failed);
return r.failed == 0 ? 0 : 1;
}