[PR #2302] dstorage_vectors: add CLI validation and atomic output write #2308

Open
opened 2026-11-26 21:20:46 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2302
Author: @kirigayakazima
Created: 11/26/2026
Status: 🔄 Open

Base: main ← Head: fix/dstorage-vectors-safety


📝 Commits (1)

  • 5b7271b dstorage_vectors: add CLI validation and atomic output write

📊 Changes

2 files changed (+169 additions, -2 deletions)

View changed files

📝 runtime/test/dstorage_vectors.py (+77 -2)
➕ tests/test_dstorage_vectors.py (+92 -0)

📄 Description

Claimed in the coordination issue as: DSTORAGE-VECTORS-CLI-USAGE-AND-ATOMIC-WRITE (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7192927392)

What and why

  • Wrap CLI execution in runtime/test/dstorage_vectors.py into main(argv=None) -> int using argparse (output positional argument with -h/--help support instead of indexing sys.argv[1]).
  • Add _validate_output_path() to reject empty/whitespace paths, trailing separators, directory/symlink-to-directory targets, and non-directory ancestors upfront with exit code 2 before generating vectors.
  • Add write_file_atomic() writing UTF-8 LF (newline="\n") via sibling temp file, fsync, POSIX mode preservation, transient Windows PermissionError retry, and existing-file preservation on failure, returning exit code 1 with an ERROR: message on OSError.
  • Add standard-library unit tests in tests/test_dstorage_vectors.py.

Tested

  • python -I tests/test_dstorage_vectors.py -v: 2 passed, 0 failed (detached upstream/main baseline with only the new test file fails with 2 errors).
  • python -I tests/test_ci_registration.py: 16 passed.
  • python -I tests/test_text_write_line_endings.py: 3 passed.
  • python -I scripts/check_no_game_data.py, python -I -m compileall -q runtime/test/dstorage_vectors.py tests/test_dstorage_vectors.py, and git diff --cached --check: passed.

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2302 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/dstorage-vectors-safety` --- ### 📝 Commits (1) - [`5b7271b`](https://github.com/ubiquitarianism/leonida/commit/5b7271be750f97dd4bcc9de444864462255bfd9e) dstorage_vectors: add CLI validation and atomic output write ### 📊 Changes **2 files changed** (+169 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `runtime/test/dstorage_vectors.py` (+77 -2) ➕ `tests/test_dstorage_vectors.py` (+92 -0) </details> ### 📄 Description Claimed in the coordination issue as: DSTORAGE-VECTORS-CLI-USAGE-AND-ATOMIC-WRITE (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7192927392) ### What and why - Wrap CLI execution in `runtime/test/dstorage_vectors.py` into `main(argv=None) -> int` using `argparse` (`output` positional argument with `-h`/`--help` support instead of indexing `sys.argv[1]`). - Add `_validate_output_path()` to reject empty/whitespace paths, trailing separators, directory/symlink-to-directory targets, and non-directory ancestors upfront with exit code `2` before generating vectors. - Add `write_file_atomic()` writing UTF-8 LF (`newline="\n"`) via sibling temp file, `fsync`, POSIX mode preservation, transient Windows `PermissionError` retry, and existing-file preservation on failure, returning exit code `1` with an `ERROR:` message on `OSError`. - Add standard-library unit tests in `tests/test_dstorage_vectors.py`. ### Tested - `python -I tests/test_dstorage_vectors.py -v`: 2 passed, 0 failed (detached `upstream/main` baseline with only the new test file fails with 2 errors). - `python -I tests/test_ci_registration.py`: 16 passed. - `python -I tests/test_text_write_line_endings.py`: 3 passed. - `python -I scripts/check_no_game_data.py`, `python -I -m compileall -q runtime/test/dstorage_vectors.py tests/test_dstorage_vectors.py`, and `git diff --cached --check`: passed. GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#2308
No description provided.