`scripts/run_tests.sh tests/<dir>/` is how a change gets its regression
coverage run, so a test filed under the wrong directory is a test nobody
runs when that code changes. Two kinds of drift had accumulated.
Parallel directories for one source package, folded into the mirror:
tests/acp -> tests/acp_adapter (its __init__/conftest move with it)
tests/cli -> tests/hermes_cli (prompt_toolkit fixture merged into
hermes_cli/conftest.py)
tests/run_agent -> tests/agent (backoff fixture becomes
agent/conftest.py)
tests/relay -> tests/gateway/relay
tests/state -> tests/hermes_state
246 loose files at tests/ root, routed by the package they import/patch:
hermes_cli, hermes_state, agent, gateway, tools, plugins, tui_gateway, cron.
Installer and desktop-update script tests go to tests/scripts/{install,
desktop_update}/. 43 tests of root-level modules (batch_runner, utils,
hermes_constants, packaging) stay at the root.
Filenames drop their issue numbers (95 files: test_89315_x.py -> test_x.py);
the number stays in the module docstring where it has context.
Collisions: test_cli_skin_integration.py existed in both tests/ and tests/cli
with different subsets — merged into one (10 tests, all kept);
run_agent/test_pre_compress_memory_context.py -> agent/..._handoff.py;
tests/test_account_usage.py -> agent/test_account_usage_fetch.py;
tests/test_web_server.py -> hermes_cli/test_web_server_ws_ping.py.
Deleted: test_minisweagent_path.py (empty since PR #2804),
test_model_picker_scroll.py (tested a private copy of the logic, imported
nothing), test_process_loop_event_loop_warning.py (asserted asyncio behaviour,
imported nothing from Hermes).
Repo-root path arithmetic (Path(__file__).parents[N], dirname chains) is
bumped for the 202 files that changed depth and verified by evaluating every
such expression against the new location. classify_changes' desktop-updater
lane prefix, tests-os.yml's ignore glob and every in-tree path comment follow
the moves. tests/test_tests_tree_layout.py keeps the tree from drifting back.
70 lines
2.3 KiB
Python
70 lines
2.3 KiB
Python
"""The runner's status glyphs must not crash narrow console encodings.
|
|
|
|
On native Windows, piped or legacy-console stdio defaults to cp1252, which
|
|
cannot encode the runner's ✓/✗ progress glyphs — before the fix, the first
|
|
per-file status line killed the whole run with UnicodeEncodeError. The
|
|
failure depends only on the stream's encoding, so these tests pin it on
|
|
every OS by building a cp1252 stream explicitly.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import importlib.util
|
|
import io
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parents[2]
|
|
_RUNNER_PATH = REPO_ROOT / "scripts" / "run_tests_parallel.py"
|
|
|
|
|
|
def _load_runner():
|
|
spec = importlib.util.spec_from_file_location("run_tests_parallel", _RUNNER_PATH)
|
|
mod = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(mod)
|
|
return mod
|
|
|
|
|
|
def _cp1252_stream() -> tuple[io.TextIOWrapper, io.BytesIO]:
|
|
raw = io.BytesIO()
|
|
return io.TextIOWrapper(raw, encoding="cp1252", errors="strict"), raw
|
|
|
|
|
|
def test_cp1252_stream_reproduces_the_crash_without_the_fix() -> None:
|
|
# Baseline for the bug: a strict cp1252 stream cannot take the glyph.
|
|
stream, _raw = _cp1252_stream()
|
|
try:
|
|
stream.write("✓")
|
|
except UnicodeEncodeError:
|
|
return
|
|
raise AssertionError("expected UnicodeEncodeError on strict cp1252")
|
|
|
|
|
|
def test_glyph_safe_stdio_survives_cp1252(monkeypatch) -> None:
|
|
mod = _load_runner()
|
|
stream, raw = _cp1252_stream()
|
|
monkeypatch.setattr(sys, "stdout", stream)
|
|
monkeypatch.setattr(sys, "stderr", stream)
|
|
|
|
mod._make_stdio_glyph_safe()
|
|
print("✓ tests/foo.py (3 tests, 1.2s) ✗")
|
|
sys.stdout.flush()
|
|
|
|
out = raw.getvalue()
|
|
assert "✓".encode("utf-8") in out, "stream should now carry UTF-8 glyphs"
|
|
assert b"tests/foo.py (3 tests, 1.2s)" in out, "line content must survive"
|
|
|
|
|
|
def test_glyph_safe_stdio_noop_without_reconfigure(monkeypatch) -> None:
|
|
# Streams without .reconfigure (e.g. pytest's capture buffers, plain
|
|
# StringIO) must pass through untouched instead of raising.
|
|
mod = _load_runner()
|
|
plain = io.StringIO()
|
|
monkeypatch.setattr(sys, "stdout", plain)
|
|
monkeypatch.setattr(sys, "stderr", plain)
|
|
|
|
mod._make_stdio_glyph_safe()
|
|
print("✓ still fine")
|
|
|
|
assert "✓ still fine" in plain.getvalue()
|