Skip to content
Merged
6 changes: 0 additions & 6 deletions scripts/e2e/catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
},
Expand Down
90 changes: 59 additions & 31 deletions src/autoskillit/cli/doctor/_doctor_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,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
Expand Down Expand Up @@ -450,53 +452,78 @@ 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 ``<base>/lib/pythonX.Y/site-packages``
(also ``lib64`` and ``dist-packages``; ``<base>/Lib/site-packages``
on Windows). Standard
script and data targets lie under ``<base>``. Other layouts, such as
an unpacked uv cache archive, are bounded to themselves.
"""
lib = site_packages.parent
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
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(
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:
return DoctorResult(
Severity.ERROR,
"installation_record_invalid",
f"Invalid RECORD path {row[0]!r} in {_display(installation)}",
)
candidate = site_packages / relative
candidate = site_packages / row[0]
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:
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, RuntimeError, ValueError):
return DoctorResult(
Severity.ERROR,
"installation_record_invalid",
f"Invalid RECORD hash for {row[0]} in {_display(installation)}",
"installation_record_unreadable_entry",
f"Unreadable RECORD entry {candidate} in {_display(installation)}",
)
algorithm, expected = parsed_hash
try:
observed = hashlib.new(algorithm, candidate.read_bytes()).digest()
except ValueError:
observed = hashlib.new(algorithm, content).digest()
except (TypeError, ValueError):
return DoctorResult(
Severity.ERROR,
"installation_record_unknown_algorithm",
f"Unknown RECORD hash algorithm {algorithm!r} "
"installation_record_unsupported_algorithm",
f"Unsupported RECORD hash algorithm {algorithm!r} "
f"for {candidate} in {_display(installation)}",
)
except OSError:
return DoctorResult(
Severity.ERROR,
"installation_record_unreadable_entry",
f"Unreadable RECORD entry {candidate} in {_display(installation)}",
)
if observed != expected:
return DoctorResult(
Severity.ERROR,
Expand All @@ -511,10 +538,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).resolve()
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:
Expand Down
14 changes: 8 additions & 6 deletions tests/arch/test_autoskillit_root_children_registered.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:355.
# 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,
Expand Down
24 changes: 24 additions & 0 deletions tests/cli/_installation_integrity_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""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()}"


def record_text(rows: list[str], dist_info: str) -> str:
return "\n".join([*rows, f"{dist_info}/RECORD,,"]) + "\n"
Loading
Loading