fix: managed-runtime guard no longer trips on sdist/build copies in the workspace

The bare-which() scanner rglobs the repo root; a CI job that builds the
wheel leaves an sdist extraction (hermes_agent-<version>/) in the
workspace, and the scanner re-found every already-exempted call site
under that versioned prefix — which can never match an _ALLOWED key —
failing the guard on untouched code (flaked PR #93420's Python-tests
job). _source_files now skips build/, dist/, *.egg-info, and any
top-level dir carrying PKG-INFO.

A/B: planted a fake hermes_agent-9.9.9/ sdist with a which('node')
site — old scanner 1 failed, fixed scanner 7 passed, clean tree
unchanged.
This commit is contained in:
Teknium
2026-08-23 19:01:27 -07:00
parent 7526bd39a8
commit 3f5d37568e
+22
View File
@@ -26,6 +26,7 @@ whose behavior is separately covered by a real test.
from __future__ import annotations
import ast
import functools
from pathlib import Path
import pytest
@@ -125,10 +126,31 @@ def _source_files() -> list[Path]:
rel = path.relative_to(REPO_ROOT)
if rel.parts and rel.parts[0] in _EXEMPT_DIRS:
continue
# Skip packaging copies of the source tree (sdist extractions like
# hermes_agent-0.20.5/, build/ and *.egg-info dirs). CI jobs that
# build the wheel leave one in the workspace; scanning it re-finds
# every already-exempted call site under a versioned path prefix
# that can never match an _ALLOWED key, failing the guard on code
# that was never touched. A dir is a packaging copy iff its top
# level carries PKG-INFO (sdist/egg metadata) or it is a build/
# dist output directory.
if rel.parts and _is_packaging_copy(rel.parts[0]):
continue
files.append(path)
return files
@functools.lru_cache(maxsize=None)
def _is_packaging_copy(top_level: str) -> bool:
"""Whether *top_level* (a dir name under REPO_ROOT) is a build artifact."""
if top_level in ("build", "dist") or top_level.endswith(".egg-info"):
return True
candidate = REPO_ROOT / top_level
if not candidate.is_dir():
return False
return (candidate / "PKG-INFO").exists()
def _findings() -> list[tuple[str, str, int]]:
"""Return (relpath, command, lineno) for every bare managed lookup."""
found: list[tuple[str, str, int]] = []