127 lines
4.8 KiB
Python
127 lines
4.8 KiB
Python
#!/usr/bin/env python3
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
"""Mutation guardrails for the inactive Phase-1.0V collector model."""
|
|
|
|
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("phase10v_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_phase10v.py")
|
|
record = validator.load_json(
|
|
root / "manifests/retroarch/phase-1.0v-inactive-shsrv-collector.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 authorization is rejected")
|
|
def _():
|
|
value = dict(record["authorizations"]); value["ps5_connection_authorized"] = True
|
|
require(not validator.all_authorizations_false(value), "connection allowed")
|
|
|
|
@case("03 automatic retry is rejected")
|
|
def _():
|
|
value = dict(record["authorizations"]); value["automatic_retry"] = True
|
|
require(not validator.all_authorizations_false(value), "retry allowed")
|
|
|
|
@case("04 activation remains inert")
|
|
def _(): require(validator.activation_is_inactive(record["activation"]), "activation rejected")
|
|
|
|
@case("05 target address activates and fails gate")
|
|
def _():
|
|
value = dict(record["activation"]); value["target_address"] = "example.invalid"
|
|
require(not validator.activation_is_inactive(value), "target accepted")
|
|
|
|
@case("06 command activation fails gate")
|
|
def _():
|
|
value = dict(record["activation"]); value["commands"] = ["help"]
|
|
require(not validator.activation_is_inactive(value), "command accepted")
|
|
|
|
@case("07 model has no network transport")
|
|
def _(): require(validator.model_is_offline(record["model"]), "model rejected")
|
|
|
|
@case("08 live port argument remains absent")
|
|
def _(): require(record["model"]["port_argument_present"] is False, "port present")
|
|
|
|
@case("09 collector bounds are exact")
|
|
def _(): require(validator.bounds_are_fail_closed(record["bounds"]), "bounds rejected")
|
|
|
|
@case("10 oversized bound relaxation fails")
|
|
def _():
|
|
value = dict(record["bounds"]); value["max_raw_bytes"] = 131072
|
|
require(not validator.bounds_are_fail_closed(value), "larger input accepted")
|
|
|
|
@case("11 Telnet model remains offline and partial")
|
|
def _(): require(validator.telnet_is_offline_partial(record["telnet_model"]), "Telnet boundary rejected")
|
|
|
|
@case("12 invented negotiation replies fail")
|
|
def _():
|
|
value = dict(record["telnet_model"]); value["negotiation_replies_sent"] = True
|
|
require(not validator.telnet_is_offline_partial(value), "reply behavior invented")
|
|
|
|
@case("13 sanitization is strict")
|
|
def _(): require(validator.sanitization_is_strict(record["sanitization"]), "sanitization rejected")
|
|
|
|
@case("14 raw transcript output fails")
|
|
def _():
|
|
value = dict(record["sanitization"]); value["raw_transcript_output"] = True
|
|
require(not validator.sanitization_is_strict(value), "raw transcript allowed")
|
|
|
|
@case("15 physical memory erasure remains unproven")
|
|
def _(): require(record["sanitization"]["physical_memory_erasure_proven"] is False, "erasure invented")
|
|
|
|
@case("16 exact identity remains false")
|
|
def _(): require(record["sanitization"]["exact_identity_output"] is False, "identity promoted")
|
|
|
|
@case("17 decision requires human review and no live client")
|
|
def _(): require(validator.decision_requires_review(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 model 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.0V guardrails passed: {len(cases)}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|