The CI-only failure on test_layer_timelapse_expected_archive came from
the test driving the entire on_print_start flow through ~12 patches and
a MagicMock printer, which behaved differently between Python 3.11 (CI)
and 3.13 (local) — execution stopped silently somewhere in the
expected-archive path under CI's pytest-xdist parallelism but completed
locally.
Fix root-shape instead of fix the symptom:
1. Extract the three identical start_session call sites in on_print_start
(expected-archive promotion at 2030, fallback archive at 2554, fresh
archive at 2644) into one helper _maybe_start_layer_timelapse() with
the same external_camera_enabled / external_camera_url guard. The
three inline blocks had already started drifting (#1353 originally
only fixed one of them on the first pass) — the helper keeps them
locked together going forward.
2. Rewrite the test to call the helper directly. Uses SimpleNamespace
(strict attribute access) instead of MagicMock (default-truthy), no
DB mocking, no event loop, no parallel-state surface. Four small
cases instead of two integration-style ones: enabled→starts,
disabled→skips, URL-missing→skips, camera_type default 'mjpeg'.
Test was passing locally but failing in CI on the merge of v0.2.4.1.
Root cause: MagicMock returns a truthy default for any unset attribute,
so mock_printer.plate_detection_enabled was truthy and the production
code's plate detection block ran for real. Locally with ffmpeg present
the capture path completed cleanly (try/except swallowed errors) and
flow continued to start_session. In CI without ffmpeg, the failure path
in capture_camera_frame_bytes prevented execution from reaching the
expected-archive branch's start_session call, so the assert_called_once
on the patched start_session tripped.
Plate detection isn't the subject under test (start_session in the
expected-archive branch is). Setting plate_detection_enabled = False
explicitly on the mock skips that block entirely and makes the test
robust to environmental differences. Test also drops from ~9s to ~2s
since real frame-capture attempts no longer run.
Synthetic value on mock_archive.file_path was "/tmp/fake.3mf" - Bandit
flagged it as "Probable insecure usage of temp file/directory" even
though the string is never used as a filesystem path. Swapped to
"/test/archives/fake.3mf", matching the pattern used in commit 9f1188d7
to clear the same finding on test_library_trash_api.py and
test_pending_upload_display_name.py. No suppression comment needed -
the new path no longer matches Bandit's regex.
Reporter @Andlar94 ran the external-camera flow on an A1 dispatched via the
print queue and got no MP4 output even though the log said "Stitching layer
timelapse for printer 1" after each print. Support bundle confirmed the
external camera was working (Obico was polling the snapshot URL fine for
plate detection).
Root cause: start_session() only ran in the two new-archive paths in
on_print_start (fallback_archive at main.py:2510 and regular new-archive at
2600). The expected-archive branch at main.py:1981-2052 — where every
reprint and every queue/VP-dispatched print lands — updated the existing
archive row to status=printing but never started a timelapse session.
So _background_layer_timelapse ran at print complete, called tl_complete(),
found nothing in _active_sessions, returned None silently, and the wrapper
at main.py:3917 produced no log message for the no-session case. Every
print through the queue silently lost its timelapse — likely the reason
this hasn't been caught before (direct slice-and-send-to-printer prints
take the new-archive path and work fine).
Fix: mirror the same start_session() call in the expected-archive branch,
guarded by the same external_camera_enabled + external_camera_url check the
other two paths use.
Also reworded the snapshot URL help text across all 8 locales to make clear
that timelapse and plate detection each require their own per-printer
toggle — the URL is just the image source they pull from when active. The
previous wording read as if filling in the URL was sufficient.