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
9 changes: 7 additions & 2 deletions scripts/scip_harness/scip_ts_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import argparse
import json
import os
import re
import sys
from pathlib import Path
Expand Down Expand Up @@ -277,7 +278,11 @@ def select_projects_for_delta(projects: list[str], changed_paths: list[str]) ->
def _read_lines(path: Path | None) -> list[str]:
if path is None or not path.is_file():
return []
return [line.strip() for line in path.read_text(encoding="utf-8").splitlines() if line.strip()]
# git_paths prints a name as the tree stores it, which need not be UTF-8.
# Decode it as argv is decoded, so it compares equal to a member path
# passed on the command line and is printed back unchanged.
text = os.fsdecode(path.read_bytes())
return [line.strip() for line in text.splitlines() if line.strip()]


def main(argv: list[str] | None = None) -> int:
Expand Down Expand Up @@ -321,7 +326,7 @@ def main(argv: list[str] | None = None) -> int:
# One path per line so a member whose path contains a space is not split
# by the shell when it loads the list.
for project in projects:
sys.stdout.write(f"{project}\n")
sys.stdout.buffer.write(os.fsencode(project) + b"\n")
return 0


Expand Down
53 changes: 53 additions & 0 deletions tests/unit/test_run_typescript_delta_umbrella.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,3 +455,56 @@ def test_unowned_package_json_skips_the_indexer(tmp_path: Path) -> None:
log = _run(tmp_path, repo, base, head)
assert _runs(log) == []
assert not (tmp_path / "delta.json").exists()


def _commit_tree_files(repo: Path, parent: str, files: dict[bytes, bytes]) -> str:
"""Commit `files` on top of `parent` with Git plumbing and return the new sha.

Nothing is written to the working tree, so a name that is not valid UTF-8
reaches Git without the filesystem (macOS rejects it) having to create it.
"""
for name, content in files.items():
blob = subprocess.run(
["git", "-C", str(repo), "hash-object", "-w", "--stdin"],
input=content,
check=True,
capture_output=True,
).stdout.strip()
entry = b"100644," + blob + b"," + name
_git(repo, "update-index", "--add", "--cacheinfo", os.fsdecode(entry))
tree = _git(repo, "write-tree")
return _git(
repo,
"-c",
"user.name=t",
"-c",
"user.email=t@t",
"commit-tree",
tree,
"-p",
parent,
"-m",
"latin-1 name",
)


def test_delta_with_a_non_utf8_file_name_in_the_window(tmp_path: Path) -> None:
"""git prints a name as the tree stores it; a Latin-1 byte must not fail the pass."""
repo = _repo(tmp_path)
base = _git(repo, "rev-parse", "HEAD")
head = _commit_tree_files(
repo,
base,
{
b"packages/app/src/a.ts": b"export const a = 2;\n",
b"packages/lib/caf\xe9.md": b"notes\n",
},
)
window = subprocess.run(
["git", "-C", str(repo), "-c", "core.quotePath=false", "diff", "--name-only", base, head],
check=True,
capture_output=True,
).stdout
assert b"packages/lib/caf\xe9.md" in window.split(b"\n")
log = _run(tmp_path, repo, base, head)
assert _targets(_runs(log)) == ["packages/app"]
34 changes: 34 additions & 0 deletions tests/unit/test_scip_ts_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

import importlib.util
import json
import os
import subprocess
import sys
from pathlib import Path

_SCRIPT = Path(__file__).resolve().parents[2] / "scripts" / "scip_harness" / "scip_ts_projects.py"
Expand Down Expand Up @@ -206,3 +209,34 @@ def test_delta_selects_a_root_tsconfig_for_a_root_source_change() -> None:
"tsconfig.app.json",
"packages/lib",
]


def test_filter_reads_and_prints_names_that_are_not_utf8(tmp_path: Path) -> None:
"""Window lists carry raw git names; a member path is printed back byte for byte."""
changed = tmp_path / "changed.txt"
changed.write_bytes(b"packages/caf\xe9/src/a.ts\npackages/lib/caf\xe9.md\n")
# A UTF-8 locale other than C gives stdout the strict error handler;
# pin it so the test does not depend on the host's locale.
env = {**os.environ, "PYTHONIOENCODING": "utf-8:strict"}
env.pop("PYTHONUTF8", None)
out = subprocess.run(
[
sys.executable,
os.fsencode(_SCRIPT),
b"filter",
b"--changed-file-list",
os.fsencode(changed),
b"--",
b"packages/caf\xe9",
b"packages/lib",
],
env=env,
check=True,
capture_output=True,
)
assert out.stdout == b"packages/caf\xe9\n"
changed.write_bytes(b"caf\xe9.md\npackage.json\n")
for cmd in (b"has-config", b"has-shared"):
argv = [sys.executable, os.fsencode(_SCRIPT), cmd, b"--changed-file-list"]
rc = subprocess.run([*argv, os.fsencode(changed)], env=env, capture_output=True)
assert rc.returncode == 0, rc.stderr
Loading