mirror of
https://github.com/elder-plinius/OBLITERATUS.git
synced 2026-12-05 18:44:41 +01:00
(cherry picked from commit f9a289e267889c297cefcdc67eea92c4b8eb8d4d) Ported for #244 (part 2/6). Internal-only content from the archived commit was dropped: .aiwg records and the internal security-docs test. Marked experimental in user docs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
690 lines
23 KiB
Python
690 lines
23 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.probe_contracts import ProbeDistillConfig
|
|
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_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 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_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",
|
|
]
|
|
|
|
|
|
def _llama_tp_evidence() -> 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
|
|
hardware_digest = hashlib.sha256(
|
|
json.dumps(
|
|
{
|
|
"devices": [
|
|
{
|
|
"rank": item["rank"],
|
|
"device_config_digest": item["device_config_digest"],
|
|
"device_profile_digest": item["device_profile_digest"],
|
|
}
|
|
for item in devices
|
|
],
|
|
"source_mount_attestation_digest": source_mount_attestation_digest,
|
|
},
|
|
ensure_ascii=True,
|
|
allow_nan=False,
|
|
sort_keys=True,
|
|
separators=(",", ":"),
|
|
).encode("ascii")
|
|
).hexdigest()
|
|
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,
|
|
}
|
|
)
|
|
topology_digest = check_llama_tp_hardware_evidence._record_digest(
|
|
{
|
|
"backend": "gloo",
|
|
"coordinator_rank": 0,
|
|
"placement_plan_digest": digest,
|
|
"world_size": 2,
|
|
}
|
|
)
|
|
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,
|
|
"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,
|
|
}
|
|
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,
|
|
"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,
|
|
},
|
|
"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,
|
|
},
|
|
"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,
|
|
},
|
|
},
|
|
}
|
|
|
|
|
|
def test_llama_tp_hardware_evidence_accepts_only_the_exact_closed_envelope():
|
|
evidence = _llama_tp_evidence()
|
|
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_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 == ["#60 qualification is exactly one physical host"]
|
|
|
|
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"]
|
|
|
|
|
|
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
|