Verify HLS adaptive bitrate end-to-end#98
Conversation
Adds scripts/verify-hls-abr.mjs to fetch a Cloudflare Stream master manifest and assert >=2 ABR variants with a monotonic throttle ladder, plus a runbook documenting the manual DevTools throttle procedure.
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
ECC bundle files are already tracked in this repository. Skipping generation of another bundle PR. |
There was a problem hiding this comment.
Code Review
This pull request introduces a new runbook and a Node.js script for verifying HLS adaptive bitrate (ABR) functionality. The script fetches a master manifest, parses its variants, and simulates a bandwidth throttle ladder to ensure that resolution steps down monotonically. Feedback focuses on cleaning up unrelated metadata changes in package-lock.json likely caused by npm version mismatches, as well as technical improvements to the script such as handling UTF-8 Byte Order Marks (BOM) in manifests and resolving variable shadowing for better code clarity.
| "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.27.1.tgz", | ||
| "integrity": "sha512-qMlSxKbpRlAridDExk92nSobyDdpPijUq2DW6oDnUqd0iOGxmQjyqhMIihI9+zv4LPyZdRje2cavWPbCbWm3eA==", | ||
| "dev": true, | ||
| "devOptional": true, |
There was a problem hiding this comment.
The package-lock.json contains a large amount of metadata changes (e.g., dev: true being replaced by devOptional: true or removed) that appear unrelated to the actual code changes. This typically happens when using a different version of npm than the one used to generate the original lockfile. To keep the pull request clean and avoid potential environment-specific dependency resolution issues, consider reverting these changes unless a lockfile format upgrade is intended.
|
|
||
| function parseHlsMaster(text) { | ||
| const lines = text.split(/\r?\n/); | ||
| if (lines.length === 0 || !lines[0].startsWith('#EXTM3U')) return []; |
There was a problem hiding this comment.
HLS manifests can sometimes include a UTF-8 Byte Order Mark (BOM) at the beginning of the file. fetch().text() does not automatically strip this, which would cause the startsWith('#EXTM3U') check to fail even for valid manifests. It is safer to strip the BOM before checking.
| if (lines.length === 0 || !lines[0].startsWith('#EXTM3U')) return []; | |
| if (lines.length === 0 || !lines[0].replace(/^\uFEFF/, '').startsWith('#EXTM3U')) return []; |
| const res = v.resolution ? `${v.resolution.width}x${v.resolution.height}` : '?'; | ||
| console.log(` ${(v.bandwidth / 1000).toFixed(0).padStart(6)} kbps ${res.padEnd(10)} ${v.uri}`); |
There was a problem hiding this comment.
The variable name res is shadowing the Response object returned by fetch on line 85. While the original res is not used later in the function, renaming this to something more descriptive like resolutionStr improves readability and avoids confusion.
| const res = v.resolution ? `${v.resolution.width}x${v.resolution.height}` : '?'; | |
| console.log(` ${(v.bandwidth / 1000).toFixed(0).padStart(6)} kbps ${res.padEnd(10)} ${v.uri}`); | |
| const resolutionStr = v.resolution ? `${v.resolution.width}x${v.resolution.height}` : '?'; | |
| console.log(` ${(v.bandwidth / 1000).toFixed(0).padStart(6)} kbps ${resolutionStr.padEnd(10)} ${v.uri}`); |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 73e1ce0c36
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (/^[a-f0-9]{20,}$/i.test(arg)) { | ||
| return `https://videodelivery.net/${arg}/manifest/video.m3u8`; |
There was a problem hiding this comment.
Expand bare Stream IDs regardless of character set
The runbook says this script accepts a bare stream_video_id, but resolveUrl only expands IDs that match a 20+ hex pattern. Any valid opaque ID outside that regex (for example cf-uid) is passed straight to fetch, which throws ERR_INVALID_URL before verification runs. This makes the advertised CLI mode unreliable unless callers already know the hidden hex-only constraint.
Useful? React with 👍 / 👎.
| const r = v?.resolution ? `${v.resolution.height}p` : '?'; | ||
| console.log(` ceiling ${(c / 1_000_000).toFixed(2)} Mbps -> ${r} @ ${v?.bandwidth ?? 0} bps`); | ||
| } | ||
| const heights = picks.map((p) => p.v?.resolution?.height ?? 0); |
There was a problem hiding this comment.
Reject manifests with unknown rendition resolutions
The monotonic ABR check converts missing RESOLUTION values to 0, so a manifest with multiple variants but no resolution metadata still prints OK even though no resolution step-down was actually verified. That is a false positive for the script’s stated goal (checking rendition downshifts under throttling); it should fail (or explicitly mark inconclusive) when picked variants lack resolution heights.
Useful? React with 👍 / 👎.
- Strip UTF-8 BOM in parseHlsMaster so manifests with a leading BOM don't silently fail the #EXTM3U tag check. - Rename inner `res` → `resolutionStr` so it no longer shadows the fetch Response on the surrounding scope. - Loosen `resolveUrl` to expand any opaque-looking token (>=8 chars, [a-z0-9_-]) to the canonical Stream URL — Cloudflare Stream UIDs are documented as opaque, so the previous hex-only regex rejected valid ids and broke the advertised CLI mode. - Fall back to BANDWIDTH for the monotonic check (with an explicit WARN) when any picked variant lacks RESOLUTION metadata, so a manifest with no rendition heights doesn't silently exit OK. - Revert package-lock.json metadata churn that was unrelated to ALO-142 and only appeared because the PR was generated under a different npm. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Closes ALO-142.
Adds an end-to-end verification path for Cloudflare Stream HLS adaptive bitrate:
scripts/verify-hls-abr.mjs— fetches a Stream master manifest (URL or bare video id), parsesEXT-X-STREAM-INFentries, and exits non-zero unless the manifest exposes ≥2 variants and the throttle ladder (10 Mbps → 250 kbps using the same "highest variant ≤ ceiling" rule as hls.js) steps down monotonically.docs/runbooks/hls-abr-verification.md— runbook covering the script and the manual Chrome DevTools throttle procedure for confirming hls.js switches renditions without stalls.Existing unit coverage in
src/frontend/lib/hls-manifest.test.tsalready validates the parser + ABR ladder simulation; this PR adds the runtime/manual leg to round out the verification.Test plan
npm test(491 passed)npm run lintnode scripts/verify-hls-abr.mjs <ready stream_video_id>against a real Stream-encoded clip in staging and confirmOK:exit.