Skip to content

test: add path safety, validation, and JSON deserialize regression coverage#334

Draft
cursor[bot] wants to merge 4 commits into
masterfrom
impl/missing-test-coverage-9755
Draft

test: add path safety, validation, and JSON deserialize regression coverage#334
cursor[bot] wants to merge 4 commits into
masterfrom
impl/missing-test-coverage-9755

Conversation

@cursor

@cursor cursor Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Risky behavior now covered

  • Path traversal on extract (path_safety.py): rejects writes outside allowed base, ../ escapes, overlong paths, and strict missing-path mode; validates PYKOTOR_EXTRACT_DIR behavior.
  • CLI get output safety: cmd_get returns exit code 1 and logs rejection when output resolves outside CWD.
  • Installation validation (validation.py): missing essential 2DAs, TXI/2DA lookup, module resource reference checks, and get_installation_summary counts.
  • JSON archive deserialize (resource_json.py / archive_serializer.py): base64 and GFF-JSON embedded payloads, direct JSON binary wrapper, and ERF base64 round-trip via dict_to_archive.

Test files added/updated

File Change
Libraries/PyKotor/tests/test_path_safety.py New — 10 unit tests
Libraries/PyKotor/tests/test_validation.py New — 7 unit tests
Libraries/PyKotor/tests/test_resource_json_deserialize.py New — 6 unit tests
Libraries/PyKotor/tests/resource/formats/test_archive_serializer_regressions.py ERF base64 round-trip
Libraries/PyKotor/tests/cli/test_json_commands.py cmd_get path rejection

Production fixes uncovered by new tests

  • deserialize_embedded_resource_payload: pass raw bytes instead of BytesIO to JSON readers (peek pass closed the stream).
  • _dict_to_erf / _dict_to_rim: use bytearray instead of BytesIO after write_* closes the stream.

Why this reduces regression risk

These areas guard high-blast-radius flows: MCP/CLI extract path safety, installation health checks used by CLI and MCP tools, and archive JSON round-trips used by from-json / archive conversion. The new tests are deterministic, use tmp_path fixtures, and do not require a game install.

Validation

QT_QPA_PLATFORM=offscreen uv run pytest --import-mode=importlib -m "not gui and not slow" --timeout=120 \
  tests/test_path_safety.py tests/test_validation.py tests/test_resource_json_deserialize.py \
  tests/resource/formats/test_archive_serializer_regressions.py \
  tests/cli/test_json_commands.py::test_cmd_get_rejects_output_path_outside_cwd

29 passed

Open in Web View Automation 

cursoragent and others added 4 commits June 11, 2026 10:15
Co-authored-by: PuritanWizard <th3w1zard1@users.noreply.github.com>
Co-authored-by: PuritanWizard <th3w1zard1@users.noreply.github.com>
Co-authored-by: PuritanWizard <th3w1zard1@users.noreply.github.com>
Co-authored-by: PuritanWizard <th3w1zard1@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

Message that will be displayed on users' first pull request

@github-actions github-actions Bot added python Pull requests that update python code libraries size/L Large PR (300-500 lines) labels Jun 11, 2026

from __future__ import annotations

import os

import pytest

from pykotor.resource.formats.gff import bytes_gff, read_gff
@github-actions

Copy link
Copy Markdown
Contributor

🔨 Build Validation Summary

Version Check: Passed

Tool Builds

HoloPatcher: Build failed
HoloPazaak: Build failed
HolocronToolset: Build failed
KotorDiff: Build failed
KotorMCP: Build failed


⚠️ Some builds failed. Please review the logs and fix any issues before merging.

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

Labels

libraries python Pull requests that update python code size/L Large PR (300-500 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant