pe_inspect: refuse aliased JSON/Markdown report outputs (PE-REPORT-OUTPUT-ALIAS) #384

Open
github-bot wants to merge 1 commit from github-bot/gh-384 into main AGit
Owner

@⁠tahffo68hk-hash on GitHub · 2026-11-24 04:16 UTC · original
tahffo68hk-hash:fix/pe-report-output-alias → main · +65 −0 · 2 files · 1 commits · open

Claimed in the coordination issue as: PE-REPORT-OUTPUT-ALIAS

Problem

tools/pe_inspect.py checks same_output_path() between each report output (.json / .md) and every input image, but did not check:

  1. Whether json_path and md_path refer to the same underlying file (e.g., via hard link or symlink). Writing .json and then .md silently truncated and overwrote the JSON report with Markdown while still returning exit code 0.
  2. Whether a later image's report output in the same run aliases a report already written for an earlier image.

Fix

  • Check same_output_path(json_path, md_path) before writing either report; refuse and return exit code 1 without modifying the aliased file.
  • Track written_outputs across the run and refuse if a subsequent image's .json or .md aliases an earlier report.
  • Add synthetic regression tests in tests/test_pe_inspect.py covering both hard-linked .json/.md outputs and cross-image report aliasing.

Verification

  • Command: python -I tests/test_pe_inspect.py
  • Result: 62 tests ran, 61 passed, 1 skipped (os.symlink privilege on Windows), 0 failed.
  • Environment: Windows 11, Python 3.13.12 (no game files, CPU-only).
  • AI-assisted: Yes (Antigravity).
中文翻译

在协调帖 #14 中认领的 ID:PE-REPORT-OUTPUT-ALIAS

问题描述

tools/pe_inspect.py 检查了输出报告(.json / .md)与输入文件是否指向同一路径,但未检查:

  1. json_path 与 md_path 彼此是否指向同一底层文件(例如硬链接或符号链接),导致后写入的 Markdown 静默截断并覆盖 JSON 报告,且程序仍返回退出码 0。
  2. 同一次批量运行中,后续镜像的报告输出是否与先前已写入的报告互为别名。

修复方案

  • 写入前检查 same_output_path(json_path, md_path),若互为别名则拒绝写入并返回退出码 1,不破坏原文件。
  • 记录本次运行已写入的 written_outputs,拒绝后续镜像的报告覆盖先前已写入的报告。
  • 在 tests/test_pe_inspect.py 中补充合成回归测试,覆盖同镜像 .json/.md 硬链接别名与跨镜像报告别名两种场景。

验证结果

  • 命令:python -I tests/test_pe_inspect.py
  • 结果:共 62 项测试,61 通过,1 跳过(Windows os.symlink 权限限制),0 失败。
  • 环境:Windows 11,Python 3.13.12(无游戏文件,纯 CPU 测试)。
  • AI 辅助:是(Antigravity)。
**@⁠tahffo68hk-hash** on GitHub · 2026-11-24 04:16 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/384) `tahffo68hk-hash:fix/pe-report-output-alias` → `main` · +65 −0 · 2 files · 1 commits · open Claimed in the coordination issue as: `PE-REPORT-OUTPUT-ALIAS` ## Problem `tools/pe_inspect.py` checks `same_output_path()` between each report output (`.json` / `.md`) and every input image, but did not check: 1. Whether `json_path` and `md_path` refer to the same underlying file (e.g., via hard link or symlink). Writing `.json` and then `.md` silently truncated and overwrote the JSON report with Markdown while still returning exit code `0`. 2. Whether a later image's report output in the same run aliases a report already written for an earlier image. ## Fix - Check `same_output_path(json_path, md_path)` before writing either report; refuse and return exit code `1` without modifying the aliased file. - Track `written_outputs` across the run and refuse if a subsequent image's `.json` or `.md` aliases an earlier report. - Add synthetic regression tests in `tests/test_pe_inspect.py` covering both hard-linked `.json`/`.md` outputs and cross-image report aliasing. ## Verification - Command: `python -I tests/test_pe_inspect.py` - Result: 62 tests ran, 61 passed, 1 skipped (`os.symlink` privilege on Windows), 0 failed. - Environment: Windows 11, Python 3.13.12 (no game files, CPU-only). - AI-assisted: Yes (Antigravity). <details> <summary>中文翻译</summary> 在协调帖 #14 中认领的 ID:`PE-REPORT-OUTPUT-ALIAS` ## 问题描述 `tools/pe_inspect.py` 检查了输出报告(`.json` / `.md`)与输入文件是否指向同一路径,但未检查: 1. `json_path` 与 `md_path` 彼此是否指向同一底层文件(例如硬链接或符号链接),导致后写入的 Markdown 静默截断并覆盖 JSON 报告,且程序仍返回退出码 `0`。 2. 同一次批量运行中,后续镜像的报告输出是否与先前已写入的报告互为别名。 ## 修复方案 - 写入前检查 `same_output_path(json_path, md_path)`,若互为别名则拒绝写入并返回退出码 `1`,不破坏原文件。 - 记录本次运行已写入的 `written_outputs`,拒绝后续镜像的报告覆盖先前已写入的报告。 - 在 `tests/test_pe_inspect.py` 中补充合成回归测试,覆盖同镜像 `.json`/`.md` 硬链接别名与跨镜像报告别名两种场景。 ## 验证结果 - 命令:`python -I tests/test_pe_inspect.py` - 结果:共 62 项测试,61 通过,1 跳过(Windows `os.symlink` 权限限制),0 失败。 - 环境:Windows 11,Python 3.13.12(无游戏文件,纯 CPU 测试)。 - AI 辅助:是(Antigravity)。 </details>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:57:00 +00:00
Author
Owner

@⁠Oliwettoo on GitHub · 2026-11-24 10:34 UTC · original

Looks good; tests/test_pe_inspect.py passes with the PR on current main. One suggestion: CONTRIBUTING asks report writers to use tools/report_paths.same_report_path rather than a private check. pe_inspect.same_output_path (already on main, extended here) uses normcase, which doesn't fold case on macOS's default volume, so Out/a.json vs out/a.json there slips through; switching the three calls to same_report_path would cover that. AI-assisted review.

**@⁠Oliwettoo** on GitHub · 2026-11-24 10:34 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/384#issuecomment-7128957748) Looks good; `tests/test_pe_inspect.py` passes with the PR on current `main`. One suggestion: CONTRIBUTING asks report writers to use `tools/report_paths.same_report_path` rather than a private check. `pe_inspect.same_output_path` (already on `main`, extended here) uses `normcase`, which doesn't fold case on macOS's default volume, so `Out/a.json` vs `out/a.json` there slips through; switching the three calls to `same_report_path` would cover that. AI-assisted review.
This pull request has changes conflicting with the target branch.
  • tools/pe_inspect.py
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/384/head:github-bot/gh-384'
git switch 'github-bot/gh-384'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-384'
git switch 'github-bot/gh-384'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-384'
git switch 'github-bot/gh-384'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-384'
git switch 'main'
git merge --squash 'github-bot/gh-384'
git switch 'main'
git merge --ff-only 'github-bot/gh-384'
git switch 'main'
git merge 'github-bot/gh-384'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.