test_archive_display_stem.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. """Tests for resolve_display_stem — Bambu Studio filename normalisation (#1152).
  2. Bambu Studio's "Send to printer" dialog typically writes ``Plate_1.gcode.3mf``
  3. (a sliced gcode payload wrapped in a 3MF container). ``Path(name).stem`` only
  4. strips the last suffix and leaves ``Plate_1.gcode``, which then surfaces in
  5. the archive UI as a confusing ``Plate_1.gcode`` rather than ``Plate_1``.
  6. Pin the canonicalisation rules so a future refactor can't silently regress
  7. this path. We don't need a dedicated test for ``archive_print``'s consumption
  8. of the helper — the existing test suite covers that flow end-to-end via the
  9. integration tests and a behaviour change there would surface as a different
  10. ``archive.print_name`` value.
  11. """
  12. import pytest
  13. from backend.app.services.archive import resolve_display_stem
  14. @pytest.mark.parametrize(
  15. ("filename", "expected"),
  16. [
  17. # The headline case: Bambu Studio's default name for a sliced 3MF.
  18. ("Plate_1.gcode.3mf", "Plate_1"),
  19. # User-renamed file with the double-suffix pattern.
  20. ("MyAwesomeBenchy.gcode.3mf", "MyAwesomeBenchy"),
  21. # Plain .3mf (already-clean export from Bambu Studio's Save As).
  22. ("Benchy.3mf", "Benchy"),
  23. # Standalone gcode upload — rare but supported.
  24. ("standalone.gcode", "standalone"),
  25. # Mixed-case suffix — many slicers / OSes preserve user-typed case.
  26. ("UPPERCASE.GCODE.3MF", "UPPERCASE"),
  27. ("mixed.GCode.3mf", "mixed"),
  28. # Names that contain dots in the middle should keep them.
  29. ("my.cool.model.gcode.3mf", "my.cool.model"),
  30. ("v1.2.3-prototype.3mf", "v1.2.3-prototype"),
  31. # No recognised suffix → fall through to Path.stem.
  32. ("Cura_export.zip", "Cura_export"),
  33. ("README.md", "README"),
  34. # Edge: just the suffix with nothing in front. Strip honestly — the
  35. # caller is responsible for sanity-checking empty stems.
  36. (".gcode.3mf", ""),
  37. (".3mf", ""),
  38. # Path components must not leak in. The helper takes a filename, but
  39. # callers occasionally pass a full path string.
  40. ("/some/dir/Plate_1.gcode.3mf", "Plate_1"),
  41. ("subdir/MyModel.3mf", "MyModel"),
  42. ],
  43. )
  44. def test_resolve_display_stem(filename: str, expected: str) -> None:
  45. assert resolve_display_stem(filename) == expected