test_scheduler_ams_mapping.py 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094
  1. """Tests for the AMS mapping computation in the print scheduler."""
  2. import io
  3. import json
  4. import zipfile
  5. import pytest
  6. from backend.app.services.print_scheduler import PrintScheduler
  7. from backend.app.utils.threemf_tools import extract_nozzle_mapping_from_3mf
  8. class TestSchedulerAmsMappingHelpers:
  9. """Test the AMS mapping helper methods in PrintScheduler."""
  10. @pytest.fixture
  11. def scheduler(self):
  12. return PrintScheduler()
  13. def test_normalize_color_with_hash(self, scheduler):
  14. """Color with hash should return #RRGGBB format."""
  15. result = scheduler._normalize_color("#FF5500")
  16. assert result == "#FF5500"
  17. def test_normalize_color_without_hash(self, scheduler):
  18. """Color without hash should add hash prefix."""
  19. result = scheduler._normalize_color("FF5500")
  20. assert result == "#FF5500"
  21. def test_normalize_color_with_alpha(self, scheduler):
  22. """Color with alpha channel should strip it."""
  23. result = scheduler._normalize_color("FF5500AA")
  24. assert result == "#FF5500"
  25. def test_normalize_color_none(self, scheduler):
  26. """None color should return default gray."""
  27. result = scheduler._normalize_color(None)
  28. assert result == "#808080"
  29. def test_normalize_color_empty(self, scheduler):
  30. """Empty color should return default gray."""
  31. result = scheduler._normalize_color("")
  32. assert result == "#808080"
  33. def test_normalize_color_for_compare(self, scheduler):
  34. """Color for compare should be lowercase without hash."""
  35. result = scheduler._normalize_color_for_compare("#FF5500")
  36. assert result == "ff5500"
  37. def test_normalize_color_for_compare_with_alpha(self, scheduler):
  38. """Alpha channel should be stripped for comparison."""
  39. result = scheduler._normalize_color_for_compare("#FF5500AA")
  40. assert result == "ff5500"
  41. def test_colors_are_similar_exact_match(self, scheduler):
  42. """Exact same colors should be similar."""
  43. assert scheduler._colors_are_similar("#FF5500", "#FF5500") is True
  44. def test_colors_are_similar_within_threshold(self, scheduler):
  45. """Colors within threshold should be similar."""
  46. # Red difference of 10, well within default threshold of 40
  47. assert scheduler._colors_are_similar("#FF5500", "#F55500") is True
  48. def test_colors_are_similar_outside_threshold(self, scheduler):
  49. """Colors outside threshold should not be similar."""
  50. # Red: FF (255) vs 00 (0) = 255 difference
  51. assert scheduler._colors_are_similar("#FF0000", "#00FF00") is False
  52. def test_colors_are_similar_none_colors(self, scheduler):
  53. """None colors should not be similar."""
  54. assert scheduler._colors_are_similar(None, "#FF5500") is False
  55. assert scheduler._colors_are_similar("#FF5500", None) is False
  56. class TestBuildLoadedFilaments:
  57. """Test the _build_loaded_filaments method."""
  58. @pytest.fixture
  59. def scheduler(self):
  60. return PrintScheduler()
  61. def test_build_loaded_filaments_empty_status(self, scheduler):
  62. """Empty status should return empty list."""
  63. class MockStatus:
  64. raw_data = {}
  65. result = scheduler._build_loaded_filaments(MockStatus())
  66. assert result == []
  67. def test_build_loaded_filaments_with_ams(self, scheduler):
  68. """Should extract filaments from AMS units."""
  69. class MockStatus:
  70. raw_data = {
  71. "ams": [
  72. {
  73. "id": 0,
  74. "tray": [
  75. {"id": 0, "tray_type": "PLA", "tray_color": "FF0000"},
  76. {"id": 1, "tray_type": "PETG", "tray_color": "00FF00"},
  77. ],
  78. }
  79. ]
  80. }
  81. result = scheduler._build_loaded_filaments(MockStatus())
  82. assert len(result) == 2
  83. # First filament
  84. assert result[0]["type"] == "PLA"
  85. assert result[0]["color"] == "#FF0000"
  86. assert result[0]["ams_id"] == 0
  87. assert result[0]["tray_id"] == 0
  88. assert result[0]["global_tray_id"] == 0 # 0 * 4 + 0
  89. # Second filament
  90. assert result[1]["type"] == "PETG"
  91. assert result[1]["global_tray_id"] == 1 # 0 * 4 + 1
  92. def test_build_loaded_filaments_with_ht_ams(self, scheduler):
  93. """AMS-HT (single tray) should be marked as is_ht."""
  94. class MockStatus:
  95. raw_data = {
  96. "ams": [
  97. {
  98. "id": 128,
  99. "tray": [{"id": 0, "tray_type": "PLA-CF", "tray_color": "000000"}],
  100. }
  101. ]
  102. }
  103. result = scheduler._build_loaded_filaments(MockStatus())
  104. assert len(result) == 1
  105. assert result[0]["is_ht"] is True
  106. assert result[0]["global_tray_id"] == 128 # AMS-HT uses ams_id directly
  107. def test_build_loaded_filaments_with_external(self, scheduler):
  108. """Should include external spool."""
  109. class MockStatus:
  110. raw_data = {"vt_tray": [{"tray_type": "TPU", "tray_color": "0000FF"}]}
  111. result = scheduler._build_loaded_filaments(MockStatus())
  112. assert len(result) == 1
  113. assert result[0]["type"] == "TPU"
  114. assert result[0]["is_external"] is True
  115. assert result[0]["global_tray_id"] == 254
  116. def test_build_loaded_filaments_skips_empty_trays(self, scheduler):
  117. """Trays without tray_type should be skipped."""
  118. class MockStatus:
  119. raw_data = {
  120. "ams": [
  121. {
  122. "id": 0,
  123. "tray": [
  124. {"id": 0, "tray_type": "PLA", "tray_color": "FF0000"},
  125. {"id": 1, "tray_type": "", "tray_color": ""}, # Empty
  126. {"id": 2}, # No tray_type key
  127. ],
  128. }
  129. ]
  130. }
  131. result = scheduler._build_loaded_filaments(MockStatus())
  132. assert len(result) == 1
  133. assert result[0]["type"] == "PLA"
  134. class TestMatchFilamentsToSlots:
  135. """Test the _match_filaments_to_slots method."""
  136. @pytest.fixture
  137. def scheduler(self):
  138. return PrintScheduler()
  139. def test_match_empty_required(self, scheduler):
  140. """Empty required list should return None."""
  141. result = scheduler._match_filaments_to_slots([], [])
  142. assert result is None
  143. def test_match_exact_color(self, scheduler):
  144. """Should prefer exact color match."""
  145. required = [{"slot_id": 1, "type": "PLA", "color": "#FF0000"}]
  146. loaded = [
  147. {"type": "PLA", "color": "#00FF00", "global_tray_id": 0}, # Wrong color
  148. {"type": "PLA", "color": "#FF0000", "global_tray_id": 1}, # Exact match
  149. ]
  150. result = scheduler._match_filaments_to_slots(required, loaded)
  151. assert result == [1] # Should pick tray 1 (exact color match)
  152. def test_match_similar_color(self, scheduler):
  153. """Should match similar colors when no exact match."""
  154. required = [{"slot_id": 1, "type": "PLA", "color": "#FF5500"}]
  155. loaded = [
  156. {"type": "PLA", "color": "#FF5510", "global_tray_id": 0}, # Similar
  157. ]
  158. result = scheduler._match_filaments_to_slots(required, loaded)
  159. assert result == [0]
  160. def test_match_type_only(self, scheduler):
  161. """Should match by type when colors don't match."""
  162. required = [{"slot_id": 1, "type": "PLA", "color": "#FF0000"}]
  163. loaded = [
  164. {"type": "PLA", "color": "#0000FF", "global_tray_id": 5}, # Type match, color way off
  165. ]
  166. result = scheduler._match_filaments_to_slots(required, loaded)
  167. assert result == [5]
  168. def test_match_no_match_returns_minus_one(self, scheduler):
  169. """Unmatched filaments should have -1 in mapping."""
  170. required = [{"slot_id": 1, "type": "PLA", "color": "#FF0000"}]
  171. loaded = [
  172. {"type": "PETG", "color": "#FF0000", "global_tray_id": 0}, # Wrong type
  173. ]
  174. result = scheduler._match_filaments_to_slots(required, loaded)
  175. assert result == [-1]
  176. def test_match_multiple_filaments(self, scheduler):
  177. """Should match multiple filaments correctly."""
  178. required = [
  179. {"slot_id": 1, "type": "PLA", "color": "#FF0000"},
  180. {"slot_id": 2, "type": "PETG", "color": "#00FF00"},
  181. ]
  182. loaded = [
  183. {"type": "PLA", "color": "#FF0000", "global_tray_id": 0},
  184. {"type": "PETG", "color": "#00FF00", "global_tray_id": 1},
  185. ]
  186. result = scheduler._match_filaments_to_slots(required, loaded)
  187. assert result == [0, 1]
  188. def test_match_avoids_duplicate_assignment(self, scheduler):
  189. """Same tray should not be assigned to multiple slots."""
  190. required = [
  191. {"slot_id": 1, "type": "PLA", "color": "#FF0000"},
  192. {"slot_id": 2, "type": "PLA", "color": "#FF0000"}, # Same requirements
  193. ]
  194. loaded = [
  195. {"type": "PLA", "color": "#FF0000", "global_tray_id": 0}, # Only one PLA
  196. ]
  197. result = scheduler._match_filaments_to_slots(required, loaded)
  198. # First slot gets the match, second slot gets -1
  199. assert result == [0, -1]
  200. def test_match_h2d_pro_ams_ids(self, scheduler):
  201. """Should work with H2D Pro's high AMS IDs (128+)."""
  202. required = [{"slot_id": 1, "type": "PLA", "color": "#FF0000"}]
  203. loaded = [
  204. {"type": "PLA", "color": "#FF0000", "global_tray_id": 512}, # AMS 128, slot 0
  205. ]
  206. result = scheduler._match_filaments_to_slots(required, loaded)
  207. assert result == [512]
  208. def test_match_external_spool(self, scheduler):
  209. """Should match external spool with ID 254."""
  210. required = [{"slot_id": 1, "type": "TPU", "color": "#0000FF"}]
  211. loaded = [
  212. {"type": "TPU", "color": "#0000FF", "global_tray_id": 254, "is_external": True},
  213. ]
  214. result = scheduler._match_filaments_to_slots(required, loaded)
  215. assert result == [254]
  216. def test_match_by_tray_info_idx_priority(self, scheduler):
  217. """tray_info_idx match should have highest priority over color match."""
  218. required = [{"slot_id": 1, "type": "PLA", "color": "#000000", "tray_info_idx": "GFA00"}]
  219. loaded = [
  220. {
  221. "type": "PLA",
  222. "color": "#000000",
  223. "global_tray_id": 0,
  224. "tray_info_idx": "GFB00",
  225. }, # Same color, different spool
  226. {
  227. "type": "PLA",
  228. "color": "#000000",
  229. "global_tray_id": 1,
  230. "tray_info_idx": "GFA00",
  231. }, # Same color, exact spool
  232. {
  233. "type": "PLA",
  234. "color": "#000000",
  235. "global_tray_id": 2,
  236. "tray_info_idx": "GFC00",
  237. }, # Same color, different spool
  238. ]
  239. result = scheduler._match_filaments_to_slots(required, loaded)
  240. assert result == [1] # Should pick tray 1 (exact tray_info_idx match)
  241. def test_match_by_tray_info_idx_with_different_colors(self, scheduler):
  242. """tray_info_idx match should work even if colors differ slightly."""
  243. required = [{"slot_id": 1, "type": "PLA", "color": "#000000", "tray_info_idx": "P4d64437"}]
  244. loaded = [
  245. {"type": "PLA", "color": "#000000", "global_tray_id": 0, "tray_info_idx": ""}, # No idx
  246. {
  247. "type": "PLA",
  248. "color": "#000010",
  249. "global_tray_id": 3,
  250. "tray_info_idx": "P4d64437",
  251. }, # Exact spool (slightly different color reported)
  252. ]
  253. result = scheduler._match_filaments_to_slots(required, loaded)
  254. assert result == [3] # Should pick tray 3 (exact tray_info_idx match)
  255. def test_match_fallback_to_color_when_no_tray_info_idx(self, scheduler):
  256. """Should fall back to color matching when tray_info_idx is empty."""
  257. required = [{"slot_id": 1, "type": "PLA", "color": "#FF0000", "tray_info_idx": ""}]
  258. loaded = [
  259. {"type": "PLA", "color": "#00FF00", "global_tray_id": 0, "tray_info_idx": "GFA00"},
  260. {"type": "PLA", "color": "#FF0000", "global_tray_id": 1, "tray_info_idx": "GFB00"}, # Color match
  261. ]
  262. result = scheduler._match_filaments_to_slots(required, loaded)
  263. assert result == [1] # Should pick tray 1 (color match)
  264. def test_match_fallback_to_color_when_no_matching_tray_info_idx(self, scheduler):
  265. """Should fall back to color when tray_info_idx doesn't match any loaded spool."""
  266. required = [{"slot_id": 1, "type": "PLA", "color": "#FF0000", "tray_info_idx": "OLD_SPOOL"}]
  267. loaded = [
  268. {
  269. "type": "PLA",
  270. "color": "#FF0000",
  271. "global_tray_id": 0,
  272. "tray_info_idx": "NEW_SPOOL",
  273. }, # Different idx but same color
  274. ]
  275. result = scheduler._match_filaments_to_slots(required, loaded)
  276. assert result == [0] # Should fall back to color match
  277. def test_match_multiple_same_color_with_tray_info_idx(self, scheduler):
  278. """Multiple identical filaments should be matched by tray_info_idx (H2D Pro scenario)."""
  279. # This is the exact scenario from issue #245 - 3 black PLA spools
  280. required = [
  281. {"slot_id": 1, "type": "PLA", "color": "#000000", "tray_info_idx": "GFA03"}, # Wants tray 3
  282. ]
  283. loaded = [
  284. {"type": "PLA", "color": "#000000", "global_tray_id": 0, "tray_info_idx": "GFA00"}, # Tray 0
  285. {"type": "PLA", "color": "#000000", "global_tray_id": 1, "tray_info_idx": "GFA01"}, # Tray 1
  286. {"type": "PLA", "color": "#000000", "global_tray_id": 2, "tray_info_idx": "GFA02"}, # Tray 2
  287. {
  288. "type": "PLA",
  289. "color": "#000000",
  290. "global_tray_id": 3,
  291. "tray_info_idx": "GFA03",
  292. }, # Tray 3 - the one we want
  293. ]
  294. result = scheduler._match_filaments_to_slots(required, loaded)
  295. assert result == [3] # Should pick tray 3, not tray 0
  296. def test_match_tray_info_idx_not_reused(self, scheduler):
  297. """tray_info_idx matched trays should not be reused for other slots."""
  298. required = [
  299. {"slot_id": 1, "type": "PLA", "color": "#000000", "tray_info_idx": "GFA00"},
  300. {"slot_id": 2, "type": "PLA", "color": "#000000", "tray_info_idx": "GFA01"},
  301. ]
  302. loaded = [
  303. {"type": "PLA", "color": "#000000", "global_tray_id": 0, "tray_info_idx": "GFA00"},
  304. {"type": "PLA", "color": "#000000", "global_tray_id": 1, "tray_info_idx": "GFA01"},
  305. ]
  306. result = scheduler._match_filaments_to_slots(required, loaded)
  307. assert result == [0, 1] # Each slot gets its specific tray
  308. def test_match_non_unique_tray_info_idx_uses_color(self, scheduler):
  309. """Non-unique tray_info_idx should fall back to color matching.
  310. This is the scenario where multiple trays have the same tray_info_idx
  311. (e.g., two spools of generic PLA both have GFA00). The color should
  312. be used as tiebreaker instead of just picking the first match.
  313. """
  314. # User sliced with green PLA (tray_info_idx=GFA00)
  315. # Two trays have GFA00: tray 3 (white) and tray 4 (green)
  316. # Should pick tray 4 because the color matches
  317. required = [
  318. {"slot_id": 2, "type": "PLA", "color": "#00FF00", "tray_info_idx": "GFA00"}, # Green PLA
  319. ]
  320. loaded = [
  321. {"type": "PLA", "color": "#FFFFFF", "global_tray_id": 3, "tray_info_idx": "GFA00"}, # White PLA
  322. {"type": "PLA", "color": "#00FF00", "global_tray_id": 4, "tray_info_idx": "GFA00"}, # Green PLA
  323. ]
  324. result = scheduler._match_filaments_to_slots(required, loaded)
  325. assert result == [-1, 4] # Should pick tray 4 (color match), not tray 3 (first match)
  326. def test_match_non_unique_tray_info_idx_same_color(self, scheduler):
  327. """Non-unique tray_info_idx with identical colors picks first match.
  328. When multiple trays have the same tray_info_idx AND same color,
  329. there's no way to differentiate, so first match is used.
  330. """
  331. required = [
  332. {"slot_id": 2, "type": "PLA", "color": "#FFFFFF", "tray_info_idx": "GFA00"},
  333. ]
  334. loaded = [
  335. {"type": "PLA", "color": "#FFFFFF", "global_tray_id": 3, "tray_info_idx": "GFA00"},
  336. {"type": "PLA", "color": "#FFFFFF", "global_tray_id": 4, "tray_info_idx": "GFA00"},
  337. ]
  338. result = scheduler._match_filaments_to_slots(required, loaded)
  339. # Both have same color, so first is used
  340. assert result == [-1, 3]
  341. class TestBuildLoadedFilamentsTrayInfoIdx:
  342. """Test tray_info_idx extraction in _build_loaded_filaments."""
  343. @pytest.fixture
  344. def scheduler(self):
  345. return PrintScheduler()
  346. def test_build_loaded_filaments_includes_tray_info_idx(self, scheduler):
  347. """Should extract tray_info_idx from AMS trays."""
  348. class MockStatus:
  349. raw_data = {
  350. "ams": [
  351. {
  352. "id": 0,
  353. "tray": [
  354. {"id": 0, "tray_type": "PLA", "tray_color": "000000", "tray_info_idx": "GFA00"},
  355. {"id": 1, "tray_type": "PLA", "tray_color": "000000", "tray_info_idx": "GFA01"},
  356. ],
  357. }
  358. ]
  359. }
  360. result = scheduler._build_loaded_filaments(MockStatus())
  361. assert len(result) == 2
  362. assert result[0]["tray_info_idx"] == "GFA00"
  363. assert result[1]["tray_info_idx"] == "GFA01"
  364. def test_build_loaded_filaments_empty_tray_info_idx(self, scheduler):
  365. """Missing tray_info_idx should default to empty string."""
  366. class MockStatus:
  367. raw_data = {
  368. "ams": [
  369. {
  370. "id": 0,
  371. "tray": [
  372. {"id": 0, "tray_type": "PLA", "tray_color": "FF0000"}, # No tray_info_idx
  373. ],
  374. }
  375. ]
  376. }
  377. result = scheduler._build_loaded_filaments(MockStatus())
  378. assert len(result) == 1
  379. assert result[0]["tray_info_idx"] == ""
  380. def test_build_loaded_filaments_external_spool_tray_info_idx(self, scheduler):
  381. """Should extract tray_info_idx from external spool."""
  382. class MockStatus:
  383. raw_data = {"vt_tray": [{"tray_type": "TPU", "tray_color": "0000FF", "tray_info_idx": "P4d64437"}]}
  384. result = scheduler._build_loaded_filaments(MockStatus())
  385. assert len(result) == 1
  386. assert result[0]["tray_info_idx"] == "P4d64437"
  387. assert result[0]["is_external"] is True
  388. def _make_3mf_zip(
  389. project_settings: dict | None = None,
  390. slice_info_xml: str | None = None,
  391. ) -> zipfile.ZipFile:
  392. """Create an in-memory ZipFile mimicking a 3MF with project_settings.config."""
  393. buf = io.BytesIO()
  394. with zipfile.ZipFile(buf, "w") as zf:
  395. if project_settings is not None:
  396. zf.writestr("Metadata/project_settings.config", json.dumps(project_settings))
  397. if slice_info_xml is not None:
  398. zf.writestr("Metadata/slice_info.config", slice_info_xml)
  399. buf.seek(0)
  400. return zipfile.ZipFile(buf, "r")
  401. class TestExtractNozzleMappingFrom3mf:
  402. """Test the extract_nozzle_mapping_from_3mf utility."""
  403. def test_group_id_priority_over_filament_nozzle_map(self):
  404. """group_id from slice_info should override filament_nozzle_map from project_settings.
  405. Real-world scenario: "Auto For Flush" mode sets filament_nozzle_map all to 0
  406. (user preference) but the actual assignment in slice_info has different group_ids.
  407. """
  408. # filament_nozzle_map says all on slicer ext 0 → MQTT ext 1 (LEFT)
  409. # But slice_info group_id says slot 6 → group 0 (LEFT), slot 12 → group 1 (RIGHT)
  410. slice_info = """<?xml version="1.0" encoding="UTF-8"?>
  411. <config>
  412. <plate>
  413. <filament id="6" type="PLA" color="#56B7E6" used_g="1.84" group_id="0"/>
  414. <filament id="12" type="PLA" color="#B39B84" used_g="1.76" group_id="1"/>
  415. </plate>
  416. </config>"""
  417. zf = _make_3mf_zip(
  418. {
  419. "filament_nozzle_map": ["0"] * 12,
  420. "physical_extruder_map": ["1", "0"],
  421. },
  422. slice_info_xml=slice_info,
  423. )
  424. result = extract_nozzle_mapping_from_3mf(zf)
  425. # group_id 0 → physical_extruder_map[0] = 1 (LEFT)
  426. # group_id 1 → physical_extruder_map[1] = 0 (RIGHT)
  427. assert result == {6: 1, 12: 0}
  428. zf.close()
  429. def test_fallback_to_filament_nozzle_map_without_group_id(self):
  430. """Should fall back to filament_nozzle_map when slice_info has no group_id."""
  431. slice_info = """<?xml version="1.0" encoding="UTF-8"?>
  432. <config>
  433. <plate>
  434. <filament id="1" type="PLA" color="#FF0000" used_g="5.0"/>
  435. </plate>
  436. </config>"""
  437. zf = _make_3mf_zip(
  438. {
  439. "filament_nozzle_map": ["0", "1", "0"],
  440. "physical_extruder_map": ["0", "1"],
  441. },
  442. slice_info_xml=slice_info,
  443. )
  444. result = extract_nozzle_mapping_from_3mf(zf)
  445. assert result == {1: 0, 2: 1, 3: 0}
  446. zf.close()
  447. def test_fallback_to_filament_nozzle_map_without_slice_info(self):
  448. """Should fall back to filament_nozzle_map when no slice_info.config exists."""
  449. zf = _make_3mf_zip(
  450. {
  451. "filament_nozzle_map": ["0", "1", "0"],
  452. "physical_extruder_map": ["0", "1"],
  453. }
  454. )
  455. result = extract_nozzle_mapping_from_3mf(zf)
  456. assert result == {1: 0, 2: 1, 3: 0}
  457. zf.close()
  458. def test_single_nozzle_returns_none(self):
  459. """Single physical_extruder_map entry should return None (single-nozzle)."""
  460. zf = _make_3mf_zip(
  461. {
  462. "filament_nozzle_map": ["0", "0", "0"],
  463. "physical_extruder_map": ["0"],
  464. }
  465. )
  466. result = extract_nozzle_mapping_from_3mf(zf)
  467. assert result is None
  468. zf.close()
  469. def test_missing_project_settings_returns_none(self):
  470. """Missing project_settings.config should return None."""
  471. zf = _make_3mf_zip(None)
  472. result = extract_nozzle_mapping_from_3mf(zf)
  473. assert result is None
  474. zf.close()
  475. def test_missing_fields_returns_none(self):
  476. """Missing physical_extruder_map should return None."""
  477. zf = _make_3mf_zip({"some_other_key": "value"})
  478. result = extract_nozzle_mapping_from_3mf(zf)
  479. assert result is None
  480. zf.close()
  481. def test_physical_extruder_map_remapping(self):
  482. """Should apply physical_extruder_map to remap slicer extruder to MQTT extruder."""
  483. # Slicer ext 0 -> MQTT ext 1, slicer ext 1 -> MQTT ext 0
  484. zf = _make_3mf_zip(
  485. {
  486. "filament_nozzle_map": ["0", "1"],
  487. "physical_extruder_map": ["1", "0"],
  488. }
  489. )
  490. result = extract_nozzle_mapping_from_3mf(zf)
  491. assert result == {1: 1, 2: 0}
  492. zf.close()
  493. def test_single_active_extruder_maps_all_slots(self):
  494. """When only one extruder has nozzles installed, all filaments map to it.
  495. H2C scenario: left extruder has no nozzles (Standard#0|High Flow#0),
  496. right extruder has one Standard nozzle (Standard#1). Print uses only
  497. the right extruder, so all filaments should map to physical extruder 0.
  498. """
  499. slice_info = """<?xml version="1.0" encoding="UTF-8"?>
  500. <config>
  501. <plate>
  502. <filament id="1" type="PLA" color="#FF0000" used_g="5.0" group_id="0"/>
  503. <filament id="2" type="PLA" color="#00FF00" used_g="3.0" group_id="0"/>
  504. </plate>
  505. </config>"""
  506. zf = _make_3mf_zip(
  507. {
  508. "physical_extruder_map": ["1", "0"],
  509. "extruder_nozzle_stats": ["Standard#0|High Flow#0", "Standard#1"],
  510. },
  511. slice_info_xml=slice_info,
  512. )
  513. result = extract_nozzle_mapping_from_3mf(zf)
  514. # Only extruder index 1 is active → physical_extruder_map[1] = 0 (RIGHT)
  515. assert result == {1: 0, 2: 0}
  516. zf.close()
  517. def test_two_active_extruders_falls_through(self):
  518. """When both extruders have nozzles, the single-active shortcut is skipped.
  519. Should fall through to the normal group_id-based mapping.
  520. """
  521. slice_info = """<?xml version="1.0" encoding="UTF-8"?>
  522. <config>
  523. <plate>
  524. <filament id="1" type="PLA" color="#FF0000" used_g="5.0" group_id="0"/>
  525. <filament id="2" type="PLA" color="#00FF00" used_g="3.0" group_id="1"/>
  526. </plate>
  527. </config>"""
  528. zf = _make_3mf_zip(
  529. {
  530. "physical_extruder_map": ["1", "0"],
  531. "extruder_nozzle_stats": ["Standard#1", "High Flow#1"],
  532. },
  533. slice_info_xml=slice_info,
  534. )
  535. result = extract_nozzle_mapping_from_3mf(zf)
  536. # Both active → normal group_id mapping: group 0 → phys 1, group 1 → phys 0
  537. assert result == {1: 1, 2: 0}
  538. zf.close()
  539. def test_missing_extruder_nozzle_stats_falls_through(self):
  540. """When extruder_nozzle_stats is absent, the single-active shortcut is skipped.
  541. Should fall through to the normal group_id-based mapping.
  542. """
  543. slice_info = """<?xml version="1.0" encoding="UTF-8"?>
  544. <config>
  545. <plate>
  546. <filament id="1" type="PLA" color="#FF0000" used_g="5.0" group_id="0"/>
  547. <filament id="2" type="PLA" color="#00FF00" used_g="3.0" group_id="1"/>
  548. </plate>
  549. </config>"""
  550. zf = _make_3mf_zip(
  551. {
  552. "physical_extruder_map": ["1", "0"],
  553. },
  554. slice_info_xml=slice_info,
  555. )
  556. result = extract_nozzle_mapping_from_3mf(zf)
  557. # No extruder_nozzle_stats → normal group_id mapping
  558. assert result == {1: 1, 2: 0}
  559. zf.close()
  560. def test_single_active_extruder_no_slice_info_returns_none(self):
  561. """Single active extruder but no slice_info should return None."""
  562. zf = _make_3mf_zip(
  563. {
  564. "physical_extruder_map": ["1", "0"],
  565. "extruder_nozzle_stats": ["Standard#0", "Standard#1"],
  566. },
  567. )
  568. result = extract_nozzle_mapping_from_3mf(zf)
  569. assert result is None
  570. zf.close()
  571. class TestNozzleAwareMapping:
  572. """Test nozzle-aware filament matching in the print scheduler."""
  573. @pytest.fixture
  574. def scheduler(self):
  575. return PrintScheduler()
  576. def test_dual_nozzle_matching(self, scheduler):
  577. """Filaments assigned to different nozzles should match to correct AMS units."""
  578. required = [
  579. {"slot_id": 1, "type": "PLA", "color": "#FF0000", "nozzle_id": 0}, # Right nozzle
  580. {"slot_id": 2, "type": "PLA", "color": "#00FF00", "nozzle_id": 1}, # Left nozzle
  581. ]
  582. loaded = [
  583. {"type": "PLA", "color": "#00FF00", "global_tray_id": 0, "extruder_id": 0}, # AMS0 on right
  584. {"type": "PLA", "color": "#FF0000", "global_tray_id": 4, "extruder_id": 1}, # AMS1 on left
  585. ]
  586. # Without nozzle filtering, slot 1 (red, right) would match tray 4 (red, left) by color.
  587. # With nozzle filtering, slot 1 (right nozzle) can only use tray 0 (right extruder),
  588. # and slot 2 (left nozzle) can only use tray 4 (left extruder).
  589. result = scheduler._match_filaments_to_slots(required, loaded)
  590. assert result == [0, 4]
  591. def test_nozzle_hard_filter_no_fallback(self, scheduler):
  592. """Hard filter: no fallback to wrong nozzle when target nozzle has no trays."""
  593. required = [
  594. {"slot_id": 1, "type": "PLA", "color": "#FF0000", "nozzle_id": 0}, # Right nozzle
  595. ]
  596. loaded = [
  597. # Only a tray on the left nozzle, none on right
  598. {"type": "PLA", "color": "#FF0000", "global_tray_id": 4, "extruder_id": 1},
  599. ]
  600. # No trays on extruder 0 — hard filter returns -1, no cross-nozzle fallback
  601. result = scheduler._match_filaments_to_slots(required, loaded)
  602. assert result == [-1]
  603. def test_no_nozzle_id_skips_filtering(self, scheduler):
  604. """When nozzle_id is None, no nozzle filtering should be applied."""
  605. required = [
  606. {"slot_id": 1, "type": "PLA", "color": "#FF0000"}, # No nozzle_id
  607. ]
  608. loaded = [
  609. {"type": "PLA", "color": "#FF0000", "global_tray_id": 0, "extruder_id": 0},
  610. {"type": "PLA", "color": "#FF0000", "global_tray_id": 4, "extruder_id": 1},
  611. ]
  612. # Should match first available (tray 0) regardless of extruder
  613. result = scheduler._match_filaments_to_slots(required, loaded)
  614. assert result == [0]
  615. def test_extruder_id_in_loaded_filaments(self, scheduler):
  616. """_build_loaded_filaments should include extruder_id from ams_extruder_map."""
  617. class MockStatus:
  618. raw_data = {
  619. "ams": [
  620. {"id": 0, "tray": [{"id": 0, "tray_type": "PLA", "tray_color": "FF0000"}]},
  621. {"id": 1, "tray": [{"id": 0, "tray_type": "PLA", "tray_color": "00FF00"}]},
  622. ],
  623. "ams_extruder_map": {"0": 0, "1": 1},
  624. }
  625. result = scheduler._build_loaded_filaments(MockStatus())
  626. assert len(result) == 2
  627. assert result[0]["extruder_id"] == 0
  628. assert result[1]["extruder_id"] == 1
  629. def test_extruder_id_none_without_map(self, scheduler):
  630. """extruder_id should be None when ams_extruder_map is absent."""
  631. class MockStatus:
  632. raw_data = {
  633. "ams": [
  634. {"id": 0, "tray": [{"id": 0, "tray_type": "PLA", "tray_color": "FF0000"}]},
  635. ]
  636. }
  637. result = scheduler._build_loaded_filaments(MockStatus())
  638. assert len(result) == 1
  639. assert result[0]["extruder_id"] is None
  640. def test_external_spool_extruder_id(self, scheduler):
  641. """External spool 254 (Ext-L) should have extruder_id=1 (LEFT) when ams_extruder_map exists."""
  642. class MockStatus:
  643. raw_data = {
  644. "vt_tray": [{"tray_type": "TPU", "tray_color": "0000FF"}],
  645. "ams_extruder_map": {"0": 0},
  646. }
  647. result = scheduler._build_loaded_filaments(MockStatus())
  648. assert len(result) == 1
  649. # Default vt_tray id=254 → Ext-L → LEFT nozzle (extruder 1)
  650. assert result[0]["extruder_id"] == 1
  651. assert result[0]["is_external"] is True
  652. def test_external_spool_no_extruder_map(self, scheduler):
  653. """External spool extruder_id should be None without ams_extruder_map."""
  654. class MockStatus:
  655. raw_data = {"vt_tray": [{"tray_type": "TPU", "tray_color": "0000FF"}]}
  656. result = scheduler._build_loaded_filaments(MockStatus())
  657. assert len(result) == 1
  658. assert result[0]["extruder_id"] is None
  659. def test_dual_nozzle_with_tray_info_idx(self, scheduler):
  660. """Nozzle filtering should work together with tray_info_idx matching."""
  661. required = [
  662. {"slot_id": 1, "type": "PLA", "color": "#000000", "tray_info_idx": "GFA00", "nozzle_id": 0},
  663. {"slot_id": 2, "type": "PLA", "color": "#000000", "tray_info_idx": "GFA01", "nozzle_id": 1},
  664. ]
  665. loaded = [
  666. {"type": "PLA", "color": "#000000", "global_tray_id": 0, "tray_info_idx": "GFA00", "extruder_id": 0},
  667. {"type": "PLA", "color": "#000000", "global_tray_id": 4, "tray_info_idx": "GFA01", "extruder_id": 1},
  668. ]
  669. result = scheduler._match_filaments_to_slots(required, loaded)
  670. assert result == [0, 4]
  671. # ============================================================================
  672. # MODEL-SPECIFIC TESTS: Real data from actual printers
  673. # ============================================================================
  674. def _h2d_raw_data():
  675. """H2D real data fixture (from live API response 2026-02-18).
  676. Configuration:
  677. LEFT nozzle (extruder 1): AMS 0 (4-slot), AMS 2 (4-slot)
  678. RIGHT nozzle (extruder 0): AMS 1 (4-slot), AMS-HT 128 (1-slot, empty)
  679. External: 254 (Ext-L, LEFT), 255 (Ext-R, RIGHT, empty)
  680. ams_extruder_map: {"0": 1, "1": 0, "2": 1, "128": 0}
  681. """
  682. return {
  683. "ams": [
  684. {
  685. "id": 0,
  686. "tray": [
  687. {"id": 0, "tray_type": "PETG", "tray_color": "FFFFFFFF", "tray_info_idx": "GFG02"},
  688. {"id": 1, "tray_type": "PLA", "tray_color": "C8C8C8FF", "tray_info_idx": "GFA06"},
  689. {"id": 2, "tray_type": "PETG", "tray_color": "875718FF", "tray_info_idx": "GFG02"},
  690. {"id": 3, "tray_type": "PLA", "tray_color": "000000FF", "tray_info_idx": "GFA00"},
  691. ],
  692. },
  693. {
  694. "id": 1,
  695. "tray": [
  696. {"id": 0, "tray_type": "PLA", "tray_color": "FFFFFFFF", "tray_info_idx": "GFA00"},
  697. {"id": 1, "tray_type": "PETG", "tray_color": "000000FF", "tray_info_idx": "GFG02"},
  698. {"id": 2, "tray_type": "PLA", "tray_color": "5F6367FF", "tray_info_idx": "GFA06"},
  699. {"id": 3, "tray_type": "PLA", "tray_color": "B39B84FF", "tray_info_idx": "GFA02"},
  700. ],
  701. },
  702. {
  703. "id": 128,
  704. "tray": [{"id": 0}], # AMS-HT, empty
  705. },
  706. {
  707. "id": 2,
  708. "tray": [
  709. {"id": 0, "tray_type": "PLA-S", "tray_color": "FFFFFFFF", "tray_info_idx": "P8aa1726"},
  710. {"id": 1, "tray_type": "PLA", "tray_color": "56B7E6FF", "tray_info_idx": "PFUS9924"},
  711. {"id": 2, "tray_type": "PETG", "tray_color": "6EE53CFF", "tray_info_idx": "GFG02"},
  712. {"id": 3, "tray_type": "PLA", "tray_color": "FF0000FF", "tray_info_idx": "PFUS9ac9"},
  713. ],
  714. },
  715. ],
  716. "vt_tray": [
  717. {"id": 254, "tray_type": "PLA", "tray_color": "000000FF", "tray_info_idx": "P4d64437"},
  718. {"id": 255, "tray_type": "", "tray_color": "00000000"}, # empty
  719. ],
  720. "ams_extruder_map": {"0": 1, "1": 0, "2": 1, "128": 0},
  721. }
  722. def _x1c_raw_data():
  723. """X1C real data fixture (from live API response 2026-02-18).
  724. Configuration:
  725. Single nozzle (extruder 0): AMS 0 (4-slot, all empty), AMS 1 (4-slot, 3 loaded)
  726. External: 254 (single, empty)
  727. ams_extruder_map: {"0": 0, "1": 0} ← NOT empty, all on extruder 0
  728. """
  729. return {
  730. "ams": [
  731. {
  732. "id": 0,
  733. "tray": [
  734. {"id": 0}, # empty
  735. {"id": 1}, # empty
  736. {"id": 2}, # empty
  737. {"id": 3}, # empty
  738. ],
  739. },
  740. {
  741. "id": 1,
  742. "tray": [
  743. {"id": 0}, # empty
  744. {"id": 1, "tray_type": "PLA", "tray_color": "EBCFA6FF", "tray_info_idx": "PFUS22b2"},
  745. {"id": 2, "tray_type": "PLA", "tray_color": "FCECD6FF", "tray_info_idx": "P4d64437"},
  746. {"id": 3, "tray_type": "PLA", "tray_color": "0066FFFF", "tray_info_idx": "P4d64437"},
  747. ],
  748. },
  749. ],
  750. "vt_tray": [
  751. {"id": 254, "tray_type": "", "tray_color": "00000000"}, # empty
  752. ],
  753. "ams_extruder_map": {"0": 0, "1": 0},
  754. }
  755. class TestH2DModel:
  756. """H2D-specific tests with real printer data (dual nozzle, AMS-HT)."""
  757. @pytest.fixture
  758. def scheduler(self):
  759. return PrintScheduler()
  760. def test_build_loaded_filaments_h2d(self, scheduler):
  761. """H2D: correct extruder_id, global_tray_id, AMS-HT handling."""
  762. class MockStatus:
  763. raw_data = _h2d_raw_data()
  764. result = scheduler._build_loaded_filaments(MockStatus())
  765. # Should have 13 loaded filaments (4 + 4 + 0 + 4 + 1 external)
  766. assert len(result) == 13
  767. # AMS 0 trays → extruder 1 (LEFT)
  768. ams0 = [f for f in result if f["ams_id"] == 0]
  769. assert len(ams0) == 4
  770. assert all(f["extruder_id"] == 1 for f in ams0)
  771. assert [f["global_tray_id"] for f in ams0] == [0, 1, 2, 3]
  772. # AMS 1 trays → extruder 0 (RIGHT)
  773. ams1 = [f for f in result if f["ams_id"] == 1]
  774. assert len(ams1) == 4
  775. assert all(f["extruder_id"] == 0 for f in ams1)
  776. assert [f["global_tray_id"] for f in ams1] == [4, 5, 6, 7]
  777. # AMS-HT 128 → empty, should not appear
  778. ams_ht = [f for f in result if f["ams_id"] == 128]
  779. assert len(ams_ht) == 0
  780. # AMS 2 trays → extruder 1 (LEFT)
  781. ams2 = [f for f in result if f["ams_id"] == 2]
  782. assert len(ams2) == 4
  783. assert all(f["extruder_id"] == 1 for f in ams2)
  784. assert [f["global_tray_id"] for f in ams2] == [8, 9, 10, 11]
  785. def test_external_spool_extruder_h2d(self, scheduler):
  786. """H2D: Ext-L (254) = LEFT (extruder 1), Ext-R (255) = RIGHT (extruder 0)."""
  787. class MockStatus:
  788. raw_data = _h2d_raw_data()
  789. result = scheduler._build_loaded_filaments(MockStatus())
  790. ext = [f for f in result if f["is_external"]]
  791. assert len(ext) == 1 # Only 254 has filament
  792. assert ext[0]["global_tray_id"] == 254
  793. # Ext-L (254) should be LEFT nozzle (extruder 1)
  794. assert ext[0]["extruder_id"] == 1
  795. def test_match_left_nozzle_only(self, scheduler):
  796. """H2D: left-nozzle requirement only matches left-nozzle AMS."""
  797. class MockStatus:
  798. raw_data = _h2d_raw_data()
  799. loaded = scheduler._build_loaded_filaments(MockStatus())
  800. required = [
  801. {"slot_id": 1, "type": "PLA", "color": "#000000", "nozzle_id": 1}, # LEFT
  802. ]
  803. result = scheduler._match_filaments_to_slots(required, loaded)
  804. # Black PLA on LEFT: AMS 0 T4 (global 3)
  805. assert result == [3]
  806. def test_match_right_nozzle_only(self, scheduler):
  807. """H2D: right-nozzle requirement only matches right-nozzle AMS."""
  808. class MockStatus:
  809. raw_data = _h2d_raw_data()
  810. loaded = scheduler._build_loaded_filaments(MockStatus())
  811. required = [
  812. {"slot_id": 1, "type": "PLA", "color": "#FFFFFF", "nozzle_id": 0}, # RIGHT
  813. ]
  814. result = scheduler._match_filaments_to_slots(required, loaded)
  815. # White PLA on RIGHT: AMS 1 T1 (global 4)
  816. assert result == [4]
  817. def test_reject_cross_nozzle(self, scheduler):
  818. """H2D: hard filter rejects cross-nozzle assignment."""
  819. class MockStatus:
  820. raw_data = _h2d_raw_data()
  821. loaded = scheduler._build_loaded_filaments(MockStatus())
  822. # PLA-S only exists on AMS 2 T1 (LEFT), require on RIGHT
  823. required = [
  824. {"slot_id": 1, "type": "PLA-S", "color": "#FFFFFF", "nozzle_id": 0},
  825. ]
  826. result = scheduler._match_filaments_to_slots(required, loaded)
  827. assert result == [-1] # No fallback to wrong nozzle
  828. def test_dual_nozzle_multi_filament(self, scheduler):
  829. """H2D: multi-filament print maps to correct nozzles."""
  830. class MockStatus:
  831. raw_data = _h2d_raw_data()
  832. loaded = scheduler._build_loaded_filaments(MockStatus())
  833. required = [
  834. {"slot_id": 1, "type": "PETG", "color": "#FFFFFF", "nozzle_id": 1, "tray_info_idx": "GFG02"},
  835. {"slot_id": 2, "type": "PLA", "color": "#FFFFFF", "nozzle_id": 0, "tray_info_idx": "GFA00"},
  836. ]
  837. result = scheduler._match_filaments_to_slots(required, loaded)
  838. # PETG white on LEFT: AMS 0 T1 (global 0)
  839. # PLA white on RIGHT: AMS 1 T1 (global 4)
  840. assert result == [0, 4]
  841. def test_external_spool_matches_on_correct_nozzle(self, scheduler):
  842. """H2D: external spool on left nozzle matches left-nozzle requirement."""
  843. class MockStatus:
  844. raw_data = _h2d_raw_data()
  845. loaded = scheduler._build_loaded_filaments(MockStatus())
  846. required = [
  847. {"slot_id": 1, "type": "PLA", "color": "#000000", "nozzle_id": 1, "tray_info_idx": "P4d64437"},
  848. ]
  849. result = scheduler._match_filaments_to_slots(required, loaded)
  850. assert result == [254] # External spool on left nozzle
  851. class TestX1CModel:
  852. """X1C-specific tests with real printer data (single nozzle, 2x regular AMS)."""
  853. @pytest.fixture
  854. def scheduler(self):
  855. return PrintScheduler()
  856. def test_build_loaded_filaments_x1c(self, scheduler):
  857. """X1C: all filaments on extruder 0, correct global_tray_id."""
  858. class MockStatus:
  859. raw_data = _x1c_raw_data()
  860. result = scheduler._build_loaded_filaments(MockStatus())
  861. # Only 3 loaded (AMS 1 trays 1-3)
  862. assert len(result) == 3
  863. # All on extruder 0
  864. assert all(f["extruder_id"] == 0 for f in result)
  865. # Correct global tray IDs
  866. assert [f["global_tray_id"] for f in result] == [5, 6, 7]
  867. def test_single_nozzle_no_filtering(self, scheduler):
  868. """X1C: single-nozzle 3MF has no nozzle_id, all trays available."""
  869. class MockStatus:
  870. raw_data = _x1c_raw_data()
  871. loaded = scheduler._build_loaded_filaments(MockStatus())
  872. required = [
  873. {"slot_id": 1, "type": "PLA", "color": "#0066FF"}, # No nozzle_id
  874. ]
  875. result = scheduler._match_filaments_to_slots(required, loaded)
  876. # Blue PLA → AMS 1 T4 (global 7)
  877. assert result == [7]
  878. def test_tray_info_idx_matching_x1c(self, scheduler):
  879. """X1C: tray_info_idx matching works across AMS units."""
  880. class MockStatus:
  881. raw_data = _x1c_raw_data()
  882. loaded = scheduler._build_loaded_filaments(MockStatus())
  883. required = [
  884. {"slot_id": 1, "type": "PLA", "color": "#EBCFA6", "tray_info_idx": "PFUS22b2"},
  885. ]
  886. result = scheduler._match_filaments_to_slots(required, loaded)
  887. # Unique tray_info_idx → AMS 1 T2 (global 5)
  888. assert result == [5]
  889. def test_non_unique_tray_info_idx_color_match_x1c(self, scheduler):
  890. """X1C: non-unique tray_info_idx falls back to color matching."""
  891. class MockStatus:
  892. raw_data = _x1c_raw_data()
  893. loaded = scheduler._build_loaded_filaments(MockStatus())
  894. # P4d64437 appears in AMS 1 T3 and T4
  895. required = [
  896. {"slot_id": 1, "type": "PLA", "color": "#FCECD6", "tray_info_idx": "P4d64437"},
  897. ]
  898. result = scheduler._match_filaments_to_slots(required, loaded)
  899. # Should pick AMS 1 T3 (global 6, color FCECD6) over T4 (0066FF)
  900. assert result == [6]
  901. def test_multi_filament_x1c(self, scheduler):
  902. """X1C: multi-filament print matches freely across AMS units."""
  903. class MockStatus:
  904. raw_data = _x1c_raw_data()
  905. loaded = scheduler._build_loaded_filaments(MockStatus())
  906. required = [
  907. {"slot_id": 1, "type": "PLA", "color": "#EBCFA6"},
  908. {"slot_id": 2, "type": "PLA", "color": "#0066FF"},
  909. ]
  910. result = scheduler._match_filaments_to_slots(required, loaded)
  911. assert result == [5, 7]