Repository navigation
test(fl/fled): use stub fs to actually exercise FileSystem::loadFled (#3311) - #3333
Conversation
…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]>
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]>
📝 WalkthroughWalkthroughReplaces the minimal smoke tests in ChangesFLED FileSystem end-to-end tests
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
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.
🧹 Nitpick comments (1)
tests/fl/fled/fled_filesystem.cpp (1)
29-112: 🏗️ Heavy liftPrefer the existing test harness path over introducing new filesystem mocks.
This block introduces
MemoryFilebuf/MemoryFsmocks inside a test file, which conflicts with the test guideline to keep tests simple and avoid mocks. Consider routing these cases through the existing harness pattern instead of adding local mock infrastructure.As per coding guidelines, “Keep tests simple and avoid mocks; on-device/hardware tests should go through
examples/AutoResearch/AutoResearch.inoby reusing or augmenting existing test harnesses rather than creating new.inofiles.”🤖 Prompt for 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. In `@tests/fl/fled/fled_filesystem.cpp` around lines 29 - 112, Remove the MemoryFilebuf and MemoryFs mock classes from this test file and instead route the test cases through the existing test harness infrastructure. Rather than creating local mock filesystem implementations, refactor the tests to reuse or augment the established test harness patterns already available in the codebase, following the guideline to keep tests simple and avoid introducing new mock infrastructure at the test file level.Source: Coding guidelines
🤖 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.
Nitpick comments:
In `@tests/fl/fled/fled_filesystem.cpp`:
- Around line 29-112: Remove the MemoryFilebuf and MemoryFs mock classes from
this test file and instead route the test cases through the existing test
harness infrastructure. Rather than creating local mock filesystem
implementations, refactor the tests to reuse or augment the established test
harness patterns already available in the codebase, following the guideline to
keep tests simple and avoid introducing new mock infrastructure at the test file
level.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 8e6f6b21-bc1a-4c51-835f-fcd74e268450
📒 Files selected for processing (1)
tests/fl/fled/fled_filesystem.cpp
Summary
The tests added in #3327 (PR3) just verified the new
FileSystem::sd/loadFledentry points did not crash — they did not actually exercise the load path, because the testFileSystemhad no backend mounted.This PR rewrites
tests/fl/fled/fled_filesystem.cppto use the stub filesystem (platforms/stub/fs_stub.hpp) the waytests/fl/system/file_system.cppalready does.What's tested now
TestDirGuardRAII helper aroundStubFileSystem::createDirectory/forceRemoveDirectoryso a failed run cannot poison the next run.buildBundle()assembles a real v1.fledbyte buffer in memory (12-byte header + JSON envelope + payload).dropBundle()writes the bundle bytes to the stub fs root viaStubFileSystem::createTextFile(which opens withios::binary | truncand writes viaofs.write, so it's binary-clean).setTestFileSystemRootpoints the stub backend at the temp dir.FileSystem::sd(5).loadFled(\"sketch.fled\")parses the bundle —version,sectionCount,json()[\"video\"][\"fps\"],blob(\"frame_payload\", &n)bytes all round-trip correctly.loadFledreturns a nullFled.loadFledreturns a nullFled.Whole file gated on
FASTLED_TESTINGso the stub headers are only pulled into the test binary.Test plan
bash test fled --debug— greenbash lint --cpp— greenRefs #3311 #3327
🤖 Generated with Claude Code
Summary by CodeRabbit
Tests