enqueueResult function

void enqueueResult(
  1. ReporterState? state,
  2. PendingResult? item
)

Resolves the result's pending attachments and buffers it for upload.

With an upload pool armed the work runs there, so the test never waits on a blob; endReporting drains the pool before the final flush. A result that is never reported hands its blob bodies back instead of holding the bytes.

Implementation

void enqueueResult(ReporterState? state, PendingResult? item) {
  if (item == null || item.ctx == null) return;
  item.payload ??= snapshotPayload(item.ctx);

  final session = state?.session;
  final buffer = state?.buffer;
  if (state == null ||
      state.softDisabled ||
      session == null ||
      buffer == null ||
      (item.ctx?.testCaseId ?? 0) <= 0) {
    discardPendingBlobs(item.payload);
    return;
  }

  Future<void> report() async {
    if (!session.reportingEnabled) {
      discardPendingBlobs(item.payload);
      return;
    }
    if (!await resolveResultAttachments(session, item.payload!)) return;
    buffer.enqueue(item);
  }

  final pool = state.uploadPool;
  if (pool == null) {
    // No pool: the caller owns the wait. Fire it and let the final flush
    // pick the result up — errors inside report() are handled by the session.
    unawaited(report());
    return;
  }
  pool.enqueue(report);
}