You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The unit tests mock our own runtime's primitives (Bun.file, Bun.write, Bun.spawn, fs.unlink/symlink/stat). A mock encodes the author's belief about how the real thing behaves — so it can never catch the cases where that belief is wrong, which is exactly where bugs live. Proven in practice: the corrupt-cache recovery bug (BunFile caches its stat after a read, so exists() returned stale true after unlink) passed the fully-mocked unit test and was only caught by manual QA (#11, commit 7db0bd8).
Policy
Mock only at boundaries we don't own and can't run hermetically:
Telegram API → MockBotApi at the fetch boundary (already the pattern; keep).
yt-dlp / ffprobe → instead of mocking Bun.spawn, put stub executables on PATH in the test container that emit canned stdout/stderr/exit codes. Real process spawn, real stream consumption, real signal/exit handling.
Problem
The unit tests mock our own runtime's primitives (
Bun.file,Bun.write,Bun.spawn,fs.unlink/symlink/stat). A mock encodes the author's belief about how the real thing behaves — so it can never catch the cases where that belief is wrong, which is exactly where bugs live. Proven in practice: the corrupt-cache recovery bug (BunFilecaches its stat after a read, soexists()returned staletrueafterunlink) passed the fully-mocked unit test and was only caught by manual QA (#11, commit 7db0bd8).Policy
Mock only at boundaries we don't own and can't run hermetically:
fetchboundary (already the pattern; keep).Bun.spawn, put stub executables onPATHin the test container that emit canned stdout/stderr/exit codes. Real process spawn, real stream consumption, real signal/exit handling./storage;test/download-video.integration.test.ts(added in Durable job queue with parallel downloads; contain handler errors; workflow gates #11) shows the pattern.spyMockon our own modules) → only to isolate wiring (e.g. bot.ts routing tests); behavior tests should drive the real stack.Work
download-video.test.tsoffBun.file/Bun.write/fsmocks onto real fs (fold the integration test file back in once the main file is real-fs)Bun.spawnmocks with stubyt-dlp/ffprobeexecutableshandlers.test.ts/log-message.test.tsfor module mocks that could be real code over real fsRelated: #9 (test gaps).