From d003a11eaa4e5692c1b5f2b53391c0ad867e53c5 Mon Sep 17 00:00:00 2001 From: joshinitin2016883-sketch Date: Thu, 26 Nov 2026 23:30:26 +0530 Subject: [PATCH 1/3] fix(scripts): emit UTF-8 from the bash feature.json readers When jq is unavailable, read_feature_json_feature_directory parses .specify/feature.json with python3 and returned the value with print(). On Windows a piped stdout uses the ANSI code page, so a non-ASCII feature directory reached bash as cp1252 (or GBK, ...) bytes instead of UTF-8, and every path derived from it was wrong. Write the value as UTF-8 bytes instead, in core common.sh and in the GitHub extension's copy of the reader, which also gains the encoding='utf-8' that core received in #4780. Add regression tests that force the python3 parser under cp1252 and GBK stdouts. Fixes #5593 Assisted-by: Claude Code (model: Claude Opus 5.5, autonomous) Co-Authored-By: Claude Opus 5.5 --- .../github/scripts/bash/resolve-tasks.sh | 4 +- scripts/bash/common.sh | 5 +- .../github/test_github_extension.py | 48 ++++++++++++++ tests/test_setup_plan_feature_json.py | 62 +++++++++++++++++++ 4 files changed, 117 insertions(+), 2 deletions(-) diff --git a/extensions/github/scripts/bash/resolve-tasks.sh b/extensions/github/scripts/bash/resolve-tasks.sh index 4e6c874cf2..91b60e0de9 100755 --- a/extensions/github/scripts/bash/resolve-tasks.sh +++ b/extensions/github/scripts/bash/resolve-tasks.sh @@ -152,7 +152,9 @@ read_feature_json_feature_directory() { fi fi if [[ -z "$_fd" ]] && command -v python3 >/dev/null 2>&1; then - if ! _fd=$(python3 -c "import json,sys; d=json.load(open(sys.argv[1])); v=d.get('feature_directory'); print(v if v else '')" "$fj" 2>/dev/null); then + # Read and write UTF-8 explicitly, as core does: Windows defaults both + # the file and the piped stdout to the ANSI code page. + if ! _fd=$(python3 -c "import json,sys; d=json.load(open(sys.argv[1], encoding='utf-8')); v=d.get('feature_directory'); sys.stdout.buffer.write(str(v).encode('utf-8') if v else b'')" "$fj" 2>/dev/null); then _fd='' fi fi diff --git a/scripts/bash/common.sh b/scripts/bash/common.sh index 55bcffa25c..9ea5646f29 100644 --- a/scripts/bash/common.sh +++ b/scripts/bash/common.sh @@ -112,7 +112,10 @@ read_feature_json_feature_directory() { fi if [[ -z "$_fd" ]] && command -v python3 >/dev/null 2>&1; then # Use Python so pretty-printed/multi-line JSON still parses correctly. - if ! _fd=$(python3 -c "import json,sys; d=json.load(open(sys.argv[1], encoding='utf-8')); v=d.get('feature_directory'); print(v if v else '')" "$fj" 2>/dev/null); then + # Write UTF-8 bytes instead of print(): on Windows a piped stdout uses + # the ANSI code page, which re-encodes non-ASCII names in that code + # page instead of UTF-8 (cp1252 turns "é" into the single byte 0xE9). + if ! _fd=$(python3 -c "import json,sys; d=json.load(open(sys.argv[1], encoding='utf-8')); v=d.get('feature_directory'); sys.stdout.buffer.write(str(v).encode('utf-8') if v else b'')" "$fj" 2>/dev/null); then _fd='' fi fi diff --git a/tests/extensions/github/test_github_extension.py b/tests/extensions/github/test_github_extension.py index eb79415e07..c74ede8a65 100644 --- a/tests/extensions/github/test_github_extension.py +++ b/tests/extensions/github/test_github_extension.py @@ -31,6 +31,7 @@ HAS_PWSH, POWERSHELL_EXE, WINDOWS_POWERSHELL, + make_python3_path_shim, ) @@ -1071,6 +1072,53 @@ def test_errors_when_tasks_md_is_missing(self, tmp_path: Path): assert result.returncode == 1 assert "tasks.md not found" in result.stderr + @pytest.mark.parametrize( + ("code_page", "name"), + [("cp1252", "001-café"), ("gbk", "001-功能")], + ids=["cp1252-latin", "gbk-cjk"], + ) + def test_feature_json_survives_a_legacy_stdout( + self, tmp_path: Path, code_page: str, name: str + ): + """Regression: the python3 feature.json parser printed in the code page. + + Without jq, ``read_feature_json_feature_directory`` parses feature.json + with python3, whose piped stdout uses the ANSI code page on Windows + (cp1252, or GBK on Simplified Chinese systems), so the directory + reached bash in that encoding instead of UTF-8. + """ + project = tmp_path / "project" + feature = project / "specs" / name + feature.mkdir(parents=True) + (project / ".specify").mkdir() + (project / ".specify" / "feature.json").write_text( + json.dumps({"feature_directory": f"specs/{name}"}), encoding="utf-8" + ) + (feature / "plan.md").write_text("# Plan\n", encoding="utf-8") + (feature / "tasks.md").write_text("- [ ] T001 Task\n", encoding="utf-8") + + # A working python3 and a failing jq, so python3 parses feature.json + # even on runners that have jq. + shim_dir = make_python3_path_shim(tmp_path / "bin") + jq_stub = shim_dir / "jq" + jq_stub.write_text("#!/bin/sh\nexit 1\n", encoding="utf-8", newline="\n") + jq_stub.chmod(0o755) + env = { + **_resolver_env(), + "PATH": f"{shim_dir}{os.pathsep}{os.environ.get('PATH', '')}", + "PYTHONIOENCODING": code_page, + } + result = subprocess.run( + ["bash", str(SH_SCRIPT), "--json"], + cwd=project, + capture_output=True, + env=env, + ) + + assert result.returncode == 0, result.stderr.decode("utf-8", "replace") + payload = json.loads(result.stdout.decode("utf-8")) + assert Path(payload["FEATURE_DIR"]).name == name + # -- Override contract, across all three twins -------------------------------- diff --git a/tests/test_setup_plan_feature_json.py b/tests/test_setup_plan_feature_json.py index ded0c8a5f9..ce22ca3550 100644 --- a/tests/test_setup_plan_feature_json.py +++ b/tests/test_setup_plan_feature_json.py @@ -9,6 +9,7 @@ import pytest from tests.conftest import requires_bash +from tests.parity_helpers import make_python3_path_shim PROJECT_ROOT = Path(__file__).resolve().parent.parent COMMON_SH = PROJECT_ROOT / "scripts" / "bash" / "common.sh" @@ -191,6 +192,67 @@ def test_setup_plan_survives_broken_python3_stub(plan_repo: Path) -> None: assert (feat / "plan.md").is_file() +@requires_bash +@pytest.mark.parametrize("ensure_ascii", [False, True], ids=["raw-utf8", "ascii-escaped"]) +@pytest.mark.parametrize( + ("code_page", "name"), + [("cp1252", "001-café"), ("gbk", "001-添加用户")], + ids=["cp1252-latin", "gbk-cjk"], +) +def test_setup_plan_reads_non_ascii_feature_json_through_a_legacy_stdout( + plan_repo: Path, tmp_path: Path, code_page: str, name: str, ensure_ascii: bool +) -> None: + """The python3 feature.json parser must hand bash UTF-8, not the code page. + + On Windows a piped stdout uses the ANSI code page (cp1252 on Western + systems, GBK on Simplified Chinese ones) rather than UTF-8. Without jq, + printing the parsed path re-encoded it in that code page ("é" became the + single byte 0xE9), so setup-plan.sh reported, and on some platforms + created, a different directory from the one feature.json names. + """ + subprocess.run( + ["git", "checkout", "-q", "-b", "feature/my-feature-branch"], + cwd=plan_repo, + check=True, + ) + feat = plan_repo / "specs" / name + feat.mkdir(parents=True) + (feat / "spec.md").write_text("# spec\n", encoding="utf-8") + (plan_repo / ".specify" / "feature.json").write_text( + json.dumps({"feature_directory": f"specs/{name}"}, ensure_ascii=ensure_ascii), + encoding="utf-8", + ) + + # A working python3 (Windows venvs only ship python.exe) and a failing jq, + # so feature.json is parsed by python3 even on runners that have jq. + stub_dir = make_python3_path_shim(tmp_path / "bin") + jq_stub = stub_dir / "jq" + jq_stub.write_text("#!/bin/sh\nexit 1\n", encoding="utf-8", newline="\n") + jq_stub.chmod(0o755) + env = _clean_env() + env["PATH"] = f"{stub_dir}{os.pathsep}{env.get('PATH', '')}" + env["PYTHONIOENCODING"] = code_page + + script = plan_repo / ".specify" / "scripts" / "bash" / "setup-plan.sh" + result = subprocess.run( + ["bash", str(script)], + cwd=plan_repo, + capture_output=True, + check=False, + env=env, + ) + assert result.returncode == 0, result.stderr.decode("utf-8", "replace") + assert (feat / "plan.md").is_file() + assert [p.name for p in (plan_repo / "specs").iterdir()] == [name] + # The reported paths must be UTF-8 too: agents read them from this output. + feature_dir_line = next( + line + for line in result.stdout.decode("utf-8").splitlines() + if line.startswith("FEATURE_DIR: ") + ) + assert feature_dir_line.endswith(f"/specs/{name}") + + @requires_bash def test_setup_plan_numbered_branch_works_with_feature_json( plan_repo: Path, From 9359d292c8435e76412f077d84b306125652ee84 Mon Sep 17 00:00:00 2001 From: joshinitin2016883-sketch Date: Fri, 27 Nov 2026 01:11:02 +0530 Subject: [PATCH 2/3] chore(extensions): bump the github extension to 1.0.7 The previous commit changed the github extension's resolve-tasks.sh, and the extension version guard requires a version bump for any change under extensions/github/. Bump extension.yml and the catalog entry, and update the version the manifest test expects, as #5466 did for 1.0.6. Assisted-by: Claude Code (model: Claude Opus 5.5, autonomous) Co-Authored-By: Claude Opus 5.5 --- extensions/catalog.json | 2 +- extensions/github/extension.yml | 2 +- tests/extensions/github/test_github_extension.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/extensions/catalog.json b/extensions/catalog.json index a4bc32ceb0..5d12b4af6b 100644 --- a/extensions/catalog.json +++ b/extensions/catalog.json @@ -66,7 +66,7 @@ "github": { "name": "GitHub Integration", "id": "github", - "version": "1.0.6", + "version": "1.0.7", "description": "GitHub platform integration for Spec Kit - create GitHub issues from a feature's task list", "author": "spec-kit-core", "repository": "https://github.com/github/spec-kit", diff --git a/extensions/github/extension.yml b/extensions/github/extension.yml index 4faf3428a5..aadce984b9 100644 --- a/extensions/github/extension.yml +++ b/extensions/github/extension.yml @@ -3,7 +3,7 @@ schema_version: "1.0" extension: id: github name: "GitHub Integration" - version: "1.0.6" + version: "1.0.7" description: "GitHub platform integration for Spec Kit - create GitHub issues from a feature's task list" author: spec-kit-core repository: https://github.com/github/spec-kit diff --git a/tests/extensions/github/test_github_extension.py b/tests/extensions/github/test_github_extension.py index c74ede8a65..a37fcf59d5 100644 --- a/tests/extensions/github/test_github_extension.py +++ b/tests/extensions/github/test_github_extension.py @@ -158,7 +158,7 @@ def test_manifest_validates(self): m = ExtensionManifest(EXT_DIR / "extension.yml") assert m.id == "github" - assert m.version == "1.0.6" + assert m.version == "1.0.7" assert [c["name"] for c in m.commands] == [COMMAND_NAME] def test_manifest_does_not_restore_legacy_alias(self): From d573bc040771a99853416347fca036c6c7d33082 Mon Sep 17 00:00:00 2001 From: joshinitin2016883-sketch Date: Mon, 30 Nov 2026 22:37:21 +0530 Subject: [PATCH 3/3] test(extensions): cover the github reader's UTF-8 decoding The resolve-tasks.sh regression test wrote feature.json with json.dumps defaults, so the file was ASCII-only and the reader's new encoding='utf-8' went untested. Run it with raw UTF-8 and \u-escaped JSON, as the core test does: on Windows the raw cases fail if that encoding is removed while the output stays UTF-8. Assisted-by: Claude Code (model: Claude Opus 5.5, autonomous) Co-Authored-By: Claude Opus 5.5 --- tests/extensions/github/test_github_extension.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/extensions/github/test_github_extension.py b/tests/extensions/github/test_github_extension.py index a37fcf59d5..7a5b4d6cfc 100644 --- a/tests/extensions/github/test_github_extension.py +++ b/tests/extensions/github/test_github_extension.py @@ -1072,27 +1072,31 @@ def test_errors_when_tasks_md_is_missing(self, tmp_path: Path): assert result.returncode == 1 assert "tasks.md not found" in result.stderr + @pytest.mark.parametrize("ensure_ascii", [False, True], ids=["raw-utf8", "ascii-escaped"]) @pytest.mark.parametrize( ("code_page", "name"), [("cp1252", "001-café"), ("gbk", "001-功能")], ids=["cp1252-latin", "gbk-cjk"], ) def test_feature_json_survives_a_legacy_stdout( - self, tmp_path: Path, code_page: str, name: str + self, tmp_path: Path, code_page: str, name: str, ensure_ascii: bool ): """Regression: the python3 feature.json parser printed in the code page. Without jq, ``read_feature_json_feature_directory`` parses feature.json with python3, whose piped stdout uses the ANSI code page on Windows (cp1252, or GBK on Simplified Chinese systems), so the directory - reached bash in that encoding instead of UTF-8. + reached bash in that encoding instead of UTF-8. A raw UTF-8 + feature.json also checks that the parser reads the file as UTF-8: + without ``encoding='utf-8'``, Windows decodes it in the code page too. """ project = tmp_path / "project" feature = project / "specs" / name feature.mkdir(parents=True) (project / ".specify").mkdir() (project / ".specify" / "feature.json").write_text( - json.dumps({"feature_directory": f"specs/{name}"}), encoding="utf-8" + json.dumps({"feature_directory": f"specs/{name}"}, ensure_ascii=ensure_ascii), + encoding="utf-8", ) (feature / "plan.md").write_text("# Plan\n", encoding="utf-8") (feature / "tasks.md").write_text("- [ ] T001 Task\n", encoding="utf-8")