Skip to content

Fix test-media.js loudness measurement + confirm test-posthog-funnel was a local process fluke - #801

Merged
MikeyPetrillo merged 1 commit into
mainfrom
claude/sweet-brown-i99jl3
Aug 17, 2026
Merged

Fix test-media.js loudness measurement + confirm test-posthog-funnel was a local process fluke#801
MikeyPetrillo merged 1 commit into
mainfrom
claude/sweet-brown-i99jl3

Conversation

@MikeyPetrillo

Copy link
Copy Markdown
Owner

Summary

Follow-up to #799, fixing the two test issues flagged as "pre-existing" after that PR shipped.

  • test-media.js — real bug, fixed. measureLufs() used execFileSync, which only exposes captured stderr via a thrown Error's .stderr field — but ffmpeg ... -f null - with the ebur128 filter exits 0 on success, so the try/catch never fired and the function silently returned null on every successful measurement. The loudness proof this test exists for had never actually run. Fixed by switching to spawnSync (returns {stdout, stderr, status} regardless of exit code). Once real measurements were flowing, a second bug surfaced: the test assumed a default-amplitude sine wave always measures around -3 LUFS ("very loud"), but ffmpeg's sine source has no amplitude parameter and this build's default output measures -21.8 LUFS — quieter than the -16 LUFS target, so normalizing up to target correctly makes it louder. Replaced the directional assumption with the portable claim: normalization moves loudness closer to the target than the input was, regardless of which side of the target the input falls on.
  • test-posthog-funnel.js — false alarm, no code change. Traced to a stray local server process left bound to port 3081 from earlier work in the same session (the same process that also caused test-leaderboard-envelope.js to fail during a full local sweep). Killed the process; the test now passes cleanly and consistently (53/53). The earlier "confirmed pre-existing via git stash" conclusion was itself a false negative — stashing the working tree doesn't affect an already-running background process bound to the same port.

Test plan

  • test-media.js passes consistently across repeated runs, with real measurements visible (input -21.8 LUFS → output -16.2 LUFS, target -16)
  • Mutation-tested: temporarily disabled the loudnorm filter in src/tools/media-kit.js (swapped for a no-op), confirmed the test correctly fails with "did NOT hit target", then reverted (clean, zero diff)
  • Checked all 5 execFileSync call sites in scripts/ for the same bug shape (relying on stderr from a caught exception rather than the success return value) — none of the other four have it
  • test-posthog-funnel.js 53/53 passing after killing the stray process
  • test-ci-coverage.js clean (4/4)
  • CI green, merge

🤖 Generated with Claude Code

… and its direction assumption was wrong

Two real bugs, unrelated to the CSP work, found while investigating the
"pre-existing" test-media.js failure flagged after that PR shipped.

1. measureLufs() used execFileSync, which only exposes captured stderr
   via a thrown Error's .stderr field - but `ffmpeg ... -f null -` with
   the ebur128 filter exits 0 on success (verified consistently on this
   machine's ffmpeg build), so the try/catch never fired and the
   function silently returned null on every successful measurement, for
   both the before and after readings. Only the "after" reading was ever
   asserted non-null, so the loudness proof this test exists for had
   never actually run. Fixed by switching to spawnSync, which returns
   {stdout, stderr, status} regardless of exit code.

2. Once real measurements were flowing, a second bug surfaced: the test
   asserted normalization must make the audio QUIETER (afterLufs must be
   < beforeLufs), on the assumption a default-amplitude sine wave always
   measures around -3 LUFS ("very loud"). ffmpeg's lavfi sine source has
   no amplitude parameter (verified via -h filter=sine) and its actual
   default output measures -21.8 LUFS on this build - quieter than the
   -16 LUFS target, so normalizing UP to target correctly makes it
   LOUDER, the opposite of what the old assertion required. Replaced the
   directional assumption with the real, portable claim: normalization
   moves loudness closer to the target than the input was, regardless of
   which side of the target the raw input happens to fall on.

Verified: passes consistently across repeated runs: real measurements
now visible in the output (input -21.8 LUFS -> output -16.2 LUFS,
target -16). Mutation-tested by temporarily disabling the loudnorm
filter in src/tools/media-kit.js (swapped for a no-op volume filter) -
confirmed the test correctly fails with "did NOT hit target", then
reverted (clean, zero diff on the source file). Checked every other
execFileSync use in scripts/ for the same bug shape (relying on stderr
from a caught exception rather than the success return value) - none of
the other four call sites have it; all read stdout from the normal
return path.

Also traced the earlier "test-posthog-funnel.js has 8 pre-existing
failures" finding to its root cause: a stray local server process left
bound to port 3081 from earlier work in the same session. Killed the
stray process; the test now passes cleanly and consistently (53/53).
No code changes were needed there - the earlier "confirmed pre-existing
via git stash" conclusion was itself a false negative, since a stashed
git diff does not affect an already-running background process bound to
the same port both runs happened to hit.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@MikeyPetrillo
MikeyPetrillo temporarily deployed to agent402 / production August 17, 2026 01:26 — with GitHub Actions Inactive
@railway-app
railway-app Bot temporarily deployed to agent402 / production August 17, 2026 01:26 Inactive
@MikeyPetrillo
MikeyPetrillo marked this pull request as ready for review August 17, 2026 01:28
@MikeyPetrillo
MikeyPetrillo merged commit 0aa68c0 into main Aug 17, 2026
34 checks 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