Repository navigation
feat(fl/system): FileSystem::sd factory + loadFled sugar (#3311 PR3) - #3327
Conversation
PR3 of #3311. Modest-scope addition to fl::FileSystem: - static FileSystem FileSystem::sd(int cs_pin) - one-line factory that constructs + beginSd in a single expression. Definition lives in file_system_sd.cpp.hpp so the SD-library tree-shake property of beginSd is preserved: linkers prune sd(int) along with beginSd when no sketch references either. - FileSystem::loadFled(const char* path) - one-line forwarder to Fled::load(*this, path). The Fled subsystem stays independently tree-shakeable: file_system.cpp.hpp references it only from inside loadFled, which the linker strips when unreferenced. Out of scope (deferred): the full FileSystem::littleFs / wasm / host static factory unification from the original #3311 plan. Those each require a working backend (LittleFS lib on ESP32/RP2040, the WASM VFS, desktop stdio FS) that is a much larger lift than this PR's "sugar" framing. Filed for follow-up; sd(int) and loadFled cover the immediate ergonomic need for the Fled subsystem. Tests: 2 cases in tests/fl/fled/fled_filesystem.cpp - sd factory round-trips, and loadFled on a missing path returns a null Fled. Refs #3311 (this is the third of seven planned PRs) Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds two convenience methods to ChangesFileSystem Convenience API
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/fl/system/file_system.cpp.hpp`:
- Line 1: The file is missing the required IWYU pragma directive at the top. Add
the line `// IWYU pragma: private` as the first line in the file, positioned
before the existing include statement `#include "fl/system/file_system.h"`. This
marks the `.cpp.hpp` file as an internal include-only router per coding
guidelines.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: c4800e4a-2f7c-48ac-9dd5-f8ce5bc4609f
📒 Files selected for processing (4)
src/fl/system/file_system.cpp.hppsrc/fl/system/file_system.hsrc/fl/system/sd/file_system_sd.cpp.hpptests/fl/fled/fled_filesystem.cpp
…atchet The CI-side FL_NO_EXCEPT AST ratchet (clang-tool-chain-query backed) caught the missing annotations on the new APIs added in PR3. The local lint setup skips the AST ratchet when clang-tool-chain-query is not on PATH, so the issue surfaced only after CI. Adding FL_NO_EXCEPT to: - FileSystem::sd(int) declaration + definition - FileSystem::loadFled(const char*) declaration + definition Refs #3311 #3327 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
… PR3) CI ASAN caught a null-deref in FileSystem::openRead when called on a FileSystem with no backend (default-constructed or one whose begin*() failed). My new tests for the PR3 sugar exercised the default-constructed-FS path that nothing had hit before. Returning a closed ifstream lets downstream callers branch on is_open() / is_eof() rather than crash. This matches the behavior the ifstream contract already implies (calling read on a closed stream returns 0 bytes), so no caller behavior changes. Refs #3311 #3327 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Replaces the stub-filesystem approach (which writes real bytes to a real
temp dir on the host disk and gates the whole file on FASTLED_TESTING)
with a true in-memory FsImpl mock. No disk I/O, no temp-dir teardown,
no platform gates - works uniformly anywhere the unit-test binary runs.
Two local helpers in the test TU:
- MemoryFilebuf : public fl::filebuf - seekable in-memory filebuf
over an owned byte vector; supports read/seek/tell/size/eof.
- MemoryFs : public fl::FsImpl - holds flat_map<string, vector<u8>>
of path -> bytes; openRead returns a fresh MemoryFilebuf per call
(independent read cursor across reopens).
Test usage:
auto mem = fl::make_shared<MemoryFs>();
mem->add("sketch.fled", buildBundle(env, payload, ...));
fl::FileSystem fs;
fs.begin(mem);
auto fled = fs.loadFled("sketch.fled");
Three cases as before (end-to-end round-trip with version/sectionCount/
json envelope/frame_payload byte checks, missing path, corrupt magic),
plus the FileSystem::sd factory sanity check.
The helpers live in the test TU only - if other fled-style tests want
the same mocking the natural follow-up is to extract them into a shared
test header.
Refs #3311 #3327
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…3311) (#3333) * test(fl/fled): use stub fs to actually exercise FileSystem::loadFled (#3311) The original tests/fl/fled/fled_filesystem.cpp shipped in #3327 just verified the new entry points did not crash. They did not actually exercise the load path because the test FileSystem had no backend mounted. Rewrite to use the stub filesystem (platforms/stub/fs_stub.hpp) the way tests/fl/system/file_system.cpp already does: - TestDirGuard RAII helper around StubFileSystem::createDirectory / forceRemoveDirectory so a failed run cannot poison the next run. - buildBundle() helper assembles a real v1 .fled byte buffer in memory. - dropBundle() writes the bundle bytes to the stub fs root via StubFileSystem::createTextFile (which opens with ios::binary | trunc and writes via ofs.write, so it is binary-clean). - setTestFileSystemRoot points the stub backend at the temp dir. - Three cases: - End-to-end: FileSystem::sd(5).loadFled("sketch.fled") parses the bundle - version, sectionCount, json envelope, frame_payload bytes all round-trip correctly. - Missing file: loadFled returns a null Fled. - Corrupt magic: loadFled returns a null Fled. Whole file gated on FASTLED_TESTING so the stub headers are only pulled into the test binary. Refs #3311 #3327 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * test(fl/fled): switch to a true in-memory MemoryFs mock (#3311 #3327) Replaces the stub-filesystem approach (which writes real bytes to a real temp dir on the host disk and gates the whole file on FASTLED_TESTING) with a true in-memory FsImpl mock. No disk I/O, no temp-dir teardown, no platform gates - works uniformly anywhere the unit-test binary runs. Two local helpers in the test TU: - MemoryFilebuf : public fl::filebuf - seekable in-memory filebuf over an owned byte vector; supports read/seek/tell/size/eof. - MemoryFs : public fl::FsImpl - holds flat_map<string, vector<u8>> of path -> bytes; openRead returns a fresh MemoryFilebuf per call (independent read cursor across reopens). Test usage: auto mem = fl::make_shared<MemoryFs>(); mem->add("sketch.fled", buildBundle(env, payload, ...)); fl::FileSystem fs; fs.begin(mem); auto fled = fs.loadFled("sketch.fled"); Three cases as before (end-to-end round-trip with version/sectionCount/ json envelope/frame_payload byte checks, missing path, corrupt magic), plus the FileSystem::sd factory sanity check. The helpers live in the test TU only - if other fled-style tests want the same mocking the natural follow-up is to extract them into a shared test header. Refs #3311 #3327 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Summary
PR3 of #3311. Modest-scope additions to
fl::FileSystem:static FileSystem FileSystem::sd(int cs_pin)— one-line factory equivalent tofs; fs.beginSd(cs_pin). Definition lives infile_system_sd.cpp.hppso the existing SD-library tree-shake property ofbeginSdis preserved.FileSystem::loadFled(const char* path)— one-line forwarder tofl::Fled::load(*this, path). The Fled subsystem stays independently tree-shakeable.Together these let bundle-load code read as:
Out of scope
The original #3311 plan called for additional
FileSystem::littleFs()/wasm()/host()static factories. Each requires a working backend (LittleFS lib on ESP32/RP2040, the WASM VFS, desktop stdio FS) which is a much larger lift than this PR's "sugar" framing. Filed for follow-up;sd(int)+loadFledcover the immediate ergonomic need for the Fled subsystem.Test plan
bash test fled --debug— green (3/3 DLLs in fled subdir, including the new fled_filesystem)bash lint --cpp— greenRefs #3311
🤖 Generated with Claude Code
Summary by CodeRabbit