From 4d081c03c0c16c61658eeb9c8dff16f5af1ae831 Mon Sep 17 00:00:00 2001 From: Kaloyan Naumov Date: Tue, 1 Dec 2026 22:02:04 +0000 Subject: [PATCH 1/2] TypeScript project filter reads window paths that are not UTF-8 git_paths prints a name as the tree stores it, and scip_ts_projects.py read the window lists as strict UTF-8. One file name with a Latin-1 byte anywhere in the window, a Markdown file included, raised UnicodeDecodeError, so the TypeScript pass exited 1 and the watermark stayed where it was on every pass. The lists are decoded with os.fsdecode, as Python decodes argv, so a path compares equal to a member path given on the command line; the selected members are written back with os.fsencode, byte for byte. The harness test commits a TypeScript edit beside caf\xe9.md and expects only the edited member to be indexed; the helper test reads and prints a member whose name is not UTF-8 with a strict stdout. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Kaloyan Naumov --- scripts/scip_harness/scip_ts_projects.py | 9 +++-- .../test_run_typescript_delta_umbrella.py | 13 +++++++ tests/unit/test_scip_ts_projects.py | 34 +++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/scripts/scip_harness/scip_ts_projects.py b/scripts/scip_harness/scip_ts_projects.py index 48a1d08e210..079ee5b586d 100755 --- a/scripts/scip_harness/scip_ts_projects.py +++ b/scripts/scip_harness/scip_ts_projects.py @@ -14,6 +14,7 @@ import argparse import json +import os import re import sys from pathlib import Path @@ -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: @@ -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 diff --git a/tests/unit/test_run_typescript_delta_umbrella.py b/tests/unit/test_run_typescript_delta_umbrella.py index 1890760170b..e420087ed95 100644 --- a/tests/unit/test_run_typescript_delta_umbrella.py +++ b/tests/unit/test_run_typescript_delta_umbrella.py @@ -455,3 +455,16 @@ 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 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") + (repo / "packages/app/src/a.ts").write_text("export const a = 2;\n") + (repo / os.fsdecode(b"packages/lib/caf\xe9.md")).write_text("notes\n") + _git(repo, "add", "-A") + _git(repo, "-c", "user.name=t", "-c", "user.email=t@t", "commit", "-qm", "latin-1 name") + head = _git(repo, "rev-parse", "HEAD") + log = _run(tmp_path, repo, base, head) + assert _targets(_runs(log)) == ["packages/app"] diff --git a/tests/unit/test_scip_ts_projects.py b/tests/unit/test_scip_ts_projects.py index 98cf5f5bab7..743c29e595c 100644 --- a/tests/unit/test_scip_ts_projects.py +++ b/tests/unit/test_scip_ts_projects.py @@ -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" @@ -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 From 28684e7a62be7214cb36442cad2b9b7ae23187f5 Mon Sep 17 00:00:00 2001 From: Kaloyan Naumov Date: Wed, 2 Dec 2026 00:02:40 +0000 Subject: [PATCH 2/2] The non-UTF-8 harness test builds its window with Git plumbing The test wrote caf\xe9.md into the working tree, which macOS rejects with Errno 92 before the filter runs. It now stores the name in a commit built with hash-object, update-index --cacheinfo, write-tree and commit-tree, so no file with that name is created and git_paths prints it from the tree as in production. It still fails on main (UnicodeDecodeError in the filter) and passes with the fix. Co-Authored-By: Claude Sonnet 5.5 Signed-off-by: Kaloyan Naumov --- .../test_run_typescript_delta_umbrella.py | 50 +++++++++++++++++-- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/tests/unit/test_run_typescript_delta_umbrella.py b/tests/unit/test_run_typescript_delta_umbrella.py index e420087ed95..0a2823992f5 100644 --- a/tests/unit/test_run_typescript_delta_umbrella.py +++ b/tests/unit/test_run_typescript_delta_umbrella.py @@ -457,14 +457,54 @@ def test_unowned_package_json_skips_the_indexer(tmp_path: Path) -> None: 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") - (repo / "packages/app/src/a.ts").write_text("export const a = 2;\n") - (repo / os.fsdecode(b"packages/lib/caf\xe9.md")).write_text("notes\n") - _git(repo, "add", "-A") - _git(repo, "-c", "user.name=t", "-c", "user.email=t@t", "commit", "-qm", "latin-1 name") - head = _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"]