mirror of
https://github.com/facefusion/facefusion.git
synced 2026-05-01 05:47:51 +02:00
3.0 KiB
3.0 KiB
Stream API TODO
Approach
- vibe code mass testing to get broad coverage fast
- vibe code refactoring (naming, boilerplate extraction, validation)
- hand craft production code (stream pipeline, encoder loop, IVF parsing)
- hand craft testing — thin it out to essentials only
Unit Tests
| Function | Rating | Assertions |
|---|---|---|
get_websocket_stream_mode |
essential | returns None for missing header, returns None for unknown protocol |
forward_rtc_frames |
essential | reads IVF header and forwards frame data, handles broken pipe |
run_encode_loop |
nice to have | drains deque and closes encoder |
receive_vision_frames |
skip | async generator, covered by integration tests |
submit_encoder_frame |
skip | thin glue between cv2 and subprocess stdin |
websocket_stream |
skip | routing only, covered by integration tests |
post_stream |
skip | covered by integration tests |
Integration Tests
- test stream without session — expect rejection
- test stream with expired or invalid token
- test image stream without source selected
- test video stream without source selected
- test WHEP offer without active websocket stream
- test WHEP offer with malformed SDP body
- test WHEP offer with wrong content type
- test multiple WHEP viewers on same stream
- test websocket disconnect mid-stream triggers cleanup
Naming
- rename
test_get_stream_modetotest_get_websocket_stream_modeintest_stream_helper.py— does not match function name - rename
make_scopeintest_stream_helper.pytomake_websocket_scope— more descriptive stream_helper.pymixes pure helpers (calculate_bitrate) with async handlers (handle_image_stream) — consider splitting
Dead Code
read_pipe_bufferhas a test but the test is disconnected from how it is actually used — the test reads from a closed pipe, production reads from a live subprocess stdout
Refactor
handle_image_streamandhandle_video_streamshare session setup boilerplate (subprotocol, access_token, session_id, source_paths, websocket accept) — extract common setupforward_rtc_framesassumes IVF container format with hardcoded header size 32 and frame header size 12 — document or make configurablepost_streamdoes not validate content type isapplication/sdpbefore parsing bodycalculate_bitratehas a TODO about improving the calculationhandle_video_streamhas a hardcoded fallbackoutput_video_fps or 30with a TODO to resolve from target video fps
Violations
stream_helper.py:24— comment oncalculate_bitrate(no comments)stream_helper.py:143— comment onoutput_video_fpsfallback (no comments)test_stream_helper.py:30—test_get_stream_modedoes not match function nameget_websocket_stream_mode(naming convention)
Security
endpoints/stream.py:27—request.body().decode()is not sanitized, raw user input forwarded to C library via RTC layer