run method

  1. @override
Future<StepOutcome> run(
  1. TreeContext context,
  2. StepArgs args
)

Runs the capability body, resolving to its outcome. The host maps the outcome to a cursor write through the chokepoint. Read ambient values from context at entry; after every await, check StepArgs.cancel before touching the context again.

Implementation

@override
Future<StepOutcome> run(TreeContext context, StepArgs args) async {
  final E2eOrder? order = _order(context);
  final SiblingView siblings = _siblings(context);
  if (order == null) {
    return const Failed('leonard-e2e inspect: no complete E2E order');
  }
  final String circuitPath = parentPath(args.nodePath);
  final Map<String, String> launch = siblings.resultOf(
    '$circuitPath/$kE2eLaunchStep',
  );
  final Map<String, String> run = siblings.resultOf(
    '$circuitPath/$kE2eRunStep',
  );
  final String deviceId = launch[kE2eDeviceResultKey] ?? '';
  final String trajectoryPath = run[kE2eTrajectoryResultKey] ?? '';
  final int? driverStatus = int.tryParse(
    run[kE2eDriverStatusResultKey] ?? '',
  );
  if (deviceId.isEmpty || trajectoryPath.isEmpty || driverStatus == null) {
    return const Failed(
      'leonard-e2e inspect: prior phases published an incomplete receipt',
    );
  }

  E2eVerdict verdict;
  try {
    verdict = await service.inspect(
      order.request,
      E2eRunReceipt(
        trajectoryPath: trajectoryPath,
        driverExitStatus: driverStatus,
        stdout: '',
        stderr: '',
      ),
      deviceId: deviceId,
    );
  } on Object catch (error) {
    verdict = E2eVerdict.failed(
      code: E2eFailureCode.unexpected,
      model: order.request.model,
      device: deviceId,
      durationMilliseconds: 0,
      trajectoryPath: trajectoryPath,
      driverExitStatus: driverStatus,
      evidence: <String, Object?>{'message': '$error'},
    );
  }
  if (args.cancel.isCancelled) return const Failed('cancelled');
  final String json = jsonEncode(verdict.toJson());
  return verdict.passed
      ? Ok(<String, String>{kE2eVerdictJsonResultKey: json})
      : Failed(json);
}