Skip to content

psin_psch: report missing inputs/unwritable json as ERROR + exit 2 and guard carve-dir streams - #6260

Open
Alpaca-exe wants to merge 1 commit into
ItsNotRexed:mainfrom
Alpaca-exe:psin-psch-cli-errors
Open

Alpaca-exe wants to merge 1 commit into
ItsNotRexed:mainfrom
Alpaca-exe:psin-psch-cli-errors

Conversation

@Alpaca-exe

Copy link
Copy Markdown
Contributor

Improves CLI error handling and --carve-dir collision protection in tools/psin_psch.py:

Changes

  • tools/psin_psch.py:
    • Preflight target and --carve-dir with os.path.exists(...) in main(), printing one ERROR: <path>: does not exist line to stderr and exiting 2.
    • Extend check_report_path() so --json is also checked against every carved <offset>.bin stream listed in --carve-dir/index.json (via gm.check_report_path), not only --carve-dir and index.json themselves.
    • Format CLI/IO error lines uniformly with ERROR: and return 2 for missing/unreadable OSError inputs, --json collision errors, and unwritable --json destinations (returning 1 for malformed container payloads).
  • tests/test_psin_psch.py:
    • Add test_cli_reports_missing_inputs_unwritable_json_and_carve_dir_collisions_with_exit_2 covering missing targets, missing --carve-dir, unwritable --json, and --json colliding with a carved stream in --carve-dir/index.json.

Checks (AI-assisted, Windows 11, no game files)

  • python -m compileall -q make_game.py tools tests -> exit 0
  • python -I scripts/check_no_game_data.py -> exit 0
  • python -I tests/test_psin_psch.py -v -> Ran 4 tests (OK)
  • python -I tests/test_text_write_line_endings.py -v -> Ran 3 tests (OK)
  • python -I tests/test_tool_startup.py -v -> Ran 2 tests (OK)
  • python -I tests/test_tool_stdout_encoding.py -v -> Ran 4 tests (OK)

@AsgerCode

Copy link
Copy Markdown

Tested 95492b8 on Windows 11 (NTFS), Python 3.12.10 (CPU only, no GPU, no game files): pass

What I ran:

  • python -I tests/test_psin_psch.py: 4 tests, OK (at the PR head, and again with the two PR files on current main f25ba44).
  • Same head: test_tool_startup.py 2 OK, test_tool_stdout_encoding.py 4 OK, test_text_write_line_endings.py 3 OK, test_gamedata_maps.py 23 OK, test_report_paths.py 21 OK, test_report_path_case.py 3 OK, test_missing_input_exit_codes.py 2 OK, test_bad_input_errors.py 11 OK. scripts/check_no_game_data.py: exit 0.
  • Negative control, whole merge-base tools/psin_psch.py: the new test fails (1 != 2, missing target).
  • Negative control, PR tool with only the new --carve-dir branch of check_report_path reverted: the new test fails (0 != 2). So the test also covers the carved-stream guard by itself, not only the exit codes.
  • Merge with current main (255 commits ahead): clean. main has not changed either file since the merge base.
  • Existing tests that could expect the old error: / exit 1: tests/test_psin_psch.py is the only test file that runs this tool, and its old overwrite test still passes. I also added psin_psch to MISSING_INPUT_TOOLS in tests/test_missing_input_exit_codes.py (BUILD-1046: one line, starts with ERROR:, names the path). It passes.

Edge cases by hand. Synthetic PSIN from the test's build_synthetic_psch_psin(), plus a --carve-dir with a space in its name, one 000000001000.bin and an index.json that lists it:

Case merge base PR
missing target exit 1, error: <path> exit 2, ERROR: <path>: does not exist
missing --carve-dir exit 0 (ignored) exit 2, ERROR: ... does not exist
--json = listed carved stream exit 0, stream overwritten exit 2, refused, stream unchanged
same stream as .BIN, by 8.3 short dir, by .., by hard link (os.link) exit 0 exit 2, refused, stream unchanged
--json = --carve-dir/index.json / the target / the carve dir exit 2 exit 2
--json parent is a regular file exit 1 exit 2, ERROR: cannot write ...
--carve-dir index.json is {}, with --json exit 0 exit 1, ERROR: 'files'

The last row only happens when the target is not an .rpf, so --carve-dir is not used anyway. With an .rpf target, the same index fails in ArchiveSource on main too.

Overlap with other open PRs:

AI-assisted (Claude Code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants