mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-09-30 19:21:33 +02:00
When a file sliced for the wrong nozzle size is dispatched, the printer goes IDLE -> PREPARE -> FAILED without ever entering RUNNING. Completion detection required prev=RUNNING or _was_running=True, so on_print_complete never fired and the queue item stayed at "printing" forever -- blocking every subsequent pending item for that printer (check_queue seeds busy_printers from any row in 'printing'). Fire completion on FAILED from PREPARE or SLICING too. Restricted to those two pre-print states so a stale FAILED on first connection (prev=None) still can't accidentally advance an unrelated queue item. Also populate PrintQueueItem.error_message from the current HMS error list via the existing hms_errors.py lookup, so users see e.g. "[0500_4038] The nozzle diameter in sliced file is not consistent with the current nozzle setting" instead of a blank failure reason.
55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
"""Tests for main._format_hms_error_summary — the helper that turns MQTT hms_errors
|
|
into a human-readable PrintQueueItem.error_message on pre-print failures (#1111)."""
|
|
|
|
|
|
def _format(hms_errors):
|
|
from backend.app.main import _format_hms_error_summary
|
|
|
|
return _format_hms_error_summary(hms_errors)
|
|
|
|
|
|
def test_returns_none_for_empty_list():
|
|
assert _format([]) is None
|
|
assert _format(None or []) is None
|
|
|
|
|
|
def test_formats_known_nozzle_mismatch_code():
|
|
"""0500_4038 is the nozzle-size-mismatch code from the HMS table — the common
|
|
trigger for issue #1111."""
|
|
summary = _format([{"code": "0x4038", "attr": 0x05000000, "module": 0x5, "severity": 1}])
|
|
assert summary is not None
|
|
assert "0500_4038" in summary
|
|
assert "nozzle diameter" in summary.lower()
|
|
|
|
|
|
def test_formats_unknown_code_as_bare_short_code():
|
|
summary = _format([{"code": "0x9999", "attr": 0x99990000, "module": 0x99, "severity": 1}])
|
|
assert summary == "[9999_9999]"
|
|
|
|
|
|
def test_joins_multiple_errors_with_semicolons():
|
|
summary = _format(
|
|
[
|
|
{"code": "0x4038", "attr": 0x05000000, "module": 0x5, "severity": 1},
|
|
{"code": "0x9999", "attr": 0x99990000, "module": 0x99, "severity": 1},
|
|
]
|
|
)
|
|
assert summary is not None
|
|
assert "; " in summary
|
|
assert summary.count("[") == 2
|
|
|
|
|
|
def test_tolerates_malformed_entry_and_skips_it():
|
|
summary = _format(
|
|
[
|
|
{"code": "not-hex", "attr": "also-not-int"},
|
|
{"code": "0x4038", "attr": 0x05000000, "module": 0x5, "severity": 1},
|
|
]
|
|
)
|
|
assert summary is not None
|
|
assert "0500_4038" in summary
|
|
|
|
|
|
def test_all_malformed_returns_none():
|
|
assert _format([{"code": "not-hex", "attr": "also-not-int"}]) is None
|