This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
#!/usr/bin/env python3
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""Mutation guardrails for the inactive Phase-1.0N runner record."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import copy
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
|
||||
def load(path: Path):
|
||||
spec = importlib.util.spec_from_file_location("phase10n", 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_phase10n.py")
|
||||
record = validator.load_json(root / "manifests/retroarch/phase-1.0n-write-free-one-shot-runner.json")
|
||||
approval = validator.load_json(root / "manifests/retroarch/phase-1.0n-one-shot-approval-template.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_false(record["authorizations"], validator.AUTHORIZATION_FIELDS), "authorization active")
|
||||
|
||||
@case("02 connection authorization fails")
|
||||
def _():
|
||||
value = dict(record["authorizations"]); value["ps5_connection_authorized"] = True
|
||||
require(not validator.all_false(value, validator.AUTHORIZATION_FIELDS), "connection accepted")
|
||||
|
||||
@case("03 no target or device action occurred")
|
||||
def _(): require(validator.all_false(record["phase_actions"], validator.ACTION_FIELDS), "action recorded")
|
||||
|
||||
@case("04 artifact remains exact and ineligible")
|
||||
def _(): require(validator.artifact_is_ineligible(record["artifact"]), "artifact rejected")
|
||||
|
||||
@case("05 execution eligibility fails")
|
||||
def _():
|
||||
value = dict(record["artifact"]); value["execution_eligible"] = True
|
||||
require(not validator.artifact_is_ineligible(value), "eligible artifact accepted")
|
||||
|
||||
@case("06 changed artifact hash fails")
|
||||
def _():
|
||||
value = dict(record["artifact"]); value["sha256"] = "0" * 64
|
||||
require(not validator.artifact_is_ineligible(value), "changed hash accepted")
|
||||
|
||||
@case("07 protocol is exact and inactive")
|
||||
def _(): require(validator.protocol_is_exact_and_inactive(record["result_protocol"]), "protocol rejected")
|
||||
|
||||
@case("08 phase K protocol label fails")
|
||||
def _():
|
||||
value = dict(record["result_protocol"]); value["name"] = "PHASE_1_0K_WRITE_DIAG"
|
||||
require(not validator.protocol_is_exact_and_inactive(value), "K label accepted")
|
||||
|
||||
@case("09 alphabetical D13 placement fails")
|
||||
def _():
|
||||
value = copy.deepcopy(record["result_protocol"]); value["wire_stages"][-2:] = ["D13", "C1"]
|
||||
require(not validator.protocol_is_exact_and_inactive(value), "wrong table accepted")
|
||||
|
||||
@case("10 tracked target fails")
|
||||
def _():
|
||||
value = dict(record["result_protocol"]); value["tracked_target"] = "TEST-NET"
|
||||
require(not validator.protocol_is_exact_and_inactive(value), "tracked target accepted")
|
||||
|
||||
@case("11 protocol activation fails")
|
||||
def _():
|
||||
value = dict(record["result_protocol"]); value["protocol_activation_authorized"] = True
|
||||
require(not validator.protocol_is_exact_and_inactive(value), "activation accepted")
|
||||
|
||||
@case("12 runner is fail closed")
|
||||
def _(): require(validator.runner_is_fail_closed(record["runner"]), "runner rejected")
|
||||
|
||||
@case("13 changed runner hash fails")
|
||||
def _():
|
||||
value = dict(record["runner"]); value["source_sha256"] = "0" * 64
|
||||
require(not validator.runner_is_fail_closed(value), "changed runner accepted")
|
||||
|
||||
@case("14 free protocol selector fails")
|
||||
def _():
|
||||
value = dict(record["runner"]); value["free_protocol_selector"] = True
|
||||
require(not validator.runner_is_fail_closed(value), "free selector accepted")
|
||||
|
||||
@case("15 retry fails")
|
||||
def _():
|
||||
value = dict(record["runner"]); value["retry"] = True
|
||||
require(not validator.runner_is_fail_closed(value), "retry accepted")
|
||||
|
||||
@case("16 multiple connections fail")
|
||||
def _():
|
||||
value = dict(record["runner"]); value["maximum_connections"] = 2
|
||||
require(not validator.runner_is_fail_closed(value), "multiple connections accepted")
|
||||
|
||||
@case("17 approval template is inactive")
|
||||
def _(): require(validator.approval_is_inactive(approval), "approval rejected")
|
||||
|
||||
@case("18 activated approval fails")
|
||||
def _():
|
||||
value = dict(approval); value["authorized"] = True
|
||||
require(not validator.approval_is_inactive(value), "active approval accepted")
|
||||
|
||||
@case("19 Phase K scope fails")
|
||||
def _():
|
||||
value = dict(approval); value["authorization_scope"] = "EXACT_ONE_SHOT_PHASE_1_0K"
|
||||
require(not validator.approval_is_inactive(value), "consumed K scope accepted")
|
||||
|
||||
@case("20 host tests are not hardware evidence")
|
||||
def _(): require(record["tests"]["hardware_evidence_from_phase10n"] is False, "hardware proof invented")
|
||||
|
||||
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.0N guardrails passed: {len(cases)}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user