Spaces:
Paused
Paused
File size: 4,909 Bytes
5e0b58b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | """Cross-platform verification runner for Brain-5D persistence releases."""
from __future__ import annotations
import os
import shutil
import subprocess
import sys
from collections.abc import Sequence
from dataclasses import dataclass
from pathlib import Path
from typing import Final
ROOT: Final[Path] = Path(__file__).resolve().parents[1]
PYTHON: Final[str] = sys.executable
@dataclass(frozen=True, slots=True)
class VerificationStep:
"""One fail-fast verification command."""
name: str
command: tuple[str, ...]
optional_executable: str | None = None
def _run(step: VerificationStep) -> None:
"""Run one step and stop the process on the first failure."""
if step.optional_executable is not None:
if shutil.which(step.optional_executable) is None:
print(f"\n== {step.name} ==")
print(f"SKIPPED: {step.optional_executable} executable not installed")
return
print(f"\n== {step.name} ==")
completed = subprocess.run(step.command, cwd=ROOT, check=False)
if completed.returncode != 0:
raise SystemExit(f"{step.name} failed with exit code {completed.returncode}")
def _base_steps() -> tuple[VerificationStep, ...]:
"""Return the normal release-verification steps."""
test_files: tuple[str, ...] = (
"tests/test_b5d_storage.py",
"tests/test_crc.py",
"tests/test_delta_journal.py",
"tests/test_recovery.py",
"tests/test_storage_runtime.py",
"tests/test_lazy_storage_view.py",
"tests/test_async_storage.py",
"tests/test_checkpoint.py",
"tests/test_compaction.py",
"tests/test_restore_continue.py",
)
black_targets: tuple[str, ...] = ("src", "tests")
return (
VerificationStep(
"Install dev dependencies",
(PYTHON, "-m", "pip", "install", "-e", ".[dev]", "-q"),
),
*(
VerificationStep(
f"Test {Path(test_file).name}",
(PYTHON, "-m", "pytest", test_file, "-v"),
)
for test_file in test_files
),
VerificationStep("Full regression", (PYTHON, "-m", "pytest", "-v")),
VerificationStep(
"Black",
(PYTHON, "-m", "black", "--check", *black_targets),
),
VerificationStep(
"mypy strict",
(PYTHON, "-m", "mypy", "src"),
),
VerificationStep(
"Pylint",
(PYTHON, "-m", "pylint", "src"),
),
VerificationStep(
"Compile",
(PYTHON, "-m", "compileall", "-q", "src/storage"),
),
VerificationStep(
"Format invariants",
(
PYTHON,
"-c",
"from src.storage import assert_format_invariants, "
"assert_journal_format_invariants; "
"assert_format_invariants(); "
"assert_journal_format_invariants(); "
"print('format invariants: OK')",
),
),
VerificationStep(
"Pyright strict",
("pyright", "src/storage"),
optional_executable="pyright",
),
)
def _large_steps() -> tuple[VerificationStep, ...]:
"""Return opt-in scale smoke tests."""
return (
VerificationStep(
"50k snapshot smoke test",
(
PYTHON,
"-m",
"pytest",
"tests/test_b5d_storage.py::test_large_storage_50k_neurons",
"-v",
),
),
VerificationStep(
"100k journal smoke test",
(
PYTHON,
"-m",
"pytest",
"tests/test_delta_journal.py::test_large_journal_100k_entries_opt_in",
"-v",
),
),
)
def _large_tests_enabled(environment: dict[str, str]) -> bool:
"""Return whether the opt-in large storage tests were requested."""
return (
environment.get("BRAIN5D_RUN_LARGE_STORAGE_TESTS") == "1"
or environment.get("BRAIN5D_RUN_LARGE_STORAGE_TEST") == "1"
)
def main(arguments: Sequence[str] | None = None) -> int:
"""Run all release checks and optional large persistence smoke tests."""
del arguments
print("Brain-5D v0.4.0-alpha.4 persistence verification")
print("===================================================")
for step in _base_steps():
_run(step)
if _large_tests_enabled(dict(os.environ)):
for step in _large_steps():
_run(step)
else:
print(
"\nLarge storage tests skipped. Set "
"BRAIN5D_RUN_LARGE_STORAGE_TESTS=1 to enable."
)
print("\nBrain-5D storage verification completed successfully.")
return 0
if __name__ == "__main__":
raise SystemExit(main())
|