瀏覽代碼

AMS: a slot set to a support filament is a support slot (#3559)

maziggy 5 天之前
父節點
當前提交
21b2ed02d4

+ 4 - 1
backend/app/api/routes/inventory.py

@@ -105,7 +105,7 @@ from backend.app.utils.filament_ids import (
     filament_id_to_setting_id,
     normalize_slicer_filament,
 )
-from backend.app.utils.filament_types import nozzle_temp_range, printer_filament_type
+from backend.app.utils.filament_types import nozzle_temp_range, printer_filament_type, support_filament_type
 from backend.app.utils.local_time import day_zone, local_date_end, local_date_start
 from backend.app.utils.natural_sort import natural_sort_key
 from backend.app.utils.tag_normalization import normalize_tag_uid, normalize_tray_uuid
@@ -240,6 +240,9 @@ async def apply_spool_to_slot_via_mqtt(
     # the spool has a preset, its answer wins (issue #2902, @doncaruana).
     if type_override:
         tray_type = printer_filament_type(type_override)
+    # A support material keeps the slicer's suffix ("PLA-S"), which neither the
+    # material column nor most presets' type carries (#3559).
+    tray_type = support_filament_type(tray_type, tray_info_idx, f"{slot_slicer_filament_name or ''} {tray_sub_brands}")
 
     if not tray_info_idx:
         reused = reusable_slot_filament_id(

+ 7 - 1
backend/app/api/routes/printers.py

@@ -115,7 +115,7 @@ from backend.app.utils.filament_ids import (
     filament_id_to_setting_id,
     setting_id_to_filament_id,
 )
-from backend.app.utils.filament_types import is_material_name, printer_filament_type
+from backend.app.utils.filament_types import is_material_name, printer_filament_type, support_filament_type
 from backend.app.utils.fts_routing import slot_extruder
 from backend.app.utils.http import build_content_disposition, download_error_response, safe_download_filename
 from backend.app.utils.kprofile_lookup import build_slot_k_resolver
@@ -3065,6 +3065,12 @@ async def configure_ams_slot(
         logger.info("[configure_ams_slot] tray_info_idx %r is a setting id → %r", tray_info_idx, converted)
         setting_id = setting_id or tray_info_idx
         tray_info_idx = converted
+    # A support preset arrives as plain "PLA" -- the dialog reads the type off
+    # the preset name -- where the slicer writes "PLA-S" (#3559).
+    support_type = support_filament_type(tray_type, tray_info_idx, tray_sub_brands)
+    if support_type != tray_type:
+        logger.info("[configure_ams_slot] support filament: tray_type %r → %r", tray_type, support_type)
+        tray_type = support_type
     # The K profile's filament id: it becomes the slot's when they differ
     # (the realignment below), and the printer's calibration table is keyed
     # by filament ids as well.

+ 5 - 1
backend/app/api/routes/spoolman.py

@@ -49,7 +49,7 @@ from backend.app.utils.filament_ids import (
     filament_id_to_setting_id,
     normalize_slicer_filament,
 )
-from backend.app.utils.filament_types import nozzle_temp_range, printer_filament_type
+from backend.app.utils.filament_types import nozzle_temp_range, printer_filament_type, support_filament_type
 
 logger = logging.getLogger(__name__)
 
@@ -1077,6 +1077,10 @@ async def link_spool(
                     tray_sub_brands = sub_brand_override
                 if type_override:
                     tray_type = printer_filament_type(type_override)
+                # A support material keeps the slicer's suffix ("PLA-S") (#3559).
+                tray_type = support_filament_type(
+                    tray_type, tray_info_idx, f"{slot_slicer_filament_name or ''} {tray_sub_brands}"
+                )
 
                 # The spool's own wording is tried first and the reduced type
                 # only as a further fallback, so a material that already

+ 5 - 1
backend/app/api/routes/spoolman_inventory.py

@@ -91,7 +91,7 @@ from backend.app.utils.filament_ids import (
     filament_id_to_setting_id,
     normalize_slicer_filament,
 )
-from backend.app.utils.filament_types import nozzle_temp_range, printer_filament_type
+from backend.app.utils.filament_types import nozzle_temp_range, printer_filament_type, support_filament_type
 from backend.app.utils.tray_ids import external_tray_id
 
 logger = logging.getLogger(__name__)
@@ -2114,6 +2114,10 @@ async def assign_spoolman_slot(
             # spool has one (issue #2902, @doncaruana).
             if type_override:
                 tray_type = printer_filament_type(type_override)
+            # A support material keeps the slicer's suffix ("PLA-S") (#3559).
+            tray_type = support_filament_type(
+                tray_type, tray_info_idx, f"{slot_slicer_filament_name or ''} {tray_sub_brands}"
+            )
 
             material_upper = material.upper().strip()
             # Without a preset, the slot's own filament id where it fits, as in

+ 12 - 1
backend/app/main.py

@@ -183,7 +183,7 @@ from backend.app.services.telegram_reactions import telegram_reaction_poller
 from backend.app.services.wled import wled_manager
 from backend.app.utils.ams_drying import is_drying_active, temperature_alarm_suppressed
 from backend.app.utils.ams_humidity import ams_humidity_percent
-from backend.app.utils.filament_types import printer_filament_type
+from backend.app.utils.filament_types import printer_filament_type, support_filament_type
 from backend.app.utils.fts_routing import extruder_for_inlet
 from backend.app.utils.local_time import to_naive_utc, utcnow_naive
 from backend.app.utils.print_jobs import is_internal_printer_job
@@ -3185,6 +3185,17 @@ async def _unlink_stale_assignments(printer_id: int, ams_data: list, printing_no
                                 lp_type = await db.scalar(select(_LP.filament_type).where(_LP.id == int(lp_ref)))
                                 if lp_type:
                                     spool_types.add(printer_filament_type(lp_type).upper())
+                            # A support spool went in with the slicer's suffix
+                            # ("PLA-S") that none of the above carries (#3559).
+                            # A spool made from a support RFID tray has its
+                            # material as "Support For PLA", so that counts too.
+                            support_name = (
+                                f"{spool.slicer_filament_name or ''} {spool.material or ''} {spool.subtype or ''}"
+                            )
+                            spool_types |= {
+                                support_filament_type(t, spool.slicer_filament, support_name).upper()
+                                for t in spool_types
+                            }
                             if (
                                 _colors_similar(cur_color, spool_color)
                                 and printer_filament_type(cur_type).upper() in spool_types

+ 52 - 0
backend/app/utils/filament_types.py

@@ -116,6 +116,14 @@ _PRINTER_TYPES: tuple[str, ...] = (
     "PP-CF",
     "PP-GF",
     "PE-CF",
+    # Bambu's support materials. BambuStudio writes a support preset's type
+    # with this suffix (see ``support_filament_type``) and the 3MF declares it
+    # the same way, so the suffix is part of the type, not decoration to strip:
+    # a slot reduced to "PLA" offers Support for PLA to every plain PLA part
+    # and to nothing that asks for support (#3559).
+    "PLA-S",
+    "ABS-S",
+    "PA-S",
     "PCTG",
     "PETG",
     "BVOH",
@@ -225,6 +233,50 @@ def printer_filament_type(material: str | None) -> str:
     return text
 
 
+# Bambu's own support filaments, by id, and the type BambuStudio's
+# ``get_filament_type`` (libslic3r/PrintConfig.cpp) gives each: Support W and
+# Support G by their id, the rest by adding the suffix to the preset's base
+# type -- For PLA and For PLA/PETG are PLA presets, For PA/PET a PA one, and
+# Support for ABS is the one left as it is. The id decides on its own because
+# the wording cannot: "Support for PLA/PETG" reads as PETG.
+_SUPPORT_TYPE_BY_ID: dict[str, str] = {
+    "GFS00": "PLA-S",
+    "GFS01": "PA-S",
+    "GFS02": "PLA-S",
+    "GFS03": "PA-S",
+    "GFS05": "PLA-S",
+    "GFS06": "ABS",
+}
+# Without a Bambu id, BambuStudio adds the suffix to these two types only.
+_SUPPORT_SUFFIXED = {"PLA": "PLA-S", "PA": "PA-S"}
+_SUPPORT_WORD = re.compile(r"\bSUPPORT\b", re.IGNORECASE)
+
+
+def support_filament_type(tray_type: str | None, filament_id: str | None, preset_name: str | None) -> str:
+    """The slot type for ``tray_type`` when the filament is a support material.
+
+    BambuStudio writes a support preset into a slot as "PLA-S" or "PA-S", and
+    a plate sliced with one declares the same, so the slot has to say so for a
+    print to find it (#3559). Every path that configures a slot reaches this
+    point holding a plain "PLA": the Configure dialog reads the type from the
+    preset name, and a spool's material column rarely says more.
+
+    The rule is BambuStudio's. A Bambu support id decides the type outright.
+    Otherwise -- a third-party or user preset with an id of its own -- a PLA
+    or PA filament whose preset name says "Support" gets the suffix. Any other
+    type is returned unchanged: "PLA Support for PETG" is a PETG preset and
+    stays PETG, as it does in the slicer.
+    """
+    fid = (filament_id or "").strip().upper()
+    if fid in _SUPPORT_TYPE_BY_ID:
+        return _SUPPORT_TYPE_BY_ID[fid]
+    text = (tray_type or "").strip()
+    suffixed = _SUPPORT_SUFFIXED.get(text.upper())
+    if suffixed and _SUPPORT_WORD.search(preset_name or ""):
+        return suffixed
+    return tray_type or ""
+
+
 def nozzle_temp_range(material: str | None, tray_type: str | None) -> tuple[int, int]:
     """The nozzle range to send with a slot, given a spool's material and the
     type the slot will carry.

+ 368 - 0
backend/tests/integration/test_ams_slot_support_type_3559.py

@@ -0,0 +1,368 @@
+"""A support filament has to reach its AMS slot as a support type (#3559).
+
+The reporter set a slot to "Bambu Support For PLA" and every PLA part still
+matched it. BambuStudio writes a support preset into a slot as "PLA-S" (or
+"PA-S"), and a plate sliced with one declares the same; Bambuddy wrote "PLA".
+The Configure dialog reads the type off the preset name, and the reduction
+every slot-writing route runs (#2902) then cut "PLA-S" itself back to "PLA" --
+so the slot offered support filament to every plain PLA part, and to nothing
+that asked for support.
+
+All four routes that configure a slot are covered, plus the auto-unlink check
+that has to recognise the slot it just wrote.
+"""
+
+from unittest.mock import AsyncMock, MagicMock, patch
+
+import pytest
+from httpx import AsyncClient
+from sqlalchemy.ext.asyncio import AsyncSession
+
+from backend.app.models.spool import Spool
+from backend.app.utils.filament_types import printer_filament_type, support_filament_type
+from backend.tests.integration.test_ams_slot_material_2902 import (
+    _mqtt_mock,
+    _spoolman_client,
+    _spoolman_spool,
+    _status,
+)
+
+
+class TestTheTypeRule:
+    """BambuStudio's ``get_filament_type`` (libslic3r/PrintConfig.cpp)."""
+
+    @pytest.mark.parametrize("support_type", ["PLA-S", "PA-S", "ABS-S"])
+    def test_a_support_type_is_not_reduced_to_its_base(self, support_type):
+        assert printer_filament_type(support_type) == support_type
+        assert printer_filament_type(support_type.lower()) == support_type
+
+    @pytest.mark.parametrize(
+        ("filament_id", "expected"),
+        [
+            ("GFS00", "PLA-S"),  # Support W
+            ("GFS01", "PA-S"),  # Support G
+            ("GFS02", "PLA-S"),  # Support For PLA
+            ("GFS03", "PA-S"),  # Support For PA/PET
+            ("GFS05", "PLA-S"),  # Support For PLA/PETG
+            ("GFS06", "ABS"),  # Support for ABS: the one Bambu leaves alone
+        ],
+    )
+    def test_a_bambu_support_id_decides_the_type(self, filament_id, expected):
+        # Whatever the name made of it: "Support For PLA/PETG" reads as PETG,
+        # and Support W / G name no material at all.
+        for guessed in ("PLA", "PETG", "PA"):
+            assert support_filament_type(guessed, filament_id, "") == expected
+
+    @pytest.mark.parametrize(
+        ("tray_type", "name", "expected"),
+        [
+            ("PLA", "Bambu Support For PLA", "PLA-S"),
+            ("PLA", "Sunlu Support for PLA @BBL X1C", "PLA-S"),
+            ("PA", "Acme Support for PA", "PA-S"),
+            # A third-party "X Support for Y" preset is a Y preset; the slicer
+            # keeps its declared type, and so does this (330d77198).
+            ("PETG", "PLA Support for PETG PETG Basic", "PETG"),
+            ("ABS", "Acme Support for ABS", "ABS"),
+            # A word, not a fragment of one.
+            ("PLA", "PolySupport PLA", "PLA"),
+            ("PLA", "Bambu PLA Basic", "PLA"),
+            ("PLA", "", "PLA"),
+        ],
+    )
+    def test_without_a_bambu_id_the_preset_name_says_whether_it_is_support(self, tray_type, name, expected):
+        assert support_filament_type(tray_type, "P4d64437", name) == expected
+
+    def test_an_unrelated_id_is_left_alone(self):
+        assert support_filament_type("PLA", "GFA00", "Bambu PLA Basic") == "PLA"
+        assert support_filament_type("PLA-S", "", "") == "PLA-S"
+
+
+class TestConfigureSlotModal:
+    async def _configure(self, async_client, printer_factory, **params):
+        printer = await printer_factory(model="X1C")
+        client = _mqtt_mock()
+        with patch("backend.app.api.routes.printers.printer_manager") as pm:
+            pm.get_client.return_value = client
+            pm.get_status.return_value = _status()
+            response = await async_client.post(
+                f"/api/v1/printers/{printer.id}/slots/0/3/configure",
+                params={
+                    "tray_color": "E1E9E9FF",
+                    "nozzle_temp_min": 190,
+                    "nozzle_temp_max": 230,
+                    **params,
+                },
+            )
+        assert response.status_code == 200
+        return client.ams_set_filament_setting.call_args.kwargs
+
+    @pytest.mark.asyncio
+    @pytest.mark.integration
+    async def test_the_reported_case_a_bambu_support_preset(self, async_client: AsyncClient, printer_factory):
+        """What the dialog sends for "Bambu Support For PLA": the type it read off
+        the name, and the preset's filament id."""
+        sent = await self._configure(
+            async_client,
+            printer_factory,
+            tray_info_idx="GFS02",
+            tray_type="PLA",
+            tray_sub_brands="Bambu Support For PLA",
+        )
+
+        assert sent["tray_type"] == "PLA-S"
+        assert sent["tray_info_idx"] == "GFS02"
+
+    @pytest.mark.asyncio
+    @pytest.mark.integration
+    async def test_support_for_pla_petg_is_pla_s_not_petg(self, async_client: AsyncClient, printer_factory):
+        sent = await self._configure(
+            async_client,
+            printer_factory,
+            tray_info_idx="GFS05",
+            tray_type="PETG",
+            tray_sub_brands="Bambu Support For PLA/PETG",
+        )
+
+        assert sent["tray_type"] == "PLA-S"
+
+    @pytest.mark.asyncio
+    @pytest.mark.integration
+    async def test_a_user_preset_of_its_own_by_its_name(self, async_client: AsyncClient, printer_factory):
+        """A non-Bambu support filament on a user preset: its own id, so only the
+        name can say it is support -- the reporter's case."""
+        sent = await self._configure(
+            async_client,
+            printer_factory,
+            tray_info_idx="P4d64437",
+            tray_type="PLA",
+            tray_sub_brands="Jade White Support For PLA",
+        )
+
+        assert sent["tray_type"] == "PLA-S"
+        assert sent["tray_info_idx"] == "P4d64437"
+
+    @pytest.mark.asyncio
+    @pytest.mark.integration
+    async def test_a_plain_pla_preset_is_untouched(self, async_client: AsyncClient, printer_factory):
+        sent = await self._configure(
+            async_client,
+            printer_factory,
+            tray_info_idx="GFA00",
+            tray_type="PLA",
+            tray_sub_brands="Bambu PLA Basic",
+        )
+
+        assert sent["tray_type"] == "PLA"
+
+
+class TestInternalInventoryAssign:
+    async def _assign(self, async_client, db_session, **spool_kwargs):
+        from backend.app.models.printer import Printer
+
+        printer = Printer(
+            name="X1C",
+            serial_number="SUP3559INV",
+            ip_address="192.168.1.80",
+            access_code="12345678",
+        )
+        db_session.add(printer)
+        spool = Spool(rgba="FFFFFFFF", label_weight=500, weight_used=0, **spool_kwargs)
+        db_session.add(spool)
+        await db_session.commit()
+        await db_session.refresh(printer)
+        await db_session.refresh(spool)
+
+        client = _mqtt_mock()
+        with patch("backend.app.services.printer_manager.printer_manager") as pm:
+            pm.get_client.return_value = client
+            pm.get_status.return_value = _status()
+            response = await async_client.post(
+                "/api/v1/inventory/assignments",
+                json={"spool_id": spool.id, "printer_id": printer.id, "ams_id": 0, "tray_id": 1},
+            )
+        assert response.status_code == 200
+        return client.ams_set_filament_setting.call_args.kwargs
+
+    @pytest.mark.asyncio
+    @pytest.mark.integration
+    async def test_a_spool_made_from_a_support_rfid_tray(self, async_client: AsyncClient, db_session: AsyncSession):
+        """A Bambu support spool read by RFID is stored with the tray's
+        sub-brand as its material. Moved to another slot by Bambuddy, it used to
+        go in as plain PLA."""
+        sent = await self._assign(
+            async_client, db_session, material="Support For PLA", brand="Bambu Lab", slicer_filament="GFS02"
+        )
+
+        assert sent["tray_type"] == "PLA-S"
+        assert sent["tray_info_idx"] == "GFS02"
+
+    @pytest.mark.asyncio
+    @pytest.mark.integration
+    async def test_a_spool_whose_material_already_says_pla_s(self, async_client: AsyncClient, db_session: AsyncSession):
+        sent = await self._assign(async_client, db_session, material="PLA-S", brand="Sunlu")
+
+        assert sent["tray_type"] == "PLA-S"
+        # The slot still gets a filament id the printer can resolve.
+        assert sent["tray_info_idx"] == "GFL99"
+
+
+class TestSpoolmanRoutes:
+    @pytest.fixture
+    async def settings(self, db_session):
+        from backend.app.models.settings import Settings
+
+        db_session.add(Settings(key="spoolman_enabled", value="true"))
+        db_session.add(Settings(key="spoolman_url", value="http://localhost:7912"))
+        await db_session.commit()
+
+    @pytest.fixture
+    async def printer(self, db_session):
+        from backend.app.models.printer import Printer
+
+        p = Printer(
+            name="Spoolman X1C",
+            serial_number="SUP3559SM",
+            ip_address="192.168.1.81",
+            access_code="12345678",
+        )
+        db_session.add(p)
+        await db_session.commit()
+        await db_session.refresh(p)
+        return p
+
+    @pytest.mark.asyncio
+    @pytest.mark.integration
+    async def test_the_slot_assignment_route(self, async_client: AsyncClient, settings, printer):
+        mqtt = _mqtt_mock()
+        spool = _spoolman_spool("Support For PLA")
+        with (
+            patch("backend.app.api.routes.spoolman_inventory.printer_manager") as pm,
+            patch(
+                "backend.app.api.routes.spoolman_inventory.get_spoolman_client",
+                AsyncMock(return_value=_spoolman_client(spool)),
+            ),
+        ):
+            pm.get_client.return_value = mqtt
+            pm.get_status.return_value = _status()
+            response = await async_client.post(
+                "/api/v1/spoolman/inventory/slot-assignments",
+                json={"spoolman_spool_id": 11, "printer_id": printer.id, "ams_id": 0, "tray_id": 2},
+            )
+        assert response.status_code == 200
+        assert mqtt.ams_set_filament_setting.call_args.kwargs["tray_type"] == "PLA-S"
+
+    @pytest.mark.asyncio
+    @pytest.mark.integration
+    async def test_the_tag_link_route(self, async_client: AsyncClient, settings, printer):
+        client = _spoolman_client(_spoolman_spool("Support For PLA", spool_id=12))
+        mqtt = _mqtt_mock()
+        with (
+            patch("backend.app.api.routes.spoolman.get_spoolman_client", AsyncMock(return_value=client)),
+            patch("backend.app.api.routes.spoolman.init_spoolman_client", AsyncMock(return_value=client)),
+            patch("backend.app.api.routes.spoolman.printer_manager") as pm,
+        ):
+            pm.get_client.return_value = mqtt
+            pm.get_status.return_value = _status()
+            response = await async_client.post(
+                "/api/v1/spoolman/spools/12/link",
+                json={
+                    "tray_uuid": "A1B2C3D4E5F6A1B2C3D4E5F6A1B2C3D4",
+                    "printer_id": printer.id,
+                    "ams_id": 0,
+                    "tray_id": 3,
+                },
+            )
+        assert response.status_code == 200
+        assert mqtt.ams_set_filament_setting.call_args.kwargs["tray_type"] == "PLA-S"
+
+
+class TestTheAssignmentSurvivesTheSlotItJustConfigured:
+    """on_ams_change unlinks an assignment whose slot no longer looks like its
+    spool. The slot now carries "PLA-S", which no spool column says."""
+
+    async def _push(self, db_session, printer_factory, reported_type, **spool_kwargs):
+        from backend.app.main import on_ams_change
+        from backend.app.models.spool_assignment import SpoolAssignment
+
+        printer = await printer_factory(name="X1C")
+        spool = Spool(rgba="FFFFFFFF", label_weight=500, weight_used=0, **spool_kwargs)
+        db_session.add(spool)
+        await db_session.commit()
+        await db_session.refresh(spool)
+
+        assignment = SpoolAssignment(
+            spool_id=spool.id,
+            printer_id=printer.id,
+            ams_id=0,
+            tray_id=2,
+            fingerprint_color="FFFFFFFF",
+            fingerprint_type="PETG",
+        )
+        db_session.add(assignment)
+        await db_session.commit()
+        assignment_id = assignment.id
+
+        ams_data = [{"id": 0, "tray": [{"id": 2, "tray_type": reported_type, "tray_color": "FFFFFFFF", "state": 11}]}]
+        status = _status(ams_data)
+        status.state = "IDLE"
+
+        with (
+            patch("backend.app.main.printer_manager") as pm,
+            patch("backend.app.main.mqtt_relay") as relay,
+            patch("backend.app.main.ws_manager") as ws,
+        ):
+            pm.get_printer.return_value = MagicMock(name="X1C", serial_number="00M00A000000001")
+            pm.get_status.return_value = status
+            pm.get_model.return_value = "X1C"
+            relay.on_ams_change = AsyncMock()
+            ws.send_printer_status = AsyncMock()
+            ws.broadcast = AsyncMock()
+
+            await on_ams_change(printer.id, ams_data)
+
+        db_session.expunge_all()
+        return await db_session.get(SpoolAssignment, assignment_id)
+
+    @pytest.mark.asyncio
+    @pytest.mark.integration
+    async def test_a_support_spool_stays_on_the_pla_s_slot_it_configured(
+        self, async_client: AsyncClient, db_session: AsyncSession, printer_factory
+    ):
+        surviving = await self._push(
+            db_session, printer_factory, "PLA-S", material="PLA", slicer_filament_name="Bambu Support For PLA"
+        )
+
+        assert surviving is not None
+
+    @pytest.mark.asyncio
+    @pytest.mark.integration
+    async def test_so_does_one_made_from_a_support_rfid_tray(
+        self, async_client: AsyncClient, db_session: AsyncSession, printer_factory
+    ):
+        surviving = await self._push(db_session, printer_factory, "PLA-S", material="Support For PLA")
+
+        assert surviving is not None
+
+    @pytest.mark.asyncio
+    @pytest.mark.integration
+    async def test_and_a_slot_an_older_version_configured_as_pla(
+        self, async_client: AsyncClient, db_session: AsyncSession, printer_factory
+    ):
+        """Slots configured before this fix still report "PLA" until someone
+        reconfigures them; their spools must not be unlinked meanwhile."""
+        surviving = await self._push(
+            db_session, printer_factory, "PLA", material="PLA", slicer_filament_name="Bambu Support For PLA"
+        )
+
+        assert surviving is not None
+
+    @pytest.mark.asyncio
+    @pytest.mark.integration
+    async def test_but_a_plain_pla_spool_on_a_support_slot_is_a_swap(
+        self, async_client: AsyncClient, db_session: AsyncSession, printer_factory
+    ):
+        surviving = await self._push(
+            db_session, printer_factory, "PLA-S", material="PLA", slicer_filament_name="Bambu PLA Basic"
+        )
+
+        assert surviving is None

+ 29 - 0
frontend/src/__tests__/components/spool-form/buildFilamentOptions.test.ts

@@ -160,3 +160,32 @@ describe('buildFilamentOptions', () => {
     expect(options.map(o => o.name)).toEqual(['Alpha PLA', 'Zebra PLA']);
   });
 });
+
+describe('the fallback list when every source is empty (#3559)', () => {
+  // Each entry must carry the filament id Bambu gives its name. A wrong id is
+  // what the slot gets configured with: "Bambu PLA-CF" used to be GFS00, which
+  // is Support W, and the backend now turns a GFS00 slot into PLA-S.
+  const BAMBU_IDS: Record<string, string> = {
+    'Bambu PLA Basic': 'GFA00',
+    'Bambu PLA Matte': 'GFA01',
+    'Generic PLA': 'GFL99',
+    'Bambu PETG Basic': 'GFG00',
+    'Generic PETG': 'GFG99',
+    'Bambu ABS': 'GFB00',
+    'Generic ABS': 'GFB99',
+    'Bambu ASA': 'GFB01',
+    'Bambu TPU 95A': 'GFU01',
+    'Generic TPU': 'GFU99',
+    'Bambu PC': 'GFC00',
+    'Generic PA': 'GFN99',
+    'Bambu PLA-CF': 'GFA50',
+    'Bambu PETG-CF': 'GFG50',
+    'Bambu PA-CF': 'GFN03',
+    'Bambu PVA': 'GFS04',
+  };
+
+  it('files every preset under its own Bambu filament id', () => {
+    const options = buildFilamentOptions([], new Set());
+    expect(Object.fromEntries(options.map((o) => [o.name, o.code]))).toEqual(BAMBU_IDS);
+  });
+});

+ 19 - 17
frontend/src/components/spool-form/utils.ts

@@ -64,25 +64,27 @@ export async function fetchPrinterCalibrations(
   return calibrations;
 }
 
-// Fallback filament presets when cloud is not available
+// Fallback filament presets when cloud is not available. Each code is the
+// filament id Bambu gives that name (the table in backend/app/api/routes/cloud.py).
+// Most of them used to be wrong -- Bambu PLA-CF was filed under GFS00, which is
+// Support W, and the slot it configured would now come out as support (#3559).
 const FALLBACK_PRESETS: FilamentOption[] = [
-  { code: 'GFL00', name: 'Bambu PLA Basic', displayName: 'Bambu PLA Basic', isCustom: false, allCodes: ['GFL00'], source: 'builtin' },
-  { code: 'GFL01', name: 'Bambu PLA Matte', displayName: 'Bambu PLA Matte', isCustom: false, allCodes: ['GFL01'], source: 'builtin' },
-  { code: 'GFL05', name: 'Generic PLA', displayName: 'Generic PLA', isCustom: false, allCodes: ['GFL05'], source: 'builtin' },
+  { code: 'GFA00', name: 'Bambu PLA Basic', displayName: 'Bambu PLA Basic', isCustom: false, allCodes: ['GFA00'], source: 'builtin' },
+  { code: 'GFA01', name: 'Bambu PLA Matte', displayName: 'Bambu PLA Matte', isCustom: false, allCodes: ['GFA01'], source: 'builtin' },
+  { code: 'GFL99', name: 'Generic PLA', displayName: 'Generic PLA', isCustom: false, allCodes: ['GFL99'], source: 'builtin' },
   { code: 'GFG00', name: 'Bambu PETG Basic', displayName: 'Bambu PETG Basic', isCustom: false, allCodes: ['GFG00'], source: 'builtin' },
-  { code: 'GFG05', name: 'Generic PETG', displayName: 'Generic PETG', isCustom: false, allCodes: ['GFG05'], source: 'builtin' },
-  { code: 'GFB00', name: 'Bambu ABS Basic', displayName: 'Bambu ABS Basic', isCustom: false, allCodes: ['GFB00'], source: 'builtin' },
-  { code: 'GFB05', name: 'Generic ABS', displayName: 'Generic ABS', isCustom: false, allCodes: ['GFB05'], source: 'builtin' },
-  { code: 'GFA00', name: 'Bambu ASA Basic', displayName: 'Bambu ASA Basic', isCustom: false, allCodes: ['GFA00'], source: 'builtin' },
-  { code: 'GFU00', name: 'Bambu TPU 95A', displayName: 'Bambu TPU 95A', isCustom: false, allCodes: ['GFU00'], source: 'builtin' },
-  { code: 'GFU05', name: 'Generic TPU', displayName: 'Generic TPU', isCustom: false, allCodes: ['GFU05'], source: 'builtin' },
-  { code: 'GFC00', name: 'Bambu PC Basic', displayName: 'Bambu PC Basic', isCustom: false, allCodes: ['GFC00'], source: 'builtin' },
-  { code: 'GFN00', name: 'Bambu PA Basic', displayName: 'Bambu PA Basic', isCustom: false, allCodes: ['GFN00'], source: 'builtin' },
-  { code: 'GFN05', name: 'Generic PA', displayName: 'Generic PA', isCustom: false, allCodes: ['GFN05'], source: 'builtin' },
-  { code: 'GFS00', name: 'Bambu PLA-CF', displayName: 'Bambu PLA-CF', isCustom: false, allCodes: ['GFS00'], source: 'builtin' },
-  { code: 'GFT00', name: 'Bambu PETG-CF', displayName: 'Bambu PETG-CF', isCustom: false, allCodes: ['GFT00'], source: 'builtin' },
-  { code: 'GFNC0', name: 'Bambu PA-CF', displayName: 'Bambu PA-CF', isCustom: false, allCodes: ['GFNC0'], source: 'builtin' },
-  { code: 'GFV00', name: 'Bambu PVA', displayName: 'Bambu PVA', isCustom: false, allCodes: ['GFV00'], source: 'builtin' },
+  { code: 'GFG99', name: 'Generic PETG', displayName: 'Generic PETG', isCustom: false, allCodes: ['GFG99'], source: 'builtin' },
+  { code: 'GFB00', name: 'Bambu ABS', displayName: 'Bambu ABS', isCustom: false, allCodes: ['GFB00'], source: 'builtin' },
+  { code: 'GFB99', name: 'Generic ABS', displayName: 'Generic ABS', isCustom: false, allCodes: ['GFB99'], source: 'builtin' },
+  { code: 'GFB01', name: 'Bambu ASA', displayName: 'Bambu ASA', isCustom: false, allCodes: ['GFB01'], source: 'builtin' },
+  { code: 'GFU01', name: 'Bambu TPU 95A', displayName: 'Bambu TPU 95A', isCustom: false, allCodes: ['GFU01'], source: 'builtin' },
+  { code: 'GFU99', name: 'Generic TPU', displayName: 'Generic TPU', isCustom: false, allCodes: ['GFU99'], source: 'builtin' },
+  { code: 'GFC00', name: 'Bambu PC', displayName: 'Bambu PC', isCustom: false, allCodes: ['GFC00'], source: 'builtin' },
+  { code: 'GFN99', name: 'Generic PA', displayName: 'Generic PA', isCustom: false, allCodes: ['GFN99'], source: 'builtin' },
+  { code: 'GFA50', name: 'Bambu PLA-CF', displayName: 'Bambu PLA-CF', isCustom: false, allCodes: ['GFA50'], source: 'builtin' },
+  { code: 'GFG50', name: 'Bambu PETG-CF', displayName: 'Bambu PETG-CF', isCustom: false, allCodes: ['GFG50'], source: 'builtin' },
+  { code: 'GFN03', name: 'Bambu PA-CF', displayName: 'Bambu PA-CF', isCustom: false, allCodes: ['GFN03'], source: 'builtin' },
+  { code: 'GFS04', name: 'Bambu PVA', displayName: 'Bambu PVA', isCustom: false, allCodes: ['GFS04'], source: 'builtin' },
 ];
 
 // Parse a slicer preset name to extract brand, material, and variant