Skip to content

fix: counterexamples found by property tests, faster Track loading - #44

Merged
mathieuletyrant merged 1 commit into
mainfrom
fix/invariants-property-tests
Dec 4, 2026
Merged

mathieuletyrant merged 1 commit into
mainfrom
fix/invariants-property-tests

Conversation

@mathieuletyrant

Copy link
Copy Markdown
Owner

What

Property tests (proptest, dev dependency) for the bugs fixed so far and for the invariants the code relies on, the fixes for the counterexamples they found, and a few measured speed-ups.

Counterexamples fixed

Each test was checked to fail without its fix (the CLI hang was reproduced on the previous binary).

Where Before Now
queue::scan An unmounted disk leaves an empty folder, which passed for a readable Library: every Track was deleted as an orphan An empty Library deletes nothing
lueur analyze Outside the analysis window, the command waited for ever Ignores the window, like any Analysis asked for
Config::local_path The Library /media/movies also claimed /media/movies-4k/… Whole folder names only
Track::load A file cut after 25 bytes, or an empty film on a grid without cells, crashed A damaged header is refused
render::Mapping Under 28 % of spread (API only, the UI stops at 40 %), a Strip LED between two Edge cells stayed black Reads the nearest cell
server::merge A nested null stayed in when patched over a non-object RFC 7396
parse_iso8601 A 19-digit year overflowed Refused

Also, without a test: a Library without a folder no longer makes every file reachable through the API.

The first two change visible behaviour and are the ones to review.

Property tests for past fixes

53d93fc (HDR), e714ce3 (AV1), 388efed (light positions), 825089d / 7a855d3 / 88ed7c6 (playback clock), ddc42b7 (one owner for the stream), 247473a (session first seen paused).

Not covered: the 7 web UI fixes (no web test harness), fbcd44e (threads and timing), cf23705 (Jellyfin HTTP call).

One invariant is proven by going through every case (analyze::part: never empty, never outside, tiles the side). The others are property-tested, not proven.

Speed

Measured with cargo test --release bench -- --ignored --nocapture on an Apple Silicon Mac.

Path Before After
Load the Track of a 2 h film 187 ms 131 ms
One frame to the lights (Area, 7 lights) 4.7 µs 2.4 to 3.5 µs
One frame to the lights (Strip, 135 LEDs) 6.9 µs about 4 µs
Analysis of a 10 min 1080p clip (CPU) 9.9 s unchanged
  • Analysis is bound by decoding: ffmpeg alone takes 9.8 s of the 10 s. scale_vt, LTO and an sRGB table were tried, gave nothing and are not in this PR.
  • Built assets are served as immutable; the status poll no longer renders the UI again when nothing changed; the barcode gradient and the Look page's film list are memoized.
  • Tracks written before and after are identical, byte for byte, and each version reads the other's.

Clean-up

About 65 lines: the mDNS search shared by hue.rs and wled.rs, default fields restated in Track literals, and dead web code (usePoll's unread error, Pill's red tone, stale section dividers, a duplicate body rule).

Checks

  • cargo test: 76 pass (43 before). cargo clippy --all-targets: clean.
  • pnpm --filter web typecheck and build: pass.
  • Server smoke test: cache headers on /assets/*, /api/status, a config patch.
  • Not done: the web changes were not exercised in a browser.

Added files

  • apps/server/src/bench.rs: the timings above, as an ignored test.
  • apps/server/proptest-regressions/: the seeds of the counterexamples, replayed first on every run.

Property tests (proptest) for the bugs fixed so far and for the
invariants the code relies on. Seven of them had counterexamples:

- scan: an unmounted disk leaves an empty folder, which passed for a
  readable Library, so every Track was deleted as an orphan. An empty
  Library now deletes nothing.
- analyze (CLI): outside the analysis window the command waited for
  ever. It now ignores the window, like any Analysis asked for.
- config: the Library `/media/movies` also claimed `/media/movies-4k/…`.
- track: a file cut after 25 bytes, or an empty film on a grid without
  cells, crashed `load`. A damaged header is now refused.
- render: under 28 % of spread, a Strip LED between two Edge cells read
  none and stayed black. It now reads the nearest one.
- server: a merge patch left a nested null in over a non-object.
- jellyfin: a date with a 19-digit year overflowed.

Also: a Library without a folder no longer makes every file reachable
through the API.

Faster:

- Track::load decodes straight into the grids and the Edges, undoes the
  differences 16 bytes at a time and reads luminance from tables:
  187 ms to 131 ms for a 2 h film.
- Centered smoothing reads each frame once instead of twice per sample.
- Built assets are served as immutable; the status poll no longer
  renders the UI again when nothing changed.

Tracks written before and after are identical, byte for byte.
@mathieuletyrant mathieuletyrant self-assigned this Dec 4, 2026
@mathieuletyrant
mathieuletyrant merged commit 3c3744c into main Dec 4, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant