Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,15 @@ A skipped required job on a PR is **not green test evidence**, even if GitHub
allows merging. Review the job conclusion and why it skipped. Heart's main-head
CI rollup likewise requires explicit success; a synthetic classifier regression
is not a substitute for observing the pipeline's unit/slow jobs on a live PR.

## Local smoke installer paths

`heart.smoke` resolves the dependency chain through the shared repository resolver
before running a workspace's `smoke_install.sh`. A temporary directory exposes
those checkouts under their flat repository names, so the workspace-owned script
keeps its existing CI contract on both flat and grouped local layouts. The links
are removed on success or failure; original checkouts are never relocated.
Missing chain directories fail explicitly. Legacy workspaces without an installer
use resolved absolute paths for local packages and optional extras.
The existing environment fingerprint/preflight remains authoritative: a failed
rebuild cannot publish a successful environment marker or silently use old state.
22 changes: 19 additions & 3 deletions heart/smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import shutil
import subprocess
import sys
import tempfile
import tomllib
import uuid
from dataclasses import dataclass
Expand Down Expand Up @@ -260,7 +261,7 @@ def _optional_local_targets(organism_root: Path, chain: Iterable[str]) -> list[s
data = tomllib.load(stream)
extras = data.get("project", {}).get("optional-dependencies", {})
if "optional" in extras:
targets.append(f"./{repo}[optional]")
targets.append(f"{pyproject.parent.resolve()}[optional]")
return targets


Expand Down Expand Up @@ -314,13 +315,28 @@ def _install_environment(
workspace = _workspace.repo_path(organism_root, spec.directory)
installer = workspace / ".github" / "scripts" / "smoke_install.sh"
if installer.is_file():
_run(["bash", installer], cwd=organism_root, env=env)
# The workspace-owned epilogue has the same flat contract as CI.
# Resolve from the real root first, then expose only this dependency
# chain. Never alter the root or leave symlinks behind after failure.
resolved = {}
for repo in spec.chain:
if Path(repo).name != repo or repo in {".", ".."}:
raise SmokeEnvironmentError(f"Invalid dependency checkout name: {repo}")
path = _workspace.repo_path(organism_root, repo).resolve()
if not path.is_dir():
raise SmokeEnvironmentError(f"Missing dependency checkout {repo}: {path}")
resolved[repo] = path
with tempfile.TemporaryDirectory(prefix="pyauto-smoke-install-") as directory:
staging = Path(directory)
for repo, path in resolved.items():
(staging / repo).symlink_to(path, target_is_directory=True)
_run(["bash", installer.resolve()], cwd=staging, env=env)
return

# Legacy workspaces have no CI epilogue yet. Install their local chain and
# discover the conventional `optional` extras from package metadata; Heart
# does not carry a second list of third-party packages.
local_targets = [f"./{repo}" for repo in spec.chain]
local_targets = [str(_workspace.repo_path(organism_root, repo).resolve()) for repo in spec.chain]
_run([python, "-m", "pip", "install", *local_targets], cwd=organism_root, env=env)
optional_targets = _optional_local_targets(organism_root, spec.chain)
if optional_targets:
Expand Down
51 changes: 48 additions & 3 deletions tests/test_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def test_workspace_installer_is_the_dependency_source_of_truth(tmp_path, monkeyp
assert any(command == ["bash", str(installer)] for command, _ in calls)
assert all("./LibraryA" not in command for command, _ in calls)
installer_call = next(kwargs for command, kwargs in calls if command[0] == "bash")
assert installer_call["cwd"] == root
assert not installer_call["cwd"].exists() # temporary layout cleaned up
assert installer_call["env"]["PYTHON_VERSION"] == "3.12"


Expand Down Expand Up @@ -230,8 +230,8 @@ def test_legacy_installer_derives_optional_extras_from_pyproject(tmp_path, monke
{"executable": "/fake/python", "version": "3.12.8"},
)

assert any("./LibraryB" in command for command in commands)
assert any("./LibraryB[optional]" in command for command in commands)
assert any(str(root / "LibraryB") in command for command in commands)
assert any(str(root / "LibraryB") + "[optional]" in command for command in commands)
assert all("nufftax" not in command for command in commands)


Expand Down Expand Up @@ -664,3 +664,48 @@ def test_pip_check_passes_through_when_clean(tmp_path, monkeypatch):
spec = smoke.WorkspaceSpec("demo", "demo_workspace", ("LibraryB",), True)

smoke._pip_check(Path("/fake/python"), {}, spec) # must not raise


@pytest.mark.parametrize('grouped', [False, True])
@pytest.mark.parametrize('fail', [False, True])
def test_installer_sees_flat_chain_and_cleans_up(tmp_path, monkeypatch, grouped, fail):
spec = smoke.WorkspaceSpec('demo', 'demo_workspace', ('LibraryA',))
root = make_tree(tmp_path, spec)
library = root / 'LibraryA'
if grouped:
(root / 'family').mkdir()
library.rename(root / 'family' / 'LibraryA')
library = root / 'family' / 'LibraryA'
monkeypatch.setattr(smoke._workspace, 'repo_path',
lambda root, name: library if name == 'LibraryA' else root / name)
installer = root / spec.directory / '.github/scripts/smoke_install.sh'
installer.write_text('set -e\ntest -f ./LibraryA/pyproject.toml\n' +
('exit 17\n' if fail else ''))
staging = []
original = smoke._run
def run(command, **kwargs):
if command[0] == 'bash':
staging.append(kwargs['cwd'])
assert (kwargs['cwd'] / 'LibraryA').resolve() == library
return original(command, **kwargs)
return completed()
monkeypatch.setattr(smoke, '_run', run)
if fail:
with pytest.raises(subprocess.CalledProcessError):
smoke._install_environment(tmp_path / 'env', root, spec, {'version': '3.12.8'})
else:
smoke._install_environment(tmp_path / 'env', root, spec, {'version': '3.12.8'})
assert staging and not staging[0].exists()
assert library.is_dir()


def test_installer_rejects_missing_chain_checkout(tmp_path, monkeypatch):
spec = smoke.WorkspaceSpec('demo', 'demo_workspace', ('LibraryA',))
root = make_tree(tmp_path, spec)
(root / 'LibraryA/pyproject.toml').unlink()
(root / 'LibraryA').rmdir()
calls = []
monkeypatch.setattr(smoke, '_run', lambda command, **kw: calls.append(command))
with pytest.raises(smoke.SmokeEnvironmentError, match='Missing dependency checkout LibraryA'):
smoke._install_environment(tmp_path / 'env', root, spec, {'version': '3.12.8'})
assert not any(c[0] == 'bash' for c in calls)
Loading