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

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/384
Author: @tahffo68hk-hash
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: fix/pe-report-output-alias


📝 Commits (1)

  • 56354fa pe_inspect: refuse aliased JSON/Markdown and prior report outputs (PE-REPORT-OUTPUT-ALIAS)

📊 Changes

2 files changed (+65 additions, -0 deletions)

View changed files

📝 tests/test_pe_inspect.py (+46 -0)
📝 tools/pe_inspect.py (+19 -0)

📄 Description

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)。

🔄 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/384 **Author:** [@tahffo68hk-hash](https://github.com/tahffo68hk-hash) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/pe-report-output-alias` --- ### 📝 Commits (1) - [`56354fa`](https://github.com/ubiquitarianism/leonida/commit/56354fa39c2b0f1de0da9e804b6c90c7c43e05f9) pe_inspect: refuse aliased JSON/Markdown and prior report outputs (PE-REPORT-OUTPUT-ALIAS) ### 📊 Changes **2 files changed** (+65 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_pe_inspect.py` (+46 -0) 📝 `tools/pe_inspect.py` (+19 -0) </details> ### 📄 Description 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> --- <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#435
No description provided.