Decompose oversized Rust files by responsibility
This commit is contained in:
parent
03bfe92ca0
commit
ee9201b057
1 changed files with 18648 additions and 18513 deletions
|
|
@ -14,6 +14,7 @@ import tempfile
|
|||
import tomllib
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
VERIFICATION_TEMP_ROOT = ROOT / "target" / "verification"
|
||||
MATERIALIZED_FUSER_MANIFEST = (
|
||||
ROOT / ".lazaret/vendor/fuser-0.17.0/Cargo.toml"
|
||||
).resolve()
|
||||
|
|
@ -165,14 +166,13 @@ PROCESS_LINT_ALLOWANCES = {
|
|||
"crates/lazaret-linux/src/process.rs": {
|
||||
"append_to",
|
||||
"send_signal",
|
||||
},
|
||||
"crates/lazaret-linux/src/process/broker.rs": {
|
||||
"acquire",
|
||||
"acquire_with_stdio",
|
||||
"acquire_with_stdio_after_ack",
|
||||
"acquire_captured",
|
||||
"private_role_command",
|
||||
"require_reapable_sigchld",
|
||||
"cleanup_sigchld_probe",
|
||||
"fail_sigchld_probe",
|
||||
"reap",
|
||||
"reap_status",
|
||||
"fail_running_captured",
|
||||
|
|
@ -180,16 +180,23 @@ PROCESS_LINT_ALLOWANCES = {
|
|||
"verify_direct_child_pidfd",
|
||||
"fail_before_pidfd",
|
||||
"fail_after_pidfd_closed",
|
||||
"recover_process",
|
||||
"current_process_identity",
|
||||
"append_parent_identity",
|
||||
"exec_target",
|
||||
"run_transient",
|
||||
"run_transient_with_stdout",
|
||||
"run_transient_captured",
|
||||
"spawn_bootstrap",
|
||||
"captured_process",
|
||||
},
|
||||
"crates/lazaret-linux/src/process/recovery.rs": {
|
||||
"recover_process",
|
||||
"current_process_identity",
|
||||
"match_recovery_process",
|
||||
"require_reapable_sigchld",
|
||||
"cleanup_sigchld_probe",
|
||||
"fail_sigchld_probe",
|
||||
},
|
||||
"crates/lazaret-linux/src/process/launch.rs": {
|
||||
"append_parent_identity",
|
||||
"exec_target",
|
||||
"suspend_current_process",
|
||||
},
|
||||
"crates/lazaret-host-coordinator/tests/runtime-composition.rs": {"run_benchmark_guest"},
|
||||
|
|
@ -218,6 +225,12 @@ PROCESS_LINT_ALLOWANCES = {
|
|||
"retained_fixed_child_bind_mount_is_refused_when_mount_setup_is_available"
|
||||
},
|
||||
}
|
||||
RUST_FILE_LINE_LIMIT = 1000
|
||||
RUST_FILE_SIZE_EXCEPTIONS = {
|
||||
"crates/lazaret-host-coordinator/src/lifecycle.rs": (
|
||||
"host coordinator lifecycle transition state machine and invariant-preserving adapter"
|
||||
),
|
||||
}
|
||||
FORBIDDEN_PROCESS_SYSCALLS = tuple(
|
||||
re.compile(pattern)
|
||||
for pattern in (
|
||||
|
|
@ -250,6 +263,11 @@ class VerificationError(RuntimeError):
|
|||
pass
|
||||
|
||||
|
||||
def temporary_directory(prefix: str) -> tempfile.TemporaryDirectory[str]:
|
||||
VERIFICATION_TEMP_ROOT.mkdir(parents=True, exist_ok=True)
|
||||
return tempfile.TemporaryDirectory(prefix=prefix, dir=VERIFICATION_TEMP_ROOT)
|
||||
|
||||
|
||||
def require(condition: bool, message: str) -> None:
|
||||
if not condition:
|
||||
raise VerificationError(message)
|
||||
|
|
@ -402,6 +420,43 @@ def workspace_rust_sources(metadata: dict) -> list[Path]:
|
|||
return sorted(sources)
|
||||
|
||||
|
||||
def audit_rust_file_sizes(metadata: dict) -> None:
|
||||
sources = workspace_rust_sources(metadata)
|
||||
relative_sources = {str(path.relative_to(ROOT)): path for path in sources}
|
||||
line_counts = {
|
||||
relative: len(path.read_bytes().splitlines())
|
||||
for relative, path in relative_sources.items()
|
||||
}
|
||||
for relative, responsibility in RUST_FILE_SIZE_EXCEPTIONS.items():
|
||||
require(
|
||||
relative == Path(relative).as_posix()
|
||||
and not Path(relative).is_absolute()
|
||||
and relative.endswith(".rs"),
|
||||
f"malformed Rust file size exception path: {relative}",
|
||||
)
|
||||
require(
|
||||
"\n" not in responsibility and len(responsibility.split()) >= 3,
|
||||
f"malformed Rust file size exception responsibility: {relative}",
|
||||
)
|
||||
require(relative in relative_sources, f"stale Rust file size exception: {relative}")
|
||||
require(
|
||||
line_counts[relative] > RUST_FILE_LINE_LIMIT,
|
||||
f"stale Rust file size exception below threshold: {relative}",
|
||||
)
|
||||
|
||||
oversized = {
|
||||
relative: lines
|
||||
for relative, lines in line_counts.items()
|
||||
if lines > RUST_FILE_LINE_LIMIT and relative not in RUST_FILE_SIZE_EXCEPTIONS
|
||||
}
|
||||
require(
|
||||
not oversized,
|
||||
"Rust files exceed the reviewed responsibility threshold: "
|
||||
+ ", ".join(f"{path} ({lines})" for path, lines in sorted(oversized.items())),
|
||||
)
|
||||
print("PASS tracked Rust file responsibility size boundary")
|
||||
|
||||
|
||||
def audit_dependencies(metadata: dict) -> None:
|
||||
policy = load_toml(ROOT / "deny.toml")
|
||||
allowed_licenses = set(policy["licenses"]["allow"])
|
||||
|
|
@ -466,7 +521,7 @@ def license_permitted(expression: str, allowed: set[str]) -> bool:
|
|||
def run_models() -> None:
|
||||
tlc = shutil.which("tlc")
|
||||
require(tlc is not None, "TLC must be installed on PATH")
|
||||
with tempfile.TemporaryDirectory(prefix="lazaret-tlc-") as directory:
|
||||
with temporary_directory("tlc-") as directory:
|
||||
workdir = Path(directory)
|
||||
for module, config in MODEL_CONFIGURATIONS:
|
||||
require(module.is_file(), f"missing model: {module.relative_to(ROOT)}")
|
||||
|
|
@ -561,7 +616,7 @@ def audit_process_syscalls(metadata: dict) -> None:
|
|||
require(sys.platform == "linux", "--process-syscalls requires Linux")
|
||||
binaries = build_workspace_binaries(metadata)
|
||||
require(binaries, "workspace has no binaries to trace")
|
||||
with tempfile.TemporaryDirectory(prefix="lazaret-process-syscalls-") as directory:
|
||||
with temporary_directory("process-syscalls-") as directory:
|
||||
for binary, executable in sorted(binaries.items()):
|
||||
trace_base = Path(directory) / binary
|
||||
command = [
|
||||
|
|
@ -620,7 +675,7 @@ def run_rust_tests() -> None:
|
|||
|
||||
def run_ignored_workspace_corpus(metadata: dict) -> None:
|
||||
binaries = build_workspace_binaries(metadata)
|
||||
with tempfile.TemporaryDirectory(prefix="lazaret-ignored-workspace-corpus-") as directory:
|
||||
with temporary_directory("ignored-workspace-corpus-") as directory:
|
||||
root = Path(directory)
|
||||
run_physical(
|
||||
[
|
||||
|
|
@ -661,6 +716,7 @@ def verify(process_syscalls: bool) -> None:
|
|||
run_ignored_workspace_corpus(metadata)
|
||||
run([sys.executable, "-m", "unittest", "discover", "-s", "tests/tooling"])
|
||||
audit_workspace_lints(metadata)
|
||||
audit_rust_file_sizes(metadata)
|
||||
audit_dependencies(metadata)
|
||||
run_models()
|
||||
if process_syscalls:
|
||||
|
|
|
|||
Loading…
Reference in a new issue