tools: one cached work_root() per shader instead of nine realpath() calls (OLD-9777) #1265

Closed
ambroseautomation wants to merge 3 commits from upstream-pr/1265 into main
ambroseautomation commented 2026-11-24 21:03:07 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ambroseautomation on 2026-11-24T21:03:07Z.


Claimed in the coordination issue as: OLD-9777 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7144385534)

What and why

Carries forward old-pr/9777 (draft #55, original commit author pes7 preserved across all 3 commits; indexed in #17), rebased cleanly onto current main (0b45fdc21).

Replaces repeated os.path.realpath calls per shader in tools/rdna2spirv.py and tools/shader_meta.py with a cached work_root() helper in tools/report_paths.py:

  • Caches os.path.realpath for absolute paths so translating a shader resolves its work root once instead of nine times (byte-identical output).
  • Resolves relative paths on every call (never from the cache), so changing working directory between calls still resolves accurately.
  • Adds WorkRootTests in tests/test_report_paths.py verifying absolute-path caching, relative-path re-resolution after os.chdir, and 8.3 short-path compatibility on Windows.

Tested

  • python -I tests/test_report_paths.py -v: 24 tests, OK (1 skipped: Windows symlink privilege).
  • python -m compileall -q make_game.py tools tests: exit 0.
  • python -I scripts/check_no_game_data.py tools/report_paths.py tools/rdna2spirv.py tools/shader_meta.py tests/test_report_paths.py: exit 0 (no game data).

GPUs tested: n/a (Python path resolution helper + stdlib unit tests on Windows 11 Pro 64-bit, Python 3.12.10)

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. (n/a — path-resolution caching only, no codegen changes)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5480287582 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1265). Originally posted by [ambroseautomation](https://github.com/ambroseautomation) on 2026-11-24T21:03:07Z. --- Claimed in the coordination issue as: OLD-9777 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7144385534) ### What and why Carries forward `old-pr/9777` (draft #55, original commit author `pes7` preserved across all 3 commits; indexed in #17), rebased cleanly onto current `main` (`0b45fdc21`). Replaces repeated `os.path.realpath` calls per shader in `tools/rdna2spirv.py` and `tools/shader_meta.py` with a cached `work_root()` helper in `tools/report_paths.py`: - Caches `os.path.realpath` for absolute paths so translating a shader resolves its work root once instead of nine times (byte-identical output). - Resolves relative paths on every call (never from the cache), so changing working directory between calls still resolves accurately. - Adds `WorkRootTests` in `tests/test_report_paths.py` verifying absolute-path caching, relative-path re-resolution after `os.chdir`, and 8.3 short-path compatibility on Windows. ### Tested - `python -I tests/test_report_paths.py -v`: 24 tests, OK (1 skipped: Windows symlink privilege). - `python -m compileall -q make_game.py tools tests`: exit 0. - `python -I scripts/check_no_game_data.py tools/report_paths.py tools/rdna2spirv.py tools/shader_meta.py tests/test_report_paths.py`: exit 0 (no game data). GPUs tested: n/a (Python path resolution helper + stdlib unit tests on Windows 11 Pro 64-bit, Python 3.12.10) 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. (n/a — path-resolution caching only, no codegen changes)
tiguan26 commented 2026-11-25 06:23:13 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-25T06:23:13Z.

Review: APPROVED


Approving. Merged into current main (42537e7) with no conflicts. tests/test_report_paths.py plus the shader_meta tests pass (57 passed), and the full translator suite gives 487 files / 6,279 tests with only test_int32_to_f64 failing, as on main here (Linux, Python 3.13).

I checked every replaced call: each was the same dirname(dirname(realpath(path))), so work_root returns the same value. Only absolute spellings are cached, so a chdir can't give a stale answer, and the size cap stops the table growing past one corpus.

AI-assisted (Claude).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6052784950 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1265#pullrequestreview-6052784950). Originally posted by [tiguan26](https://github.com/tiguan26) on 2026-11-25T06:23:13Z. **Review:** APPROVED --- Approving. Merged into current main (42537e7) with no conflicts. `tests/test_report_paths.py` plus the shader_meta tests pass (57 passed), and the full translator suite gives 487 files / 6,279 tests with only `test_int32_to_f64` failing, as on main here (Linux, Python 3.13). I checked every replaced call: each was the same `dirname(dirname(realpath(path)))`, so `work_root` returns the same value. Only absolute spellings are cached, so a `chdir` can't give a stale answer, and the size cap stops the table growing past one corpus. AI-assisted (Claude).
PierreEbele commented 2026-11-25 14:42:41 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by PierreEbele on 2026-11-25T14:42:41Z.


Reviewed 74cc3eb: 3 commits (cached work_root() helper, relative-path chdir guard, tests). Ran on arm64 Linux with no game files: tests/test_report_paths.py 24 OK on the branch; the branch's test file fails on main (no work_root) as expected; test_shader_meta, test_shader_meta_operands, test_shader_library, test_pe_shader_containers, test_bvh_shaders_stage and the fspx semantic tests all pass on both trees and on the branch applied to current main (the nine call sites are unchanged there; patch applies cleanly). Probed relative/absolute/symlinked/retargeted spellings across two synthetic work folders: only difference from main is the retargeted-symlink case, which is the documented "cannot change while a build runs" assumption and unreachable in a build where each spelling is translated once; relative-path-after-chdir behaves correctly on both. No findings. AI-assisted review.

Recommendation: Merge

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7165695450 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1265#issuecomment-7165695450). Originally posted by [PierreEbele](https://github.com/PierreEbele) on 2026-11-25T14:42:41Z. --- Reviewed 74cc3eb: 3 commits (cached work_root() helper, relative-path chdir guard, tests). Ran on arm64 Linux with no game files: tests/test_report_paths.py 24 OK on the branch; the branch's test file fails on main (no work_root) as expected; test_shader_meta, test_shader_meta_operands, test_shader_library, test_pe_shader_containers, test_bvh_shaders_stage and the fspx semantic tests all pass on both trees and on the branch applied to current main (the nine call sites are unchanged there; patch applies cleanly). Probed relative/absolute/symlinked/retargeted spellings across two synthetic work folders: only difference from main is the retargeted-symlink case, which is the documented "cannot change while a build runs" assumption and unreachable in a build where each spelling is translated once; relative-path-after-chdir behaves correctly on both. No findings. AI-assisted review. **Recommendation:** Merge

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!1265
No description provided.