Finish bootstrap uv before PM replaces its store entry. Keep failure receipts stdlib-only and align the cryptography requirement and override with the locked version. Let bundle builders declare launch paths and update ownership. Remove payload discovery, Store probing, and the unused develop command. Derive Nix Python from the PM lock and share its provenance stamp. Document setup, activation, optional dependencies, and distribution ownership. Targeted Windows tests, relocated runtime launches, Electron bundling, and bilingual docs builds pass. Native Nix and signed-package acceptance remain CI gates.
67 lines
3.0 KiB
Python
67 lines
3.0 KiB
Python
"""Activation runs read-only from any cwd and restores the caller environment."""
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.mark.platforms("windows")
|
|
def test_powershell_activation_roundtrip_selected_environment(tmp_path, monkeypatch):
|
|
from hermes_cli.runtime_paths import runtime_facts_path
|
|
from pm.paths import repo_root
|
|
from pm.store import current_target
|
|
from pm.lock import Lockfile
|
|
|
|
source = repo_root()
|
|
root = tmp_path / "checkout"
|
|
root.mkdir()
|
|
shutil.copytree(source / "pm", root / "pm", ignore=shutil.ignore_patterns("__pycache__"))
|
|
(root / "hermes_cli").mkdir()
|
|
for relative in ("activate.ps1", "hermes_constants.py", "hermes_cli/__init__.py",
|
|
"hermes_cli/runtime_paths.py", "hermes_cli/runtime_state.py"):
|
|
shutil.copyfile(source / relative, root / relative)
|
|
subprocess.run([sys._base_executable, "-m", "venv", "--without-pip", str(root / ".venv")],
|
|
check=True, capture_output=True, timeout=60)
|
|
home = tmp_path / "home"
|
|
monkeypatch.setenv("HERMES_HOME", str(home))
|
|
facts = runtime_facts_path(root)
|
|
selected = facts.parent / "environments" / "a" / "venv"
|
|
site = selected / "Lib" / "site-packages"
|
|
site.mkdir(parents=True)
|
|
(selected / "pyvenv.cfg").write_text("home = test", encoding="utf-8")
|
|
facts.write_text(json.dumps({"packages": {"venv": {"environment": str(selected)}}}), encoding="utf-8")
|
|
store = tmp_path / "tools"
|
|
store.mkdir()
|
|
lock = Lockfile(root / "pm" / "lock.json")
|
|
target = current_target()
|
|
entry = store / "python-test"
|
|
entry.mkdir()
|
|
(store / "facts.json").write_text(json.dumps({"schema": 1, "packages": {"python": {
|
|
"entry": entry.name, "version": lock.version("python"), "target": target,
|
|
"artifacts": [a["sha256"] for a in lock.artifacts("python", target)],
|
|
"env": {"HERMES_ACTIVATE_CANARY": "active"},
|
|
}}}), encoding="utf-8")
|
|
env = dict(os.environ, HERMES_RUNTIME_DIR=str(store), PYTHONPATH="caller-original",
|
|
PATHEXT=".COM;.EXE;.BAT;.CMD")
|
|
script = tmp_path / "run.ps1"
|
|
script.write_text(
|
|
f"$ErrorActionPreference='Stop'; . '{root / 'activate.ps1'}'; "
|
|
"[PSCustomObject]@{canary=$env:HERMES_ACTIVATE_CANARY;pythonpath=$env:PYTHONPATH}|ConvertTo-Json -Compress; "
|
|
"deactivate; Write-Output ('restored=' + $env:PYTHONPATH); "
|
|
"Write-Output ('canary=' + $env:HERMES_ACTIVATE_CANARY)", encoding="utf-8",
|
|
)
|
|
powershell = shutil.which("powershell")
|
|
assert powershell
|
|
run = subprocess.run([powershell,"-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-File",str(script)],
|
|
cwd=tmp_path,env=env,capture_output=True,text=True,timeout=40)
|
|
assert run.returncode == 0, run.stdout + run.stderr
|
|
lines = run.stdout.splitlines()
|
|
record = json.loads(lines[0])
|
|
assert record["canary"] == "active"
|
|
assert record["pythonpath"] == str(root) + os.pathsep + str(site)
|
|
assert lines[1:] == ["restored=caller-original", "canary="]
|