129 lines
5.1 KiB
Python
129 lines
5.1 KiB
Python
#!/usr/bin/env python3
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
"""Mutation guardrails for Phase-1.0W inactive client architecture."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import importlib.util
|
|
from pathlib import Path
|
|
import sys
|
|
|
|
|
|
def load(path: Path):
|
|
spec = importlib.util.spec_from_file_location("phase10w_validator", path)
|
|
assert spec and spec.loader
|
|
module = importlib.util.module_from_spec(spec)
|
|
sys.modules[spec.name] = module
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
def require(value: bool, message: str) -> None:
|
|
if not value:
|
|
raise RuntimeError(message)
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--root", type=Path, required=True)
|
|
args = parser.parse_args()
|
|
root = args.root.resolve()
|
|
validator = load(root / "tools/validate_retroarch_phase10w.py")
|
|
record = validator.load_json(
|
|
root / "manifests/retroarch/phase-1.0w-inactive-client-architecture.json")
|
|
cases = []
|
|
|
|
def case(name):
|
|
def register(function):
|
|
cases.append((name, function))
|
|
return function
|
|
return register
|
|
|
|
@case("01 all authorizations remain false")
|
|
def _(): require(validator.all_authorizations_false(record["authorizations"]), "authority active")
|
|
|
|
@case("02 connection authority is rejected")
|
|
def _():
|
|
value = dict(record["authorizations"]); value["ps5_connection_authorized"] = True
|
|
require(not validator.all_authorizations_false(value), "connection allowed")
|
|
|
|
@case("03 tracked activation is inert")
|
|
def _(): require(validator.activation_is_inactive(record["activation"]), "activation rejected")
|
|
|
|
@case("04 target value fails inactive gate")
|
|
def _():
|
|
value = dict(record["activation"]); value["target_address"] = "device.invalid"
|
|
require(not validator.activation_is_inactive(value), "target accepted")
|
|
|
|
@case("05 command value fails inactive gate")
|
|
def _():
|
|
value = dict(record["activation"]); value["commands"] = ["help"]
|
|
require(not validator.activation_is_inactive(value), "command accepted")
|
|
|
|
@case("06 architecture has no transport")
|
|
def _(): require(validator.architecture_has_no_transport(record["architecture"]), "architecture rejected")
|
|
|
|
@case("07 invented socket fails architecture")
|
|
def _():
|
|
value = dict(record["architecture"]); value["socket_import_present"] = True
|
|
require(not validator.architecture_has_no_transport(value), "socket accepted")
|
|
|
|
@case("08 future contract is bounded")
|
|
def _(): require(validator.future_contract_is_bounded(record["future_contract"]), "contract rejected")
|
|
|
|
@case("09 second connection fails contract")
|
|
def _():
|
|
value = dict(record["future_contract"]); value["maximum_connections"] = 2
|
|
require(not validator.future_contract_is_bounded(value), "second connection accepted")
|
|
|
|
@case("10 deadline relaxation fails contract")
|
|
def _():
|
|
value = dict(record["future_contract"]); value["maximum_deadline_seconds"] = 11
|
|
require(not validator.future_contract_is_bounded(value), "deadline relaxed")
|
|
|
|
@case("11 serial effect acceptance remains mandatory")
|
|
def _(): require(record["future_contract"]["serial_query_acceptance_required"] is True, "serial effect hidden")
|
|
|
|
@case("12 retry remains forbidden")
|
|
def _(): require(record["future_contract"]["automatic_retry"] is False, "retry allowed")
|
|
|
|
@case("13 live components remain missing")
|
|
def _(): require(validator.live_components_remain_missing(record["missing_live_components"]), "missing set rejected")
|
|
|
|
@case("14 receipt cannot be claimed implemented")
|
|
def _():
|
|
value = dict(record["missing_live_components"]); value["consumed_attempt_receipt"] = False
|
|
require(not validator.live_components_remain_missing(value), "receipt invented")
|
|
|
|
@case("15 remediated physical memory erasure remains unproven")
|
|
def _():
|
|
phase_v = validator.load_json(root / "manifests/retroarch/phase-1.0v-inactive-shsrv-collector.json")
|
|
require(phase_v["review_remediation"]["physical_memory_erasure_proven"] is False, "memory erasure invented")
|
|
|
|
@case("16 exact deployed identity remains unproven")
|
|
def _(): require(record["decision"]["exact_deployed_shsrv_identity"] == "UNPROVEN", "identity promoted")
|
|
|
|
@case("17 next phase is offline implementation only")
|
|
def _(): require(validator.decision_is_offline_only(record["decision"]), "decision enabled")
|
|
|
|
@case("18 no device action and no hardware proof")
|
|
def _(): require(all(value is False for value in record["performed_actions"].values()) and record["tests"]["hardware_claim_from_host_test"] is False, "host architecture promoted")
|
|
|
|
failures = []
|
|
for name, function in cases:
|
|
try:
|
|
function()
|
|
print(f"PASS {name}")
|
|
except Exception as error: # noqa: BLE001 - mutation harness
|
|
failures.append(f"{name}: {error}")
|
|
print(f"FAIL {name}: {error}")
|
|
if failures:
|
|
return 1
|
|
print(f"Phase-1.0W guardrails passed: {len(cases)}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|