mirror of
https://github.com/elder-plinius/OBLITERATUS.git
synced 2026-12-05 02:24:12 +01:00
Prepare only locked dependencies in owned release environments before installing the exact project. Preserve verified wheel-supplied caches outside import paths, require zero caches before compilation, and bind generated cache bytes to source and retained diagnostics. Keep project caches forbidden, preserve the no-write startup policy, sanitize inherited compilation settings, and retain bootstrap evidence separately without changing test selection or release gates. Refs #306
118 lines
5.9 KiB
Python
118 lines
5.9 KiB
Python
"""Bootstrap failures retain separate diagnostics without moving partition roots."""
|
|
|
|
import fnmatch
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
|
|
import pytest
|
|
|
|
from tests.test_release_ci_workflow import step
|
|
|
|
|
|
PATHS = [
|
|
("release-core-tests", "Install locked package and test tools", "partition", "TEST_ENV"),
|
|
("release-gloo-tests", "Install locked package and test tools", "partition", "TEST_ENV"),
|
|
("test", "Install locked package and test tools", "head", "TEST_ENV"),
|
|
("test", "Generate exact-base coverage for module regression comparison", "base", "BASE_TEST_ENV"),
|
|
]
|
|
|
|
|
|
@pytest.mark.parametrize("job,step_name,label,variable", PATHS)
|
|
def test_each_path_uses_noncompiling_project_sync_and_separate_diagnostics(job, step_name, label, variable):
|
|
script = step(job, step_name)["run"]
|
|
syncs = [line for line in script.splitlines() if "uv sync" in line]
|
|
assert len(syncs) == 2
|
|
assert "--no-install-project" in syncs[0] and "--no-compile-bytecode" in syncs[0]
|
|
assert "--no-install-project" not in syncs[1] and "--no-compile-bytecode" in syncs[1]
|
|
assert all("--locked --no-default-groups" in line and "--no-editable" in line for line in syncs)
|
|
assert all("env -u UV_COMPILE_BYTECODE" in line for line in syncs)
|
|
assert script.index(syncs[0]) < script.index("scripts.release_dependency_bytecode compile") < script.index(syncs[1])
|
|
assert script.index(syncs[1]) < script.index("scripts.release_dependency_bytecode verify") < script.index(' install --environment ')
|
|
assert f'BOOTSTRAP_DIAGNOSTICS="$RUNNER_TEMP/dependency-bootstrap/{label}"' in script
|
|
assert f'--environment "${variable}"' in script
|
|
upload = step(job, "Upload dependency bootstrap diagnostics")
|
|
assert upload["if"] == "always()" and upload["with"]["retention-days"] == 90
|
|
assert upload["with"]["path"] == "${{ runner.temp }}/dependency-bootstrap/"
|
|
assert upload["with"]["name"].startswith("dependency-bootstrap-")
|
|
# Diagnostic names must never match the existing partition download globs.
|
|
name = upload["with"]["name"].replace("${{ matrix.python-version }}", "3.12").replace(
|
|
"${{ matrix.target }}", "head").replace("${{ matrix.shard }}", "0")
|
|
for target in ("head", "base"):
|
|
pattern = step("test", f"Download {target} release partitions")["with"]["pattern"]
|
|
pattern = pattern.replace("${{ matrix.python-version }}", "3.12")
|
|
assert not fnmatch.fnmatchcase(name, pattern)
|
|
if job != "test":
|
|
assert step(job, "Upload release partition evidence")["with"]["path"] == "test-results/partition/"
|
|
|
|
|
|
@pytest.fixture
|
|
def workflow_runtime(tmp_path):
|
|
binary, tools, workspace, runner = [tmp_path / name for name in ("bin", "tools", "workspace", "runner")]
|
|
for path in (binary, tools, workspace, runner):
|
|
path.mkdir()
|
|
driver = binary / "python"
|
|
driver.write_text(f"#!{sys.executable} -B\n" + r'''
|
|
import os
|
|
from pathlib import Path
|
|
import shutil
|
|
import sys
|
|
args = sys.argv[1:]
|
|
if args[:1] == ["-B"]:
|
|
args = args[1:]
|
|
def result(stage):
|
|
print("retained stage " + stage, flush=True)
|
|
if os.environ["FAIL_STAGE"] == stage:
|
|
raise SystemExit(42)
|
|
if Path(sys.argv[0]).name == "uv":
|
|
assert "--no-compile-bytecode" in args
|
|
assert "UV_COMPILE_BYTECODE" not in os.environ
|
|
result("initial-sync" if "--no-install-project" in args else "project-sync")
|
|
elif "create" in args:
|
|
root = Path(args[args.index("--environment") + 1])
|
|
(root / "bin").mkdir(parents=True)
|
|
shutil.copyfile(sys.argv[0], root / "bin/python")
|
|
(root / "bin/python").chmod(0o755)
|
|
result("create")
|
|
elif "scripts.release_test_environment" in args:
|
|
Path(args[args.index("--output") + 1]).write_text("--extra\ndev\n--extra\nrecovery\n--extra\nmcp\n")
|
|
elif "scripts.release_dependency_bytecode" in args:
|
|
stage = "compile" if "compile" in args else "verify"
|
|
result(stage)
|
|
if stage == "compile":
|
|
Path(args[args.index("--receipt") + 1]).write_text('{"fixture":true}\n')
|
|
elif args and args[0].endswith("release_bytecode_policy.py"):
|
|
result("hook-install" if "install" in args else "hook-verify")
|
|
else:
|
|
result("remaining-step")
|
|
''')
|
|
driver.chmod(0o755)
|
|
(binary / "uv").write_bytes(driver.read_bytes())
|
|
(binary / "uv").chmod(0o755)
|
|
(binary / "git").write_text("#!/bin/sh\nexit 0\n")
|
|
(binary / "git").chmod(0o755)
|
|
base = tmp_path / "base"
|
|
base.mkdir()
|
|
env = {**os.environ, "PATH": str(binary) + os.pathsep + os.environ["PATH"],
|
|
"PYTHONDONTWRITEBYTECODE": "1", "UV_COMPILE_BYTECODE": "true", "UV_VERSION": "0.12.4",
|
|
"RELEASE_TOOLS": str(tools), "GITHUB_WORKSPACE": str(workspace), "RUNNER_TEMP": str(runner),
|
|
"TEST_ENV": str(tmp_path / "head-env"), "BASE_TEST_ENV": str(tmp_path / "base-env"),
|
|
"BASE_WORKTREE": str(base), "COVERAGE_BASE": "b" * 40, "CANDIDATE_SHA": "a" * 40,
|
|
"CORE_RESULT": "success", "GLOO_RESULT": "success"}
|
|
return env, workspace, runner
|
|
|
|
|
|
@pytest.mark.parametrize("job,step_name,label,variable", PATHS)
|
|
@pytest.mark.parametrize("failure", ["initial-sync", "compile", "project-sync", "verify", "hook-install", "hook-verify"])
|
|
def test_failure_retains_diagnostics_without_prepopulating_any_runner_output(workflow_runtime, job, step_name, label, variable, failure):
|
|
env, workspace, runner = workflow_runtime
|
|
env["FAIL_STAGE"] = failure
|
|
script = step(job, step_name)["run"].replace("${{ matrix.python-version }}", "3.12")
|
|
completed = subprocess.run(["bash", "-euo", "pipefail", "-c", script], cwd=workspace,
|
|
env=env, capture_output=True, text=True, timeout=30)
|
|
assert completed.returncode == 42, completed.stdout + completed.stderr
|
|
diagnostics = runner / "dependency-bootstrap" / label
|
|
assert f"retained stage {failure}" in (diagnostics / f"{failure}.log").read_text()
|
|
assert not (workspace / "test-results").exists()
|
|
assert (diagnostics / "dependencies.json").exists() == (failure in {"project-sync", "verify", "hook-install", "hook-verify"})
|