mirror of
https://github.com/elder-plinius/OBLITERATUS.git
synced 2026-12-05 10:34:23 +01:00
1236 lines
46 KiB
Python
1236 lines
46 KiB
Python
"""Tests for conditional policy, runner, and evidence helpers."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import hashlib
|
|
import json
|
|
import sys
|
|
from datetime import date, timedelta
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from obliteratus.distributed.contracts import contract_digest
|
|
from obliteratus.distributed.model_topology import TP2DeploymentLayout, TP2TopologyBinding
|
|
from obliteratus.distributed.probe_contracts import ProbeDistillConfig
|
|
from obliteratus.distributed.export_contracts import ExportConfig
|
|
from obliteratus.distributed.surgery_contracts import ExciseConfig
|
|
from obliteratus.distributed.verification_contracts import VerificationConfig
|
|
from scripts import check_conditional_policy
|
|
from scripts import check_llama_tp_hardware_evidence
|
|
from scripts import conditional_gate_summary
|
|
from scripts import run_conditional_gate
|
|
from scripts import run_readonly_mount_namespace
|
|
|
|
|
|
ROOT = Path(__file__).parents[1]
|
|
TODAY = date(2026, 8, 16)
|
|
|
|
|
|
def _waiver(gate: str, **overrides) -> dict:
|
|
value = {
|
|
"gate": gate,
|
|
"reason": "No runner is currently attached.",
|
|
"issue": "https://github.com/elder-plinius/OBLITERATUS/issues/110",
|
|
"opened": "2026-08-16",
|
|
"expires": "2026-09-15",
|
|
"blocked_claim": f"{gate} support is not claimed.",
|
|
}
|
|
value.update(overrides)
|
|
return value
|
|
|
|
|
|
def test_committed_conditional_policy_is_complete():
|
|
policy = json.loads((ROOT / "ci" / "conditional-test-policy.json").read_text())
|
|
# Structural tests use the declared review date. The CI policy command
|
|
# separately enforces expiry against the real clock.
|
|
reviewed = max(date.fromisoformat(waiver["opened"]) for waiver in policy["environment_waivers"])
|
|
assert check_conditional_policy.validate(
|
|
ROOT / "ci" / "conditional-test-policy.json",
|
|
ROOT / "ci" / "test-quality-policy.json",
|
|
ROOT / ".github" / "workflows" / "conditional-tests.yml",
|
|
today=reviewed,
|
|
) == []
|
|
|
|
|
|
def test_ordinary_module_qualification_is_manual_and_rejects_required_skips():
|
|
workflow = (ROOT / ".github/workflows/conditional-tests.yml").read_text()
|
|
job = workflow.split(" module_placement_gpu:\n", 1)[1].split(" jetson:\n", 1)[0]
|
|
assert "github.event_name == 'workflow_dispatch' && inputs.run_module_gpu" in job
|
|
assert "scripts/run_conditional_gate.py module-placement-gpu" in job
|
|
assert "inputs.module_gpu_count" in job
|
|
assert "retention-days: 30" in job
|
|
assert run_conditional_gate.GATES["module-placement-gpu"] == "tests/conditional/test_gpu_qualification.py"
|
|
|
|
|
|
def test_committed_waivers_fail_closed_after_expiry():
|
|
policy = json.loads((ROOT / "ci" / "conditional-test-policy.json").read_text())
|
|
expired = max(date.fromisoformat(waiver["expires"]) for waiver in policy["environment_waivers"])
|
|
errors = check_conditional_policy.validate(
|
|
ROOT / "ci" / "conditional-test-policy.json",
|
|
ROOT / "ci" / "test-quality-policy.json",
|
|
ROOT / ".github" / "workflows" / "conditional-tests.yml",
|
|
today=expired + timedelta(days=1),
|
|
)
|
|
assert errors == [
|
|
f"environment waiver {waiver['gate']} expired on {waiver['expires']}"
|
|
for waiver in policy["environment_waivers"]
|
|
]
|
|
|
|
|
|
def test_cuda_job_replaces_locked_cpu_torch_with_same_version_cuda_build():
|
|
workflow = (ROOT / ".github" / "workflows" / "conditional-tests.yml").read_text()
|
|
cuda_job = workflow.split(" cuda:\n", maxsplit=1)[1].split(" mps:\n", maxsplit=1)[0]
|
|
|
|
assert "torch.__version__.split" in cuda_job
|
|
assert "--extra recovery" in cuda_job
|
|
assert "--extra quantization" in cuda_job
|
|
assert "UV_TORCH_BACKEND=cu130 uv pip install" in cuda_job
|
|
assert "--reinstall-package torch" in cuda_job
|
|
assert '"torch==$CUDA_TORCH_VERSION"' in cuda_job
|
|
assert "assert torch.version.cuda is not None" in cuda_job
|
|
assert 'uv pip check --python "$CONDITIONAL_ENV/bin/python"' in cuda_job
|
|
|
|
|
|
def test_documented_cuda_setup_installs_recovery_and_quantization():
|
|
guide = (ROOT / "docs" / "conditional-testing.md").read_text()
|
|
cuda_section = guide.split("## CUDA and bitsandbytes\n", maxsplit=1)[1].split(
|
|
"\n### ", maxsplit=1,
|
|
)[0]
|
|
setup = next(line for line in cuda_section.splitlines() if line.startswith("uv sync "))
|
|
assert "--extra dev" in setup
|
|
assert "--extra recovery" in setup
|
|
assert "--extra quantization" in setup
|
|
|
|
|
|
def test_jetson_job_is_manual_physical_trusted_and_retains_sanitized_evidence():
|
|
workflow = (ROOT / ".github" / "workflows" / "conditional-tests.yml").read_text()
|
|
jetson_job = workflow.split(" jetson:\n", maxsplit=1)[1].split(
|
|
" mps:\n",
|
|
maxsplit=1,
|
|
)[0]
|
|
|
|
assert "github.event_name == 'workflow_dispatch' && inputs.run_jetson" in jetson_job
|
|
assert "runs-on: [self-hosted, linux, ARM64, jetson]" in jetson_job
|
|
assert "scripts/setup_jetson.py" in jetson_job
|
|
assert "scripts/run_conditional_gate.py jetson-runtime" in jetson_job
|
|
assert "scripts/jetson_support.py" in jetson_job
|
|
assert "conditional-jetson-${{ github.run_attempt }}" in jetson_job
|
|
assert "retention-days: 30" in jetson_job
|
|
assert "actions/setup-python" not in jetson_job
|
|
|
|
policy = json.loads((ROOT / "ci" / "conditional-test-policy.json").read_text())
|
|
gate = next(value for value in policy["gates"] if value["id"] == "jetson-runtime")
|
|
assert gate["job"] == "jetson"
|
|
assert gate["runner"] == "self-hosted, linux, ARM64, jetson"
|
|
|
|
|
|
def test_policy_rejects_unknown_cpu_exclusion_gate(tmp_path):
|
|
policy = json.loads((ROOT / "ci" / "conditional-test-policy.json").read_text())
|
|
policy["environment_waivers"] = []
|
|
quality = {
|
|
"mature_cpu_scope": {
|
|
"exclusions": [{"path": "obliteratus/device.py", "conditional_gate": "missing"}]
|
|
}
|
|
}
|
|
policy_path = tmp_path / "policy.json"
|
|
quality_path = tmp_path / "quality.json"
|
|
policy_path.write_text(json.dumps(policy))
|
|
quality_path.write_text(json.dumps(quality))
|
|
errors = check_conditional_policy.validate(
|
|
policy_path,
|
|
quality_path,
|
|
ROOT / ".github" / "workflows" / "conditional-tests.yml",
|
|
today=TODAY,
|
|
)
|
|
assert errors == ["CPU exclusion obliteratus/device.py references unknown gate missing"]
|
|
|
|
|
|
def test_junit_counts_and_report_are_machine_readable(tmp_path):
|
|
junit = tmp_path / "result.xml"
|
|
junit.write_text(
|
|
'<testsuites><testsuite tests="3" failures="1" errors="0" skipped="1"/>'
|
|
'<testsuite tests="2" failures="0" errors="1" skipped="0"/></testsuites>'
|
|
)
|
|
assert run_conditional_gate.counts(junit) == {
|
|
"tests": 5,
|
|
"failures": 1,
|
|
"errors": 1,
|
|
"skipped": 1,
|
|
}
|
|
report = tmp_path / "report.json"
|
|
run_conditional_gate.write_report(report, "network-services", "passed", counts={"tests": 1})
|
|
evidence = json.loads(report.read_text())
|
|
assert evidence["gate"] == "network-services"
|
|
assert evidence["status"] == "passed"
|
|
assert evidence["counts"] == {"tests": 1}
|
|
|
|
|
|
def test_remote_prerequisites_are_actionable(monkeypatch):
|
|
names = {
|
|
"OBLITERATUS_REMOTE_HOST",
|
|
"OBLITERATUS_REMOTE_USER",
|
|
"OBLITERATUS_REMOTE_KEY",
|
|
"OBLITERATUS_REMOTE_KNOWN_HOSTS",
|
|
}
|
|
for name in names:
|
|
monkeypatch.delenv(name, raising=False)
|
|
assert set(run_conditional_gate.missing_prerequisites("remote-execution")) == names
|
|
for name in names:
|
|
monkeypatch.setenv(name, "fixture")
|
|
assert run_conditional_gate.missing_prerequisites("remote-execution") == []
|
|
|
|
|
|
def test_summary_rejects_selected_failure_and_marks_unselected_stale():
|
|
policy = {
|
|
"gates": [
|
|
{"id": "first", "job": "shared"},
|
|
{"id": "second", "job": "shared"},
|
|
{"id": "optional", "job": "optional"},
|
|
]
|
|
}
|
|
rows, failures = conditional_gate_summary.summarize(
|
|
policy,
|
|
{"shared": "failure", "optional": "skipped"},
|
|
{"shared": True, "optional": False},
|
|
)
|
|
assert failures == ["shared: selected but result was failure"]
|
|
assert rows[0]["status"] == "failure"
|
|
assert rows[1]["status"] == "failure"
|
|
assert rows[2]["status"] == "not_selected_no_fresh_evidence"
|
|
|
|
|
|
def test_summary_records_active_waiver_and_selected_success_overrides_it():
|
|
policy = {
|
|
"gates": [{"id": "cuda-runtime", "job": "cuda"}],
|
|
"environment_waivers": [_waiver("cuda-runtime")],
|
|
}
|
|
|
|
rows, failures = conditional_gate_summary.summarize(
|
|
policy,
|
|
{"cuda": "skipped"},
|
|
{"cuda": False},
|
|
today=TODAY,
|
|
)
|
|
assert failures == []
|
|
assert rows == [{
|
|
"gate": "cuda-runtime",
|
|
"job": "cuda",
|
|
"selected": False,
|
|
"status": "waived_no_support_claim",
|
|
"waiver": {
|
|
"issue": "https://github.com/elder-plinius/OBLITERATUS/issues/110",
|
|
"expires": "2026-09-15",
|
|
"blocked_claim": "cuda-runtime support is not claimed.",
|
|
},
|
|
}]
|
|
|
|
rows, failures = conditional_gate_summary.summarize(
|
|
policy,
|
|
{"cuda": "success"},
|
|
{"cuda": True},
|
|
today=TODAY,
|
|
)
|
|
assert failures == []
|
|
assert rows[0]["status"] == "success"
|
|
assert "waiver" not in rows[0]
|
|
|
|
|
|
def test_environment_waiver_validation_rejects_duplicate_expired_and_overlong_records():
|
|
policy = {
|
|
"gates": [
|
|
{"id": "cuda-runtime"},
|
|
{"id": "mps-runtime"},
|
|
{"id": "mlx-runtime"},
|
|
],
|
|
"environment_waivers": [
|
|
_waiver("cuda-runtime"),
|
|
_waiver("cuda-runtime"),
|
|
_waiver("mps-runtime", opened="2026-07-01", expires="2026-07-31"),
|
|
_waiver("mlx-runtime", expires="2026-09-16"),
|
|
],
|
|
}
|
|
|
|
active, errors = check_conditional_policy.validate_environment_waivers(
|
|
policy,
|
|
today=TODAY,
|
|
)
|
|
|
|
assert active == {"cuda-runtime": policy["environment_waivers"][0]}
|
|
assert "duplicate environment waiver gate: cuda-runtime" in errors
|
|
assert "environment waiver mps-runtime expired on 2026-07-31" in errors
|
|
assert "environment waiver mlx-runtime exceeds 30 days" in errors
|
|
|
|
|
|
def test_environment_waiver_validation_rejects_malformed_or_software_records():
|
|
policy = {
|
|
"gates": [
|
|
{"id": "network-services"},
|
|
{"id": "remote-execution"},
|
|
],
|
|
"environment_waivers": [
|
|
_waiver("network-services"),
|
|
_waiver("remote-execution", issue="not-an-issue", blocked_claim=""),
|
|
"not-an-object",
|
|
],
|
|
}
|
|
|
|
active, errors = check_conditional_policy.validate_environment_waivers(
|
|
policy,
|
|
today=TODAY,
|
|
)
|
|
|
|
assert active == {}
|
|
assert "software-only gate may not use an environment waiver: network-services" in errors
|
|
assert "environment waiver remote-execution issue must be a canonical issue URL" in errors
|
|
assert "environment waiver remote-execution blocked_claim must be non-empty" in errors
|
|
assert "environment waiver 2 must be an object" in errors
|
|
|
|
|
|
def test_environment_waiver_validation_rejects_missing_future_and_reversed_dates():
|
|
missing = _waiver("remote-execution")
|
|
missing.pop("reason")
|
|
policy = {
|
|
"gates": [
|
|
{"id": "remote-execution"},
|
|
{"id": "mps-runtime"},
|
|
{"id": "mlx-runtime"},
|
|
],
|
|
"environment_waivers": [
|
|
missing,
|
|
_waiver("mps-runtime", opened="2026-08-17", expires="2026-09-15"),
|
|
_waiver("mlx-runtime", opened="2026-08-16", expires="2026-08-15"),
|
|
],
|
|
}
|
|
|
|
active, errors = check_conditional_policy.validate_environment_waivers(
|
|
policy,
|
|
today=TODAY,
|
|
)
|
|
|
|
assert active == {}
|
|
assert "environment waiver 0 is missing fields: ['reason']" in errors
|
|
assert "environment waiver mps-runtime opens in the future: 2026-08-17" in errors
|
|
assert "environment waiver mlx-runtime expires before it opens" in errors
|
|
assert "environment waiver mlx-runtime expired on 2026-08-15" in errors
|
|
|
|
|
|
def test_summary_fails_an_expired_waiver():
|
|
policy = {
|
|
"gates": [{"id": "cuda-runtime", "job": "cuda"}],
|
|
"environment_waivers": [
|
|
_waiver("cuda-runtime", opened="2026-07-01", expires="2026-07-31"),
|
|
],
|
|
}
|
|
|
|
rows, failures = conditional_gate_summary.summarize(
|
|
policy,
|
|
{"cuda": "skipped"},
|
|
{"cuda": False},
|
|
today=TODAY,
|
|
)
|
|
|
|
assert rows[0]["status"] == "not_selected_no_fresh_evidence"
|
|
assert failures == [
|
|
"waiver policy: environment waiver cuda-runtime expired on 2026-07-31",
|
|
]
|
|
|
|
|
|
@pytest.mark.parametrize("gate, marker", [
|
|
("cuda-runtime", "gpu and not network and not download"),
|
|
("bitsandbytes-runtime", "gpu and not network and not download"),
|
|
("model-download-runtime", "network and download and not gpu"),
|
|
])
|
|
def test_recovery_runner_selects_matching_runtime_contracts(tmp_path, monkeypatch, gate, marker):
|
|
from types import SimpleNamespace
|
|
|
|
monkeypatch.setattr(
|
|
run_conditional_gate.sys, "argv",
|
|
["run_conditional_gate", gate, "--evidence-dir", str(tmp_path)],
|
|
)
|
|
monkeypatch.setattr(run_conditional_gate, "missing_prerequisites", lambda gate: [])
|
|
commands = []
|
|
|
|
def run(command, *, check):
|
|
commands.append(command)
|
|
(tmp_path / f"{gate}.xml").write_text(
|
|
'<testsuite tests="2" failures="0" errors="0" skipped="0"/>'
|
|
)
|
|
return SimpleNamespace(returncode=0)
|
|
|
|
monkeypatch.setattr(run_conditional_gate.subprocess, "run", run)
|
|
assert run_conditional_gate.main() == 0
|
|
assert run_conditional_gate.GATES[gate] in commands[0]
|
|
assert "tests/conditional/test_recovery_runtime.py" in commands[0]
|
|
assert commands[0][-2:] == ["-m", marker]
|
|
assert ("tests/conditional/test_phase_admission_gpu.py" in commands[0]) == (gate == "cuda-runtime")
|
|
|
|
|
|
def _llama_tp_physical_hardware_digest(host: str, devices: tuple[str, str]) -> str:
|
|
return check_llama_tp_hardware_evidence._record_digest(
|
|
[
|
|
{
|
|
"rank": rank,
|
|
"identity_digest": check_llama_tp_hardware_evidence._record_digest(
|
|
{
|
|
"candidate_sha": "b" * 40,
|
|
"host_identity": host,
|
|
"device_identity": device,
|
|
}
|
|
),
|
|
}
|
|
for rank, device in enumerate(devices)
|
|
]
|
|
)
|
|
|
|
|
|
def _llama_tp_deployment_topology(
|
|
topology_digest: str, host_digest: str, device_digests: tuple[str, str],
|
|
) -> tuple[dict, str]:
|
|
ranks = [
|
|
{
|
|
"rank": rank, "group_rank": 0, "local_rank": rank,
|
|
"host_digest": host_digest, "device_digest": device_digest,
|
|
}
|
|
for rank, device_digest in enumerate(device_digests)
|
|
]
|
|
binding = TP2TopologyBinding(
|
|
schema_version=1, layout=TP2DeploymentLayout.LOCAL_TP2,
|
|
world_size=2, local_world_size=2, host_count=1,
|
|
rank_mapping_digest=contract_digest(((0, 0, 0), (1, 0, 1))),
|
|
host_mapping_digest=contract_digest(tuple((item["rank"], item["host_digest"]) for item in ranks)),
|
|
device_mapping_digest=contract_digest(tuple((item["rank"], item["device_digest"]) for item in ranks)),
|
|
topology_plan_digest=topology_digest,
|
|
)
|
|
return {
|
|
"schema_version": 1, "layout": "local_tp2", "world_size": 2,
|
|
"local_world_size": 2, "host_count": 1, "ranks": ranks,
|
|
"topology_plan_digest": topology_digest,
|
|
}, binding.digest
|
|
|
|
|
|
def _llama_tp_evidence(
|
|
*, verification_host: str = "host", verification_devices: tuple[str, str] = ("gpu0", "gpu1")
|
|
) -> dict:
|
|
digest = "a" * 64
|
|
devices = [
|
|
{
|
|
"rank": rank,
|
|
"device_digest": chr(ord("c") + rank) * 64,
|
|
"device_config_digest": "1" * 64,
|
|
"device_profile_digest": "2" * 64,
|
|
"name_digest": "e" * 64,
|
|
"compute_capability": "8.9",
|
|
"total_memory_bytes": 24_000_000_000,
|
|
}
|
|
for rank in range(2)
|
|
]
|
|
source_mount_attestation_digest = "3" * 64
|
|
verification_source_mount_attestation_digest = "8" * 64
|
|
hardware_devices = [
|
|
{
|
|
"rank": item["rank"],
|
|
"device_config_digest": item["device_config_digest"],
|
|
"device_profile_digest": item["device_profile_digest"],
|
|
}
|
|
for item in devices
|
|
]
|
|
hardware_digest = hashlib.sha256(
|
|
json.dumps(
|
|
{
|
|
"devices": hardware_devices,
|
|
"source_mount_attestation_digest": source_mount_attestation_digest,
|
|
},
|
|
ensure_ascii=True,
|
|
allow_nan=False,
|
|
sort_keys=True,
|
|
separators=(",", ":"),
|
|
).encode("ascii")
|
|
).hexdigest()
|
|
verification_hardware_digest = check_llama_tp_hardware_evidence._record_digest(
|
|
{
|
|
"devices": hardware_devices,
|
|
"source_mount_attestation_digest": verification_source_mount_attestation_digest,
|
|
}
|
|
)
|
|
acquisition_digest = hashlib.sha256(
|
|
json.dumps(
|
|
{
|
|
"kind": "project_generated_fixture_v1",
|
|
"source_digest": digest,
|
|
"config_digest": digest,
|
|
"fixture_digest": digest,
|
|
"reference_digest": digest,
|
|
},
|
|
ensure_ascii=True,
|
|
allow_nan=False,
|
|
sort_keys=True,
|
|
separators=(",", ":"),
|
|
).encode("ascii")
|
|
).hexdigest()
|
|
control_group_digest = check_llama_tp_hardware_evidence._record_digest(
|
|
{"backend": "gloo", "ranks": [0, 1], "world_size": 2}
|
|
)
|
|
data_group_digest = check_llama_tp_hardware_evidence._record_digest(
|
|
{
|
|
"backend": "nccl",
|
|
"device_type": "cuda",
|
|
"mesh_dim_names": ["tp"],
|
|
"ranks": [0, 1],
|
|
"world_size": 2,
|
|
"deployment_layout": "local_tp2",
|
|
}
|
|
)
|
|
topology_digest = check_llama_tp_hardware_evidence._record_digest(
|
|
{
|
|
"backend": "gloo",
|
|
"coordinator_rank": 0,
|
|
"placement_plan_digest": digest,
|
|
"world_size": 2,
|
|
}
|
|
)
|
|
deployment_topology, deployment_layout_digest = _llama_tp_deployment_topology(
|
|
topology_digest, "5" * 64, ("c" * 64, "d" * 64),
|
|
)
|
|
verification_deployment_topology, verification_deployment_layout_digest = (
|
|
_llama_tp_deployment_topology(topology_digest, "6" * 64, ("7" * 64, "8" * 64))
|
|
)
|
|
session_bindings = {
|
|
"api_digest": digest,
|
|
"artifact_manifest_digest": acquisition_digest,
|
|
"code_digest": digest,
|
|
"config_digest": digest,
|
|
"control_group_digest": control_group_digest,
|
|
"data_group_digest": data_group_digest,
|
|
"deployment_layout_digest": deployment_layout_digest,
|
|
"hardware_digest": hardware_digest,
|
|
"identity_digest": "4" * 64,
|
|
"image_digest": digest,
|
|
"lock_digest": digest,
|
|
"logical_manifest_digest": digest,
|
|
"model_config_digest": digest,
|
|
"model_digest": digest,
|
|
"package_digest": digest,
|
|
"plan_digest": digest,
|
|
"profile_digest": digest,
|
|
"runtime_digest": digest,
|
|
"source_digest": digest,
|
|
"tokenizer_digest": digest,
|
|
"topology_digest": topology_digest,
|
|
"torch_wheel_digest": digest,
|
|
}
|
|
verification_bindings = {
|
|
**session_bindings,
|
|
"config_digest": "6" * 64,
|
|
"hardware_digest": verification_hardware_digest,
|
|
"deployment_layout_digest": verification_deployment_layout_digest,
|
|
"identity_digest": "7" * 64,
|
|
}
|
|
verification_bindings_digest = check_llama_tp_hardware_evidence._record_digest(
|
|
verification_bindings
|
|
)
|
|
verification_attempt_digest = check_llama_tp_hardware_evidence._record_digest(
|
|
{
|
|
"fixture_digest": digest,
|
|
"source_digest": digest,
|
|
"verification_bindings_digest": verification_bindings_digest,
|
|
"verification_summary_digest": digest,
|
|
}
|
|
)
|
|
export_attempt_digest = check_llama_tp_hardware_evidence._record_digest(
|
|
{
|
|
"source_digest": digest,
|
|
"verification_bindings_digest": verification_bindings_digest,
|
|
"verification_summary_digest": digest,
|
|
"export_summary_digest": digest,
|
|
}
|
|
)
|
|
return {
|
|
"schema_version": 1,
|
|
"gate": "llama-tp-local-gpu",
|
|
"status": "passed",
|
|
"candidate_sha": "b" * 40,
|
|
"generated_at": "2026-09-04T03:00:00+00:00",
|
|
"environment": {
|
|
"image_digest": f"sha256:{digest}",
|
|
"lock_digest": digest,
|
|
"torch_wheel_digest": digest,
|
|
"package_digest": digest,
|
|
"runtime_digest": digest,
|
|
"api_digest": digest,
|
|
"hardware_digest": hardware_digest,
|
|
"python": "3.12.11",
|
|
"torch": "2.13.0+cu130",
|
|
"transformers": "5.15.0",
|
|
"accelerate": "1.14.0",
|
|
"safetensors": "0.8.0",
|
|
"cuda": "13.0",
|
|
"nccl": "2.27.5",
|
|
"driver": "580.82.07",
|
|
},
|
|
"topology": {
|
|
"world_size": 2,
|
|
"local_world_size": 2,
|
|
"tensor_parallel_size": 2,
|
|
"host_count": 1,
|
|
"deployment_layout": "local_tp2",
|
|
"control_backend": "gloo",
|
|
"data_backend": "nccl",
|
|
},
|
|
"devices": devices,
|
|
"artifacts": {
|
|
"source_digest": digest,
|
|
"distributed_config_digest": digest,
|
|
"model_config_digest": digest,
|
|
"tokenizer_digest": digest,
|
|
"model_digest": digest,
|
|
"plan_digest": digest,
|
|
"manifest_digest": digest,
|
|
"fixture_digest": digest,
|
|
"reference_digest": digest,
|
|
"acquisition_manifest_digest": acquisition_digest,
|
|
"code_digest": digest,
|
|
"profile_digest": digest,
|
|
"verification_attempt_digest": verification_attempt_digest,
|
|
"export_attempt_digest": export_attempt_digest,
|
|
},
|
|
"session": {
|
|
"bindings": session_bindings,
|
|
"bindings_digest": check_llama_tp_hardware_evidence._record_digest(session_bindings),
|
|
"load_summary_set_digest": "5" * 64,
|
|
"source_mount_attestation_digest": source_mount_attestation_digest,
|
|
"deployment_topology": deployment_topology,
|
|
"physical_hardware_digest": _llama_tp_physical_hardware_digest(
|
|
"host", ("gpu0", "gpu1")
|
|
),
|
|
"verification_source_mount_attestation_digest": (
|
|
verification_source_mount_attestation_digest
|
|
),
|
|
"verification_physical_hardware_digest": _llama_tp_physical_hardware_digest(
|
|
verification_host, verification_devices
|
|
),
|
|
"verification_bindings": verification_bindings,
|
|
"verification_deployment_topology": verification_deployment_topology,
|
|
"verification_bindings_digest": verification_bindings_digest,
|
|
},
|
|
"qualification": {
|
|
"rtol": 0.01,
|
|
"atol": 0.02,
|
|
"max_abs_error": 0.001,
|
|
"max_rel_error": 0.002,
|
|
"finite": True,
|
|
"within_tolerance": True,
|
|
"greedy_match": True,
|
|
"activation_sites": [
|
|
{
|
|
"site_digest": "f" * 64,
|
|
"complete": True,
|
|
"replicated": True,
|
|
"within_tolerance": True,
|
|
"max_abs_error": 0.001,
|
|
"max_rel_error": 0.002,
|
|
},
|
|
],
|
|
"probe_distill": {
|
|
"summary_digest": digest,
|
|
"config_digest": ProbeDistillConfig(
|
|
n_directions=1,
|
|
selected_layer_count=1,
|
|
max_samples_per_class=2,
|
|
max_tokens=8,
|
|
batch_size=2,
|
|
max_activation_bytes=1024 * 1024,
|
|
activation_atol=0.02,
|
|
activation_rtol=0.01,
|
|
stage_timeout_seconds=120,
|
|
add_special_tokens=False,
|
|
).digest,
|
|
"tokenization_digest": digest,
|
|
"selected_site_digests": ["f" * 64],
|
|
"direction_method": "difference_of_means",
|
|
"direction_count": 1,
|
|
"harmful_count": 2,
|
|
"harmless_count": 2,
|
|
"finite": True,
|
|
"within_tolerance": True,
|
|
"rank_agreement": True,
|
|
"parameters_unchanged": True,
|
|
"max_mean_abs_error": 0.001,
|
|
"max_direction_abs_error": 0.002,
|
|
},
|
|
"excise": {
|
|
"summary_digest": digest,
|
|
"config_digest": ExciseConfig(
|
|
norm_preserve=True,
|
|
regularization=0.2,
|
|
projection_row_fraction=0.5,
|
|
max_norm_ratio=1.1,
|
|
max_journal_bytes=16 * 1024 * 1024,
|
|
max_update_bytes=4 * 1024 * 1024,
|
|
safety_margin_bytes=1024 * 1024,
|
|
stage_timeout_seconds=120,
|
|
).digest,
|
|
"operation_count": 7,
|
|
"finite": True,
|
|
"complete_tensor_match": True,
|
|
"postconditions_match": True,
|
|
"journal_private": True,
|
|
"rollback_restored": True,
|
|
"verified": False,
|
|
"journal_removed": True,
|
|
"rank_agreement": True,
|
|
"max_abs_error": 0.001,
|
|
"max_rel_error": 0.002,
|
|
},
|
|
"verification": {
|
|
"summary_digest": digest,
|
|
"baseline_digest": digest,
|
|
"config_digest": VerificationConfig(
|
|
max_samples=3,
|
|
max_tokens=8,
|
|
batch_size=2,
|
|
max_baseline_bytes=4 * 1024 * 1024,
|
|
safety_margin_bytes=1024 * 1024,
|
|
rank_logit_atol=0.02,
|
|
rank_logit_rtol=0.01,
|
|
max_refusal_rate=1.0,
|
|
min_coherence_retention=0.0,
|
|
max_forward_kl=100.0,
|
|
min_capability_retention=0.0,
|
|
stage_timeout_seconds=120,
|
|
add_special_tokens=False,
|
|
).digest,
|
|
"rank_evidence_set_digest": digest,
|
|
"quality_accepted": True,
|
|
"rank_agreement": True,
|
|
"refusal_rate": 0.0,
|
|
"coherence_retention": 1.0,
|
|
"forward_kl": 0.01,
|
|
"capability_retention": 0.99,
|
|
"nonfinite_count": 0,
|
|
"journal_removed": True,
|
|
"fresh_attempt_identity": True,
|
|
"max_excise_abs_error": 0.001,
|
|
"max_excise_rel_error": 0.002,
|
|
},
|
|
"export": {
|
|
"summary_digest": digest,
|
|
"config_digest": ExportConfig(
|
|
export_id="5" * 32,
|
|
output_name="canonical-output",
|
|
max_output_bytes=128 * 1024 * 1024,
|
|
max_staging_bytes=256 * 1024 * 1024,
|
|
max_host_bytes_per_rank=1024 * 1024 * 1024,
|
|
max_device_bytes_per_rank=128 * 1024 * 1024,
|
|
semantic_reload_host_bytes_per_rank=256 * 1024 * 1024,
|
|
semantic_reload_device_bytes_per_rank=1024 * 1024,
|
|
max_tensor_bytes=64 * 1024 * 1024,
|
|
max_metadata_bytes=16 * 1024 * 1024,
|
|
max_metadata_files=100,
|
|
safety_margin_bytes=1024 * 1024,
|
|
stage_timeout_seconds=120,
|
|
).digest,
|
|
"verification_digest": digest,
|
|
"assignment_set_digest": digest,
|
|
"tensor_record_set_digest": digest,
|
|
"rank_evidence_set_digest": digest,
|
|
"reload_evidence_set_digest": digest,
|
|
"hf_index_digest": digest,
|
|
"tensor_count": 7,
|
|
"logical_bytes": 1024,
|
|
"published": True,
|
|
"rank_agreement": True,
|
|
"semantic_reload": True,
|
|
"fresh_attempt_identity": True,
|
|
},
|
|
},
|
|
}
|
|
|
|
|
|
def test_llama_tp_hardware_evidence_accepts_only_the_exact_closed_envelope():
|
|
evidence = _llama_tp_evidence()
|
|
assert evidence["session"]["source_mount_attestation_digest"] != evidence["session"][
|
|
"verification_source_mount_attestation_digest"
|
|
]
|
|
assert evidence["session"]["bindings"]["hardware_digest"] != evidence["session"][
|
|
"verification_bindings"
|
|
]["hardware_digest"]
|
|
assert (
|
|
check_llama_tp_hardware_evidence.validate(
|
|
evidence,
|
|
candidate_sha="b" * 40,
|
|
lock_digest="a" * 64,
|
|
image_digest="sha256:" + "a" * 64,
|
|
torch_wheel_digest="a" * 64,
|
|
package_digest="a" * 64,
|
|
runtime_digest="a" * 64,
|
|
api_digest="a" * 64,
|
|
code_digest="a" * 64,
|
|
profile_digest="a" * 64,
|
|
)
|
|
== []
|
|
)
|
|
|
|
|
|
def test_llama_tp_evidence_accepts_streamed_verify_baseline_identities():
|
|
from dataclasses import asdict
|
|
|
|
import torch
|
|
|
|
from obliteratus.distributed.verification import _snapshot_digest, _state_roots_digest
|
|
from obliteratus.distributed.verification_contracts import (
|
|
VerificationBaselineSummary, prepare_verification_corpus,
|
|
)
|
|
from tests.conditional.test_distributed_llama_tp_cuda import (
|
|
_verification_config, _verification_samples,
|
|
)
|
|
from tests.test_distributed_verification_contracts import _Tokenizer
|
|
|
|
config = _verification_config()
|
|
corpus = prepare_verification_corpus(
|
|
_Tokenizer(), _verification_samples(), refusal_token_ids=(2,),
|
|
source_tokenizer_digest="a" * 64, config=config,
|
|
)
|
|
row = torch.zeros(1, corpus.vocab_size)
|
|
next_rows = torch.zeros(3, corpus.vocab_size)
|
|
baseline = VerificationBaselineSummary(
|
|
schema_version=1, run_id="1" * 32, distilled_digest="a" * 64,
|
|
manifest_digest="a" * 64, expected_excise_config_digest="a" * 64,
|
|
verification_config_digest=config.digest, corpus_digest=corpus.corpus_digest,
|
|
sample_ids_digest=corpus.sample_ids_digest,
|
|
tokenizer_contract_digest=corpus.tokenizer_contract_digest,
|
|
tokenization_digest=corpus.tokenization_digest,
|
|
pristine_state_digest=_state_roots_digest({f"parameter-{i}": "a" * 64 for i in range(1024)}),
|
|
baseline_logit_digest=_snapshot_digest((row,) * 3, next_rows),
|
|
sample_count=3, sequence_position_count=3, vocab_size=corpus.vocab_size,
|
|
baseline_bytes=6 * corpus.vocab_size * 4,
|
|
rank_max_abs_error_hex=(0.0).hex(), rank_max_rel_error_hex=(0.0).hex(),
|
|
)
|
|
# The qualifier calls production VERIFY; the checker hashes only the closed
|
|
# outer summaries, so streamed inner roots remain opaque 64-character ids.
|
|
assert baseline.digest == check_llama_tp_hardware_evidence._record_digest(asdict(baseline))
|
|
evidence = _llama_tp_evidence()
|
|
evidence["qualification"]["verification"]["baseline_digest"] = baseline.digest
|
|
assert evidence["qualification"]["verification"]["config_digest"] == config.digest
|
|
assert check_llama_tp_hardware_evidence.validate(
|
|
evidence, candidate_sha="b" * 40, lock_digest="a" * 64,
|
|
image_digest="sha256:" + "a" * 64, torch_wheel_digest="a" * 64,
|
|
package_digest="a" * 64, runtime_digest="a" * 64, api_digest="a" * 64,
|
|
code_digest="a" * 64, profile_digest="a" * 64,
|
|
) == []
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("host", "devices"),
|
|
[("different-host", ("gpu0", "gpu1")), ("host", ("gpu0", "different-gpu"))],
|
|
)
|
|
def test_llama_tp_hardware_evidence_rejects_different_physical_host_or_gpu(host, devices):
|
|
evidence = _llama_tp_evidence(verification_host=host, verification_devices=devices)
|
|
errors = check_llama_tp_hardware_evidence.validate(
|
|
evidence,
|
|
candidate_sha="b" * 40,
|
|
lock_digest="a" * 64,
|
|
image_digest="sha256:" + "a" * 64,
|
|
torch_wheel_digest="a" * 64,
|
|
package_digest="a" * 64,
|
|
runtime_digest="a" * 64,
|
|
api_digest="a" * 64,
|
|
code_digest="a" * 64,
|
|
profile_digest="a" * 64,
|
|
)
|
|
assert errors == ["verification attempt does not use the same physical host and GPUs"]
|
|
|
|
|
|
def _validate_llama_tp_evidence(evidence):
|
|
return check_llama_tp_hardware_evidence.validate(
|
|
evidence, candidate_sha="b" * 40, lock_digest="a" * 64,
|
|
image_digest="sha256:" + "a" * 64, torch_wheel_digest="a" * 64,
|
|
package_digest="a" * 64, runtime_digest="a" * 64, api_digest="a" * 64,
|
|
code_digest="a" * 64, profile_digest="a" * 64,
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize("attempt", ["", "verification_"])
|
|
@pytest.mark.parametrize(
|
|
("path", "value", "message"),
|
|
[
|
|
(("layout",), "two_host_tp2", "requires the local_tp2 deployment layout"),
|
|
(("local_world_size",), 1, "requires the local TP2 geometry"),
|
|
(("schema_version",), True, "schema_version is outside its integer boundary"),
|
|
(("topology_plan_digest",), "f" * 64, "disagrees with the placement topology"),
|
|
(("ranks",), [], "requires exactly two rank identities"),
|
|
(("ranks", 1, "local_rank"), 0, "has an invalid local TP2 rank mapping"),
|
|
(("ranks", 1, "host_digest"), "f" * 64, "requires one physical host identity"),
|
|
(("ranks", 0, "prompt"), "unretained", "rank 0 does not match its closed schema"),
|
|
],
|
|
)
|
|
def test_llama_tp_evidence_rejects_invalid_per_attempt_deployment(attempt, path, value, message):
|
|
evidence = _llama_tp_evidence()
|
|
target = evidence["session"][attempt + "deployment_topology"]
|
|
for field in path[:-1]:
|
|
target = target[field]
|
|
target[path[-1]] = value
|
|
name = "verification deployment topology" if attempt else "session deployment topology"
|
|
assert _validate_llama_tp_evidence(evidence) == [f"{name} {message}"]
|
|
|
|
|
|
@pytest.mark.parametrize("attempt", ["", "verification_"])
|
|
def test_llama_tp_evidence_rejects_opaque_deployment_binding(attempt):
|
|
evidence = _llama_tp_evidence()
|
|
bindings = evidence["session"][attempt + "bindings"]
|
|
bindings["deployment_layout_digest"] = "f" * 64
|
|
evidence["session"][attempt + "bindings_digest"] = contract_digest(bindings)
|
|
name = "verification deployment topology" if attempt else "session deployment topology"
|
|
assert _validate_llama_tp_evidence(evidence) == [f"{name} does not match its deployment binding"]
|
|
|
|
|
|
def test_llama_tp_evidence_rejects_device_drift_and_reused_deployment_identity():
|
|
evidence = _llama_tp_evidence()
|
|
evidence["session"]["deployment_topology"]["ranks"][0]["device_digest"] = "f" * 64
|
|
assert _validate_llama_tp_evidence(evidence) == [
|
|
"session deployment topology device identity disagrees with hardware evidence"
|
|
]
|
|
evidence = _llama_tp_evidence()
|
|
evidence["session"]["verification_deployment_topology"] = evidence["session"]["deployment_topology"]
|
|
bindings = evidence["session"]["verification_bindings"]
|
|
bindings["deployment_layout_digest"] = evidence["session"]["bindings"]["deployment_layout_digest"]
|
|
evidence["session"]["verification_bindings_digest"] = contract_digest(bindings)
|
|
assert _validate_llama_tp_evidence(evidence) == [
|
|
"verification session did not bind a fresh deployment identity"
|
|
]
|
|
|
|
|
|
def test_llama_tp_evidence_binds_verify_and_export_to_per_attempt_mount_and_topology():
|
|
evidence = _llama_tp_evidence()
|
|
session = evidence["session"]
|
|
topology, layout_digest = _llama_tp_deployment_topology(
|
|
session["bindings"]["topology_digest"], "f" * 64, ("7" * 64, "8" * 64),
|
|
)
|
|
session["verification_deployment_topology"] = topology
|
|
session["verification_bindings"]["deployment_layout_digest"] = layout_digest
|
|
session["verification_source_mount_attestation_digest"] = "9" * 64
|
|
session["verification_bindings"]["hardware_digest"] = contract_digest({
|
|
"devices": [
|
|
{field: device[field] for field in ("rank", "device_config_digest", "device_profile_digest")}
|
|
for device in evidence["devices"]
|
|
],
|
|
"source_mount_attestation_digest": session["verification_source_mount_attestation_digest"],
|
|
})
|
|
session["verification_bindings_digest"] = contract_digest(session["verification_bindings"])
|
|
assert _validate_llama_tp_evidence(evidence) == [
|
|
"verification attempt digest does not bind the retained evidence"
|
|
]
|
|
evidence["artifacts"]["verification_attempt_digest"] = contract_digest({
|
|
"fixture_digest": evidence["artifacts"]["fixture_digest"],
|
|
"source_digest": evidence["artifacts"]["source_digest"],
|
|
"verification_bindings_digest": session["verification_bindings_digest"],
|
|
"verification_summary_digest": evidence["qualification"]["verification"]["summary_digest"],
|
|
})
|
|
assert _validate_llama_tp_evidence(evidence) == [
|
|
"export attempt digest does not bind the retained evidence"
|
|
]
|
|
evidence["artifacts"]["export_attempt_digest"] = contract_digest({
|
|
"source_digest": evidence["artifacts"]["source_digest"],
|
|
"verification_bindings_digest": session["verification_bindings_digest"],
|
|
"verification_summary_digest": evidence["qualification"]["verification"]["summary_digest"],
|
|
"export_summary_digest": evidence["qualification"]["export"]["summary_digest"],
|
|
})
|
|
assert _validate_llama_tp_evidence(evidence) == []
|
|
|
|
|
|
def test_llama_tp_hardware_evidence_rejects_drift_and_payload_expansion():
|
|
evidence = _llama_tp_evidence()
|
|
evidence["candidate_sha"] = "c" * 40
|
|
errors = check_llama_tp_hardware_evidence.validate(
|
|
evidence,
|
|
candidate_sha="b" * 40,
|
|
lock_digest="a" * 64,
|
|
image_digest="sha256:" + "a" * 64,
|
|
torch_wheel_digest="a" * 64,
|
|
package_digest="a" * 64,
|
|
runtime_digest="a" * 64,
|
|
api_digest="a" * 64,
|
|
code_digest="a" * 64,
|
|
profile_digest="a" * 64,
|
|
)
|
|
assert errors == ["hardware evidence candidate does not match the exact requested head"]
|
|
|
|
evidence = _llama_tp_evidence()
|
|
evidence["qualification"]["prompt"] = "must not be retained"
|
|
errors = check_llama_tp_hardware_evidence.validate(
|
|
evidence,
|
|
candidate_sha="b" * 40,
|
|
lock_digest="a" * 64,
|
|
image_digest="sha256:" + "a" * 64,
|
|
torch_wheel_digest="a" * 64,
|
|
package_digest="a" * 64,
|
|
runtime_digest="a" * 64,
|
|
api_digest="a" * 64,
|
|
code_digest="a" * 64,
|
|
profile_digest="a" * 64,
|
|
)
|
|
assert errors == ["qualification does not match its closed schema"]
|
|
|
|
evidence = _llama_tp_evidence()
|
|
evidence["topology"]["host_count"] = 2
|
|
errors = check_llama_tp_hardware_evidence.validate(
|
|
evidence,
|
|
candidate_sha="b" * 40,
|
|
lock_digest="a" * 64,
|
|
image_digest="sha256:" + "a" * 64,
|
|
torch_wheel_digest="a" * 64,
|
|
package_digest="a" * 64,
|
|
runtime_digest="a" * 64,
|
|
api_digest="a" * 64,
|
|
code_digest="a" * 64,
|
|
profile_digest="a" * 64,
|
|
)
|
|
assert errors == ["upstream #244 local qualification is exactly one physical host"]
|
|
|
|
evidence = _llama_tp_evidence()
|
|
evidence["topology"]["deployment_layout"] = "two_host_tp2"
|
|
errors = check_llama_tp_hardware_evidence.validate(
|
|
evidence,
|
|
candidate_sha="b" * 40,
|
|
lock_digest="a" * 64,
|
|
image_digest="sha256:" + "a" * 64,
|
|
torch_wheel_digest="a" * 64,
|
|
package_digest="a" * 64,
|
|
runtime_digest="a" * 64,
|
|
api_digest="a" * 64,
|
|
code_digest="a" * 64,
|
|
profile_digest="a" * 64,
|
|
)
|
|
assert errors == ["upstream #244 local qualification requires the local_tp2 deployment layout"]
|
|
|
|
evidence = _llama_tp_evidence()
|
|
evidence["session"]["bindings"]["model_digest"] = "6" * 64
|
|
evidence["session"]["bindings_digest"] = check_llama_tp_hardware_evidence._record_digest(
|
|
evidence["session"]["bindings"]
|
|
)
|
|
errors = check_llama_tp_hardware_evidence.validate(
|
|
evidence,
|
|
candidate_sha="b" * 40,
|
|
lock_digest="a" * 64,
|
|
image_digest="sha256:" + "a" * 64,
|
|
torch_wheel_digest="a" * 64,
|
|
package_digest="a" * 64,
|
|
runtime_digest="a" * 64,
|
|
api_digest="a" * 64,
|
|
code_digest="a" * 64,
|
|
profile_digest="a" * 64,
|
|
)
|
|
assert errors == ["session binding model_digest disagrees with hardware evidence"]
|
|
|
|
evidence = _llama_tp_evidence()
|
|
evidence["artifacts"]["reference_digest"] = "7" * 64
|
|
errors = check_llama_tp_hardware_evidence.validate(
|
|
evidence,
|
|
candidate_sha="b" * 40,
|
|
lock_digest="a" * 64,
|
|
image_digest="sha256:" + "a" * 64,
|
|
torch_wheel_digest="a" * 64,
|
|
package_digest="a" * 64,
|
|
runtime_digest="a" * 64,
|
|
api_digest="a" * 64,
|
|
code_digest="a" * 64,
|
|
profile_digest="a" * 64,
|
|
)
|
|
assert errors == ["acquisition manifest digest does not bind the generated fixture"]
|
|
|
|
evidence = _llama_tp_evidence()
|
|
evidence["qualification"]["excise"]["rollback_restored"] = False
|
|
errors = check_llama_tp_hardware_evidence.validate(
|
|
evidence,
|
|
candidate_sha="b" * 40,
|
|
lock_digest="a" * 64,
|
|
image_digest="sha256:" + "a" * 64,
|
|
torch_wheel_digest="a" * 64,
|
|
package_digest="a" * 64,
|
|
runtime_digest="a" * 64,
|
|
api_digest="a" * 64,
|
|
code_digest="a" * 64,
|
|
profile_digest="a" * 64,
|
|
)
|
|
assert errors == ["excise rollback_restored must be true"]
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("path", "value", "expected"),
|
|
[
|
|
(
|
|
("qualification", "verification", "nonfinite_count"),
|
|
1,
|
|
"verification nonfinite_count must equal zero",
|
|
),
|
|
(
|
|
("qualification", "verification", "fresh_attempt_identity"),
|
|
False,
|
|
"verification fresh_attempt_identity must be true",
|
|
),
|
|
(
|
|
("qualification", "verification", "config_digest"),
|
|
"9" * 64,
|
|
"verification config digest differs from preregistered profile",
|
|
),
|
|
(
|
|
("session", "verification_bindings_digest"),
|
|
None,
|
|
"verification session must use a fresh binding identity",
|
|
),
|
|
(
|
|
("session", "verification_source_mount_attestation_digest"),
|
|
"9" * 64,
|
|
"verification hardware digest does not bind its device and mount evidence",
|
|
),
|
|
],
|
|
)
|
|
def test_llama_tp_hardware_evidence_rejects_invalid_verification(path, value, expected):
|
|
evidence = _llama_tp_evidence()
|
|
if value is None:
|
|
evidence["session"]["verification_bindings"] = dict(evidence["session"]["bindings"])
|
|
value = evidence["session"]["bindings_digest"]
|
|
target = evidence
|
|
for name in path[:-1]:
|
|
target = target[name]
|
|
target[path[-1]] = value
|
|
|
|
errors = check_llama_tp_hardware_evidence.validate(
|
|
evidence,
|
|
candidate_sha="b" * 40,
|
|
lock_digest="a" * 64,
|
|
image_digest="sha256:" + "a" * 64,
|
|
torch_wheel_digest="a" * 64,
|
|
package_digest="a" * 64,
|
|
runtime_digest="a" * 64,
|
|
api_digest="a" * 64,
|
|
code_digest="a" * 64,
|
|
profile_digest="a" * 64,
|
|
)
|
|
assert errors == [expected]
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("path", "value", "expected"),
|
|
[
|
|
(
|
|
("qualification", "export", "published"),
|
|
False,
|
|
"export published must be true",
|
|
),
|
|
(
|
|
("qualification", "export", "verification_digest"),
|
|
"9" * 64,
|
|
"export does not bind the accepted verification result",
|
|
),
|
|
(
|
|
("qualification", "export", "config_digest"),
|
|
"9" * 64,
|
|
"export config digest differs from the preregistered profile",
|
|
),
|
|
],
|
|
)
|
|
def test_llama_tp_hardware_evidence_rejects_invalid_export(path, value, expected):
|
|
evidence = _llama_tp_evidence()
|
|
target = evidence
|
|
for name in path[:-1]:
|
|
target = target[name]
|
|
target[path[-1]] = value
|
|
|
|
errors = check_llama_tp_hardware_evidence.validate(
|
|
evidence,
|
|
candidate_sha="b" * 40,
|
|
lock_digest="a" * 64,
|
|
image_digest="sha256:" + "a" * 64,
|
|
torch_wheel_digest="a" * 64,
|
|
package_digest="a" * 64,
|
|
runtime_digest="a" * 64,
|
|
api_digest="a" * 64,
|
|
code_digest="a" * 64,
|
|
profile_digest="a" * 64,
|
|
)
|
|
assert errors == [expected]
|
|
|
|
|
|
def test_readonly_mount_namespace_applies_closed_flags_before_exec(monkeypatch, tmp_path):
|
|
source = tmp_path / f"source-{'a' * 64}"
|
|
source.mkdir()
|
|
operations: list[tuple[str | None, str, int]] = []
|
|
|
|
class ExecCalled(BaseException):
|
|
pass
|
|
|
|
monkeypatch.setattr(
|
|
run_readonly_mount_namespace,
|
|
"_mount",
|
|
lambda source, target, flags: operations.append((source, target, flags)),
|
|
)
|
|
monkeypatch.setattr(
|
|
run_readonly_mount_namespace.os,
|
|
"execve",
|
|
lambda *_args: (_ for _ in ()).throw(ExecCalled()),
|
|
)
|
|
monkeypatch.setattr(
|
|
sys,
|
|
"argv",
|
|
[
|
|
"run_readonly_mount_namespace.py",
|
|
"--source",
|
|
str(source),
|
|
"--",
|
|
"/bin/true",
|
|
],
|
|
)
|
|
|
|
try:
|
|
run_readonly_mount_namespace.main()
|
|
except ExecCalled:
|
|
pass
|
|
else:
|
|
raise AssertionError("the wrapper did not exec the bounded child")
|
|
|
|
assert operations == [
|
|
(None, "/", (1 << 18) | 16384),
|
|
(str(source), str(source), 4096),
|
|
(None, str(source), 4096 | 32 | 1 | 2 | 4 | 8),
|
|
]
|
|
|
|
|
|
def test_readonly_mount_namespace_rejects_non_content_addressed_source(monkeypatch, tmp_path):
|
|
source = tmp_path / "source"
|
|
source.mkdir()
|
|
monkeypatch.setattr(
|
|
sys,
|
|
"argv",
|
|
[
|
|
"run_readonly_mount_namespace.py",
|
|
"--source",
|
|
str(source),
|
|
"--",
|
|
"/bin/true",
|
|
],
|
|
)
|
|
monkeypatch.setattr(
|
|
run_readonly_mount_namespace,
|
|
"_mount",
|
|
lambda *_args: (_ for _ in ()).throw(AssertionError("mount must not run")),
|
|
)
|
|
assert run_readonly_mount_namespace.main() == 70
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("address", "expected"),
|
|
[
|
|
("10.1.2.3", True),
|
|
("172.31.255.254", True),
|
|
("192.168.4.5", True),
|
|
("127.0.0.1", False),
|
|
("169.254.1.2", False),
|
|
("203.0.113.5", False),
|
|
("not-an-address", False),
|
|
(None, False),
|
|
],
|
|
)
|
|
def test_llama_tp_private_interface_check_is_total(address, expected):
|
|
assert run_conditional_gate._is_private_rfc1918_ipv4(address) is expected
|