fromEnvironment static method

RunnerExecutionContext? fromEnvironment(
  1. Map<String, String> environment
)

Implementation

static RunnerExecutionContext? fromEnvironment(
  Map<String, String> environment,
) {
  const keys = [
    'ZUKE_RESULT_DIR',
    'ZUKE_PROFILE',
    'ZUKE_TARGET',
    'ZUKE_RUNNER_ID',
    'ZUKE_RUNNER_COMPATIBILITY_ID',
    'ZUKE_SOURCE_PACKAGE',
    'ZUKE_SOURCE_ADAPTER',
    'ZUKE_SOURCE_COMPATIBILITY_ID',
  ];
  // Presence, rather than non-empty value, determines whether execution is
  // managed. An explicitly exported empty variable is still a partial
  // managed context and must fail closed instead of silently becoming an
  // ordinary unmanaged test.
  if (!keys.any(environment.containsKey)) return null;

  String required(String key) {
    final value = environment[key];
    if (value == null || value.trim().isEmpty) {
      throw FormatException(
        'Managed runner context is incomplete; missing $key',
      );
    }
    return value;
  }

  return RunnerExecutionContext(
    resultDirectory: required('ZUKE_RESULT_DIR'),
    profile: required('ZUKE_PROFILE'),
    target: required('ZUKE_TARGET'),
    runnerId: required('ZUKE_RUNNER_ID'),
    runnerCompatibilityId: required('ZUKE_RUNNER_COMPATIBILITY_ID'),
    sourceIdentity: ExecutionSourceIdentity(
      sourcePackage: required('ZUKE_SOURCE_PACKAGE'),
      sourceAdapter: required('ZUKE_SOURCE_ADAPTER'),
      sourceCompatibilityId: required('ZUKE_SOURCE_COMPATIBILITY_ID'),
    ),
  );
}