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

Closed
tahffo68hk-hash wants to merge 0 commits from upstream-pr/384 into main
tahffo68hk-hash commented 2026-11-24 04:16:01 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tahffo68hk-hash on 2026-11-24T04:16:01Z.


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)。
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5465975128 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/384). Originally posted by [tahffo68hk-hash](https://github.com/tahffo68hk-hash) on 2026-11-24T04:16:01Z. --- 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>
Oliwettoo commented 2026-11-24 10:34:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Oliwettoo on 2026-11-24T10:34:19Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7128957748 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/384#issuecomment-7128957748). Originally posted by [Oliwettoo](https://github.com/Oliwettoo) on 2026-11-24T10:34:19Z. --- 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.
MoonEyes commented 2026-11-27 23:19:27 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-27T23:19:27Z.


Hi @tahffo68hk-hash, thanks for this pull request. It currently conflicts with main (conflicting file(s): tools/pe_inspect.py), so it carries the needs rebase label. CONTRIBUTING.md asks authors to rebase their branch on main; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.

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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7230051460 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/384#issuecomment-7230051460). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-27T23:19:27Z. --- Hi @tahffo68hk-hash, thanks for this pull request. It currently conflicts with `main` (conflicting file(s): `tools/pe_inspect.py`), so it carries the `needs rebase` label. CONTRIBUTING.md asks authors to rebase their branch on `main`; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here. AI-assisted (Claude Code, Claude Opus 5.5).
aslan2142 commented 2026-12-01 11:50:36 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:50:36Z.

Review: CHANGES_REQUESTED


Reviewed against current main: this branch conflicts with main in tools/pe_inspect.py and has failing CI. Please rebase onto current main (and consider delegating path equality to tools/report_paths.same_report_path per repo convention) so CI runs cleanly.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6130669296 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/384#pullrequestreview-6130669296). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T11:50:36Z. **Review:** CHANGES_REQUESTED --- Reviewed against current `main`: this branch conflicts with `main` in `tools/pe_inspect.py` and has failing CI. Please rebase onto current `main` (and consider delegating path equality to `tools/report_paths.same_report_path` per repo convention) so CI runs cleanly. *(AI-assisted review.)*
MoonEyes commented 2026-12-02 10:32:07 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T10:32:07Z.


For information: this pull request is carried in #3085, which merges your head (your commits are kept) into current main, resolves the conflicts keeping both sides, and fixes the points raised in review here (details in its description). This one stays open until a maintainer decides; if you pick it up again, say so and the carry can be closed.

AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7342611595 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/384#issuecomment-7342611595). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T10:32:07Z. --- For information: this pull request is carried in #3085, which merges your head (your commits are kept) into current `main`, resolves the conflicts keeping both sides, and fixes the points raised in review here (details in its description). This one stays open until a maintainer decides; if you pick it up again, say so and the carry can be closed. AI-assisted (Claude Code, Claude Opus 5.5)
MoonEyes commented 2026-12-02 11:39:32 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T11:39:32Z.


Closing: this pull request no longer applies to current main (merge conflict in tools/pe_inspect.py), and open pull requests that have fallen out of step with main are being closed so the list stays workable. Your work is not lost: it is carried in #3085, which keeps your commits and resolves the conflict on current main.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7344226463 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/384#issuecomment-7344226463). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T11:39:32Z. --- Closing: this pull request no longer applies to current `main` (merge conflict in `tools/pe_inspect.py`), and open pull requests that have fallen out of step with `main` are being closed so the list stays workable. Your work is not lost: it is carried in #3085, which keeps your commits and resolves the conflict on current `main`. AI-assisted (Claude Code).

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!384
No description provided.