mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-06 05:17:15 +00:00
Review follow-up on #145364 (kshitijk4poor): - tool_store_pins.py now asks pm's own rule, _installed_location (new heal=False keyword keeps it read-only), and also requires each entry's recorded env to equal what this checkout's package code records. A store at the right pins but with a stale env made `pm install`'s _refresh_found_env re-record the shared facts.json. - run_tests.sh: the concurrency comment now says the unlocked check keeps runs that START on different pins apart and names the window before pm install's lock; UV_PYTHON_INSTALL_DIR is reused only when the pinned minor is already cached; dscl parsed with sed, same-home test with -ef; PATH caveat and a never-forward note at the env -i allowlist. - The test separates the checks: setup-hermes' uv copy broken while pm's uv entry is fine, a non-executable ripgrep, and a stale node env, each asserting the store is left byte-for-byte and mode-for-mode unchanged.
63 lines
2.8 KiB
Python
63 lines
2.8 KiB
Python
"""Exit 0 only when a tool store already holds this checkout's pins.
|
|
|
|
Usage: python -I -B scripts/tool_store_pins.py REPO STORE
|
|
(on success prints the pinned Python major.minor)
|
|
|
|
scripts/run_tests.sh asks this before sharing the account's tool store with a
|
|
faked HOME. facts.json selects ONE entry per package, not one per version:
|
|
provisioning a checkout with other pins re-points the account's own runtime at
|
|
them and pulls the selection from under a concurrent run on the store's pins.
|
|
So share only when every tool `pm install` would provision here (cmd_install's
|
|
roots, defaults and the venv's deps) passes PM's own installed-at-the-pin lookup
|
|
without an exec-bit heal, and records the env this checkout's package code
|
|
would record: a stale env makes `pm install` re-record the shared facts.json,
|
|
and a missing or non-executable binary (setup-hermes.sh's uv copy included)
|
|
sends setup or `pm install` into a re-stage whose unlocked remove + publish
|
|
races other runs on the shared store. Read-only: no lock, no install, no
|
|
bytecode; any unreadable record or error means "do not share".
|
|
"""
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
def _setup_uv(store: Path, target: str, version: str) -> Path:
|
|
"""setup-hermes.sh's exact uv path: $store/uv-$uv_version-$os-$arch/uv[.exe]."""
|
|
os_arch = "-".join(target.split("-")[:2])
|
|
return store / f"uv-{version}-{os_arch}" / ("uv.exe" if os_arch.startswith("win32") else "uv")
|
|
|
|
|
|
def main(repo: str, store: Path) -> int:
|
|
sys.path.insert(0, repo)
|
|
from pm.defaults import default_packages
|
|
from pm.install import _installed_location
|
|
from pm.lock import Facts, Lockfile
|
|
from pm.package import StatePackage
|
|
from pm.registry import tool_roots, walk
|
|
from pm.store import current_target
|
|
|
|
lock = Lockfile(Path(repo, "pm", "lock.json"))
|
|
# Strict first: PM's lenient read would quarantine an unparsable file as .corrupt.
|
|
Facts(store / "facts.json", strict=True)
|
|
names, target = lock.names(), current_target()
|
|
for package in walk(tool_roots(names) + default_packages(names) + ["venv"]):
|
|
if isinstance(package, StatePackage):
|
|
continue
|
|
location = _installed_location(package, lock, target, roots=(store,), heal=False)
|
|
if location is None:
|
|
return 1
|
|
facts, found = location
|
|
entry = found.entry(facts.get(package.name)["entry"])
|
|
if facts.env_for(package.name, found.root) != package.env(entry, target):
|
|
return 1
|
|
uv = _setup_uv(store, target, lock.version("uv"))
|
|
if not uv.is_file() or not (os.name == "nt" or os.access(uv, os.X_OK)):
|
|
return 1
|
|
# The runner reuses uv's interpreter cache only when it already holds this minor.
|
|
print(".".join(lock.version("python").split("+")[0].split(".")[:2]))
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main(sys.argv[1], Path(sys.argv[2])))
|