Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion extensions/catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion extensions/github/extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion extensions/github/scripts/bash/resolve-tasks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion scripts/bash/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 53 additions & 1 deletion tests/extensions/github/test_github_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
HAS_PWSH,
POWERSHELL_EXE,
WINDOWS_POWERSHELL,
make_python3_path_shim,
)


Expand Down Expand Up @@ -157,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):
Expand Down Expand Up @@ -1071,6 +1072,57 @@ 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, 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. 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}"}, 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")

# 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 --------------------------------

Expand Down
62 changes: 62 additions & 0 deletions tests/test_setup_plan_feature_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
Loading