runtime: guard empty destination and null data in write_pipeline_cache_file and add tests (RT-PIPELINE-CACHE-FILE-GUARDS-AND-TESTS) #2061

Merged
leonida/mandy
abnalstlll-byte merged 1 commit from feat/rt-pipeline-cache-file-guards-and-tests into main 2026-11-28 18:12:54 +00:00

Pull request successfully merged and closed

abnalstlll-byte commented 2026-11-25 19:14:51 +00:00

Claimed in the coordination issue as: RT-PIPELINE-CACHE-FILE-GUARDS-AND-TESTS (claim)

What and why

runtime/src/pipeline_cache_file.h provides atomic, crash-safe checkpoint writes for the pipeline cache file via same-directory staging and renaming.

  1. Input guards:

    • write_pipeline_cache_file: returns std::errc::invalid_argument immediately if destination.empty() (preventing creation of orphan .tmp... files in the working directory) or if size > 0 && !data (preventing null pointer dereference in std::fwrite).
    • Safely allows writing an empty 0-byte file when size == 0 (even if data is null).
  2. Test suite extension (runtime/test/pipeline_cache_file_test.cpp):

    • Verifies destination.empty() returns std::errc::invalid_argument.
    • Verifies null buffer with positive size returns std::errc::invalid_argument.
    • Verifies writing 0 bytes with null data creates an empty file and succeeds.
    • Cleans up temporary test file to preserve directory file-count invariants.

Tested

  • Standalone test execution: pipeline_cache_file_test passes cleanly (exit 0).
  • python -I tests/test_ci_registration.py: 16/16 pass.
  • python -I tests/test_text_write_line_endings.py: 3/3 pass.
  • python -I scripts/check_no_game_data.py: clean (0 violations, no game data).

AI-assisted (Claude Code)

Claimed in the coordination issue as: RT-PIPELINE-CACHE-FILE-GUARDS-AND-TESTS ([claim](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7171974710)) ### What and why `runtime/src/pipeline_cache_file.h` provides atomic, crash-safe checkpoint writes for the pipeline cache file via same-directory staging and renaming. 1. **Input guards**: - `write_pipeline_cache_file`: returns `std::errc::invalid_argument` immediately if `destination.empty()` (preventing creation of orphan `.tmp...` files in the working directory) or if `size > 0 && !data` (preventing null pointer dereference in `std::fwrite`). - Safely allows writing an empty 0-byte file when `size == 0` (even if `data` is null). 2. **Test suite extension (`runtime/test/pipeline_cache_file_test.cpp`)**: - Verifies `destination.empty()` returns `std::errc::invalid_argument`. - Verifies null buffer with positive size returns `std::errc::invalid_argument`. - Verifies writing 0 bytes with null data creates an empty file and succeeds. - Cleans up temporary test file to preserve directory file-count invariants. ### Tested - Standalone test execution: `pipeline_cache_file_test` passes cleanly (exit 0). - `python -I tests/test_ci_registration.py`: 16/16 pass. - `python -I tests/test_text_write_line_endings.py`: 3/3 pass. - `python -I scripts/check_no_game_data.py`: clean (0 violations, no game data). AI-assisted (Claude Code)
zmasi commented 2026-11-28 11:28:39 +00:00

Verified on Windows 11 (10.0.26200.9974) with MSVC 19.44.35228 (x64, /std:c++20 /EHsc /W4 /permissive- /utf-8 /O2) against main 4a54aedcb + ca0c72f81 (claim #2570#issuecomment-7238486276):

  • Line-by-line diff audit: Clean (runtime/src/pipeline_cache_file.h, runtime/test/pipeline_cache_file_test.cpp); rejects empty destination or null data when size > 0 with std::errc::invalid_argument, while preserving (nullptr, 0) empty-file writes. check_no_game_data.py clean.
  • Red (4a54aedcb + PR test): pipeline_cache_file_test.exe fails (rc=1 at line 50: write_pipeline_cache_file("", "data", 4) == std::make_error_code(std::errc::invalid_argument)).
  • Green (4a54aedcb + ca0c72f81 merge): Merges cleanly (rc=0), compiles cleanly, and pipeline_cache_file_test.exe passes (rc=0).

AI-assisted.

Verified on Windows 11 (`10.0.26200.9974`) with MSVC `19.44.35228` (`x64`, `/std:c++20 /EHsc /W4 /permissive- /utf-8 /O2`) against `main` `4a54aedcb` + `ca0c72f81` (claim `#2570#issuecomment-7238486276`): - **Line-by-line diff audit**: Clean (`runtime/src/pipeline_cache_file.h`, `runtime/test/pipeline_cache_file_test.cpp`); rejects empty `destination` or null `data` when `size > 0` with `std::errc::invalid_argument`, while preserving `(nullptr, 0)` empty-file writes. `check_no_game_data.py` clean. - **Red (`4a54aedcb` + PR test)**: `pipeline_cache_file_test.exe` fails (`rc=1` at `line 50: write_pipeline_cache_file("", "data", 4) == std::make_error_code(std::errc::invalid_argument)`). - **Green (`4a54aedcb` + `ca0c72f81` merge)**: Merges cleanly (`rc=0`), compiles cleanly, and `pipeline_cache_file_test.exe` passes (`rc=0`). AI-assisted.
MoonEyes commented 2026-11-28 18:12:52 +00:00

Red/green: On main pipeline_cache_file_test fails at line 50 (an empty destination is not refused with invalid_argument), and with the PR ctest -R "^pipeline_cache_file$" passes.
Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.

Red/green: On main pipeline_cache_file_test fails at line 50 (an empty destination is not refused with invalid_argument), and with the PR ctest -R "^pipeline_cache_file$" passes. Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.
OreoFR commented 2026-11-28 21:59:28 +00:00

Verified by OreoFR

  • Base: main c1ecf04ed + PR head ca0c72f81; green run in a merge package of 16 PRs, no new ctest failure vs main
  • Test: ctest -R "^pipeline_cache_file$"
  • Red on main: 1 failure, line 50 (empty destination not refused with invalid_argument)
  • Green with the PR: OK
  • Verdict: READY
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

AI-assisted (Claude Code, Claude Opus 5.5).

**Verified by OreoFR** - Base: main `c1ecf04ed` + PR head `ca0c72f81`; green run in a merge package of 16 PRs, no new ctest failure vs main - Test: `ctest -R "^pipeline_cache_file$"` - Red on main: 1 failure, line 50 (empty destination not refused with invalid_argument) - Green with the PR: OK - Verdict: READY - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 AI-assisted (Claude Code, Claude Opus 5.5).
Sign in to join this conversation.
No description provided.