Skip to content

Consolidate test temp helpers and move file I/O + lock platform code into src/platform (#793 follow-up)#851

Open
bmehta001 wants to merge 2 commits into
mainfrom
bhamehta/flcore/platform-test-cleanup
Open

Consolidate test temp helpers and move file I/O + lock platform code into src/platform (#793 follow-up)#851
bmehta001 wants to merge 2 commits into
mainfrom
bhamehta/flcore/platform-test-cleanup

Conversation

@bmehta001

Copy link
Copy Markdown
Contributor

Follow-up to #793 addressing two review nits from @skottmckay that were deferred to a separate PR.

1. Consolidate TempDir / TempPath into a shared test helper

nit: Multiple tests have a TempDir class and we also have a TempPath. can we consolidate the temp dir/path logic into a shared helper in test/utils?

Four unit tests (download_test, cross_process_file_lock_test, blob_download_state_test, file_writer_test) each defined a near-identical local TempDir/TempPath RAII class, and test_helpers.h carried the CurrentPid/MakeUniqueTempPath helpers. These now live in a single test/utils/temp_dir.h (fl::test namespace); the tests use it via the existing test_helpers.h umbrella include.

2. Move platform #ifdef code into src/platform

file_writer.cc: consider moving platform code in src/platform like ORT

Both file_writer.cc and cross_process_file_lock.cc carried Win32/POSIX branches behind in-file #ifdef _WIN32. Following the existing src/platform/{windows,posix}/path.cc pattern:

  • New src/platform/file_io.h declares fl::platform OpenWritableFile / WriteFileAt / CloseFile primitives over an integer handle, implemented per-OS in src/platform/{windows,posix}/file_io.cc. FileWriter stores an intptr_t handle and delegates — no more #ifdef member or branches.
  • CrossProcessFileLock is split: the platform-specific State, its releasing destructor, FormatProcessInfo, the ctor/dtor, 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.
  • The four new sources are wired into FOUNDRY_LOCAL_PLATFORM_SOURCES.

Validation

  • No behavior change — pure refactor.
  • Windows RelWithDebInfo build green; 83 download / lock / file-writer / state unit tests pass (incl. all 9 CrossProcessFileLockTest).
  • POSIX sources syntax-clean under g++ -std=c++20 -Wall -Wextra; full POSIX link validated by CI.

bmehta001 and others added 2 commits June 30, 2026 05:25
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>
Copilot AI review requested due to automatic review settings June 30, 2026 10:28
@vercel

vercel Bot commented Jun 30, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
foundry-local Ready Ready Preview, Comment Jun 30, 2026 10:28am

Request Review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.h and removed the local copies plus the old test_helpers.h definitions.
  • Extracted Win32/POSIX file I/O behind fl::platform::{OpenWritableFile,WriteFileAt,CloseFile} (src/platform/file_io.h + per-OS .cc); FileWriter now stores an intptr_t and delegates.
  • Split CrossProcessFileLock so platform pieces (State, ctor/dtor, FormatProcessInfo, TryAcquireForDirectory) move per-OS while WaitForDirectoryLock orchestration stays neutral; wired the four new sources into FOUNDRY_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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants