From a723b9ed4874d3b11004f2fe841aeae5415945d2 Mon Sep 17 00:00:00 2001 From: Trecek Date: Sun, 25 Oct 2026 14:21:42 -0700 Subject: [PATCH 1/9] fix(doctor): bound RECORD paths by installation scheme --- scripts/e2e/catalog.json | 6 - src/autoskillit/cli/doctor/_doctor_install.py | 51 ++++-- ...st_autoskillit_root_children_registered.py | 2 +- tests/cli/test_installation_integrity.py | 159 +++++++++++++++++- tests/cli/test_installation_integrity_uv.py | 74 ++++++++ 5 files changed, 267 insertions(+), 25 deletions(-) create mode 100644 tests/cli/test_installation_integrity_uv.py diff --git a/scripts/e2e/catalog.json b/scripts/e2e/catalog.json index 00bf957ce1..7dfdd54199 100644 --- a/scripts/e2e/catalog.json +++ b/scripts/e2e/catalog.json @@ -42,12 +42,6 @@ "check": "plugin_cache_integrity", "message": "Plugin cache directory is absent, so hook paths could not be verified: /home/autoskillit/.claude/plugins/cache/autoskillit-local/autoskillit. Run `autoskillit install` to rebuild it.", "issue": "https://github.com/TalonT-Org/AutoSkillit/issues/5243" - }, - { - "severity": "error", - "check": "installation_record_invalid", - "message": "Invalid RECORD path '../../../bin/autoskillit' in /home/autoskillit/.local/share/uv/tools/autoskillit/lib/python3.11/site-packages/autoskillit (active distribution: /home/autoskillit/.local/share/uv/tools/autoskillit/lib/python3.11/site-packages/autoskillit; uv tool: /home/autoskillit/.local/share/uv/tools/autoskillit/lib/python3.11/site-packages/autoskillit)", - "issue": "https://github.com/TalonT-Org/AutoSkillit/issues/5244" } ] }, diff --git a/src/autoskillit/cli/doctor/_doctor_install.py b/src/autoskillit/cli/doctor/_doctor_install.py index c5c8fb9560..55fedc924b 100644 --- a/src/autoskillit/cli/doctor/_doctor_install.py +++ b/src/autoskillit/cli/doctor/_doctor_install.py @@ -7,6 +7,7 @@ import hashlib import importlib.metadata import json +import os import shutil import stat import subprocess @@ -15,6 +16,8 @@ from pathlib import Path from typing import TYPE_CHECKING +import regex as re + from autoskillit.core import Severity, file_url_path, get_logger, is_python_bytecode_path from ._doctor_types import DoctorResult @@ -450,22 +453,41 @@ def _regular_files(root: Path) -> Iterator[Path]: return +def _scheme_base(site_packages: Path) -> Path: + """Return the install-scheme base that bounds RECORD rows. + + Installers record console scripts and data relative to purelib, e.g. + ``../../../bin/autoskillit`` from ``/lib/pythonX.Y/site-packages`` + (also ``lib64``; ``/Lib/site-packages`` on Windows). Standard + script and data targets lie under ````. Other layouts, such as + an unpacked uv cache archive, are bounded to themselves. + """ + lib = site_packages.parent + if site_packages != site_packages.parent / "site-packages": + return site_packages + if re.fullmatch(r"python[0-9]+\.[0-9]+t?", lib.name) and lib.parent.name in {"lib", "lib64"}: + return lib.parent.parent + if lib == lib.parent / "Lib": + return lib.parent + return site_packages + + def _verify_record_entry( installation: _Installation, site_packages: Path, + bound: Path, row: list[str], tracked: set[str], ) -> DoctorResult | None: if len(row) < 2: return None - relative = Path(row[0]) - if relative.is_absolute() or ".." in relative.parts: + candidate = Path(os.path.normpath(site_packages / row[0])) + if not candidate.is_relative_to(bound): return DoctorResult( Severity.ERROR, "installation_record_invalid", - f"Invalid RECORD path {row[0]!r} in {_display(installation)}", + f"Invalid RECORD path {row[0]!r} outside {bound} in {_display(installation)}", ) - candidate = site_packages / relative try: package_relative = candidate.relative_to(installation.package_root) except ValueError: @@ -483,19 +505,21 @@ def _verify_record_entry( ) algorithm, expected = parsed_hash try: - observed = hashlib.new(algorithm, candidate.read_bytes()).digest() - except ValueError: + content = candidate.read_bytes() + except (OSError, ValueError): return DoctorResult( Severity.ERROR, - "installation_record_unknown_algorithm", - f"Unknown RECORD hash algorithm {algorithm!r} " - f"for {candidate} in {_display(installation)}", + "installation_record_unreadable_entry", + f"Unreadable RECORD entry {candidate} in {_display(installation)}", ) - except OSError: + try: + observed = hashlib.new(algorithm, content).digest() + except (TypeError, ValueError): return DoctorResult( Severity.ERROR, - "installation_record_unreadable_entry", - f"Unreadable RECORD entry {candidate} in {_display(installation)}", + "installation_record_unsupported_algorithm", + f"Unsupported RECORD hash algorithm {algorithm!r} " + f"for {candidate} in {_display(installation)}", ) if observed != expected: return DoctorResult( @@ -511,10 +535,11 @@ def _verify_record(installation: _Installation) -> tuple[list[DoctorResult], set results: list[DoctorResult] = [] tracked: set[str] = set() site_packages = installation.record_path.parent.parent + bound = _scheme_base(site_packages) try: rows = csv.reader(installation.record_path.read_text(encoding="utf-8").splitlines()) for row in rows: - result = _verify_record_entry(installation, site_packages, row, tracked) + result = _verify_record_entry(installation, site_packages, bound, row, tracked) if result is not None: results.append(result) except (OSError, UnicodeDecodeError, csv.Error) as exc: diff --git a/tests/arch/test_autoskillit_root_children_registered.py b/tests/arch/test_autoskillit_root_children_registered.py index c865e74668..4b698cbafe 100644 --- a/tests/arch/test_autoskillit_root_children_registered.py +++ b/tests/arch/test_autoskillit_root_children_registered.py @@ -20,7 +20,7 @@ "active_kitchens.json": 1, # Home-level marketplace shape: core/types/constants/_type_constants_retirements.py:309. "marketplace": 1, - # Home-level plugin storage: cli/doctor/_doctor_install.py:355. + # Home-level plugin storage: cli/doctor/_doctor_install.py:358. "plugin-generations": 1, # Home-level hook projection repair: workspace/_projected_artifact/_hook_repair.py:538. "plugin-projections": 1, diff --git a/tests/cli/test_installation_integrity.py b/tests/cli/test_installation_integrity.py index c428b11f12..9a502bbf43 100644 --- a/tests/cli/test_installation_integrity.py +++ b/tests/cli/test_installation_integrity.py @@ -12,33 +12,182 @@ import autoskillit.cli.doctor._doctor_install as _integrity import autoskillit.cli.update._update_checks as _update_checks +from autoskillit.cli.doctor._doctor_types import DoctorResult from autoskillit.cli.install._install_info import InstallInfo, InstallType from autoskillit.core import Severity pytestmark = [pytest.mark.layer("cli"), pytest.mark.small] +_CLEAN = DoctorResult( + Severity.OK, + "installation_integrity", + "All discoverable AutoSkillit installations match their RECORD files", +) + def _record_hash(content: bytes) -> str: encoded = base64.urlsafe_b64encode(hashlib.sha256(content).digest()).rstrip(b"=") return f"sha256={encoded.decode()}" -def _write_install(root: Path, *, content: bytes = b"VERSION = '1.0'\n") -> Path: - site_packages = root / "autoskillit" / "lib" / "python3.14" / "site-packages" +def _write_install( + root: Path, + *, + content: bytes = b"VERSION = '1.0'\n", + layout: tuple[str, ...] = ("lib", "python3.14", "site-packages"), +) -> Path: + env = root / "autoskillit" + site_packages = env.joinpath(*layout) package = site_packages / "autoskillit" package.mkdir(parents=True) - module = package / "__init__.py" - module.write_bytes(content) + script_parts = ( + ("Scripts", "autoskillit.exe") + if layout == ("Lib", "site-packages") + else ("bin", "autoskillit") + ) + script = env.joinpath(*script_parts) + script.parent.mkdir(parents=True) + files = {package / "__init__.py": content, script: b"#!/bin/sh\nexec python -m autoskillit\n"} + for path, data in files.items(): + path.write_bytes(data) record = site_packages / "autoskillit-1.0.0.dist-info" / "RECORD" record.parent.mkdir() - record.write_text(f"autoskillit/__init__.py,{_record_hash(content)},{len(content)}\n") + rows = [ + f"{Path(os.path.relpath(path, site_packages)).as_posix()},{_record_hash(data)},{len(data)}" + for path, data in files.items() + ] + record.write_text("\n".join([*rows, "autoskillit-1.0.0.dist-info/RECORD,,"]) + "\n") return package +def _record(package: Path) -> Path: + return package.parent / "autoskillit-1.0.0.dist-info" / "RECORD" + + def _findings(*roots: Path) -> list: return _integrity.verify_installations(roots=roots) +@pytest.mark.parametrize( + "layout", + [ + ("lib", "python3.14", "site-packages"), + ("lib64", "python3.14", "site-packages"), + ("Lib", "site-packages"), + ], +) +def test_clean_install_reports_integrity_ok(tmp_path: Path, layout: tuple[str, ...]) -> None: + _write_install(tmp_path, layout=layout) + + assert _findings(tmp_path) == [_CLEAN] + + +def test_console_script_mutation_detected(tmp_path: Path) -> None: + _write_install(tmp_path) + script = tmp_path / "autoskillit" / "bin" / "autoskillit" + script.write_bytes(b"mutated script") + + assert any( + finding.check == "installation_record_mismatch" + and str(script.resolve()) in finding.message + for finding in _findings(tmp_path) + ) + + +@pytest.mark.parametrize("case", ["parent_escape", "sibling_prefix", "absolute"]) +def test_record_row_outside_installation_is_invalid(tmp_path: Path, case: str) -> None: + package = _write_install(tmp_path) + outside = tmp_path / "outside.txt" + outside.write_bytes(b"x") + sibling = tmp_path / "autoskillit-evil" / "x.py" + sibling.parent.mkdir() + sibling.write_bytes(b"x") + row = { + "parent_escape": "../../../../outside.txt", + "sibling_prefix": "../../../../autoskillit-evil/x.py", + "absolute": str(outside.resolve()), + }[case] + record = _record(package) + record.write_text(record.read_text() + f"{row},{_record_hash(b'x')},1\n") + + assert any( + finding.check == "installation_record_invalid" and repr(row) in finding.message + for finding in _findings(tmp_path) + ) + + +@pytest.mark.parametrize("case", ["absolute_script", "redundant_dotdot"]) +def test_equivalent_spellings_inside_installation_stay_clean(tmp_path: Path, case: str) -> None: + package = _write_install(tmp_path) + record = _record(package) + old, new = ( + ("../../../bin/autoskillit", str((tmp_path / "autoskillit/bin/autoskillit").resolve())) + if case == "absolute_script" + else ("autoskillit/__init__.py", "autoskillit/../autoskillit/__init__.py") + ) + record.write_text(record.read_text().replace(old, new)) + + assert _findings(tmp_path) == [_CLEAN] + + +def test_unrecognized_layout_is_bounded_to_itself(tmp_path: Path) -> None: + package = _write_install(tmp_path, layout=("archive",)) + + assert any( + finding.check == "installation_record_invalid" + and f"outside {package.parent.resolve()}" in finding.message + for finding in _findings(tmp_path) + ) + + +@pytest.mark.parametrize( + ("site_packages", "expected"), + [ + ("/e/lib/python3.13/site-packages", "/e"), + ("/e/lib64/python3.13/site-packages", "/e"), + ("/e/lib/python3.13t/site-packages", "/e"), + ("/e/Lib/site-packages", "/e"), + ("/e/lib/python3.13/dist-packages", "/e/lib/python3.13/dist-packages"), + ("/e/share/python3.13/site-packages", "/e/share/python3.13/site-packages"), + ("/e/lib/pythonjunk/site-packages", "/e/lib/pythonjunk/site-packages"), + ("/c/archive-v0/abc", "/c/archive-v0/abc"), + pytest.param( + "C:/e/LIB/SITE-PACKAGES", + "C:/e", + marks=pytest.mark.skipif(os.name != "nt", reason="Native Windows path casing"), + ), + ], +) +def test_scheme_base(site_packages: str, expected: str) -> None: + assert _integrity._scheme_base(Path(site_packages)) == Path(expected) + + +@pytest.mark.parametrize( + ("case", "expected"), + [ + ("nul_path", "installation_record_unreadable_entry"), + ("variable_length_digest", "installation_record_unsupported_algorithm"), + ("unknown_digest", "installation_record_unsupported_algorithm"), + ], +) +def test_read_and_digest_failures_are_distinguished( + tmp_path: Path, case: str, expected: str +) -> None: + package = _write_install(tmp_path) + record = _record(package) + rows = record.read_text() + if case == "nul_path": + rows += f"autoskillit/a\x00b.py,{_record_hash(b'x')},1\n" + else: + algorithm = "shake_128" if case == "variable_length_digest" else "not_a_hash_algorithm" + rows = rows.replace( + _record_hash((package / "__init__.py").read_bytes()), f"{algorithm}=AAAA" + ) + record.write_text(rows) + + assert any(finding.check == expected for finding in _findings(tmp_path)) + + def test_record_mismatch_detected(tmp_path: Path) -> None: package = _write_install(tmp_path / "install") (package / "__init__.py").write_text("VERSION = 'mutated'\n") diff --git a/tests/cli/test_installation_integrity_uv.py b/tests/cli/test_installation_integrity_uv.py new file mode 100644 index 0000000000..7d6ae30c8c --- /dev/null +++ b/tests/cli/test_installation_integrity_uv.py @@ -0,0 +1,74 @@ +"""Medium, offline coverage of installation integrity using a real uv-installed wheel.""" + +from __future__ import annotations + +import subprocess +import sys +import zipfile +from pathlib import Path + +import pytest + +import autoskillit.cli.doctor._doctor_install as _integrity +from tests.conftest import production_interpreter_env + +from .test_installation_integrity import _CLEAN, _record_hash + +pytestmark = [pytest.mark.layer("cli"), pytest.mark.medium] + + +def test_uv_tool_install_verifies_clean(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: + wheel = tmp_path / "dist" / "autoskillit-1.0.0-py3-none-any.whl" + wheel.parent.mkdir(parents=True) + dist_info = "autoskillit-1.0.0.dist-info" + members = { + "autoskillit/__init__.py": b"def main() -> int:\n return 0\n", + f"{dist_info}/METADATA": b"Metadata-Version: 2.1\nName: autoskillit\nVersion: 1.0.0\n", + f"{dist_info}/WHEEL": ( + b"Wheel-Version: 1.0\nGenerator: autoskillit-tests\n" + b"Root-Is-Purelib: true\nTag: py3-none-any\n" + ), + f"{dist_info}/entry_points.txt": b"[console_scripts]\nautoskillit = autoskillit:main\n", + } + rows = [f"{name},{_record_hash(content)},{len(content)}" for name, content in members.items()] + with zipfile.ZipFile(wheel, "w") as archive: + for name, content in members.items(): + archive.writestr(name, content) + archive.writestr(f"{dist_info}/RECORD", "\n".join([*rows, f"{dist_info}/RECORD,,"]) + "\n") + + home = tmp_path / "home" + tool_dir = home / ".local" / "share" / "uv" / "tools" + result = subprocess.run( + [ + "uv", + "tool", + "install", + "--offline", + "--no-cache", + "--python", + sys.executable, + str(wheel), + ], + env={ + **production_interpreter_env(), + "UV_TOOL_DIR": str(tool_dir), + "UV_TOOL_BIN_DIR": str(tool_dir.parent / ".tools-bin"), + "UV_NO_CONFIG": "1", + "UV_PYTHON_DOWNLOADS": "never", + }, + cwd=tmp_path, + capture_output=True, + text=True, + timeout=50, + ) + assert result.returncode == 0, result.stdout + result.stderr + record = next( + (tool_dir / "autoskillit").glob( + "lib/python*/site-packages/autoskillit-1.0.0.dist-info/RECORD" + ) + ) + assert any(row.startswith("../") for row in record.read_text().splitlines()) + + monkeypatch.setattr(_integrity, "_active_record_paths", lambda: iter(())) + findings = _integrity.verify_installations(home=home) + assert findings == [_CLEAN], "\n".join(finding.message for finding in findings) From ad386630bf17f799e56ba54e486e35f294806ef2 Mon Sep 17 00:00:00 2001 From: Trecek Date: Sun, 25 Oct 2026 15:34:54 -0700 Subject: [PATCH 2/9] fix(review): resolve RECORD members before checking installation bounds --- src/autoskillit/cli/doctor/_doctor_install.py | 52 +++++++++---------- tests/cli/test_installation_integrity.py | 37 ++++++++++++- 2 files changed, 62 insertions(+), 27 deletions(-) diff --git a/src/autoskillit/cli/doctor/_doctor_install.py b/src/autoskillit/cli/doctor/_doctor_install.py index 55fedc924b..9bb67c38e0 100644 --- a/src/autoskillit/cli/doctor/_doctor_install.py +++ b/src/autoskillit/cli/doctor/_doctor_install.py @@ -7,7 +7,6 @@ import hashlib import importlib.metadata import json -import os import shutil import stat import subprocess @@ -481,32 +480,33 @@ def _verify_record_entry( ) -> DoctorResult | None: if len(row) < 2: return None - candidate = Path(os.path.normpath(site_packages / row[0])) - if not candidate.is_relative_to(bound): - return DoctorResult( - Severity.ERROR, - "installation_record_invalid", - f"Invalid RECORD path {row[0]!r} outside {bound} in {_display(installation)}", - ) - try: - package_relative = candidate.relative_to(installation.package_root) - except ValueError: - pass - else: - tracked.add(package_relative.as_posix()) - if not row[1]: - return None - parsed_hash = _record_hash(row[1]) - if parsed_hash is None: - return DoctorResult( - Severity.ERROR, - "installation_record_invalid", - f"Invalid RECORD hash for {row[0]} in {_display(installation)}", - ) - algorithm, expected = parsed_hash + candidate = site_packages / row[0] try: + candidate = candidate.resolve() + if not candidate.is_relative_to(bound): + return DoctorResult( + Severity.ERROR, + "installation_record_invalid", + f"Invalid RECORD path {row[0]!r} outside {bound} in {_display(installation)}", + ) + try: + package_relative = candidate.relative_to(installation.package_root) + except ValueError: + pass + else: + tracked.add(package_relative.as_posix()) + if not row[1]: + return None + parsed_hash = _record_hash(row[1]) + if parsed_hash is None: + return DoctorResult( + Severity.ERROR, + "installation_record_invalid", + f"Invalid RECORD hash for {row[0]} in {_display(installation)}", + ) + algorithm, expected = parsed_hash content = candidate.read_bytes() - except (OSError, ValueError): + except (OSError, RuntimeError, ValueError): return DoctorResult( Severity.ERROR, "installation_record_unreadable_entry", @@ -535,7 +535,7 @@ def _verify_record(installation: _Installation) -> tuple[list[DoctorResult], set results: list[DoctorResult] = [] tracked: set[str] = set() site_packages = installation.record_path.parent.parent - bound = _scheme_base(site_packages) + bound = _scheme_base(site_packages).resolve() try: rows = csv.reader(installation.record_path.read_text(encoding="utf-8").splitlines()) for row in rows: diff --git a/tests/cli/test_installation_integrity.py b/tests/cli/test_installation_integrity.py index 9a502bbf43..3f933f5bd9 100644 --- a/tests/cli/test_installation_integrity.py +++ b/tests/cli/test_installation_integrity.py @@ -116,7 +116,17 @@ def test_record_row_outside_installation_is_invalid(tmp_path: Path, case: str) - ) -@pytest.mark.parametrize("case", ["absolute_script", "redundant_dotdot"]) +@pytest.mark.parametrize( + "case", + [ + "absolute_script", + "redundant_dotdot", + pytest.param( + "double_slash", + marks=pytest.mark.skipif(os.name == "nt", reason="POSIX double-leading slash"), + ), + ], +) def test_equivalent_spellings_inside_installation_stay_clean(tmp_path: Path, case: str) -> None: package = _write_install(tmp_path) record = _record(package) @@ -125,11 +135,36 @@ def test_equivalent_spellings_inside_installation_stay_clean(tmp_path: Path, cas if case == "absolute_script" else ("autoskillit/__init__.py", "autoskillit/../autoskillit/__init__.py") ) + if case == "double_slash": + old = "../../../bin/autoskillit" + new = "/" + str((tmp_path / "autoskillit/bin/autoskillit").resolve()) record.write_text(record.read_text().replace(old, new)) assert _findings(tmp_path) == [_CLEAN] +@pytest.mark.parametrize( + ("target", "expected"), + [ + ("outside", "installation_record_invalid"), + ("loop", "installation_record_unreadable_entry"), + ], +) +def test_record_symlink_target_is_checked(tmp_path: Path, target: str, expected: str) -> None: + package = _write_install(tmp_path) + link = package / "linked.py" + if target == "outside": + destination = tmp_path / "outside.py" + destination.write_bytes(b"x") + else: + destination = link + link.symlink_to(destination) + record = _record(package) + record.write_text(record.read_text() + f"autoskillit/linked.py,{_record_hash(b'x')},1\n") + + assert any(finding.check == expected for finding in _findings(tmp_path)) + + def test_unrecognized_layout_is_bounded_to_itself(tmp_path: Path) -> None: package = _write_install(tmp_path, layout=("archive",)) From f04917fdd15d5a5c81981e4e60d2fed773d6d4f1 Mon Sep 17 00:00:00 2001 From: Trecek Date: Sun, 25 Oct 2026 15:36:28 -0700 Subject: [PATCH 3/9] fix(review): keep root-prefix RECORD bounds inside purelib --- src/autoskillit/cli/doctor/_doctor_install.py | 10 ++++++---- tests/cli/test_installation_integrity.py | 2 ++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/autoskillit/cli/doctor/_doctor_install.py b/src/autoskillit/cli/doctor/_doctor_install.py index 9bb67c38e0..b2f9280323 100644 --- a/src/autoskillit/cli/doctor/_doctor_install.py +++ b/src/autoskillit/cli/doctor/_doctor_install.py @@ -465,10 +465,12 @@ def _scheme_base(site_packages: Path) -> Path: if site_packages != site_packages.parent / "site-packages": return site_packages if re.fullmatch(r"python[0-9]+\.[0-9]+t?", lib.name) and lib.parent.name in {"lib", "lib64"}: - return lib.parent.parent - if lib == lib.parent / "Lib": - return lib.parent - return site_packages + base = lib.parent.parent + elif lib == lib.parent / "Lib": + base = lib.parent + else: + return site_packages + return base if base.parent != base else site_packages def _verify_record_entry( diff --git a/tests/cli/test_installation_integrity.py b/tests/cli/test_installation_integrity.py index 3f933f5bd9..593b654bb9 100644 --- a/tests/cli/test_installation_integrity.py +++ b/tests/cli/test_installation_integrity.py @@ -179,6 +179,8 @@ def test_unrecognized_layout_is_bounded_to_itself(tmp_path: Path) -> None: ("site_packages", "expected"), [ ("/e/lib/python3.13/site-packages", "/e"), + ("/lib/python3.13/site-packages", "/lib/python3.13/site-packages"), + ("/Lib/site-packages", "/Lib/site-packages"), ("/e/lib64/python3.13/site-packages", "/e"), ("/e/lib/python3.13t/site-packages", "/e"), ("/e/Lib/site-packages", "/e"), From 42cb127dc0f91def89bf049dd0089db9cdcba1b5 Mon Sep 17 00:00:00 2001 From: Trecek Date: Sun, 25 Oct 2026 15:37:50 -0700 Subject: [PATCH 4/9] fix(review): recognize dist-packages installation schemes --- src/autoskillit/cli/doctor/_doctor_install.py | 5 +++-- tests/cli/test_installation_integrity.py | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/autoskillit/cli/doctor/_doctor_install.py b/src/autoskillit/cli/doctor/_doctor_install.py index b2f9280323..c3592c1988 100644 --- a/src/autoskillit/cli/doctor/_doctor_install.py +++ b/src/autoskillit/cli/doctor/_doctor_install.py @@ -457,12 +457,13 @@ def _scheme_base(site_packages: Path) -> Path: Installers record console scripts and data relative to purelib, e.g. ``../../../bin/autoskillit`` from ``/lib/pythonX.Y/site-packages`` - (also ``lib64``; ``/Lib/site-packages`` on Windows). Standard + (also ``lib64`` and ``dist-packages``; ``/Lib/site-packages`` + on Windows). Standard script and data targets lie under ````. Other layouts, such as an unpacked uv cache archive, are bounded to themselves. """ lib = site_packages.parent - if site_packages != site_packages.parent / "site-packages": + if site_packages not in (lib / "site-packages", lib / "dist-packages"): return site_packages if re.fullmatch(r"python[0-9]+\.[0-9]+t?", lib.name) and lib.parent.name in {"lib", "lib64"}: base = lib.parent.parent diff --git a/tests/cli/test_installation_integrity.py b/tests/cli/test_installation_integrity.py index 593b654bb9..3376410056 100644 --- a/tests/cli/test_installation_integrity.py +++ b/tests/cli/test_installation_integrity.py @@ -73,6 +73,7 @@ def _findings(*roots: Path) -> list: [ ("lib", "python3.14", "site-packages"), ("lib64", "python3.14", "site-packages"), + ("lib", "python3.14", "dist-packages"), ("Lib", "site-packages"), ], ) @@ -184,7 +185,7 @@ def test_unrecognized_layout_is_bounded_to_itself(tmp_path: Path) -> None: ("/e/lib64/python3.13/site-packages", "/e"), ("/e/lib/python3.13t/site-packages", "/e"), ("/e/Lib/site-packages", "/e"), - ("/e/lib/python3.13/dist-packages", "/e/lib/python3.13/dist-packages"), + ("/e/lib/python3.13/dist-packages", "/e"), ("/e/share/python3.13/site-packages", "/e/share/python3.13/site-packages"), ("/e/lib/pythonjunk/site-packages", "/e/lib/pythonjunk/site-packages"), ("/c/archive-v0/abc", "/c/archive-v0/abc"), From 5b09516cbb1f41ea7735628c5f3a33a54973d596 Mon Sep 17 00:00:00 2001 From: Trecek Date: Sun, 25 Oct 2026 15:38:58 -0700 Subject: [PATCH 5/9] refactor(review): share installation-integrity test data and hashes --- tests/cli/_installation_integrity_helpers.py | 20 ++++++++++++++ tests/cli/test_installation_integrity.py | 29 ++++++-------------- tests/cli/test_installation_integrity_uv.py | 7 ++--- 3 files changed, 31 insertions(+), 25 deletions(-) create mode 100644 tests/cli/_installation_integrity_helpers.py diff --git a/tests/cli/_installation_integrity_helpers.py b/tests/cli/_installation_integrity_helpers.py new file mode 100644 index 0000000000..fc8d2d3cca --- /dev/null +++ b/tests/cli/_installation_integrity_helpers.py @@ -0,0 +1,20 @@ +"""Shared RECORD fixtures for installation-integrity tests.""" + +from __future__ import annotations + +import base64 +import hashlib + +from autoskillit.cli.doctor._doctor_types import DoctorResult +from autoskillit.core import Severity + +CLEAN = DoctorResult( + Severity.OK, + "installation_integrity", + "All discoverable AutoSkillit installations match their RECORD files", +) + + +def record_hash(content: bytes) -> str: + encoded = base64.urlsafe_b64encode(hashlib.sha256(content).digest()).rstrip(b"=") + return f"sha256={encoded.decode()}" diff --git a/tests/cli/test_installation_integrity.py b/tests/cli/test_installation_integrity.py index 3376410056..514e40fa02 100644 --- a/tests/cli/test_installation_integrity.py +++ b/tests/cli/test_installation_integrity.py @@ -2,8 +2,6 @@ from __future__ import annotations -import base64 -import hashlib import os import sys from pathlib import Path @@ -12,23 +10,12 @@ import autoskillit.cli.doctor._doctor_install as _integrity import autoskillit.cli.update._update_checks as _update_checks -from autoskillit.cli.doctor._doctor_types import DoctorResult from autoskillit.cli.install._install_info import InstallInfo, InstallType from autoskillit.core import Severity +from tests.cli._installation_integrity_helpers import CLEAN, record_hash pytestmark = [pytest.mark.layer("cli"), pytest.mark.small] -_CLEAN = DoctorResult( - Severity.OK, - "installation_integrity", - "All discoverable AutoSkillit installations match their RECORD files", -) - - -def _record_hash(content: bytes) -> str: - encoded = base64.urlsafe_b64encode(hashlib.sha256(content).digest()).rstrip(b"=") - return f"sha256={encoded.decode()}" - def _write_install( root: Path, @@ -53,7 +40,7 @@ def _write_install( record = site_packages / "autoskillit-1.0.0.dist-info" / "RECORD" record.parent.mkdir() rows = [ - f"{Path(os.path.relpath(path, site_packages)).as_posix()},{_record_hash(data)},{len(data)}" + f"{Path(os.path.relpath(path, site_packages)).as_posix()},{record_hash(data)},{len(data)}" for path, data in files.items() ] record.write_text("\n".join([*rows, "autoskillit-1.0.0.dist-info/RECORD,,"]) + "\n") @@ -80,7 +67,7 @@ def _findings(*roots: Path) -> list: def test_clean_install_reports_integrity_ok(tmp_path: Path, layout: tuple[str, ...]) -> None: _write_install(tmp_path, layout=layout) - assert _findings(tmp_path) == [_CLEAN] + assert _findings(tmp_path) == [CLEAN] def test_console_script_mutation_detected(tmp_path: Path) -> None: @@ -109,7 +96,7 @@ def test_record_row_outside_installation_is_invalid(tmp_path: Path, case: str) - "absolute": str(outside.resolve()), }[case] record = _record(package) - record.write_text(record.read_text() + f"{row},{_record_hash(b'x')},1\n") + record.write_text(record.read_text() + f"{row},{record_hash(b'x')},1\n") assert any( finding.check == "installation_record_invalid" and repr(row) in finding.message @@ -141,7 +128,7 @@ def test_equivalent_spellings_inside_installation_stay_clean(tmp_path: Path, cas new = "/" + str((tmp_path / "autoskillit/bin/autoskillit").resolve()) record.write_text(record.read_text().replace(old, new)) - assert _findings(tmp_path) == [_CLEAN] + assert _findings(tmp_path) == [CLEAN] @pytest.mark.parametrize( @@ -161,7 +148,7 @@ def test_record_symlink_target_is_checked(tmp_path: Path, target: str, expected: destination = link link.symlink_to(destination) record = _record(package) - record.write_text(record.read_text() + f"autoskillit/linked.py,{_record_hash(b'x')},1\n") + record.write_text(record.read_text() + f"autoskillit/linked.py,{record_hash(b'x')},1\n") assert any(finding.check == expected for finding in _findings(tmp_path)) @@ -215,11 +202,11 @@ def test_read_and_digest_failures_are_distinguished( record = _record(package) rows = record.read_text() if case == "nul_path": - rows += f"autoskillit/a\x00b.py,{_record_hash(b'x')},1\n" + rows += f"autoskillit/a\x00b.py,{record_hash(b'x')},1\n" else: algorithm = "shake_128" if case == "variable_length_digest" else "not_a_hash_algorithm" rows = rows.replace( - _record_hash((package / "__init__.py").read_bytes()), f"{algorithm}=AAAA" + record_hash((package / "__init__.py").read_bytes()), f"{algorithm}=AAAA" ) record.write_text(rows) diff --git a/tests/cli/test_installation_integrity_uv.py b/tests/cli/test_installation_integrity_uv.py index 7d6ae30c8c..653e7ae032 100644 --- a/tests/cli/test_installation_integrity_uv.py +++ b/tests/cli/test_installation_integrity_uv.py @@ -10,10 +10,9 @@ import pytest import autoskillit.cli.doctor._doctor_install as _integrity +from tests.cli._installation_integrity_helpers import CLEAN, record_hash from tests.conftest import production_interpreter_env -from .test_installation_integrity import _CLEAN, _record_hash - pytestmark = [pytest.mark.layer("cli"), pytest.mark.medium] @@ -30,7 +29,7 @@ def test_uv_tool_install_verifies_clean(tmp_path: Path, monkeypatch: pytest.Monk ), f"{dist_info}/entry_points.txt": b"[console_scripts]\nautoskillit = autoskillit:main\n", } - rows = [f"{name},{_record_hash(content)},{len(content)}" for name, content in members.items()] + rows = [f"{name},{record_hash(content)},{len(content)}" for name, content in members.items()] with zipfile.ZipFile(wheel, "w") as archive: for name, content in members.items(): archive.writestr(name, content) @@ -71,4 +70,4 @@ def test_uv_tool_install_verifies_clean(tmp_path: Path, monkeypatch: pytest.Monk monkeypatch.setattr(_integrity, "_active_record_paths", lambda: iter(())) findings = _integrity.verify_installations(home=home) - assert findings == [_CLEAN], "\n".join(finding.message for finding in findings) + assert findings == [CLEAN], "\n".join(finding.message for finding in findings) From 60b04ca3d0a60476f7bc1e215fe42a2670a34cf9 Mon Sep 17 00:00:00 2001 From: Trecek Date: Sun, 25 Oct 2026 15:39:39 -0700 Subject: [PATCH 6/9] refactor(review): share RECORD serialization across integrity fixtures --- tests/cli/_installation_integrity_helpers.py | 4 ++++ tests/cli/test_installation_integrity.py | 4 ++-- tests/cli/test_installation_integrity_uv.py | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/cli/_installation_integrity_helpers.py b/tests/cli/_installation_integrity_helpers.py index fc8d2d3cca..d5548c96ec 100644 --- a/tests/cli/_installation_integrity_helpers.py +++ b/tests/cli/_installation_integrity_helpers.py @@ -18,3 +18,7 @@ def record_hash(content: bytes) -> str: encoded = base64.urlsafe_b64encode(hashlib.sha256(content).digest()).rstrip(b"=") return f"sha256={encoded.decode()}" + + +def record_text(rows: list[str], dist_info: str) -> str: + return "\n".join([*rows, f"{dist_info}/RECORD,,"]) + "\n" diff --git a/tests/cli/test_installation_integrity.py b/tests/cli/test_installation_integrity.py index 514e40fa02..3e94171ccf 100644 --- a/tests/cli/test_installation_integrity.py +++ b/tests/cli/test_installation_integrity.py @@ -12,7 +12,7 @@ import autoskillit.cli.update._update_checks as _update_checks from autoskillit.cli.install._install_info import InstallInfo, InstallType from autoskillit.core import Severity -from tests.cli._installation_integrity_helpers import CLEAN, record_hash +from tests.cli._installation_integrity_helpers import CLEAN, record_hash, record_text pytestmark = [pytest.mark.layer("cli"), pytest.mark.small] @@ -43,7 +43,7 @@ def _write_install( f"{Path(os.path.relpath(path, site_packages)).as_posix()},{record_hash(data)},{len(data)}" for path, data in files.items() ] - record.write_text("\n".join([*rows, "autoskillit-1.0.0.dist-info/RECORD,,"]) + "\n") + record.write_text(record_text(rows, record.parent.name)) return package diff --git a/tests/cli/test_installation_integrity_uv.py b/tests/cli/test_installation_integrity_uv.py index 653e7ae032..bf236a6570 100644 --- a/tests/cli/test_installation_integrity_uv.py +++ b/tests/cli/test_installation_integrity_uv.py @@ -10,7 +10,7 @@ import pytest import autoskillit.cli.doctor._doctor_install as _integrity -from tests.cli._installation_integrity_helpers import CLEAN, record_hash +from tests.cli._installation_integrity_helpers import CLEAN, record_hash, record_text from tests.conftest import production_interpreter_env pytestmark = [pytest.mark.layer("cli"), pytest.mark.medium] @@ -33,7 +33,7 @@ def test_uv_tool_install_verifies_clean(tmp_path: Path, monkeypatch: pytest.Monk with zipfile.ZipFile(wheel, "w") as archive: for name, content in members.items(): archive.writestr(name, content) - archive.writestr(f"{dist_info}/RECORD", "\n".join([*rows, f"{dist_info}/RECORD,,"]) + "\n") + archive.writestr(f"{dist_info}/RECORD", record_text(rows, dist_info)) home = tmp_path / "home" tool_dir = home / ".local" / "share" / "uv" / "tools" From bf592c0a5ad3ceb78f65df94a3d463966ceb4610 Mon Sep 17 00:00:00 2001 From: Trecek Date: Sun, 25 Oct 2026 15:40:25 -0700 Subject: [PATCH 7/9] test(review): require the console-script RECORD row in the uv regression --- tests/cli/test_installation_integrity_uv.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/cli/test_installation_integrity_uv.py b/tests/cli/test_installation_integrity_uv.py index bf236a6570..edf5ca1096 100644 --- a/tests/cli/test_installation_integrity_uv.py +++ b/tests/cli/test_installation_integrity_uv.py @@ -2,6 +2,7 @@ from __future__ import annotations +import csv import subprocess import sys import zipfile @@ -66,7 +67,9 @@ def test_uv_tool_install_verifies_clean(tmp_path: Path, monkeypatch: pytest.Monk "lib/python*/site-packages/autoskillit-1.0.0.dist-info/RECORD" ) ) - assert any(row.startswith("../") for row in record.read_text().splitlines()) + assert "../../../bin/autoskillit" in { + row[0] for row in csv.reader(record.read_text().splitlines()) + } monkeypatch.setattr(_integrity, "_active_record_paths", lambda: iter(())) findings = _integrity.verify_installations(home=home) From 39a812220f4cbdcea8edb6e1635004e8b28c76c7 Mon Sep 17 00:00:00 2001 From: Trecek Date: Sun, 25 Oct 2026 15:41:00 -0700 Subject: [PATCH 8/9] test(review): remove unused out-of-bound fixture files --- tests/cli/test_installation_integrity.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/cli/test_installation_integrity.py b/tests/cli/test_installation_integrity.py index 3e94171ccf..35a78984ed 100644 --- a/tests/cli/test_installation_integrity.py +++ b/tests/cli/test_installation_integrity.py @@ -86,10 +86,6 @@ def test_console_script_mutation_detected(tmp_path: Path) -> None: def test_record_row_outside_installation_is_invalid(tmp_path: Path, case: str) -> None: package = _write_install(tmp_path) outside = tmp_path / "outside.txt" - outside.write_bytes(b"x") - sibling = tmp_path / "autoskillit-evil" / "x.py" - sibling.parent.mkdir() - sibling.write_bytes(b"x") row = { "parent_escape": "../../../../outside.txt", "sibling_prefix": "../../../../autoskillit-evil/x.py", From 24a6053d08c771e4d6b0af8c4ab39c9959c0a667 Mon Sep 17 00:00:00 2001 From: Trecek Date: Sun, 25 Oct 2026 15:42:20 -0700 Subject: [PATCH 9/9] docs(review): anchor root-child classifications to source symbols --- .../test_autoskillit_root_children_registered.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/arch/test_autoskillit_root_children_registered.py b/tests/arch/test_autoskillit_root_children_registered.py index 4b698cbafe..3a6ee8b9c8 100644 --- a/tests/arch/test_autoskillit_root_children_registered.py +++ b/tests/arch/test_autoskillit_root_children_registered.py @@ -16,17 +16,19 @@ # These names are accounted for elsewhere: home-level artifacts, a read-only # legacy path, and a runtime directory with a real-git proof. _CLASSIFIED_ELSEWHERE: dict[str, int] = { - # Home-level hook state: hooks/guards/mcp_health_advisor.py:36. + # Home-level hook state: hooks/guards/mcp_health_advisor.py:_active_kitchens_path. "active_kitchens.json": 1, - # Home-level marketplace shape: core/types/constants/_type_constants_retirements.py:309. + # Home-level marketplace shape: + # core/types/constants/_type_constants_retirements.py:RETIRED_INSTALL_ARTIFACT_SHAPES. "marketplace": 1, - # Home-level plugin storage: cli/doctor/_doctor_install.py:358. + # Home-level plugin storage: cli/doctor/_doctor_install.py:_owned_installation_roots. "plugin-generations": 1, - # Home-level hook projection repair: workspace/_projected_artifact/_hook_repair.py:538. + # Home-level hook projection repair: + # workspace/_projected_artifact/_hook_repair.py:repair_broken_projection_hooks. "plugin-projections": 1, - # Home-level dismissal state: cli/update/_update_checks.py:79. + # Home-level dismissal state: cli/update/_update_checks.py:_read_dismiss_state. "update_check.json": 1, - # Legacy path is read only for migration: cli/install/_marketplace.py:162. + # Legacy path is read only for migration: cli/install/_marketplace.py:_ensure_workspace_ready. "scripts": 1, # Runtime self-ignore is proven by tests/workspace/test_clone_gate_runtime_state.py. "managed-headless-session-lineage": 1,