mirror of
https://github.com/elder-plinius/OBLITERATUS.git
synced 2026-12-05 02:24:12 +01:00
99 lines
5.5 KiB
Python
99 lines
5.5 KiB
Python
"""Real Git/pytest integration distinguishes execution inputs from generated outputs."""
|
|
|
|
import importlib.metadata
|
|
import json
|
|
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
from types import SimpleNamespace
|
|
|
|
import pytest
|
|
|
|
from scripts import run_release_partition as runner
|
|
from scripts.check_release_partitions import junit_nodes
|
|
from scripts.release_checkout_identity import verify_checkout
|
|
from tests.release_partition_cases import POLICY_IDENTITY
|
|
|
|
|
|
@pytest.fixture
|
|
def committed_checkout(tmp_path, monkeypatch):
|
|
source = Path(__file__).parents[1]
|
|
monkeypatch.setenv("PYTHONDONTWRITEBYTECODE", "1")
|
|
revision = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=source, text=True).strip()
|
|
objects = subprocess.check_output(["git", "rev-parse", "--git-path", "objects"], cwd=source, text=True).strip()
|
|
monkeypatch.setenv("GIT_ALTERNATE_OBJECT_DIRECTORIES", str((source / objects).resolve()))
|
|
root = tmp_path / "checkout"
|
|
subprocess.run(["git", "init", "--quiet", str(root)], check=True, capture_output=True)
|
|
# Existing commit objects are read-only; all index/ref/checkout writes are private.
|
|
subprocess.run(["git", "checkout", "--quiet", "--detach", revision], cwd=root, check=True)
|
|
assert not list(root.rglob("__pycache__"))
|
|
return root, revision
|
|
|
|
|
|
@pytest.mark.parametrize("build_outputs", [False, True])
|
|
def test_real_partition_accepts_its_workflow_evidence_path_and_build_outputs(committed_checkout, tmp_path, monkeypatch, build_outputs):
|
|
monkeypatch.setattr(runner, "bytecode_identity", lambda: POLICY_IDENTITY)
|
|
root, revision = committed_checkout
|
|
baseline = verify_checkout(root, revision)
|
|
# Noneditable setuptools builds leave this ignored source copy behind.
|
|
if build_outputs:
|
|
build = root / "build/lib/obliteratus"
|
|
shutil.copytree(root / "obliteratus", build)
|
|
assert subprocess.run(["git", "check-ignore", "build/lib/obliteratus/__init__.py"],
|
|
cwd=root, capture_output=True).returncode == 0
|
|
assert verify_checkout(root, revision) == baseline
|
|
installed = tmp_path / "site-packages/obliteratus"
|
|
shutil.copytree(root / "obliteratus", installed)
|
|
distribution = importlib.metadata.distribution
|
|
# Isolate installed-package lookup only; Git, tree verification, metadata,
|
|
# the sharder, subprocess pytest, plugin and coverage configuration are real.
|
|
monkeypatch.setattr(importlib.metadata, "distribution", lambda name:
|
|
SimpleNamespace(locate_file=lambda path: installed.parent / path)
|
|
if name == "obliteratus" else distribution(name))
|
|
durations = tmp_path / "durations.json"
|
|
# Give this one existing file shard zero, balancing all zero-weight files
|
|
# onto another shard. This bounds execution without mocking the sharder.
|
|
durations.write_text(json.dumps({"schema_version": 1, "source": "workflow layout regression",
|
|
"default_seconds": 0, "files": {"tests/test_config.py": 1}}))
|
|
output = root / "test-results/partition"
|
|
args = SimpleNamespace(root=root, output=output, command="run", candidate_sha=revision,
|
|
target_sha=revision, target="head", kind="core", shard=0, durations=durations)
|
|
assert runner.execute(args) == 0
|
|
status = json.loads((output / "status.json").read_text())
|
|
assert status["exit_code"] == 0
|
|
assert status["checkout_tree_digest"] == baseline
|
|
assert status["target_sha"] == revision
|
|
selected = json.loads((output / "collection.json").read_text())["nodes"]["core"]
|
|
assert selected and all(node.startswith("tests/test_config.py::") for node in selected)
|
|
assert sorted(junit_nodes(output / "junit.xml")) == sorted(selected)
|
|
assert (output / "coverage.data").stat().st_size > 0
|
|
assert f'context = "release:{revision}"' in (output / "coverage-config.toml").read_text()
|
|
assert subprocess.run(["git", "check-ignore", "test-results/partition/coverage-config.toml"],
|
|
cwd=root, capture_output=True).returncode == 0
|
|
assert verify_checkout(root, revision) == baseline
|
|
assert not (output / "pytest-tmp").exists()
|
|
# Report jobs download complete partition artifacts before fresh collection.
|
|
downloaded = root / f"test-results/partitions/head/release-core-py{status['python_version']}-head-0"
|
|
shutil.copytree(output, downloaded)
|
|
assert (downloaded / "coverage-config.toml").is_file()
|
|
assert runner.target_metadata(root, revision, revision, "head")["checkout_tree_digest"] == baseline
|
|
|
|
|
|
@pytest.mark.parametrize("name", [
|
|
"tests/ignored/test_injected.py", "tests/ignored/pytest.toml",
|
|
"tests/test-results/partition/coverage-config.toml", "scripts/build/lib/injected.py",
|
|
"scripts/__pycache__/check_conditional_policy.cpython-312.pyc",
|
|
"obliteratus/ignored/plugin.py", "ci/ignored/policy.toml", ".github/ignored/job.cfg",
|
|
"injected.py", "injected.toml", "pytest.ini", "injected.cfg", "injected.lock", ".coveragerc",
|
|
])
|
|
def test_ignored_execution_inputs_still_fail_after_scoping(committed_checkout, name):
|
|
root, revision = committed_checkout
|
|
path = root / name
|
|
assert not path.exists()
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
path.write_text("# uncommitted execution input\n")
|
|
(root / ".git/info/exclude").write_text(name + "\n")
|
|
assert subprocess.run(["git", "check-ignore", name], cwd=root, capture_output=True).returncode == 0
|
|
with pytest.raises(ValueError, match="uncommitted test/source/config"):
|
|
verify_checkout(root, revision)
|