Store network plug-in identity by AA.BB.CC series

The stored plug-in identity is now the AA.BB.CC series (matching BambuStudio)
rather than the full build version, so the meaningless 4th build digit stops
driving config, the whitelist, filenames, and the version selector. This fixes
the macOS "can't switch to an older build" bug: the cloud endpoint is
series-keyed and only ever serves a series' newest build, so downgrade-by-
download was impossible and the download silently adopted the latest.

A startup migration normalizes an existing full-version config and file name to
the series form with no re-download, the loader resolves a bare series to the
newest same-series build on disk, and user-provided custom-named plug-ins
(libbambu_networking_02.08.01_custom.*) are still enumerated and loaded.
This commit is contained in:
SoftFever
2026-07-19 00:26:05 +08:00
parent 2804e06cf2
commit afb4505ea7
7 changed files with 290 additions and 152 deletions

View File

@@ -61,76 +61,105 @@ int count_version(const std::vector<NetworkLibraryVersionInfo>& versions, const
} // namespace
TEST_CASE_METHOD(PluginFolderFixture, "Same-series OTA plugin versions are surfaced", "[NetworkVersions]")
TEST_CASE("Series and managed classification", "[NetworkVersions]")
{
add_plugin("02.08.01.55"); // same series as the whitelisted latest -> listed
add_plugin("02.09.00.10"); // unknown series -> not listed
add_plugin("02.08.01.52-custom"); // suffixed build of a whitelisted base -> listed (existing behavior)
add_plugin("02.03.00.62"); // series no longer whitelisted -> not listed
// The AA.BB.CC series is the stored identity of every modern build.
CHECK(network_plugin_series("02.08.01.53") == "02.08.01");
CHECK(network_plugin_series("02.08.01") == "02.08.01"); // idempotent
CHECK(network_plugin_series("02.08.01_custom") == "02.08.01");
CHECK(network_plugin_series("02.08.01.52-dev") == "02.08.01");
CHECK(network_plugin_series(BAMBU_NETWORK_AGENT_VERSION_LEGACY) == BAMBU_NETWORK_AGENT_VERSION_LEGACY);
CHECK(network_plugin_series("").empty());
// Only pure dotted-numeric builds collapse into their series entry; legacy and any
// custom-named build keep their own identity.
CHECK(is_series_managed_version("02.08.01"));
CHECK(is_series_managed_version("02.08.01.53"));
CHECK_FALSE(is_series_managed_version("02.08.01_custom"));
CHECK_FALSE(is_series_managed_version("02.08.01.52-dev"));
CHECK_FALSE(is_series_managed_version(BAMBU_NETWORK_AGENT_VERSION_LEGACY));
CHECK_FALSE(is_series_managed_version(""));
}
TEST_CASE_METHOD(PluginFolderFixture, "Managed builds fold into the series; customs are surfaced", "[NetworkVersions]")
{
add_plugin("02.08.01.55"); // managed, same series -> folded into the 02.08.01 row
add_plugin("02.09.00.10"); // managed, unknown series -> not listed
add_plugin("02.03.00.62"); // managed, series no longer whitelisted -> not listed
add_plugin("02.08.01_custom"); // custom, whitelisted series -> listed under it
add_plugin("02.08.01.52-dev"); // custom (dash-suffixed), whitelisted series -> listed
auto versions = get_all_available_versions();
REQUIRE(count_version(versions, "02.08.01.55") == 1);
// The specific managed build never gets its own row - the series represents it.
REQUIRE(count_version(versions, "02.08.01.55") == 0);
REQUIRE(count_version(versions, "02.08.01") == 1);
REQUIRE(count_version(versions, "02.09.00.10") == 0);
REQUIRE(count_version(versions, "02.08.01.52-custom") == 1);
REQUIRE(count_version(versions, "02.03.00.62") == 0);
// Custom-named builds are distinct files kept under their own name.
REQUIRE(count_version(versions, "02.08.01_custom") == 1);
REQUIRE(count_version(versions, "02.08.01.52-dev") == 1);
// Newest first, regardless of whether a version came from the whitelist or from
// disk: the OTA build outranks the older whitelist entry it was discovered under.
REQUIRE(versions[0].version == "02.08.01.55");
REQUIRE(versions[1].version == "02.08.01.52");
// Suffixed dev builds stay nested directly under the base version they build on.
REQUIRE(versions[2].version == "02.08.01.52-custom");
REQUIRE(versions[2].base_version == "02.08.01.52");
// The legacy series is the oldest, so it sorts last.
// Newest series first, its customs nested under it (suffix sort: "" < ".52-dev" < "_custom"),
// legacy last.
REQUIRE(versions[0].version == "02.08.01");
REQUIRE(versions[1].version == "02.08.01.52-dev");
REQUIRE(versions[2].version == "02.08.01_custom");
REQUIRE(versions.back().version == BAMBU_NETWORK_AGENT_VERSION_LEGACY);
const auto& ota = versions[0];
REQUIRE(ota.is_discovered);
REQUIRE(ota.suffix.empty());
// Customs sort/render nested under their series (non-empty suffix, base = the series).
REQUIRE(versions[1].base_version == "02.08.01");
REQUIRE_FALSE(versions[1].suffix.empty());
REQUIRE(versions[2].base_version == "02.08.01");
REQUIRE_FALSE(versions[2].suffix.empty());
// "(Latest)" is dynamic: the OTA build is the highest listed version, so it takes
// the label from the static whitelist entry.
REQUIRE(ota.is_latest);
// "(Latest)" is the series row, never a nested custom build.
REQUIRE(versions[0].suffix.empty());
REQUIRE(versions[0].is_latest);
REQUIRE_FALSE(versions[1].is_latest);
REQUIRE_FALSE(versions[2].is_latest);
// The static default used for download and update-check decisions is unchanged.
REQUIRE(std::string(get_latest_network_version()) == "02.08.01.52");
// The stored default that drives download and update-check decisions is now the series.
REQUIRE(std::string(get_latest_network_version()) == "02.08.01");
}
TEST_CASE_METHOD(PluginFolderFixture, "Only the loaded build is marked installed", "[NetworkVersions]")
TEST_CASE_METHOD(PluginFolderFixture, "Only the loaded series is marked installed", "[NetworkVersions]")
{
// Switching versions leaves the previous library on disk, so presence on disk is
// not what "(installed)" reports - the build actually loaded in this session is.
add_plugin("02.08.01.55");
add_plugin("02.08.01.52");
add_plugin("02.08.01_custom");
auto versions = get_all_available_versions("02.08.01.52");
int marked = 0;
for (const auto& info : versions) {
if (info.is_loaded) {
++marked;
REQUIRE(info.version == "02.08.01.52");
}
// The loaded plug-in reports its full build (02.08.01.55); the series row is what gets marked.
{
auto versions = get_all_available_versions("02.08.01.55");
int marked = 0;
for (const auto& info : versions)
if (info.is_loaded) { ++marked; REQUIRE(info.version == "02.08.01"); }
REQUIRE(marked == 1);
}
REQUIRE(marked == 1);
// Nothing loaded (plug-in disabled or failed to load) marks nothing, even though
// both libraries are on disk.
// A loaded custom build matches its own row, never the bare series.
{
auto versions = get_all_available_versions("02.08.01_custom");
int marked = 0;
for (const auto& info : versions)
if (info.is_loaded) { ++marked; REQUIRE(info.version == "02.08.01_custom"); }
REQUIRE(marked == 1);
}
// Nothing loaded marks nothing, even though libraries are on disk.
for (const auto& info : get_all_available_versions(""))
REQUIRE_FALSE(info.is_loaded);
}
TEST_CASE("Only whitelisted series pass the load gate", "[NetworkVersions]")
{
// Exact whitelist entries.
// The whitelisted series, its builds, and custom-named builds of that series.
REQUIRE(is_supported_network_version("02.08.01"));
REQUIRE(is_supported_network_version("02.08.01.52"));
REQUIRE(is_supported_network_version(BAMBU_NETWORK_AGENT_VERSION_LEGACY));
// Same-series OTA builds and suffixed dev builds of the whitelisted latest.
REQUIRE(is_supported_network_version("02.08.01.55"));
REQUIRE(is_supported_network_version("02.08.01.52-custom"));
REQUIRE(is_supported_network_version("02.08.01_custom"));
REQUIRE(is_supported_network_version("02.08.01.52-dev"));
REQUIRE(is_supported_network_version(BAMBU_NETWORK_AGENT_VERSION_LEGACY));
// Series whitelisted by previous Orca releases - their ABI no longer matches.
REQUIRE_FALSE(is_supported_network_version("02.03.00.62"));
@@ -159,10 +188,10 @@ TEST_CASE_METHOD(PluginFolderFixture, "Legacy series never adopts discovered bui
REQUIRE(count_version(versions, legacy_sibling) == 0);
REQUIRE(count_version(versions, legacy) == 1);
// With nothing else on disk, the highest whitelisted version holds "(Latest)"
// even though its library is not installed.
// With nothing else on disk, the series holds "(Latest)" even though its library is
// not installed.
for (const auto& info : versions) {
if (info.version == "02.08.01.52") {
if (info.version == "02.08.01") {
REQUIRE(info.is_latest);
REQUIRE_FALSE(info.is_loaded);
}