[PR #1590] wave_trace: validate select_case and --out upfront, harden render_report, unlink partial output (WAVE-TRACE-VALIDATION-AND-WRITE-CLEANUP) #1608

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1590
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/wave-trace-validation-and-write-cleanup


📝 Commits (1)

  • 4f30acf wave_trace: validate select_case and --out upfront, harden render_report, unlink partial output

📊 Changes

2 files changed (+126 additions, -7 deletions)

View changed files

📝 tests/test_wave_trace.py (+80 -0)
📝 tools/wave_trace.py (+46 -7)

📄 Description

Item: WAVE-TRACE-VALIDATION-AND-WRITE-CLEANUP (unclaimed — coordination issue #14 is at GitHub's 2,500-comment cap with no successor open issue yet, and 0 open PRs touch tools/wave_trace.py).

Summary

  • Validate case_index (type is int, >= 0) and max_ops (type is int, >= 1) in select_case() so negative case_index raises ValueError instead of UnboundLocalError and booleans are rejected.
  • Harden render_report() by verifying the <!-- WAVE_TRACE_DATA --> placeholder exists in wave_trace.html, passing allow_nan=False to json.dumps(), and escaping > (\u003e) alongside < (\u003c).
  • Validate --out before running inspect_case() (reject empty/whitespace strings, trailing directory separators, existing paths via os.path.lexists(), and missing parent directories) instead of silently accepting Path("") as . or wasting simulation work before failing.
  • Keep exclusive creation (open("x")) so existing files are never overwritten, and close and unlink the newly created file if stream.write() fails mid-write so no partial HTML report is left behind.

Verification

  • python3 -W error -I tests/test_wave_trace.py -v: 10/10 passed.
  • python3 -I tests/test_text_write_line_endings.py: 3/3 passed.
  • python3 -I scripts/check_no_game_data.py tools/wave_trace.py tests/test_wave_trace.py: passed.
  • python3 -m compileall -q tools/wave_trace.py tests/test_wave_trace.py: passed.
  • Mutation check (running tests/test_wave_trace.py against unpatched main:tools/wave_trace.py): failures=9, errors=1 across all 4 new regression tests.

AI-assisted: yes
GPUs tested: none (CPU-only Python interpreter/report tool; synthetic wave32 cases only, no game data)


🔄 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/1590 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/wave-trace-validation-and-write-cleanup` --- ### 📝 Commits (1) - [`4f30acf`](https://github.com/ubiquitarianism/leonida/commit/4f30acfcf050eddb79b3b9ce2bd7779fb06675f6) wave_trace: validate select_case and --out upfront, harden render_report, unlink partial output ### 📊 Changes **2 files changed** (+126 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_wave_trace.py` (+80 -0) 📝 `tools/wave_trace.py` (+46 -7) </details> ### 📄 Description Item: `WAVE-TRACE-VALIDATION-AND-WRITE-CLEANUP` (unclaimed — coordination issue #14 is at GitHub's 2,500-comment cap with no successor open issue yet, and 0 open PRs touch `tools/wave_trace.py`). ### Summary - Validate `case_index` (`type is int`, `>= 0`) and `max_ops` (`type is int`, `>= 1`) in `select_case()` so negative `case_index` raises `ValueError` instead of `UnboundLocalError` and booleans are rejected. - Harden `render_report()` by verifying the `<!-- WAVE_TRACE_DATA -->` placeholder exists in `wave_trace.html`, passing `allow_nan=False` to `json.dumps()`, and escaping `>` (`\u003e`) alongside `<` (`\u003c`). - Validate `--out` before running `inspect_case()` (reject empty/whitespace strings, trailing directory separators, existing paths via `os.path.lexists()`, and missing parent directories) instead of silently accepting `Path("")` as `.` or wasting simulation work before failing. - Keep exclusive creation (`open("x")`) so existing files are never overwritten, and close and unlink the newly created file if `stream.write()` fails mid-write so no partial HTML report is left behind. ### Verification - `python3 -W error -I tests/test_wave_trace.py -v`: 10/10 passed. - `python3 -I tests/test_text_write_line_endings.py`: 3/3 passed. - `python3 -I scripts/check_no_game_data.py tools/wave_trace.py tests/test_wave_trace.py`: passed. - `python3 -m compileall -q tools/wave_trace.py tests/test_wave_trace.py`: passed. - Mutation check (running `tests/test_wave_trace.py` against unpatched `main:tools/wave_trace.py`): `failures=9, errors=1` across all 4 new regression tests. AI-assisted: yes GPUs tested: none (CPU-only Python interpreter/report tool; synthetic wave32 cases only, no game data) --- <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#1608
No description provided.