The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(pm): judge overrides only against a complete pip-check report
Maciej Lisiewski776496e3bdd6
diff --git a/pm/environment.py b/pm/environment.pyindex b4e84a1a501..3eaa1ab8efe 100644--- a/pm/environment.py+++ b/pm/environment.py@@ -8,7 +8,7 @@ from __future__ import annotationsimport codecsfrom collections.abc import Iterator, Mapping, Sequencefrom contextlib import contextmanager-from dataclasses import dataclass+from dataclasses import dataclass, replaceimport ioimport osfrom pathlib import Path@@ -490,8 +490,10 @@ class PythonEnvironment:"""`uv pip check` the environment; *lock* is the uv.lock it was installed from.Mismatches the lock's manifest overrides account for are expected (pm.pip_check).+ The check is a quiet step, so it runs captured even for a streaming environment:+ a streamed run keeps only the output's tail, which can drop the report's head."""- result = self._run(+ result = replace(self, output=None)._run(["pip", "check", "--no-config", "--python", str(self.executable)],cwd=self.destination.parent, timeout=60,)diff --git a/pm/pip_check.py b/pm/pip_check.pyindex c3786144620..35a309ce466 100644--- a/pm/pip_check.py+++ b/pm/pip_check.py@@ -58,13 +58,14 @@ def overridden_versions(lock: Path) -> dict[str, set[str]]:def unexpected_incompatibilities(report: str, lock: Path | None) -> list[str] | None:"""The report lines *lock* does not account for.- None when the report cannot be read line by line (no lines, or fewer than the- "Found N" total uv printed), so the caller fails on the raw output instead of- trusting a partial parse.+ None when the report cannot be read line by line: no lines, or uv's "Found N"+ total missing or different from the lines recognised (a truncated report loses+ its head, and any failure printed there). The caller then fails on the raw output+ instead of trusting a partial parse."""lines = [line.strip() for line in report.splitlines() if _REPORT_LINE.match(line.strip())]found = _FOUND.search(report)- if not lines or (found and int(found.group(1)) != len(lines)):+ if not lines or not found or int(found.group(1)) != len(lines):return Noneif lock is None or not lock.is_file():return linesdiff --git a/tests/pm/test_pip_check.py b/tests/pm/test_pip_check.pyindex 499dc567199..1ac39d57584 100644--- a/tests/pm/test_pip_check.py+++ b/tests/pm/test_pip_check.py@@ -7,6 +7,7 @@ version are what make that line expected; nothing else may pass."""from __future__ import annotations+import ioimport jsonimport osfrom pathlib import Path@@ -90,6 +91,8 @@ def test_without_a_lock_every_line_fails(tmp_path):"error: failed to inspect the environment\n",# uv counted more incompatibilities than the parser recognised."Found 2 incompatibilities\n" + OVERRIDDEN + "\nThe package `x` has an unreadable requirement\n",+ # No count: the head of the report may be missing, taking unrelated failures with it.+ OVERRIDDEN + "\n",])def test_unrecognised_report_is_never_read_as_clean(lock, report):assert unexpected_incompatibilities(report, lock) is None@@ -106,19 +109,28 @@ def test_stdlib_fallback_reads_the_real_lock_like_tomllib(monkeypatch):@pytest.fixturedef overridden_project(tmp_path):"""A real project whose dependency pins shared-dep==1.0, overridden to 2.0."""+ return _overridden_project(tmp_path, ["shared_dep"])+++def _overridden_project(tmp_path, overridden, extra_wheels=(), extra_dependencies=()):uv = shutil.which("uv")assert uv, "environment construction tests require uv on PATH"source = tmp_path / "source"source.mkdir()wheels = tmp_path / "wheels"wheels.mkdir()- _wheel(wheels, "pinned_parent", requirements=("shared-dep==1.0",))- _wheel(wheels, "shared_dep", "1.0")- _wheel(wheels, "shared_dep", "2.0")+ _wheel(wheels, "pinned_parent", requirements=[f"{name.replace('_', '-')}==1.0" for name in overridden])+ for name in overridden:+ _wheel(wheels, name, "1.0")+ _wheel(wheels, name, "2.0")+ for name, requirements in extra_wheels:+ _wheel(wheels, name, requirements=requirements)+ dependencies = json.dumps(["pinned-parent==1.0", *extra_dependencies])+ overrides = json.dumps([f"{name.replace('_', '-')}==2.0" for name in overridden])(source / "pyproject.toml").write_text('[project]\nname="override-root"\nversion="1"\nrequires-python=">=3.11"\n'- 'dependencies=["pinned-parent==1.0"]\n'- '[tool.uv]\npackage=false\nno-index=true\noverride-dependencies=["shared-dep==2.0"]\n'+ f'dependencies={dependencies}\n'+ f'[tool.uv]\npackage=false\nno-index=true\noverride-dependencies={overrides}\n'f'find-links=[{json.dumps(wheels.as_posix())}]\n', encoding="utf-8",)home = tmp_path / "isolated-home"@@ -155,3 +167,26 @@ def test_build_accepts_the_override_and_check_still_rejects_what_it_does_not_covassert overridden_versions(stale) == {"shared-dep": {"1.0"}}with pytest.raises(InstallError, match="dependency validation failed"):environment.check(stale)+++def test_streamed_check_still_sees_failures_ahead_of_a_long_expected_report(tmp_path):+ """Interactive builds stream uv output and keep only its tail. An unrelated failure+ reported before 2,000+ characters of override-covered lines must still fail the check."""+ from pm import build_environment+ from pm.environment import managed_environment+ from pm.environments import site_packages++ overridden = [f"shared_dep_{index:02d}" for index in range(30)]+ source, env = _overridden_project(tmp_path, overridden,+ extra_wheels=[("aa_parent", ["aa-dep==1.0"]), ("aa_dep", [])],+ extra_dependencies=["aa-parent==1.0"])+ out = tmp_path / "environment"+ build_environment(explicit=True, source=source, python=Path(sys.executable), out=out,+ cache=tmp_path / "cache", env=env, offline=True, frozen=True)+ # Break the environment in a way no override explains.+ shutil.rmtree(next(site_packages(out).glob("aa_dep-1.0.dist-info")))++ environment = managed_environment(out, python=Path(sys.executable), cache=tmp_path / "cache",+ env=env, offline=True, explicit=True, output=io.StringIO())+ with pytest.raises(InstallError, match="requires `aa-dep==1.0`, but it's not installed"):+ environment.check(source / "uv.lock")