From 3f5d37568eea351825b5e3ccbbdc1e8161f2c61d Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Sun, 23 Aug 2026 19:01:27 -0700 Subject: [PATCH] fix: managed-runtime guard no longer trips on sdist/build copies in the workspace MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The bare-which() scanner rglobs the repo root; a CI job that builds the wheel leaves an sdist extraction (hermes_agent-/) 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. --- tests/test_managed_runtime_resolution.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_managed_runtime_resolution.py b/tests/test_managed_runtime_resolution.py index 8d4c48eeae..e52a4ddcfb 100644 --- a/tests/test_managed_runtime_resolution.py +++ b/tests/test_managed_runtime_resolution.py @@ -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]] = []