From d55e7834c8b21b6c5ff1b696c1c3c38b3a6eb4e4 Mon Sep 17 00:00:00 2001 From: SoftFever Date: Wed, 15 Jul 2026 14:55:41 +0800 Subject: [PATCH] Fix unit-test segfault on missing shipped profile in sparse CI checkout The Unit Tests job sparse-checks-out only .github/scripts/tests, so the baked-in absolute PROFILES_DIR was missing at runtime; the shipped-profile test then read a non-existent JSON and null-dereferenced in opt_string. Check out resources/ in the unit-test job, and guard the test helper to skip when the profile is absent and require the key before dereferencing. --- .github/workflows/unit_tests.yml | 6 +++++- tests/fff_print/test_gcodewriter.cpp | 12 +++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 0fe91c7440..5f54f6581d 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -28,11 +28,15 @@ jobs: - name: Checkout uses: actions/checkout@v7 with: - # tests/data is referenced by absolute path (TEST_DATA_DIR). + # Tests reach outside tests/ at runtime: tests/data (TEST_DATA_DIR) and + # resources/profiles (PROFILES_DIR) by baked-in absolute path, plus + # resources/info (nozzle data) via resources_dir() during a real slice. + # Check out all of resources/ so no test hits a missing-file path. sparse-checkout: | .github scripts tests + resources - name: Apt-Install Dependencies if: runner.os == 'Linux' && !vars.SELF_HOSTED uses: ./.github/actions/apt-install-deps diff --git a/tests/fff_print/test_gcodewriter.cpp b/tests/fff_print/test_gcodewriter.cpp index f75c886eca..022b7841fc 100644 --- a/tests/fff_print/test_gcodewriter.cpp +++ b/tests/fff_print/test_gcodewriter.cpp @@ -12,6 +12,8 @@ #include "libslic3r/Print.hpp" #include "libslic3r/ModelArrange.hpp" +#include + #include "test_helpers.hpp" using namespace Slic3r; @@ -723,11 +725,19 @@ static std::string slice_two_object_bbl(DynamicPrintConfig &config) // The real change_filament_gcode of a shipped " 0.4 nozzle" machine profile. static std::string shipped_change_filament_gcode(const std::string &printer) { - const std::string path = std::string(PROFILES_DIR) + "/BBL/machine/Bambu Lab " + printer + " 0.4 nozzle.json"; + const std::string path = std::string(PROFILES_DIR) + "/BBL/machine/Bambu Lab " + printer + " 0.4 nozzle.json"; + // PROFILES_DIR is an absolute path baked in at build time; a sparse test checkout + // without resources/ leaves it missing. Skip rather than dereference a config that + // never loaded - this is the only fff_print test that reads a shipped profile. + if (!boost::filesystem::exists(path)) + SKIP("shipped profile not present in this checkout: " << path); DynamicPrintConfig config; std::map key_values; std::string reason; config.load_from_json(path, ForwardCompatibilitySubstitutionRule::Enable, key_values, reason); + // Fail loudly on a malformed/renamed profile instead of null-dereferencing in opt_string. + INFO("profile: " << path << (reason.empty() ? "" : (" load reason: " + reason))); + REQUIRE(config.has("change_filament_gcode")); return config.opt_string("change_filament_gcode"); }