mirror of
https://github.com/elder-plinius/OBLITERATUS.git
synced 2026-12-05 18:44:41 +01:00
Integrate bounded admission, UI ownership and controls, opt-in durable MCP execution, rank-local TP2 groundwork, regression hardening and operator guides. Physical larger-memory and two-host qualification remain separate.
243 lines
14 KiB
Python
243 lines
14 KiB
Python
"""Qualification authority and physical-tier rejection use synthetic schema oracles."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import hashlib
|
|
import json
|
|
from dataclasses import asdict, fields, replace
|
|
from types import SimpleNamespace
|
|
|
|
import pytest
|
|
|
|
from obliteratus.distributed.contracts import ContractError, contract_digest
|
|
from obliteratus.distributed.export_contracts import ExportSummary, export_aggregate_digest
|
|
from obliteratus.distributed.rank_local import (
|
|
policy_digest, require_reviewed_profile, review_bindings, HOST_CAPACITY_DOMAIN,
|
|
hardware_observation_digest,
|
|
)
|
|
from obliteratus.distributed.rank_local_qualification import qualification_checks, validate_qualification, publish_qualification
|
|
from tests.test_distributed_rank_local import install_review, rank_config, review_record
|
|
|
|
|
|
def evidence_fixture(tmp_path, monkeypatch, tier="LMS-E3", capacity=64):
|
|
config = rank_config(tmp_path)
|
|
config = replace(config, rank_storage=replace(config.rank_storage, tier=tier),
|
|
device_kind="cuda", evidence_tier="candidate_preflight")
|
|
storage = config.rank_storage
|
|
values = {item.name: "a" * 64 for item in fields(ExportSummary) if item.name.endswith("digest")}
|
|
values.update(schema_version=1, run_id=config.run_id, export_id="2" * 32,
|
|
commit_sha=config.commit_sha, output_name="canonical-output", tensor_count=2, logical_bytes=128,
|
|
code_digest=config.code_digest, runtime_config_digest=config.digest)
|
|
values.update(source_digest=config.source_digest, model_digest=config.model_digest,
|
|
tokenizer_digest=config.tokenizer_digest, hf_config_digest=config.model.hf_config_digest,
|
|
placement_plan_digest=config.placement_plan_digest, storage_digest=storage.mapping_digest)
|
|
manifest = {"assignments": [{"writer_rank": 0, "logical_bytes": 64}, {"writer_rank": 0, "logical_bytes": 64}],
|
|
"tensor_records": [{"sequence": 0}, {"sequence": 1}],
|
|
"metadata_records": [{"relative_path": "config.json"}],
|
|
"reload_evidence": [{"rank": 0}, {"rank": 1}],
|
|
"rank_evidence": [{"rank": 0}, {"rank": 1}], "resource_admission": {"logical_bytes": 128},
|
|
"validation": {"independent_reload": True}}
|
|
for name, domain, field in (
|
|
("assignments", "assignments", "assignment_set_digest"),
|
|
("tensor_records", "tensors", "tensor_record_set_digest"),
|
|
("metadata_records", "metadata", "metadata_set_digest"),
|
|
("reload_evidence", "reload-evidence", "reload_evidence_set_digest"),
|
|
("rank_evidence", "rank-evidence", "rank_evidence_set_digest"),
|
|
):
|
|
values[field] = export_aggregate_digest(manifest[name], domain=domain)
|
|
values["admission_digest"] = contract_digest(manifest["resource_admission"])
|
|
summary = ExportSummary(**values)
|
|
records = []
|
|
summaries = []
|
|
for rank in range(2):
|
|
observation = {"schema_version": 1, "rank": rank, "host_digest": str(rank + 1) * 64,
|
|
"domain": HOST_CAPACITY_DOMAIN, "total_host_memory_bytes": capacity}
|
|
record = {"finite": True, "within_tolerance": True, "greedy_match": True,
|
|
"activation_sites": [{"complete": True, "replicated": True, "within_tolerance": True}],
|
|
"probe_distill": {"finite": True, "within_tolerance": True, "parameters_unchanged": True},
|
|
"excise": dict.fromkeys(("finite", "complete_tensor_match", "postconditions_match", "journal_private", "verified", "journal_removed"), True),
|
|
"verification": {"quality_accepted": True, "rank_agreement": True, "journal_removed": True, "nonfinite_count": 0},
|
|
"export": {"published": True, "rank_agreement": True, "semantic_reload": True},
|
|
"physical_host_memory_bytes": capacity, "host_capacity_observation": observation}
|
|
records.append(record)
|
|
summaries.append({"rank": rank, "checks": qualification_checks(record),
|
|
"record_digest": hashlib.sha256(json.dumps(record, sort_keys=True, separators=(",", ":")).encode("ascii")).hexdigest(),
|
|
"host_digest": str(rank + 1) * 64, "device_digest": str(rank + 3) * 64,
|
|
"device_profile_digest": "a" * 64, "storage_digest": storage.ranks[rank].storage_digest,
|
|
"host_capacity_observation": observation,
|
|
"export_digest": summary.digest})
|
|
review = review_record(config)
|
|
review["bindings"]["hardware_digest"] = hardware_observation_digest(summaries)
|
|
install_review(monkeypatch, review)
|
|
bindings = review_bindings(config)
|
|
bindings["hardware_digest"] = review["bindings"]["hardware_digest"]
|
|
approval = require_reviewed_profile(storage, bindings)
|
|
envelope = {"schema_version": 1, "gate": "rank-local-tp2", "status": "not_qualified",
|
|
"scope": "qualification", "tier": tier, "candidate_sha": config.commit_sha,
|
|
"run_id": config.run_id, "config_digest": config.digest, "code_digest": config.code_digest,
|
|
"policy_digest": policy_digest(), "approval_digest": approval,
|
|
"mapping_digest": storage.mapping_digest, "profile_id": storage.profile_id, "rank_summaries": summaries}
|
|
manifest.update(summary=asdict(summary), publication={"mapping_digest": storage.mapping_digest,
|
|
"scope": "qualification", "evidence_tier": tier, "approval_digest": approval})
|
|
return config, envelope, tuple(records), manifest
|
|
|
|
|
|
def test_separate_qualification_checker_never_promotes_support(tmp_path, monkeypatch):
|
|
config, envelope, records, manifest = evidence_fixture(tmp_path, monkeypatch)
|
|
assert validate_qualification(envelope, records, manifest, config, config.commit_sha)
|
|
assert envelope["status"] == "not_qualified"
|
|
assert config.rank_storage.scope == "qualification"
|
|
|
|
|
|
@pytest.mark.parametrize("mutation", ("E0", "E1", "E2", "head", "profile", "policy", "record", "host", "writer", "approval"))
|
|
def test_qualification_rejects_tier_forgery_and_wrong_exact_candidate(tmp_path, monkeypatch, mutation):
|
|
config, envelope, records, manifest = evidence_fixture(tmp_path, monkeypatch)
|
|
candidate = config.commit_sha
|
|
if mutation.startswith("E"):
|
|
envelope["tier"] = "LMS-" + mutation
|
|
elif mutation == "head":
|
|
candidate = "e" * 40
|
|
elif mutation == "profile":
|
|
envelope["profile_id"] = "unreviewed"
|
|
elif mutation == "policy":
|
|
envelope["policy_digest"] = "f" * 64
|
|
elif mutation == "record":
|
|
records[1]["greedy_match"] = False
|
|
elif mutation == "host":
|
|
envelope["rank_summaries"][1]["host_digest"] = envelope["rank_summaries"][0]["host_digest"]
|
|
elif mutation == "writer":
|
|
manifest["assignments"][0]["writer_rank"] = 1
|
|
else:
|
|
envelope["approval_digest"] = "0" * 64
|
|
with pytest.raises(ContractError):
|
|
validate_qualification(envelope, records, manifest, config, candidate)
|
|
|
|
|
|
def test_e4_requires_measured_capacity_and_same_head(tmp_path, monkeypatch):
|
|
config, envelope, records, manifest = evidence_fixture(tmp_path, monkeypatch, "LMS-E4")
|
|
assert validate_qualification(envelope, records, manifest, config, config.commit_sha)
|
|
records[0]["physical_host_memory_bytes"] = 256
|
|
envelope["rank_summaries"][0]["record_digest"] = hashlib.sha256(json.dumps(records[0], sort_keys=True, separators=(",", ":")).encode("ascii")).hexdigest()
|
|
with pytest.raises(ContractError, match="E4"):
|
|
validate_qualification(envelope, records, manifest, config, config.commit_sha)
|
|
|
|
|
|
@pytest.mark.parametrize("forge_observation", (False, True))
|
|
def test_e4_low_forged_capacities_cannot_bypass_an_approved_collection_profile(tmp_path, monkeypatch, forge_observation):
|
|
config, envelope, records, manifest = evidence_fixture(tmp_path, monkeypatch, "LMS-E4", capacity=256)
|
|
with pytest.raises(ContractError, match="E4 requires"):
|
|
validate_qualification(envelope, records, manifest, config, config.commit_sha)
|
|
for rank, record in enumerate(records):
|
|
record["physical_host_memory_bytes"] = 1
|
|
if forge_observation:
|
|
forged = {**record["host_capacity_observation"], "total_host_memory_bytes": 1}
|
|
record["host_capacity_observation"] = forged
|
|
envelope["rank_summaries"][rank]["host_capacity_observation"] = forged
|
|
envelope["rank_summaries"][rank]["record_digest"] = hashlib.sha256(json.dumps(record, sort_keys=True, separators=(",", ":")).encode("ascii")).hexdigest()
|
|
with pytest.raises(ContractError):
|
|
validate_qualification(envelope, records, manifest, config, config.commit_sha)
|
|
|
|
|
|
def test_publication_rejects_caller_capacity_before_retaining_rank_evidence(tmp_path, monkeypatch):
|
|
config, envelope, records, manifest = evidence_fixture(tmp_path, monkeypatch, "LMS-E4")
|
|
attestations = tuple(SimpleNamespace(rank=row["rank"], host_digest=row["host_digest"],
|
|
device_digest=row["device_digest"], device_profile_digest=row["device_profile_digest"],
|
|
storage_digest=row["storage_digest"], total_host_memory_bytes=row["host_capacity_observation"]["total_host_memory_bytes"])
|
|
for row in envelope["rank_summaries"])
|
|
records[0]["physical_host_memory_bytes"] = 1
|
|
attempt = tmp_path / "private-qualification"
|
|
attempt.mkdir(mode=0o700)
|
|
session = SimpleNamespace(config=config, launch=SimpleNamespace(rank=0), control_group=None,
|
|
preflight=SimpleNamespace(attestations=attestations, attempt_path=attempt))
|
|
import obliteratus.distributed.consensus as consensus
|
|
votes = []
|
|
def vote(sequence, accepted, **kwargs):
|
|
votes.append((sequence, accepted))
|
|
return accepted
|
|
monkeypatch.setattr(consensus, "unanimous_vote", vote)
|
|
with pytest.raises(ContractError, match="preparation failed"):
|
|
publish_qualification(session, records[0], SimpleNamespace(digest=contract_digest(manifest)))
|
|
assert votes == [(25_000_000, False)]
|
|
assert list(attempt.iterdir()) == []
|
|
|
|
|
|
@pytest.mark.parametrize("domain", ("cgroup-budget", "free-host-memory", "operator-estimate"))
|
|
def test_e4_rejects_substitution_of_a_different_memory_domain(tmp_path, monkeypatch, domain):
|
|
config, envelope, records, manifest = evidence_fixture(tmp_path, monkeypatch, "LMS-E4")
|
|
for rank, record in enumerate(records):
|
|
forged = {**record["host_capacity_observation"], "domain": domain}
|
|
record["host_capacity_observation"] = forged
|
|
envelope["rank_summaries"][rank]["host_capacity_observation"] = forged
|
|
envelope["rank_summaries"][rank]["record_digest"] = hashlib.sha256(json.dumps(record, sort_keys=True, separators=(",", ":")).encode("ascii")).hexdigest()
|
|
with pytest.raises(ContractError, match="physical-domain observation"):
|
|
validate_qualification(envelope, records, manifest, config, config.commit_sha)
|
|
|
|
|
|
def test_missing_measurements_and_truthy_values_do_not_pass():
|
|
assert not any(qualification_checks({}).values())
|
|
assert qualification_checks({"finite": 1, "within_tolerance": True, "greedy_match": True})["pristine"] is False
|
|
|
|
|
|
@pytest.mark.parametrize("failure", (None, "lane", "measurements", "envelope"))
|
|
def test_publication_retains_private_digest_bound_records_and_votes(tmp_path, monkeypatch, failure):
|
|
import obliteratus.distributed.consensus as consensus
|
|
import obliteratus.distributed.rank_local_qualification as qualification
|
|
|
|
config, envelope, records, manifest = evidence_fixture(tmp_path, monkeypatch)
|
|
attestations = tuple(SimpleNamespace(rank=row["rank"], host_digest=row["host_digest"],
|
|
device_digest=row["device_digest"], device_profile_digest=row["device_profile_digest"],
|
|
storage_digest=row["storage_digest"],
|
|
total_host_memory_bytes=row["host_capacity_observation"]["total_host_memory_bytes"])
|
|
for row in envelope["rank_summaries"])
|
|
install_review(monkeypatch, review_record(config, attestations))
|
|
if failure == "lane":
|
|
config = replace(config, rank_storage=replace(config.rank_storage, tier="LMS-E2"))
|
|
install_review(monkeypatch, review_record(config, attestations))
|
|
elif failure == "measurements":
|
|
records[0]["finite"] = False
|
|
attempt = tmp_path / "qualification-attempt"
|
|
attempt.mkdir(mode=0o700)
|
|
session = SimpleNamespace(config=config, launch=SimpleNamespace(rank=0), control_group=None,
|
|
preflight=SimpleNamespace(attestations=attestations, attempt_path=attempt,
|
|
identity_digest="f" * 64))
|
|
votes = []
|
|
exchanged = []
|
|
|
|
def vote(sequence, accepted, **kwargs):
|
|
votes.append((sequence, accepted))
|
|
return accepted
|
|
|
|
def exchange(run_id, identity, rank, phase, sequence, payload, **kwargs):
|
|
exchanged.append((run_id, identity, rank, phase, sequence, payload))
|
|
return ({"payload": payload}, {"payload": envelope["rank_summaries"][1]})
|
|
|
|
monkeypatch.setattr(consensus, "unanimous_vote", vote)
|
|
monkeypatch.setattr(qualification, "exchange_summary", exchange)
|
|
if failure == "envelope":
|
|
(attempt / "rank-local-qualification.json").write_text("existing-evidence")
|
|
if failure is not None:
|
|
with pytest.raises(ContractError, match="envelope" if failure == "envelope" else "preparation"):
|
|
publish_qualification(session, records[0], ExportSummary(**manifest["summary"]))
|
|
if failure == "envelope":
|
|
assert votes == [(25_000_000, True), (25_000_001, False)]
|
|
assert (attempt / "rank-local-qualification.json").read_text() == "existing-evidence"
|
|
else:
|
|
assert votes == [(25_000_000, False)]
|
|
assert not exchanged
|
|
return
|
|
target = publish_qualification(session, records[0], ExportSummary(**manifest["summary"]))
|
|
retained = json.loads(target.read_text())
|
|
raw_record = (attempt / "qualification-rank-0.json").read_bytes()
|
|
assert votes == [(25_000_000, True), (25_000_001, True)]
|
|
assert exchanged[0][:5] == (config.run_id, "f" * 64, 0, "QUALIFICATION", 10)
|
|
assert retained["rank_summaries"][0]["record_digest"] == hashlib.sha256(raw_record).hexdigest()
|
|
assert retained["rank_summaries"][0]["host_capacity_observation"] == records[0]["host_capacity_observation"]
|
|
assert retained["status"] == "not_qualified"
|
|
assert target.stat().st_mode & 0o777 == 0o600
|
|
assert (attempt / "qualification-rank-0.json").stat().st_mode & 0o777 == 0o600
|
|
|
|
|
|
@pytest.mark.parametrize("record", (None, [], "untrusted", 1))
|
|
def test_non_mapping_qualification_measurements_fail_closed(record):
|
|
assert not any(qualification_checks(record).values())
|