"""Read-only checks for expected stop and resource-unknown protection states.""" from .verification_closed_loop import require def verify_stopped(service, run, *, unstarted): errors = [] for member in run['members']: attempt = service.repo.attempt(member['attempt_id']) row = service.read_item(member['item_id']) try: require(attempt['state'] not in ('queued','running','publishing','stopping','interrupted'), '停止后仍有活动尝试') require(attempt['resource_state']=='released', '停止后的资源退出未确认') if member['attempt_id'] in unstarted: require(attempt['state']=='cancelled' and attempt['reason']=='run_stopped_before_dispatch' and row['status']=='waiting', '未派发项没有保持待校验') if attempt['state']=='cancelled' and member['attempt_id'] not in unstarted: require(row['status']=='stopped', '已开始项取消未显示已停止') except ValueError as error: errors.append(str(error)) return {'passed':not errors, 'errors':errors, 'unstarted':sorted(unstarted)} def verify_unknown(service, attempt_id, *, expected_attempts): from dx_productivity.trial_task_center.verification.runner import can_start_native_export errors = [] try: attempt = service.repo.attempt(attempt_id) row = service.read_item(attempt['item_id']) require(attempt['state']=='stopping' and attempt['resource_state']=='unknown', '没有保留资源未知状态') require(row['status'] not in ('consistent','warning','different'), '未知资源被显示成有效结论') require(not can_start_native_export(service)['allowed'], '未知资源仍允许派发') count=service.repo.connection.execute('SELECT COUNT(*) FROM verification_attempts').fetchone()[0] require(count==expected_attempts, '重启后创建了额外尝试') except ValueError as error: errors.append(str(error)) return {'passed':not errors, 'errors':errors}