diff --git a/bambu_run/mcp/shapes.py b/bambu_run/mcp/shapes.py index 583a1f4..7c9fb30 100644 --- a/bambu_run/mcp/shapes.py +++ b/bambu_run/mcp/shapes.py @@ -108,7 +108,10 @@ def normalize_consumed(starting_percent, ending_percent, initial_weight_grams): fabricated zero (spec: 24/269 usage rows go negative; a -1 sentinel subtracted as a real value produces e.g. consumed=-101%). """ - if starting_percent is None or starting_percent == -1 or ending_percent is None: + if ( + starting_percent is None or starting_percent == -1 + or ending_percent is None or ending_percent == -1 + ): return None, None, "unreliable" consumed_percent = starting_percent - ending_percent if consumed_percent < 0: diff --git a/tests/test_mcp_shapes.py b/tests/test_mcp_shapes.py index 06094b0..8ff1e0a 100644 --- a/tests/test_mcp_shapes.py +++ b/tests/test_mcp_shapes.py @@ -109,6 +109,12 @@ def test_normalize_consumed_sentinel_start_goes_unreliable(): assert normalize_consumed(-1, 100, initial_weight_grams=1000) == (None, None, "unreliable") +def test_normalize_consumed_sentinel_end_goes_unreliable(): + # symmetric case: ending_percent == -1 (no RFID reading at job end) + # must not fabricate a plausible-looking consumption figure + assert normalize_consumed(74, -1, initial_weight_grams=1000) == (None, None, "unreliable") + + @pytest.mark.django_db def test_resolve_printer_by_id(): p = Printer.objects.create(name="RNL-H2C", model="H2C", is_active=True)