diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ac134f..198e371 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] ### Fixed +- **Tests on non-UTF-8 consoles (e.g. Korean Windows, cp949):** test subprocesses now + write and are read as UTF-8 (`tests/conftest.py` + `encoding="utf-8"`); 7 tests failed + there because the reader thread could not decode the CLI's emoji. Tests that pin a + console encoding still set it themselves. No package code changed. - **Concurrent appenders no longer fork the chain.** `record()` and `witness_peer()` (the two writers, both through `_seal`) now reads the head seal and writes its line under an exclusive OS lock on a sidecar `.lock` file. Before, two diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..5621771 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,11 @@ +"""Make test subprocesses speak UTF-8 regardless of the host console. + +Tests read child output with encoding="utf-8". On a non-UTF-8 Windows console +(e.g. Korean cp949) a child would otherwise print in the console codepage, and the +reader thread failed on emoji bytes, handing the test `stdout=None` (40 failures in +measure-mirror, 7 in action-mirror, 2026-11-24). Tests that pin a specific console +encoding set PYTHONIOENCODING themselves and still override this default. +""" +import os + +os.environ.setdefault("PYTHONIOENCODING", "utf-8") diff --git a/tests/test_aat.py b/tests/test_aat.py index 9a5a82f..b24c968 100644 --- a/tests/test_aat.py +++ b/tests/test_aat.py @@ -172,7 +172,7 @@ def test_verify_compares_timestamps_as_instants(tmp_path): def _cli(*args): return subprocess.run([sys.executable, "-m", "actmirror.am", *args], - capture_output=True, text=True, env=_ENV) + capture_output=True, encoding="utf-8", env=_ENV) def test_cli_export_and_verify(tmp_path): diff --git a/tests/test_cli_exit_codes.py b/tests/test_cli_exit_codes.py index e41ad0b..2c8b151 100644 --- a/tests/test_cli_exit_codes.py +++ b/tests/test_cli_exit_codes.py @@ -24,7 +24,7 @@ def cli(*args): return subprocess.run([sys.executable, "-m", "actmirror.am", *args], - capture_output=True, text=True, env=_ENV) + capture_output=True, encoding="utf-8", env=_ENV) def _tamper_field(ledger: str, field: str, value): @@ -122,7 +122,7 @@ def cli_in_encoding(encoding, *args, read_as=None): thread died on byte 0x81 (the 👁 in the witness line) with stdout coming back None. """ env = {**_ENV, "PYTHONIOENCODING": encoding} - kw = {"encoding": read_as} if read_as else {"text": True} + kw = {"encoding": read_as or encoding} return subprocess.run([sys.executable, "-m", "actmirror.am", *args], capture_output=True, env=env, **kw) diff --git a/tests/test_concurrent_append.py b/tests/test_concurrent_append.py index 97df107..ea23859 100644 --- a/tests/test_concurrent_append.py +++ b/tests/test_concurrent_append.py @@ -30,7 +30,7 @@ def test_concurrent_appenders_keep_one_chain(tmp_path): env = dict(os.environ) env["PYTHONPATH"] = ROOT + os.pathsep + env.get("PYTHONPATH", "") procs = [subprocess.Popen([sys.executable, "-c", WRITER, path, str(w), "30"], - env=env, stderr=subprocess.PIPE, text=True) + env=env, stderr=subprocess.PIPE, encoding="utf-8") for w in range(4)] for p in procs: _, err = p.communicate(timeout=120)