#!/usr/bin/env python3 """Native development acceptance: kill a preparing maintenance controller before activation.""" import argparse import json import os from pathlib import Path import subprocess import sys import uuid ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT / 'tools')) import windows_update_scope as scope def child(case): original = scope.remote_server def interrupt(action, data): if action == 'read' and data.get('helper_policy_sha256'): row = original(action, data) if scope.scoped(data, row) and row['sync_head']['helper_id']: evidence = {'case_id': case, 'killed_before_activation': True, 'server_time': row['install']['contact'], 'sync_head': row['sync_head'], 'sync_ready': row['install']['ready'], 'helper_sync_ready': row['install']['helper_ready'], 'open_jobs': row['open_jobs']} path = ROOT / 'devstate/windows-update-windows' / (case + '-fault.json') scope.atomic(path, scope.encode(evidence)) scope.emit(evidence) os._exit(85) return row scope.require(action != 'enable', 'Fault boundary missed') return original(action, data) scope.remote_server = interrupt sys.argv = [scope.__file__, 'window', '--case', case, '--minutes', '15'] scope.local() def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--execute', action='store_true', help='Run against the actual development Windows enrollment') parser.add_argument('--child', type=scope.identifier, help=argparse.SUPPRESS) args = parser.parse_args() if args.child: child(args.child) return if not args.execute: parser.print_help() return case = str(uuid.uuid4()) scope.emit({'native_abort_test':case}) state = ROOT / 'devstate/windows-update-windows' try: stopped = subprocess.run([sys.executable, __file__, '--child', case]) scope.require(stopped.returncode == 85, 'Controller did not stop at the expected fault boundary') finally: if (state / (case + '.json')).is_file(): subprocess.run([sys.executable, scope.__file__, 'close', '--case', case], check=True) scope.emit({'verified_early_abort_recovery':case}) if __name__ == '__main__': main()