"""``obliteratus experiments sequence plan|run|resume|rollback|show``.""" import json def _component(text): kind, _, rest = text.partition(":") run, sep, ident = rest.partition("@") if kind not in ("candidate", "registration") or not sep: raise ValueError(f"Component {text!r}: use candidate:@ or " "registration:@") return {"run": run, kind: ident} def add_sequence(commands): parser = commands.add_parser( "sequence", help="Transactional two-step edit sequences of verified candidates or " "persistent-pilot eligible registrations") sub = parser.add_subparsers(dest="sequence_command", required=True) plan = sub.add_parser("plan", help="Admit and freeze an ordered pair (first, then second)") plan.add_argument("first", help="candidate:@ or registration:@") plan.add_argument("second", help="candidate:@ or registration:@") plan.add_argument("--store", required=True, help="Directory holding sequences/") plan.add_argument("--source", required=True, help="Selected reference model directory") plan.add_argument("--interaction", required=True, help="Interaction result.json that measured this ordered pair") plan.add_argument("--pack", required=True, help="Evaluation dataset pack") plan.add_argument("--revision", required=True, help="Evaluation dataset revision") plan.add_argument("--role", required=True, choices=("select", "calibrate", "test")) plan.add_argument("--allow-locked-test", action="store_true") plan.add_argument("--tolerances", help="JSON object: target_rate, agreement, logit_atol") plan.add_argument("--allow-fixture-results", action="store_true", help="Count software-contract results for registration components; " "testing only") plan.add_argument("--actor") for name, text in (("run", "Execute a planned sequence"), ("resume", "Continue an interrupted sequence from its last verified step")): command = sub.add_parser(name, help=text) command.add_argument("sequence", help="Sequence id (sha256:...)") command.add_argument("--store", required=True) command.add_argument("--actor") back = sub.add_parser("rollback", help="Restore the reference or a verified step into a new " "directory and test it") back.add_argument("sequence") back.add_argument("--store", required=True) back.add_argument("--to", required=True, help="'reference' or a step position") back.add_argument("--dest", required=True, help="New directory for the restored artifact") back.add_argument("--actor") show = sub.add_parser("show", help="One sequence, or every sequence of a store") show.add_argument("sequence", nargs="?") show.add_argument("--store", required=True) def run_sequence_command(args): from obliteratus.experiments.inputs import default_pack_resolver from obliteratus.experiments.sequence_run import run_sequence, show if args.sequence_command == "plan": from obliteratus.experiments.sequence import plan_sequence dataset = {"pack": args.pack, "revision": args.revision, "role": args.role, "allow_locked_test": args.allow_locked_test} plan = plan_sequence(args.store, [_component(args.first), _component(args.second)], args.source, args.interaction, dataset, tolerances=json.loads(args.tolerances) if args.tolerances else None, allow_fixture_results=args.allow_fixture_results, actor=args.actor) return {"id": plan["id"], "location": plan["location"], "scope": plan["frozen"]["scope"], "interaction": plan["frozen"]["interaction"]} if args.sequence_command in ("run", "resume"): found = run_sequence(args.store, args.sequence, pack_resolver=default_pack_resolver, resume=args.sequence_command == "resume", actor=args.actor) return {"id": found["plan"]["id"], "state": found["state"], "steps": [{k: s[k] for k in ("position", "outcome", "checks")} for s in found["steps"]]} if args.sequence_command == "rollback": from obliteratus.experiments.sequence_rollback import rollback return rollback(args.store, args.sequence, args.to, args.dest, pack_resolver=default_pack_resolver, actor=args.actor) return show(args.store, args.sequence) __all__ = ["add_sequence", "run_sequence_command"]