Files
bambuddy/backend/tests/unit/test_printer_models.py
maziggy e737c84c6e fix(diagnostic): skip external_storage check on A1 / A1 Mini (#1703)
A1 and A1 Mini ship without a MicroSD slot at all - there is no
  firmware-side "Store sent files on external storage" toggle and the
  slicers don't surface a slicer-side equivalent either. The connection
  diagnostic was reading state.store_to_sdcard (home_flag bit 11), which
  is never set on these models, so the check fell through to fail for
  every A1-series user. Combined with the absent slicer UI it left users
  thinking Bambuddy was wrong about a setting their hardware does not
  have.

  New NO_EXTERNAL_STORAGE_MODELS frozenset in utils/printer_models.py
  enumerates A1, A1 Mini, and their internal codes (N1, N2S, A04, A11,
  A12). has_external_storage() returns False for those, True for
  everything else. Unknown models default to True so the check stays
  active for future Bambu lineup additions - new no-slot models must be
  added to the set explicitly.

  The diagnostic now short-circuits to skip before reading
  store_to_sdcard when printer.model is in the set. X1, P1, P2S, H2,
  and X2D are unchanged - the bit-off -> fail signal is still the right
  read for them.

  The companion FTP-upload-timeout symptom in the same bug report (ftp
  code 28 from BambuStudio when sending to the proxy VP) is a separate
  Docker-bridge-mode networking constraint, not addressed here.
2026-06-10 08:54:24 +02:00

182 lines
6.8 KiB
Python

"""Unit tests for printer model utilities."""
import pytest
from backend.app.services.camera import get_camera_port, supports_rtsp
from backend.app.utils.printer_models import (
CARBON_ROD_MODELS,
STEEL_ROD_MODELS,
get_rod_type,
has_ethernet,
has_external_storage,
is_dual_nozzle_model,
normalize_printer_model,
normalize_printer_model_id,
)
class TestGetRodType:
"""Tests for get_rod_type() rod/rail classification."""
@pytest.mark.parametrize("model", ["X1C", "X1", "X1E", "P1P", "P1S"])
def test_carbon_rod_models(self, model: str):
assert get_rod_type(model) == "carbon"
@pytest.mark.parametrize("model", ["C11", "C12", "C13"])
def test_carbon_rod_internal_codes(self, model: str):
assert get_rod_type(model) == "carbon"
def test_p2s_is_steel_rod(self):
"""P2S uses hardened steel rods, not carbon rods (#640)."""
assert get_rod_type("P2S") == "steel_rod"
def test_p2s_internal_code_is_steel_rod(self):
"""N7 (P2S internal code) uses steel rods."""
assert get_rod_type("N7") == "steel_rod"
@pytest.mark.parametrize("model", ["A1", "A1 Mini", "H2D", "H2D Pro", "H2C", "H2S"])
def test_linear_rail_models(self, model: str):
assert get_rod_type(model) == "linear_rail"
@pytest.mark.parametrize("model", ["N1", "N2S", "A11", "A12", "O1D", "O1E", "O2D", "O1C", "O1C2", "O1S"])
def test_linear_rail_internal_codes(self, model: str):
assert get_rod_type(model) == "linear_rail"
def test_unknown_model_returns_none(self):
assert get_rod_type("UNKNOWN") is None
def test_none_returns_none(self):
assert get_rod_type(None) is None
def test_case_insensitive(self):
assert get_rod_type("p2s") == "steel_rod"
assert get_rod_type("x1c") == "carbon"
assert get_rod_type("a1") == "linear_rail"
def test_strips_whitespace_and_dashes(self):
assert get_rod_type(" P2S ") == "steel_rod"
assert get_rod_type("A1-Mini") == "linear_rail"
class TestX2DModel:
"""X2D printer support (issue #988).
The X2D is a dual-nozzle enclosed printer launched April 2026. It shares
the hardened steel rod hardware with P2S (NOT carbon rods) and uses
RTSP on port 322 like other X/H series printers. Internal SSDP/MQTT
model code is "N6"; serial numbers begin with "20P9".
"""
def test_x2d_is_steel_rod_display_name(self):
assert get_rod_type("X2D") == "steel_rod"
def test_x2d_is_steel_rod_internal_code(self):
assert get_rod_type("N6") == "steel_rod"
def test_x2d_model_id_map(self):
assert normalize_printer_model_id("N6") == "X2D"
def test_x2d_model_map(self):
assert normalize_printer_model("Bambu Lab X2D") == "X2D"
def test_x2d_has_ethernet_display_name(self):
assert has_ethernet("X2D") is True
def test_x2d_has_ethernet_internal_code(self):
assert has_ethernet("N6") is True
def test_x2d_supports_rtsp_display_name(self):
assert supports_rtsp("X2D") is True
def test_x2d_supports_rtsp_internal_code(self):
assert supports_rtsp("N6") is True
def test_x2d_camera_port_is_rtsp(self):
assert get_camera_port("N6") == 322
assert get_camera_port("X2D") == 322
def test_x2d_not_in_carbon_rod_set(self):
"""Regression guard: X2D has hardened steel rods, not carbon (#988).
A prior PR classified X2D as carbon; the reporter confirmed it uses
the same stainless steel rod gantry as P2S. This assertion pins the
classification so a future change that reverts it will fail loudly.
"""
assert "X2D" not in CARBON_ROD_MODELS
assert "N6" not in CARBON_ROD_MODELS
assert "X2D" in STEEL_ROD_MODELS
assert "N6" in STEEL_ROD_MODELS
class TestA1SeriesModelIds:
"""Regression guard for the A1-family internal-code → display-name map.
The serial-prefix and firmware-API key tables across the codebase agree
that N2S is the A1 (serial prefix 039) and N1 is the A1 Mini (serial
prefix 030). PRINTER_MODEL_ID_MAP had these swapped, which silently
misclassified A1 as A1 Mini in any path that resolved by internal code.
"""
def test_n2s_is_a1(self):
assert normalize_printer_model_id("N2S") == "A1"
def test_n1_is_a1_mini(self):
assert normalize_printer_model_id("N1") == "A1 Mini"
class TestDualNozzleModel:
"""is_dual_nozzle_model — the single source of truth for nozzle class,
consumed by start_print, the K-profile routes, and the re-slice guard."""
def test_h2d_and_pro_are_dual(self):
# Takes a normalized model code (like has_ethernet) — "H2D Pro" with a
# space is accepted; full "Bambu Lab …" names are normalized by callers.
assert is_dual_nozzle_model("H2D") is True
assert is_dual_nozzle_model("H2D Pro") is True
assert is_dual_nozzle_model("H2DPRO") is True
def test_internal_codes_are_dual(self):
assert is_dual_nozzle_model("O1D") is True # H2D
assert is_dual_nozzle_model("O1E") is True # H2D Pro
def test_single_nozzle_models_are_not_dual(self):
# H2S is in the H2 family but single-nozzle (#1386) — must be False.
for model in ("X1C", "X1E", "P1S", "P1P", "A1", "A1 Mini", "P2S", "H2S"):
assert is_dual_nozzle_model(model) is False, model
def test_none_and_empty_are_not_dual(self):
assert is_dual_nozzle_model(None) is False
assert is_dual_nozzle_model("") is False
class TestHasExternalStorage:
"""Pins which Bambu models have a MicroSD slot. The connection
diagnostic flips its ``external_storage`` check from ``fail`` to
``skip`` based on this — a false add (X1C marked as no-storage) would
silently disable a genuine fail signal for X1/P1/P2S/H2 users."""
@pytest.mark.parametrize("model", ["A1", "A1 Mini", "A1MINI", "A1-Mini", "a1"])
def test_a1_series_has_no_external_storage(self, model: str):
assert has_external_storage(model) is False
@pytest.mark.parametrize("model", ["N1", "N2S", "A04", "A11", "A12"])
def test_a1_internal_codes_have_no_external_storage(self, model: str):
assert has_external_storage(model) is False
@pytest.mark.parametrize(
"model",
["X1C", "X1E", "X1", "P1S", "P1P", "P2S", "H2D", "H2D Pro", "H2C", "H2S", "X2D"],
)
def test_other_models_have_external_storage(self, model: str):
assert has_external_storage(model) is True
def test_unknown_model_defaults_to_true(self):
# Default-true keeps the diagnostic active for new Bambu models;
# add them to NO_EXTERNAL_STORAGE_MODELS explicitly when they ship
# without a slot.
assert has_external_storage("BrandNewModel2027") is True
def test_none_and_empty_default_to_true(self):
assert has_external_storage(None) is True
assert has_external_storage("") is True