Repository navigation
feat(fl::url): add parse_lnk() for .lnk asset link files (slice 1 of #2284) - #2286
Conversation
Introduces fl::parse_lnk(string_view) which parses the .lnk asset link format proposed in #2284: the first non-comment, non-blank line of the file is returned as a fl::url. Lines beginning with '#' are treated as comments; trailing metadata lines are reserved for future use (sha256=..., fallback=...) and ignored by the v1 parser for forward compatibility. Also adds examples/AudioUrl/data/track.mp3.lnk demonstrating the format alongside the existing AudioUrl sketch, so the .lnk convention is visible in-tree ahead of fbuild integration. This is slice 1 of the feature described in #2284. Remaining pieces (fbuild data/ scan, WASM runtime resolution, ESP32 LittleFS packing, fl::asset handle type, UIAudio asset constructor) are tracked in the issue and will land as follow-up PRs. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
📝 WalkthroughWalkthroughIntroduces a Changes
Possibly related issues
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/fl/stl/url.h (1)
258-294: LGTM — parser is small, correct, and handles the documented cases.Line-by-line walk with
find('\n'), CRLF strip, and whitespace trim all look right; returning default-constructedurl()on no-match yieldsisValid() == false, matching the documented contract and the negative tests.One small note (optional, not blocking): the doc comment on Line 250 says "one URL per line" which reads a bit ambiguously given the v1 behavior ignores all lines after the first URL. Consider tightening to e.g. "the first non-comment, non-blank line is the URL; any following lines are reserved for future metadata and ignored by v1." Purely wording.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/fl/stl/url.h` around lines 258 - 294, Update the doc comment near parse_lnk to clarify behavior: change "one URL per line" to explicitly state that parse_lnk returns the first non-comment, non-blank line as the URL and ignores any following lines (reserved for future metadata) so callers know subsequent lines are ignored in v1; reference the parse_lnk function and the returned url() behavior in the comment.tests/fl/url_lnk.cpp (1)
11-80: Good coverage; consider one more negative case.Subcases cover plain, trailing
\n, CRLF, leading blanks,#comments, leading/trailing whitespace trim, trailing metadata ignored, empty input, only-comments, and indented comments — nicely matches the parser's branches.Optional additions worth considering:
- A case with only
\r\n/\n(whitespace-only, no comments) to lock in that pure-whitespace input returns an invalidurl().- A case asserting that a line without a scheme still parses (since
fl::urlauto-repairs tohttps://) — useful to document the interaction betweenparse_lnkandurl'swasRepaired()behavior, so a future change to either side doesn't silently shift semantics.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/fl/url_lnk.cpp` around lines 11 - 80, Add two negative/behavioral subcases to tests in the FL_TEST_CASE("fl::parse_lnk") for parse_lnk: (1) a "whitespace-only returns invalid url" subcase that calls parse_lnk with a string of only newlines/CRLF/space (e.g. "\r\n" or "\n \n") and asserts the returned url::isValid() is false; (2) a "scheme-less line is repaired to https" subcase that calls parse_lnk with a host/path missing scheme (e.g. "example.com/path\n") and asserts the returned url is valid and either reports wasRepaired() true or has scheme() == "https" and host() == "example.com" to lock in the auto-repair behavior; place these alongside the existing FL_SUBCASE blocks for parse_lnk.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/fl/stl/url.h`:
- Around line 258-294: Update the doc comment near parse_lnk to clarify
behavior: change "one URL per line" to explicitly state that parse_lnk returns
the first non-comment, non-blank line as the URL and ignores any following lines
(reserved for future metadata) so callers know subsequent lines are ignored in
v1; reference the parse_lnk function and the returned url() behavior in the
comment.
In `@tests/fl/url_lnk.cpp`:
- Around line 11-80: Add two negative/behavioral subcases to tests in the
FL_TEST_CASE("fl::parse_lnk") for parse_lnk: (1) a "whitespace-only returns
invalid url" subcase that calls parse_lnk with a string of only
newlines/CRLF/space (e.g. "\r\n" or "\n \n") and asserts the returned
url::isValid() is false; (2) a "scheme-less line is repaired to https" subcase
that calls parse_lnk with a host/path missing scheme (e.g. "example.com/path\n")
and asserts the returned url is valid and either reports wasRepaired() true or
has scheme() == "https" and host() == "example.com" to lock in the auto-repair
behavior; place these alongside the existing FL_SUBCASE blocks for parse_lnk.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 0260d6d3-f97f-45a7-a067-744efd569e4c
📒 Files selected for processing (3)
examples/AudioUrl/data/track.mp3.lnksrc/fl/stl/url.htests/fl/url_lnk.cpp
📊 Header Compilation PerformanceTotal Time: 1181.12ms Top 5 Slowest Headers
Warnings
Full Report |
Summary
First slice of the
data/asset pipeline feature described in #2284.fl::parse_lnk(fl::string_view)which returns afl::urlparsed from the proposed.lnkfile format (one URL per line,#comments, blank lines skipped, trailing lines reserved for future metadata).examples/AudioUrl/data/track.mp3.lnkso the format convention is visible in-tree alongside the existingAudioUrlsketch.#comments, leading blanks, indented comments, trailing metadata lines, and empty input.No behavior changes to existing code paths —
UIAudio, fbuild, and the WASM runtime are untouched in this slice.Scope — why this slice is small
The full feature (see #2284) has four independent pieces:
.lnkformat + parser ← this PR<sketch>/data/to emit an asset manifest (lives in the externalfbuildpackage, separate repo).lnk→fl::url→ existingurlJSON field on the audio elementLanding the parser first lets downstream work (fbuild, WASM loader,
fl::assethandle) target a stable format without cross-repo coordination on the parse semantics.Test plan
bash test url_lnk— new test passes (9 subcases)bash test url— existing URL tests still pass (no regression)bash test audio_url— existing audio URL UI tests still passbash lint— cleanFollow-ups tracked in #2284
fl::asset(path)handle typedata/scan (externalfbuildpackage).lnkat load time, thread resolved URL into audio elementUIAudiooverload acceptingfl::assetCloses: none (keeps #2284 open as the umbrella tracker)
🤖 Generated with Claude Code
Summary by CodeRabbit
.lnkasset link files that declare external resource URLs, such as audio tracks and other media assets.#) and blank lines for improved readability and future extensibility.