120 lines
4.7 KiB
Python
120 lines
4.7 KiB
Python
#!/usr/bin/env python3
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
"""Mutation guardrails for the consumed Phase-1.0K device result."""
|
|
|
|
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("phase10l", 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_phase10l.py")
|
|
record = validator.load_json(
|
|
root / "manifests/retroarch/phase-1.0l-write-firewall-result-analysis.json"
|
|
)
|
|
cases = []
|
|
|
|
def case(name):
|
|
def register(function):
|
|
cases.append((name, function))
|
|
return function
|
|
return register
|
|
|
|
@case("01 protocol result is exact")
|
|
def _(): require(validator.result_is_exact(record["protocol_result"]), "result rejected")
|
|
|
|
@case("02 OPEN cannot replace observed MKDIR")
|
|
def _():
|
|
value = dict(record["protocol_result"]); value["raw_results"] = dict(value["raw_results"]); value["raw_results"]["D13_first_blocked_write"] = 1
|
|
require(not validator.result_is_exact(value), "invented OPEN accepted")
|
|
|
|
@case("03 write count must remain one")
|
|
def _():
|
|
value = dict(record["protocol_result"]); value["raw_results"] = dict(value["raw_results"]); value["raw_results"]["D13_write_block_count"] = 2
|
|
require(not validator.result_is_exact(value), "invented second write accepted")
|
|
|
|
@case("04 I04 cannot be invented")
|
|
def _():
|
|
value = dict(record["protocol_result"]); value["stages"] = list(value["stages"]); value["stages"].insert(-2, "I04"); value["frame_count"] = 10
|
|
require(not validator.result_is_exact(value), "invented I04 accepted")
|
|
|
|
@case("05 transport is exact one shot")
|
|
def _(): require(validator.transport_is_one_shot(record["transport"]), "transport rejected")
|
|
|
|
@case("06 retry fails")
|
|
def _():
|
|
value = dict(record["transport"]); value["retry_count"] = 1
|
|
require(not validator.transport_is_one_shot(value), "retry accepted")
|
|
|
|
@case("07 reconnect fails")
|
|
def _():
|
|
value = dict(record["transport"]); value["reconnect_count"] = 1
|
|
require(not validator.transport_is_one_shot(value), "reconnect accepted")
|
|
|
|
@case("08 all current authorizations are false")
|
|
def _(): require(validator.all_false(record["current_authorizations"], validator.AUTHORIZATION_FIELDS), "authority active")
|
|
|
|
@case("09 future execution authority fails")
|
|
def _():
|
|
value = dict(record["current_authorizations"]); value["device_execution_authorized"] = True
|
|
require(not validator.all_false(value, validator.AUTHORIZATION_FIELDS), "authority accepted")
|
|
|
|
@case("10 authorization is consumed")
|
|
def _(): require(record["authorization"]["consumed"] is True and record["authorization"]["authority_inherited_by_future_action"] is False, "authority reusable")
|
|
|
|
@case("11 source binding remains bounded")
|
|
def _(): require(validator.source_binding_is_bounded(record["source_binding"]), "source binding rejected")
|
|
|
|
@case("12 runtime path remains unobserved")
|
|
def _(): require(record["source_binding"]["runtime_path"] == "UNOBSERVED", "runtime path invented")
|
|
|
|
@case("13 SDL remains not reached")
|
|
def _(): require(record["source_binding"]["sdl_video"] == "NOT_REACHED", "SDL invented")
|
|
|
|
@case("14 cleanup remains unproven")
|
|
def _(): require(record["source_binding"]["complete_cleanup"] == "UNPROVEN", "cleanup invented")
|
|
|
|
@case("15 next candidate preserves firewall")
|
|
def _(): require(record["next_offline_candidate"]["preserve_global_write_firewall"] is True, "firewall weakened")
|
|
|
|
@case("16 next target build remains unauthorized")
|
|
def _(): require(record["next_offline_candidate"]["target_build_authorized"] is False and record["next_offline_candidate"]["device_action_authorized"] is False, "new authority 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.0L result guardrails passed: {len(cases)}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|