"""Verify cancellation through the real native Harness stdin/stdout protocol.""" import json from time import monotonic from uuid import uuid4 from verify_dsh_blocker_recovery import NativeDiagnosis, REPO def main(): root = REPO / 'build' / ('dsh-native-cancel-' + uuid4().hex[:8]) native = NativeDiagnosis(root) report = {'status': 'failed', 'driver': 'real native Harness', 'remoteIssueWrites': 0} try: assert native.events.get(timeout=180)['status'] == 'ready', 'native_runtime_not_ready' request_id = uuid4().hex request = {'type': 'diagnose', 'request_id': request_id, 'incident_id': uuid4().hex[:24], 'phase': 'diagnose', 'snapshot': {'task_id': '', 'issue_code': 'operation_stalled'}, 'evidence': 'Controlled cancellation acceptance; no engineering mutation is permitted.'} native.process.stdin.write(json.dumps(request) + '\n') native.process.stdin.flush() started = native.events.get(timeout=90) assert started.get('request_id') == request_id and started['status'] == 'started' before = monotonic() native.process.stdin.write(json.dumps({'type': 'diagnose_cancel', 'request_id': request_id}) + '\n') native.process.stdin.flush() terminal = native.events.get(timeout=15) assert terminal.get('request_id') == request_id and terminal['status'] == 'cancelled' assert terminal['error'] == 'diagnosis_cancelled' report.update(status='passed', cancellation_seconds=round(monotonic() - before, 3), terminal_status=terminal['status'], session_created=bool(started.get('session_id'))) except Exception as error: report['error_type'] = type(error).__name__ raise finally: native.close() root.mkdir(parents=True, exist_ok=True) (root / 'report.json').write_text(json.dumps(report, indent=2), encoding='utf8') print(json.dumps(report)) if __name__ == '__main__': main()