Consolidate test temp helpers and move file I/O + lock platform code into src/platform (#793 follow-up)#851
Consolidate test temp helpers and move file I/O + lock platform code into src/platform (#793 follow-up)#851bmehta001 wants to merge 2 commits into
Conversation
Four download/file-writer unit tests each defined a near-identical local TempDir or TempPath RAII class, and test_helpers.h carried the CurrentPid/MakeUniqueTempPath helpers they relied on. Move all of it into a single test/utils/temp_dir.h in the fl::test namespace and have the tests use it, removing the duplication Scott flagged on #793. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
file_writer.cc and cross_process_file_lock.cc each carried Win32/POSIX
implementations behind in-file #ifdef _WIN32 branches. Follow the existing
src/platform/{windows,posix}/path.cc pattern instead:
- Add src/platform/file_io.h declaring fl::platform OpenWritableFile /
WriteFileAt / CloseFile primitives over an integer handle, implemented per
OS in src/platform/{windows,posix}/file_io.cc. FileWriter now stores an
intptr_t handle and delegates, dropping its #ifdef member and branches.
- Split CrossProcessFileLock: the platform-specific State, its releasing
destructor, FormatProcessInfo, the constructor/destructor, and
TryAcquireForDirectory move verbatim into
src/platform/{windows,posix}/cross_process_file_lock.cc; the neutral
src/download/cross_process_file_lock.cc keeps only the cross-platform
WaitForDirectoryLock orchestration.
- Wire the four new sources into FOUNDRY_LOCAL_PLATFORM_SOURCES.
No behavior change; addresses Scott's #793 nit about keeping platform code in
src/platform. Verified: Windows build green, 83 download/lock/file-writer/state
tests pass, POSIX sources syntax-clean under g++ -Wall -Wextra.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
This PR is a structural cleanup following review nits from #793. It (1) eliminates four near-identical per-test TempDir/TempPath RAII classes by consolidating them into a single shared test/utils/temp_dir.h helper in the fl::test namespace, and (2) relocates the in-file #ifdef _WIN32 / POSIX branches for blob file I/O and the cross-process download lock into per-OS sources under src/platform/{windows,posix}/, matching the existing src/platform/.../path.cc pattern. It's purely internal to sdk_v2/cpp with no public C ABI change.
I verified: the moved file_io.cc/cross_process_file_lock.cc logic and error strings match the originals (the recombined "FileWriter " + error messages reproduce the prior text exactly); namespaces follow convention (fl::platform for file_io, fl for the CrossProcessFileLock member impls); removing #include "logger.h" from the neutral cross_process_file_lock.cc is safe because WaitForDirectoryLock only forwards ILogger&; the FileWriter handle sentinel change (nullptr/fd_→std::intptr_t handle_ = -1 = kInvalidFileHandle) is internally consistent; and all TempDir/TempPath references resolve via the test_helpers.h umbrella include, with the only behavioral deltas being cosmetic test-temp naming (prefixes unified to fl_test_, dropped .bin suffix).
Changes:
- Consolidated duplicated test temp-dir/path RAII helpers into
test/utils/temp_dir.hand removed the local copies plus the oldtest_helpers.hdefinitions. - Extracted Win32/POSIX file I/O behind
fl::platform::{OpenWritableFile,WriteFileAt,CloseFile}(src/platform/file_io.h+ per-OS.cc);FileWriternow stores anintptr_tand delegates. - Split
CrossProcessFileLockso platform pieces (State, ctor/dtor,FormatProcessInfo,TryAcquireForDirectory) move per-OS whileWaitForDirectoryLockorchestration stays neutral; wired the four new sources intoFOUNDRY_LOCAL_PLATFORM_SOURCES.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
sdk_v2/cpp/test/utils/temp_dir.h |
New shared fl::test TempDir/TempPath/MakeUniqueTempPath/CurrentPid helpers. |
sdk_v2/cpp/test/internal_api/test_helpers.h |
Removes inline temp helpers; includes the new umbrella header. |
sdk_v2/cpp/test/internal_api/{download,cross_process_file_lock,blob_download_state,file_writer}_test.cc |
Replace local temp classes with using fl::test::TempDir/TempPath. |
sdk_v2/cpp/src/platform/file_io.h |
New cross-platform file-handle I/O interface. |
sdk_v2/cpp/src/platform/{windows,posix}/file_io.cc |
Per-OS implementations of the file I/O primitives. |
sdk_v2/cpp/src/platform/{windows,posix}/cross_process_file_lock.cc |
Per-OS lock acquisition + State moved verbatim. |
sdk_v2/cpp/src/download/file_writer.{h,cc} |
Stores intptr_t handle and delegates to fl::platform. |
sdk_v2/cpp/src/download/cross_process_file_lock.cc |
Keeps only neutral WaitForDirectoryLock; drops platform branches. |
sdk_v2/cpp/CMakeLists.txt |
Wires the four new platform sources into the platform source list. |
Follow-up to #793 addressing two review nits from @skottmckay that were deferred to a separate PR.
1. Consolidate
TempDir/TempPathinto a shared test helperFour unit tests (
download_test,cross_process_file_lock_test,blob_download_state_test,file_writer_test) each defined a near-identical localTempDir/TempPathRAII class, andtest_helpers.hcarried theCurrentPid/MakeUniqueTempPathhelpers. These now live in a singletest/utils/temp_dir.h(fl::testnamespace); the tests use it via the existingtest_helpers.humbrella include.2. Move platform
#ifdefcode intosrc/platformBoth
file_writer.ccandcross_process_file_lock.cccarried Win32/POSIX branches behind in-file#ifdef _WIN32. Following the existingsrc/platform/{windows,posix}/path.ccpattern:src/platform/file_io.hdeclaresfl::platformOpenWritableFile/WriteFileAt/CloseFileprimitives over an integer handle, implemented per-OS insrc/platform/{windows,posix}/file_io.cc.FileWriterstores anintptr_thandle and delegates — no more#ifdefmember or branches.CrossProcessFileLockis split: the platform-specificState, its releasing destructor,FormatProcessInfo, the ctor/dtor, andTryAcquireForDirectorymove verbatim intosrc/platform/{windows,posix}/cross_process_file_lock.cc; the neutralsrc/download/cross_process_file_lock.cckeeps only the cross-platformWaitForDirectoryLockorchestration.FOUNDRY_LOCAL_PLATFORM_SOURCES.Validation
RelWithDebInfobuild green; 83 download / lock / file-writer / state unit tests pass (incl. all 9CrossProcessFileLockTest).g++ -std=c++20 -Wall -Wextra; full POSIX link validated by CI.