fix(scripts): resolve worktree root before relative_to in type_check_gate (#31906)

On macOS, tempfile.mkdtemp returns a path under /var/folders, a symlink
to /private/var. The base pass in type_check_gate.py resolved each
diagnostic path (yielding /private/var/...) but not the worktree root,
so relative_to raised ValueError for every diagnostic, base counts came
back empty, and the vacuous-run guard failed every local
make lint-basedpyright run. type_discipline_gate.py already resolves
root the same way; ruff_strict_gate.py counts rule codes without
touching worktree paths, so it is unaffected. CI runs Linux where the
temp dir is not a symlink, which is why this only bit local macOS runs
This commit is contained in:
yuneng-jiang 2026-07-01 14:09:07 -07:00 committed by GitHub
parent 34039dfe94
commit ae6dbb4a9b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 1 deletions

View file

@ -63,7 +63,7 @@ def _to_relative(raw: str, root: Path) -> str | None:
path = Path(raw)
absolute = path if path.is_absolute() else root / path
try:
return absolute.resolve().relative_to(root).as_posix()
return absolute.resolve().relative_to(root.resolve()).as_posix()
except ValueError:
return None

View file

@ -54,6 +54,21 @@ def test_paths_outside_repo_are_skipped():
assert gate.count_basedpyright(payload) == {}
def test_symlinked_root_keeps_diagnostics_in_tree(tmp_path):
real = tmp_path / "real"
real.mkdir()
link = tmp_path / "link"
link.symlink_to(real)
payload = json.dumps(
{
"generalDiagnostics": [
_bpr(link / "litellm" / "x.py", "error", "reportArgumentType")
]
}
)
assert gate.count_basedpyright(payload, root=link) == {"reportArgumentType": 1}
def test_at_or_under_ceiling_passes():
budget = {"no-any-return": {"limit": 5}}
assert gate.evaluate({"no-any-return": 5}, {}, budget) == []