mirror of
https://github.com/github/spec-kit.git
synced 2026-07-03 12:28:06 +08:00
fix: PS 5.1 compat — replace non-ASCII chars in shipped PowerShell scripts (#2709)
* Initial plan * fix: replace non-ASCII chars in PS1 files, add encoding regression tests, fix ANSI stripping in tests, update docs --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -335,10 +335,11 @@ class TestInitIntegrationFlag:
|
||||
_install_shared_infra(project, "sh", force=False)
|
||||
|
||||
captured = capsys.readouterr()
|
||||
assert "already exist and were not updated" in captured.out
|
||||
assert "specify init --here --force" in captured.out
|
||||
plain = strip_ansi(captured.out)
|
||||
assert "already exist and were not updated" in plain
|
||||
assert "specify init --here --force" in plain
|
||||
# Rich may wrap long lines; normalize whitespace for the second command
|
||||
normalized = " ".join(captured.out.split())
|
||||
normalized = " ".join(plain.split())
|
||||
assert "specify integration upgrade --force" in normalized
|
||||
|
||||
def test_shared_infra_warns_when_manifest_cannot_be_loaded(self, tmp_path, capsys):
|
||||
|
||||
@@ -7,6 +7,7 @@ import pytest
|
||||
from typer.testing import CliRunner
|
||||
|
||||
from specify_cli import app
|
||||
from tests.conftest import strip_ansi
|
||||
|
||||
|
||||
runner = CliRunner()
|
||||
@@ -49,7 +50,8 @@ def _write_invalid_manifest(project, key):
|
||||
|
||||
|
||||
def _integration_list_row_cells(output: str, key: str) -> list[str]:
|
||||
row = next(line for line in output.splitlines() if line.startswith(f"│ {key}"))
|
||||
plain = strip_ansi(output)
|
||||
row = next(line for line in plain.splitlines() if line.startswith(f"│ {key}"))
|
||||
return [cell.strip() for cell in row.split("│")[1:-1]]
|
||||
|
||||
|
||||
@@ -160,8 +162,9 @@ class TestIntegrationInstall:
|
||||
finally:
|
||||
os.chdir(old_cwd)
|
||||
assert result.exit_code == 0
|
||||
assert "already installed" in result.output
|
||||
normalized = " ".join(result.output.split())
|
||||
plain = strip_ansi(result.output)
|
||||
assert "already installed" in plain
|
||||
normalized = " ".join(plain.split())
|
||||
assert "specify integration upgrade copilot" in normalized
|
||||
assert "already the default integration" in normalized
|
||||
assert "No files were changed" in normalized
|
||||
@@ -197,9 +200,10 @@ class TestIntegrationInstall:
|
||||
finally:
|
||||
os.chdir(old_cwd)
|
||||
assert result.exit_code != 0
|
||||
assert "Installed integrations: copilot" in result.output
|
||||
assert "Default integration: copilot" in result.output
|
||||
normalized = " ".join(result.output.split())
|
||||
plain = strip_ansi(result.output)
|
||||
assert "Installed integrations: copilot" in plain
|
||||
assert "Default integration: copilot" in plain
|
||||
normalized = " ".join(plain.split())
|
||||
assert "To replace the default integration" in normalized
|
||||
assert "specify integration switch claude" in normalized
|
||||
assert "To install 'claude' alongside" in normalized
|
||||
@@ -309,9 +313,10 @@ class TestIntegrationInstall:
|
||||
finally:
|
||||
os.chdir(old_cwd)
|
||||
assert result.exit_code != 0
|
||||
assert "Installed integrations: copilot" in result.output
|
||||
assert "multi-install safe" in result.output
|
||||
normalized = " ".join(result.output.split())
|
||||
plain = strip_ansi(result.output)
|
||||
assert "Installed integrations: copilot" in plain
|
||||
assert "multi-install safe" in plain
|
||||
normalized = " ".join(plain.split())
|
||||
assert "To replace the default integration" in normalized
|
||||
assert "specify integration switch claude" in normalized
|
||||
assert "To install 'claude' alongside" in normalized
|
||||
|
||||
54
tests/test_ps1_encoding.py
Normal file
54
tests/test_ps1_encoding.py
Normal file
@@ -0,0 +1,54 @@
|
||||
"""Regression tests for PowerShell 5.1 compatibility (GitHub issue #2680).
|
||||
|
||||
PowerShell 5.1 (built-in on Windows) defaults to the system's legacy encoding
|
||||
when reading .ps1 files. Non-ASCII characters in UTF-8-encoded scripts cause
|
||||
parse errors because multi-byte sequences are misinterpreted as individual bytes.
|
||||
|
||||
These tests ensure that all shipped .ps1 files remain ASCII-only so they work
|
||||
on both PowerShell 5.1 and 7+.
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parent.parent
|
||||
|
||||
# All directories that contain shipped PowerShell scripts.
|
||||
_PS1_DIRS = [
|
||||
REPO_ROOT / "scripts" / "powershell",
|
||||
REPO_ROOT / "extensions" / "git" / "scripts" / "powershell",
|
||||
]
|
||||
|
||||
|
||||
def _collect_ps1_files():
|
||||
"""Yield all .ps1 files under the known script directories."""
|
||||
for d in _PS1_DIRS:
|
||||
if d.is_dir():
|
||||
yield from sorted(d.rglob("*.ps1"))
|
||||
|
||||
|
||||
_PS1_FILES = list(_collect_ps1_files())
|
||||
|
||||
|
||||
@pytest.mark.parametrize("ps1_file", _PS1_FILES, ids=lambda p: str(p.relative_to(REPO_ROOT)))
|
||||
def test_ps1_file_is_ascii_only(ps1_file: Path):
|
||||
"""Every .ps1 file must contain only ASCII characters (PS 5.1 compat)."""
|
||||
content = ps1_file.read_bytes()
|
||||
non_ascii = [
|
||||
(i + 1, byte)
|
||||
for i, byte in enumerate(content)
|
||||
if byte > 127
|
||||
]
|
||||
assert not non_ascii, (
|
||||
f"{ps1_file.relative_to(REPO_ROOT)} contains non-ASCII bytes "
|
||||
f"(PowerShell 5.1 incompatible): "
|
||||
f"first at byte offset {non_ascii[0][0]} (0x{non_ascii[0][1]:02x})"
|
||||
)
|
||||
|
||||
|
||||
def test_ps1_files_discovered():
|
||||
"""Sanity check: at least the known script files are found."""
|
||||
names = {p.name for p in _PS1_FILES}
|
||||
assert "common.ps1" in names
|
||||
assert "initialize-repo.ps1" in names
|
||||
Reference in New Issue
Block a user