From fdc00bb77f854d9e686b8123ea879b76e7c8cc9d Mon Sep 17 00:00:00 2001 From: Atri10 <64589033+Atri10@users.noreply.github.com> Date: Mon, 19 Oct 2026 16:02:18 +0530 Subject: [PATCH] fix(cli): print on a non-UTF-8 Windows console Windows pipes inherit the locale code page, so print(__doc__) raised UnicodeEncodeError on the help arrow (U+2192) before it wrote a line. main now reconfigures stdout and stderr to UTF-8 where the stream supports it, which also keeps ensure_ascii=False JSON intact when a title contains non-Latin text. The bare-launcher test is POSIX-only: Windows has no exec bit and CreateProcess cannot run a .py file without a registered association. The portable python3 /scripts/executor spelling stays the documented, tested form. Bumps the engine to 2.0.3 and syncs the bundle. --- CHANGELOG.md | 21 +++++++++++++++++++ README.md | 6 +++--- engine/executor/__init__.py | 2 +- engine/executor/cli.py | 12 +++++++++++ engine/tests/test_cli.py | 20 ++++++++++++++++++ engine/tests/test_engine_ships_with_skill.py | 3 +++ .../executor/scripts/lib/executor/__init__.py | 2 +- skills/executor/scripts/lib/executor/cli.py | 12 +++++++++++ 8 files changed, 73 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad7ffee..e403b3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,27 @@ project is tagged; between releases, entries are dated and `main` moves. ## [Unreleased] +## [2.0.3] — 2026-10-19 + +Patch release: the Windows suite goes green. The v2.0.2 install path was +correct on POSIX, but Windows exposed two failures the matrix caught after +the release was tagged: `--help` crashed under the cp1252 pipe encoding, and +a test tried to execute the launcher as a native program, which Windows +cannot do. + +### Fixed + +- **CLI output is UTF-8 even when Windows redirects it.** A pipe inherits + the locale code page, and `print(__doc__)` raised `UnicodeEncodeError` on + the help arrow before it could print a line. `main` now reconfigures + stdout and stderr where the stream supports it, so help text, JSON with + `ensure_ascii=False`, and error messages survive a redirect on a + non-UTF-8 Windows console. +- **The bare-launcher test is POSIX-only.** Windows has no exec bit and + `CreateProcess` cannot run a `.py` file without a registered association. + The portable spelling — `python3 /scripts/executor` — + remains the tested, documented form on every platform. + ## [2.0.2] — 2026-10-19 Patch release: the engine ships with the skill. Installing the skills used diff --git a/README.md b/README.md index cf5e7aa..d4cc54e 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ cp -R executor/skills/* / Pin to a release tag instead of `main` for stability: ```bash -git clone --branch v2.0.2 git@github.com:Atri10/executor.git +git clone --branch v2.0.3 git@github.com:Atri10/executor.git ``` There are no dependencies to install: the engine is the standard library, @@ -116,7 +116,7 @@ Install The Executor skill library for me: The engine ships inside skills/executor/scripts/lib/, so copy the whole directory — do not copy only the .md files. 4. Verify: run python3 /executor/scripts/executor --version - (prints 2.0.2), then python3 /executor/scripts/executor + (prints 2.0.3), then python3 /executor/scripts/executor --help (lists the command surface). Do not set PYTHONPATH and do not install a package: the launcher carries its engine. Also confirm every copied skills// directory contains a SKILL.md — count the @@ -572,7 +572,7 @@ flowchart TD | Path | What it is | |---|---| | `engine/executor/` | the engine source: `cli.py`, `engine.py`, `schemas.py`, `paths.py`, `store.py`, `views.py`, `policy.py` | -| `engine/tests/` | the suite (739 tests), including the tree-walking contract tests | +| `engine/tests/` | the suite (741 tests), including the tree-walking contract tests | | `skills/executor/` | the router skill, its prompt templates, the references, and the engine that ships with it | | `skills/executor/scripts/executor` | the launcher; resolves `scripts/lib/executor/` relative to itself | | `skills/executor/scripts/lib/executor/` | the installed engine — a generated mirror of `engine/executor/` | diff --git a/engine/executor/__init__.py b/engine/executor/__init__.py index 10b8802..0f8de95 100644 --- a/engine/executor/__init__.py +++ b/engine/executor/__init__.py @@ -1,6 +1,6 @@ # Executor v2 engine — single-writer, typed-payload, event-sourced. # # Public surface is the CLI in executor.cli; this package is the kernel. -__version__ = "2.0.2" +__version__ = "2.0.3" SCHEMA_VERSION = "v1" STORE_VERSION = "v1" diff --git a/engine/executor/cli.py b/engine/executor/cli.py index e8ff727..a3800e1 100755 --- a/engine/executor/cli.py +++ b/engine/executor/cli.py @@ -44,6 +44,17 @@ def _emit(obj) -> None: print(json.dumps(obj, indent=2, ensure_ascii=False)) +def _utf8_stdio() -> None: + """The engine is UTF-8 end to end, but a Windows pipe inherits the + locale code page and `print` raises on the first arrow or non-Latin + title. Reconfigure where the stream allows it; in-process test doubles + do not.""" + for stream in (sys.stdout, sys.stderr): + reconfigure = getattr(stream, "reconfigure", None) + if reconfigure is not None: + reconfigure(encoding="utf-8") + + def _err(e: ExecError | Rejection) -> int: if isinstance(e, Rejection): print(json.dumps({"rejected": e.to_dict()}, indent=2), file=sys.stderr) @@ -230,6 +241,7 @@ def cmd_migrate(args: list[str]) -> int: def main(argv: list[str]) -> int: + _utf8_stdio() if len(argv) < 2 or argv[1] in ("-h", "--help", "help"): print(__doc__) return 0 diff --git a/engine/tests/test_cli.py b/engine/tests/test_cli.py index c5267f9..5e43167 100644 --- a/engine/tests/test_cli.py +++ b/engine/tests/test_cli.py @@ -99,6 +99,26 @@ def test_importing_the_package_entry_does_not_run_it(self): self.assertTrue(hasattr(module, "main")) +class Stdio(unittest.TestCase): + """Windows pipes use the locale code page, which cannot encode the help + arrow or a non-Latin title; the streams are reconfigured to UTF-8 where + they support it.""" + + def test_a_stream_that_can_reconfigure_is_switched_to_utf8(self): + fake = mock.Mock() + with mock.patch.object(cli.sys, "stdout", fake), \ + mock.patch.object(cli.sys, "stderr", io.StringIO()): + cli._utf8_stdio() + fake.reconfigure.assert_called_once_with(encoding="utf-8") + + def test_a_stream_without_reconfigure_is_left_alone(self): + out = io.StringIO() + with mock.patch.object(cli.sys, "stdout", out), \ + mock.patch.object(cli.sys, "stderr", out): + cli._utf8_stdio() + self.assertEqual(out.getvalue(), "") + + class NewCommand(CliCase): def test_new_creates_an_initiative_through_the_engine(self): code, out, _ = self.cli("new", "Mobility", "exam", "portal") diff --git a/engine/tests/test_engine_ships_with_skill.py b/engine/tests/test_engine_ships_with_skill.py index 39dbe8f..ba73282 100644 --- a/engine/tests/test_engine_ships_with_skill.py +++ b/engine/tests/test_engine_ships_with_skill.py @@ -199,6 +199,9 @@ def test_a_full_command_runs_in_a_fresh_git_repo(self): self.assertEqual(status.returncode, 0, status.stderr) self.assertIn("INIT-0001", status.stdout) + @unittest.skipIf(os.name == "nt", + "Windows has no exec bit; the python3 spelling is the " + "portable one") def test_the_exec_bit_runs_it_directly(self): """Where the exec bit survived the copy, the bare form works.""" proc = subprocess.run( diff --git a/skills/executor/scripts/lib/executor/__init__.py b/skills/executor/scripts/lib/executor/__init__.py index 10b8802..0f8de95 100644 --- a/skills/executor/scripts/lib/executor/__init__.py +++ b/skills/executor/scripts/lib/executor/__init__.py @@ -1,6 +1,6 @@ # Executor v2 engine — single-writer, typed-payload, event-sourced. # # Public surface is the CLI in executor.cli; this package is the kernel. -__version__ = "2.0.2" +__version__ = "2.0.3" SCHEMA_VERSION = "v1" STORE_VERSION = "v1" diff --git a/skills/executor/scripts/lib/executor/cli.py b/skills/executor/scripts/lib/executor/cli.py index e8ff727..a3800e1 100755 --- a/skills/executor/scripts/lib/executor/cli.py +++ b/skills/executor/scripts/lib/executor/cli.py @@ -44,6 +44,17 @@ def _emit(obj) -> None: print(json.dumps(obj, indent=2, ensure_ascii=False)) +def _utf8_stdio() -> None: + """The engine is UTF-8 end to end, but a Windows pipe inherits the + locale code page and `print` raises on the first arrow or non-Latin + title. Reconfigure where the stream allows it; in-process test doubles + do not.""" + for stream in (sys.stdout, sys.stderr): + reconfigure = getattr(stream, "reconfigure", None) + if reconfigure is not None: + reconfigure(encoding="utf-8") + + def _err(e: ExecError | Rejection) -> int: if isinstance(e, Rejection): print(json.dumps({"rejected": e.to_dict()}, indent=2), file=sys.stderr) @@ -230,6 +241,7 @@ def cmd_migrate(args: list[str]) -> int: def main(argv: list[str]) -> int: + _utf8_stdio() if len(argv) < 2 or argv[1] in ("-h", "--help", "help"): print(__doc__) return 0