From b442fd688fee6ca28531ca96afb01685704d532d Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 17 May 2026 10:05:19 +0000 Subject: [PATCH 1/2] test(resource-json): cover ci live progress guard for json export Co-authored-by: Boden --- .../tests/test_resource_json_progress.py | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Libraries/PyKotor/tests/test_resource_json_progress.py diff --git a/Libraries/PyKotor/tests/test_resource_json_progress.py b/Libraries/PyKotor/tests/test_resource_json_progress.py new file mode 100644 index 000000000..f1de92174 --- /dev/null +++ b/Libraries/PyKotor/tests/test_resource_json_progress.py @@ -0,0 +1,41 @@ +"""Regression tests for JSON export progress reporting under automation.""" + +from __future__ import annotations + +import pytest + +from pykotor.tools.resource_json import _supports_live_progress + + +class _FakeTTYStream: + """Stream that claims to be a TTY (some CI runners attach a pseudo-TTY to stderr).""" + + def isatty(self) -> bool: + return True + + +class _FakeNonTTYStream: + def isatty(self) -> bool: + return False + + +def test_supports_live_progress_honors_ci_env(monkeypatch: pytest.MonkeyPatch) -> None: + """When CI is set, disable carriage-return live updates so logger-based progress is visible.""" + monkeypatch.delenv("CI", raising=False) + monkeypatch.delenv("GITHUB_ACTIONS", raising=False) + assert _supports_live_progress(_FakeTTYStream()) is True + + for ci_value in ("true", "True", "1", "yes", " YES "): + monkeypatch.setenv("CI", ci_value) + monkeypatch.delenv("GITHUB_ACTIONS", raising=False) + assert _supports_live_progress(_FakeTTYStream()) is False + + monkeypatch.delenv("CI", raising=False) + monkeypatch.setenv("GITHUB_ACTIONS", "1") + assert _supports_live_progress(_FakeTTYStream()) is False + + +def test_supports_live_progress_false_without_tty(monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.delenv("CI", raising=False) + monkeypatch.delenv("GITHUB_ACTIONS", raising=False) + assert _supports_live_progress(_FakeNonTTYStream()) is False From 4c00095576127f5599551de8760f56e4afb58650 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 17 May 2026 10:05:22 +0000 Subject: [PATCH 2/2] test(gff): roundtrip GFF_JSON via write_gff and read_gff Co-authored-by: Boden --- .../formats/test_gff_json_roundtrip.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Libraries/PyKotor/tests/resource/formats/test_gff_json_roundtrip.py diff --git a/Libraries/PyKotor/tests/resource/formats/test_gff_json_roundtrip.py b/Libraries/PyKotor/tests/resource/formats/test_gff_json_roundtrip.py new file mode 100644 index 000000000..7000d6785 --- /dev/null +++ b/Libraries/PyKotor/tests/resource/formats/test_gff_json_roundtrip.py @@ -0,0 +1,24 @@ +"""Regression tests for GFF JSON toolset format (GFFJSONWriter / read_gff JSON path).""" + +from __future__ import annotations + +import json + +from pykotor.resource.formats.gff import GFF, bytes_gff, read_gff +from pykotor.resource.formats.gff.gff_data import GFFFieldType +from pykotor.resource.type import ToolsetFormat + + +def test_write_gff_json_roundtrips_through_read_gff() -> None: + """write_gff(..., GFF_JSON) must stay aligned with read_gff auto-detect for `{` documents.""" + gff = GFF() + gff.root.set_uint32("SomeField", 0xDEADBEEF) + + raw_json = bytes_gff(gff, ToolsetFormat.GFF_JSON) + assert raw_json.lstrip().startswith(b"{") + parsed = json.loads(raw_json.decode("utf-8")) + assert parsed["fields"]["SomeField"]["type"] == GFFFieldType.UInt32.value + assert parsed["fields"]["SomeField"]["value"] == 0xDEADBEEF + + loaded = read_gff(raw_json) + assert loaded.root.get_uint32("SomeField") == 0xDEADBEEF