tools/classify_carve.py: normalize head case, accept argv, and validate resolved report path #2279

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

@⁠kirigayakazima on GitHub · 2026-11-26 12:25 UTC · original
kirigayakazima:fix/classify-carve-safety → main · +47 −8 · 2 files · 1 commits · open

Claimed in the coordination issue as: CLASSIFY-CARVE-ARGV-CASE-HEAD-AND-REALPATH-GUARD (#1608)

What and why

  • Add an optional argv=None parameter to main(argv=None) in tools/classify_carve.py so callers can invoke it directly without mutating sys.argv while keeping sys.argv[1:] as the default.
  • Normalize hex signatures with .lower() in classify() so uppercase hex headers (52424630..., 42400000..., DEADBEEF...) match known signatures and other:<hex> buckets instead of creating duplicate uppercase buckets.
  • Resolve dest = os.path.realpath(report) and check both os.path.isdir(...) and not os.path.isdir(dest_dir) upfront before scanning per-archive index.json files.
  • Append a trailing \n after json.dump(out, f, indent=1) when writing types.json.
  • Add unit tests in tests/test_classify_carve.py covering uppercase signatures, explicit main([root]) invocation with trailing LF verification, and upfront rejection of resolved directory/non-directory-parent report paths.

Tested

  • python -I tests/test_classify_carve.py -v: 36 passed, 0 failed (detached upstream/main baseline with only the updated test file fails with 1 failure and 3 errors).
  • python -I tests/test_ci_registration.py: 16 passed.
  • python -I tests/test_text_write_line_endings.py: 3 passed.
  • python -I scripts/check_no_game_data.py, python -I -m compileall -q tools/classify_carve.py tests/test_classify_carve.py, and git diff --cached --check: passed.

GPUs tested: n/a

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.
**@⁠kirigayakazima** on GitHub · 2026-11-26 12:25 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2279) `kirigayakazima:fix/classify-carve-safety` → `main` · +47 −8 · 2 files · 1 commits · open Claimed in the coordination issue as: CLASSIFY-CARVE-ARGV-CASE-HEAD-AND-REALPATH-GUARD (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why - Add an optional `argv=None` parameter to `main(argv=None)` in `tools/classify_carve.py` so callers can invoke it directly without mutating `sys.argv` while keeping `sys.argv[1:]` as the default. - Normalize hex signatures with `.lower()` in `classify()` so uppercase hex headers (`52424630...`, `42400000...`, `DEADBEEF...`) match known signatures and `other:<hex>` buckets instead of creating duplicate uppercase buckets. - Resolve `dest = os.path.realpath(report)` and check both `os.path.isdir(...)` and `not os.path.isdir(dest_dir)` upfront before scanning per-archive `index.json` files. - Append a trailing `\n` after `json.dump(out, f, indent=1)` when writing `types.json`. - Add unit tests in `tests/test_classify_carve.py` covering uppercase signatures, explicit `main([root])` invocation with trailing LF verification, and upfront rejection of resolved directory/non-directory-parent report paths. ### Tested - `python -I tests/test_classify_carve.py -v`: 36 passed, 0 failed (detached `upstream/main` baseline with only the updated test file fails with 1 failure and 3 errors). - `python -I tests/test_ci_registration.py`: 16 passed. - `python -I tests/test_text_write_line_endings.py`: 3 passed. - `python -I scripts/check_no_game_data.py`, `python -I -m compileall -q tools/classify_carve.py tests/test_classify_carve.py`, and `git diff --cached --check`: passed. GPUs tested: n/a 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 12:29:53 +00:00
Author
Owner

@⁠DeadlyChirp on GitHub · 2026-11-26 12:51 UTC · original

Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main.

  • tests/test_classify_carve.py: 35 passed, 1 skipped, 12 subtests passed (main: 32 passed, the same skip).

(AI-assisted test run; output checked by hand.)

**@⁠DeadlyChirp** on GitHub · 2026-11-26 12:51 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2279#issuecomment-7192559169) Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main. - `tests/test_classify_carve.py`: 35 passed, 1 skipped, 12 subtests passed (main: 32 passed, the same skip). (AI-assisted test run; output checked by hand.)
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-27 04:38 UTC · original · approved these changes

Approving 6861c7d36.

Lowercasing head cannot change a match, since the three prefixes are digits only; it only merges heads that differed in letter case into one other: bucket. main takes argv, and the resolved report path and its folder are checked before the carve is walked.

Merged onto main d1dff7949 in one batch with 15 other tool PRs of this series (no conflicts), on Linux with Python 3.13. tests/test_classify_carve.py: 35 passed, 1 skipped (main: 32). AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠tiguan26** on GitHub · 2026-11-27 04:38 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2279#pullrequestreview-6083554364) · **approved these changes** Approving 6861c7d36. Lowercasing `head` cannot change a match, since the three prefixes are digits only; it only merges heads that differed in letter case into one `other:` bucket. `main` takes argv, and the resolved report path and its folder are checked before the carve is walked. Merged onto `main` `d1dff7949` in one batch with 15 other tool PRs of this series (no conflicts), on Linux with Python 3.13. `tests/test_classify_carve.py`: 35 passed, 1 skipped (main: 32). AI-assisted (Claude Code, Claude Opus 5.5).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

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