fix(cli): resolve inherited presets through vendor manifests (#15438)

* fix(cli): resolve inherited presets through vendor manifests

* fix(cli): resolve typeless inherited presets

Probe the configured preset collections when a preset JSON omits its type. Reject missing, cross-type, and duplicate identities instead of silently selecting a candidate.

* fix(cli): allow missing app config during preset resolution

* fix(cli): tolerate malformed app config during preset resolution
This commit is contained in:
Maximilian Ghazanfar
2026-09-08 00:12:55 -04:00
committed by GitHub
parent c61d2fe5d1
commit bcb4f17d9a
8 changed files with 718 additions and 44 deletions

View File

@@ -554,6 +554,401 @@ struct LibraryFilamentTestCollection : public PresetCollection
} // namespace
TEST_CASE("Missing app config is accepted as default CLI state", "[Preset][Bundle][Regression]")
{
ScopedTemporaryDir dir;
AppConfig app_config;
app_config.set_loading_path((dir.path() / "missing.conf").string());
CHECK(app_config.load_if_exists().empty());
}
TEST_CASE("Read-only user preset loading does not create or delete files", "[Preset][Bundle][Regression]")
{
ScopedTemporaryDir dir;
PresetBundle bundle;
PresetsConfigSubstitutions substitutions;
const fs::path missing_root = dir.path() / "missing-user";
bundle.prints.load_presets(missing_root.string(), PRESET_PRINT_NAME, substitutions,
ForwardCompatibilitySubstitutionRule::EnableSilent, nullptr,
PresetOrigin(), true);
CHECK_FALSE(fs::exists(missing_root / PRESET_PRINT_NAME));
const fs::path malformed = dir.path() / "existing-user" / PRESET_PRINT_NAME / "malformed.json";
fs::create_directories(malformed.parent_path());
std::ofstream(malformed.string()) << "{not-json";
bundle.prints.load_presets((dir.path() / "existing-user").string(), PRESET_PRINT_NAME, substitutions,
ForwardCompatibilitySubstitutionRule::EnableSilent, nullptr,
PresetOrigin(), true);
CHECK(fs::exists(malformed));
}
TEST_CASE("Typeless preset resolution probes loaded FFF collections", "[Preset][Bundle][Regression]")
{
ScopedTemporaryDir dir;
const fs::path source_file = dir.path() / "typeless-process.json";
std::ofstream(source_file.string()) << R"({"name":"Typeless Process","from":"User"})";
PresetBundle bundle;
Preset &process = add_inmemory_preset(bundle.prints, "Typeless Process");
process.file = source_file.string();
process.config.option<ConfigOptionFloats>("travel_speed", true)->values = {321.0};
DynamicPrintConfig raw;
Preset::Type resolved_type = Preset::TYPE_INVALID;
std::string error;
REQUIRE(bundle.resolve_preset_config_type(raw, resolved_type, source_file.string(),
ForwardCompatibilitySubstitutionRule::EnableSilent, error, false));
CHECK(error.empty());
CHECK(resolved_type == Preset::TYPE_PRINT);
REQUIRE(raw.option<ConfigOptionFloats>("travel_speed")->values.size() == 1);
CHECK_THAT(raw.option<ConfigOptionFloats>("travel_speed")->values.front(), Catch::Matchers::WithinAbs(321.0, 1e-6));
}
TEST_CASE("Typeless preset resolution preserves duplicate identity ambiguity", "[Preset][Bundle][Regression]")
{
ScopedTemporaryDir dir;
const fs::path source_file = dir.path() / "duplicate-process.json";
std::ofstream(source_file.string()) << "{}";
PresetBundle bundle;
add_inmemory_preset(bundle.prints, "First Process Identity").file = source_file.string();
add_inmemory_preset(bundle.prints, "Second Process Identity").file = source_file.string();
DynamicPrintConfig raw;
Preset::Type resolved_type = Preset::TYPE_INVALID;
std::string error;
CHECK_FALSE(bundle.resolve_preset_config_type(raw, resolved_type, source_file.string(),
ForwardCompatibilitySubstitutionRule::EnableSilent, error, false));
CHECK(error == "Preset identity is ambiguous");
CHECK(resolved_type == Preset::TYPE_INVALID);
}
TEST_CASE("Typeless preset resolution rejects cross-type ambiguity", "[Preset][Bundle][Regression]")
{
ScopedTemporaryDir dir;
const fs::path source_file = dir.path() / "ambiguous.json";
std::ofstream(source_file.string()) << "{}";
PresetBundle bundle;
add_inmemory_preset(bundle.prints, "Process Identity").file = source_file.string();
add_inmemory_preset(bundle.filaments, "Filament Identity").file = source_file.string();
DynamicPrintConfig raw;
Preset::Type resolved_type = Preset::TYPE_INVALID;
std::string error;
CHECK_FALSE(bundle.resolve_preset_config_type(raw, resolved_type, source_file.string(),
ForwardCompatibilitySubstitutionRule::EnableSilent, error, false));
CHECK(error == "Preset type is ambiguous");
CHECK(resolved_type == Preset::TYPE_INVALID);
}
TEST_CASE("Typeless preset resolution rejects a missing type candidate", "[Preset][Bundle][Regression]")
{
ScopedTemporaryDir dir;
const fs::path source_file = dir.path() / "unknown.json";
std::ofstream(source_file.string()) << "{}";
PresetBundle bundle;
DynamicPrintConfig raw;
Preset::Type resolved_type = Preset::TYPE_INVALID;
std::string error;
CHECK_FALSE(bundle.resolve_preset_config_type(raw, resolved_type, source_file.string(),
ForwardCompatibilitySubstitutionRule::EnableSilent, error, false));
CHECK(error == "Preset type could not be resolved");
CHECK(resolved_type == Preset::TYPE_INVALID);
}
TEST_CASE("Exact file resolution rejects multiple preset identities", "[Preset][Bundle][Regression]")
{
ScopedTemporaryDir dir;
const fs::path source_file = dir.path() / "duplicate.json";
std::ofstream(source_file.string()) << "{}";
PresetBundle bundle;
Preset &first = add_inmemory_preset(bundle.prints, "First Identity");
first.file = source_file.string();
Preset &second = add_inmemory_preset(bundle.prints, "Second Identity");
second.file = source_file.string();
DynamicPrintConfig raw;
raw.option<ConfigOptionString>(BBL_JSON_KEY_INHERITS, true)->value = "Parent";
std::string error;
CHECK_FALSE(bundle.resolve_preset_config(raw, Preset::TYPE_PRINT, source_file.string(),
ForwardCompatibilitySubstitutionRule::EnableSilent, error, false));
CHECK(error == "Preset identity is ambiguous");
}
TEST_CASE("System preset resolution returns the canonical vendor configuration", "[Preset][Bundle][Regression]")
{
ScopedTemporaryDir source_dir;
PresetBundle bundle;
VendorProfile vendor("VendorB");
vendor.name = "Vendor B";
auto [vendor_it, inserted] = bundle.vendors.emplace(vendor.id, std::move(vendor));
REQUIRE(inserted);
Preset &resolved = add_inmemory_preset(bundle.prints, "Vendor B Process", "fdm_process_common");
resolved.is_system = true;
resolved.vendor = &vendor_it->second;
resolved.file = (source_dir.path() / "vendor-b-process.json").string();
std::ofstream(resolved.file) << "{}";
resolved.config.option<ConfigOptionFloats>("travel_speed", true)->values = {321.0};
resolved.config.option<ConfigOptionInt>("wall_loops", true)->value = 2;
DynamicPrintConfig raw;
raw.option<ConfigOptionString>(BBL_JSON_KEY_INHERITS, true)->value = "fdm_process_common";
raw.option<ConfigOptionInt>("wall_loops", true)->value = 5;
std::string error;
REQUIRE(bundle.resolve_preset_config(raw, Preset::TYPE_PRINT, resolved.file,
ForwardCompatibilitySubstitutionRule::EnableSilent, error));
CHECK(error.empty());
REQUIRE(raw.option<ConfigOptionFloats>("travel_speed")->values.size() == 1);
CHECK_THAT(raw.option<ConfigOptionFloats>("travel_speed")->values.front(), Catch::Matchers::WithinAbs(321.0, 1e-6));
CHECK(raw.option<ConfigOptionInt>("wall_loops")->value == 2);
}
TEST_CASE("Manifest-backed preset resolution loads the source vendor tree", "[Preset][Bundle][Regression]")
{
ScopedTemporaryDir dir;
const fs::path vendor_dir = dir.path() / "Acme";
const fs::path child_file = vendor_dir / "process" / "nested" / "child.json";
std::ofstream((dir.path() / "Acme.json").string())
<< R"({"version":"1.0.0","name":"Acme","process_list":[)"
<< R"({"name":"fdm_process_common","sub_path":"process/base.json"},)"
<< R"({"name":"Acme Process","sub_path":"process/nested/child.json"}]})";
fs::create_directories(child_file.parent_path());
std::ofstream((vendor_dir / "process" / "base.json").string())
<< R"({"type":"process","name":"fdm_process_common","from":"system",)"
<< R"("instantiation":"false","travel_speed":["321"]})";
std::ofstream(child_file.string())
<< R"({"type":"process","name":"Acme Process","from":"system",)"
<< R"("instantiation":"true","inherits":"fdm_process_common","wall_loops":"5"})";
DynamicPrintConfig raw;
raw.option<ConfigOptionString>(BBL_JSON_KEY_INHERITS, true)->value = "fdm_process_common";
raw.option<ConfigOptionInt>("wall_loops", true)->value = 5;
PresetBundle bundle;
std::string error;
REQUIRE(bundle.resolve_preset_config(raw, Preset::TYPE_PRINT, child_file.string(),
ForwardCompatibilitySubstitutionRule::EnableSilent, error));
CHECK(error.empty());
REQUIRE(raw.option<ConfigOptionFloats>("travel_speed")->values.size() == 1);
CHECK_THAT(raw.option<ConfigOptionFloats>("travel_speed")->values.front(), Catch::Matchers::WithinAbs(321.0, 1e-6));
CHECK(raw.option<ConfigOptionInt>("wall_loops")->value == 5);
}
TEST_CASE("Manifest-backed resolution is scoped to the explicit source root", "[Preset][Bundle][Regression]")
{
ScopedTemporaryDir dir;
auto write_vendor = [&](const std::string &root_name, double travel_speed) {
const fs::path root = dir.path() / root_name;
const fs::path child_file = root / "Acme" / "process" / "child.json";
fs::create_directories(child_file.parent_path());
std::ofstream((root / "Acme.json").string())
<< R"({"version":"1.0.0","name":"Acme","process_list":[)"
<< R"({"name":"fdm_process_common","sub_path":"process/base.json"},)"
<< R"({"name":"Acme Process","sub_path":"process/child.json"}]})";
std::ofstream((root / "Acme" / "process" / "base.json").string())
<< R"({"type":"process","name":"fdm_process_common","from":"system",)"
<< R"("instantiation":"false","travel_speed":[")" << travel_speed << R"("]})";
std::ofstream(child_file.string())
<< R"({"type":"process","name":"Acme Process","from":"system",)"
<< R"("instantiation":"true","inherits":"fdm_process_common"})";
return child_file;
};
const fs::path source_a = write_vendor("root-a", 111.0);
const fs::path source_b = write_vendor("root-b", 222.0);
REQUIRE(fs::exists(source_a));
DynamicPrintConfig raw;
raw.option<ConfigOptionString>(BBL_JSON_KEY_INHERITS, true)->value = "synthetic-parent-marker";
PresetBundle bundle;
std::string error;
REQUIRE(bundle.resolve_preset_config(raw, Preset::TYPE_PRINT, source_b.string(),
ForwardCompatibilitySubstitutionRule::EnableSilent, error));
REQUIRE(raw.option<ConfigOptionFloats>("travel_speed")->values.size() == 1);
CHECK_THAT(raw.option<ConfigOptionFloats>("travel_speed")->values.front(), Catch::Matchers::WithinAbs(222.0, 1e-6));
}
TEST_CASE("Exact-only resolution rejects an unconfigured manifest-backed file", "[Preset][Bundle][Regression]")
{
ScopedTemporaryDir dir;
const fs::path source_file = dir.path() / "Acme" / "process" / "child.json";
fs::create_directories(source_file.parent_path());
std::ofstream((dir.path() / "Acme.json").string())
<< R"({"version":"1.0.0","name":"Acme","process_list":[)"
<< R"({"name":"Acme Process","sub_path":"process/child.json"}]})";
std::ofstream(source_file.string())
<< R"({"type":"process","name":"Acme Process","from":"system",)"
<< R"("instantiation":"true","layer_height":"0.2"})";
DynamicPrintConfig raw;
raw.option<ConfigOptionString>(BBL_JSON_KEY_INHERITS, true)->value = "Some Parent";
PresetBundle bundle;
std::string error;
CHECK_FALSE(bundle.resolve_preset_config(raw, Preset::TYPE_PRINT, source_file.string(),
ForwardCompatibilitySubstitutionRule::EnableSilent, error, false));
CHECK(error == "Preset was not found in the loaded bundle");
}
TEST_CASE("Vendor filament resolution uses the shared Orca library base", "[Preset][Bundle][Regression]")
{
ScopedTemporaryDir dir;
const fs::path library_dir = dir.path() / PresetBundle::ORCA_FILAMENT_LIBRARY;
const fs::path vendor_dir = dir.path() / "Acme";
const fs::path child_file = vendor_dir / "filament" / "nested" / "petg.json";
std::ofstream((dir.path() / (std::string(PresetBundle::ORCA_FILAMENT_LIBRARY) + ".json")).string())
<< R"({"version":"1.0.0","name":"OrcaFilamentLibrary","filament_list":[)"
<< R"({"name":"fdm_filament_pet","sub_path":"filament/pet.json","filament_id":"GFL99"}]})";
fs::create_directories(library_dir / "filament");
std::ofstream((library_dir / "filament" / "pet.json").string())
<< R"({"type":"filament","name":"fdm_filament_pet","from":"system",)"
<< R"("filament_id":"GFL99","instantiation":"false",)"
<< R"("filament_type":["PETG"],"filament_density":["1.27"]})";
std::ofstream((dir.path() / "Acme.json").string())
<< R"({"version":"1.0.0","name":"Acme","filament_list":[)"
<< R"({"name":"Acme PETG","sub_path":"filament/nested/petg.json","filament_id":"GFA00"}]})";
fs::create_directories(child_file.parent_path());
std::ofstream(child_file.string())
<< R"({"type":"filament","name":"Acme PETG","from":"system",)"
<< R"("filament_id":"GFA00","instantiation":"true","inherits":"fdm_filament_pet"})";
DynamicPrintConfig raw;
raw.option<ConfigOptionString>(BBL_JSON_KEY_INHERITS, true)->value = "fdm_filament_pet";
PresetBundle bundle;
std::string error;
REQUIRE(bundle.resolve_preset_config(raw, Preset::TYPE_FILAMENT, child_file.string(),
ForwardCompatibilitySubstitutionRule::EnableSilent, error));
CHECK(error.empty());
CHECK(raw.opt_string("filament_type", 0u) == "PETG");
REQUIRE(raw.option<ConfigOptionFloats>("filament_density")->values.size() == 1);
CHECK_THAT(raw.option<ConfigOptionFloats>("filament_density")->values.front(), Catch::Matchers::WithinAbs(1.27, 1e-6));
}
TEST_CASE("Manifest-backed resolution rejects a missing parent", "[Preset][Bundle][Regression]")
{
ScopedTemporaryDir dir;
const fs::path child_file = dir.path() / "Acme" / "process" / "child.json";
std::ofstream((dir.path() / "Acme.json").string())
<< R"({"version":"1.0.0","name":"Acme","process_list":[)"
<< R"({"name":"Acme Process","sub_path":"process/child.json"}]})";
fs::create_directories(child_file.parent_path());
std::ofstream(child_file.string())
<< R"({"type":"process","name":"Acme Process","from":"system",)"
<< R"("instantiation":"true","inherits":"Missing Parent","layer_height":"0.2"})";
DynamicPrintConfig raw;
raw.option<ConfigOptionString>(BBL_JSON_KEY_INHERITS, true)->value = "Missing Parent";
PresetBundle bundle;
std::string error;
CHECK_FALSE(bundle.resolve_preset_config(raw, Preset::TYPE_PRINT, child_file.string(),
ForwardCompatibilitySubstitutionRule::EnableSilent, error));
CHECK_FALSE(error.empty());
}
TEST_CASE("Manifest-backed resolution rejects a vendor load with malformed entries", "[Preset][Bundle][Regression]")
{
ScopedTemporaryDir dir;
const fs::path child_file = dir.path() / "Acme" / "process" / "child.json";
std::ofstream((dir.path() / "Acme.json").string())
<< R"({"version":"1.0.0","name":"Acme","process_list":[123,)"
<< R"({"name":"Acme Process","sub_path":"process/child.json"}]})";
fs::create_directories(child_file.parent_path());
std::ofstream(child_file.string())
<< R"({"type":"process","name":"Acme Process","from":"system",)"
<< R"("instantiation":"true","layer_height":"0.2"})";
DynamicPrintConfig raw;
raw.option<ConfigOptionString>(BBL_JSON_KEY_INHERITS, true)->value = "fdm_process_common";
PresetBundle bundle;
std::string error;
CHECK_FALSE(bundle.resolve_preset_config(raw, Preset::TYPE_PRINT, child_file.string(),
ForwardCompatibilitySubstitutionRule::EnableSilent, error));
CHECK_FALSE(error.empty());
}
TEST_CASE("Manifest-backed resolution rejects files absent from the vendor manifest", "[Preset][Bundle][Regression]")
{
ScopedTemporaryDir dir;
const fs::path listed_file = dir.path() / "Acme" / "process" / "listed.json";
const fs::path unlisted_file = dir.path() / "Acme" / "process" / "unlisted.json";
std::ofstream((dir.path() / "Acme.json").string())
<< R"({"version":"1.0.0","name":"Acme","process_list":[)"
<< R"({"name":"Listed Process","sub_path":"process/listed.json"}]})";
fs::create_directories(listed_file.parent_path());
std::ofstream(listed_file.string())
<< R"({"type":"process","name":"Listed Process","from":"system",)"
<< R"("instantiation":"true","layer_height":"0.2"})";
std::ofstream(unlisted_file.string())
<< R"({"type":"process","name":"Unlisted Process","from":"system",)"
<< R"("instantiation":"true","inherits":"fdm_process_common"})";
DynamicPrintConfig raw;
raw.option<ConfigOptionString>(BBL_JSON_KEY_INHERITS, true)->value = "fdm_process_common";
PresetBundle bundle;
std::string error;
CHECK_FALSE(bundle.resolve_preset_config(raw, Preset::TYPE_PRINT, unlisted_file.string(),
ForwardCompatibilitySubstitutionRule::EnableSilent, error));
CHECK(error == "Source file is not an instantiated preset in its vendor manifest");
}
TEST_CASE("Manifest-backed resolution rejects a mismatched preset type", "[Preset][Bundle][Regression]")
{
ScopedTemporaryDir dir;
const fs::path process_file = dir.path() / "Acme" / "process" / "child.json";
std::ofstream((dir.path() / "Acme.json").string())
<< R"({"version":"1.0.0","name":"Acme","process_list":[)"
<< R"({"name":"Acme Process","sub_path":"process/child.json"}]})";
fs::create_directories(process_file.parent_path());
std::ofstream(process_file.string())
<< R"({"type":"process","name":"Acme Process","from":"system",)"
<< R"("instantiation":"true","layer_height":"0.2"})";
DynamicPrintConfig raw;
raw.option<ConfigOptionString>(BBL_JSON_KEY_INHERITS, true)->value = "fdm_filament_common";
PresetBundle bundle;
std::string error;
CHECK_FALSE(bundle.resolve_preset_config(raw, Preset::TYPE_FILAMENT, process_file.string(),
ForwardCompatibilitySubstitutionRule::EnableSilent, error));
CHECK(error == "Source file is not an instantiated preset in its vendor manifest");
}
TEST_CASE("Resolution terminates when no vendor manifest exists", "[Preset][Bundle][Regression]")
{
ScopedTemporaryDir dir;
const fs::path detached_file = dir.path() / "detached.json";
std::ofstream(detached_file.string()) << "{}";
DynamicPrintConfig raw;
raw.option<ConfigOptionString>(BBL_JSON_KEY_INHERITS, true)->value = "Missing Parent";
PresetBundle bundle;
std::string error;
CHECK_FALSE(bundle.resolve_preset_config(raw, Preset::TYPE_PRINT, detached_file.string(),
ForwardCompatibilitySubstitutionRule::EnableSilent, error));
CHECK(error == "Preset was not found in the loaded bundle");
}
// Orca: a filament in the Orca Filament Library that names its compatible printers has to hide the generic
// library filament sharing its alias, the same way a vendor owned filament does. Otherwise both are compatible
// with that printer and the plater combo box lists the shared alias twice.