shareJunnyISpectRequestWithPolicyForTesting function

  1. @visibleForTesting
Future<void> shareJunnyISpectRequestWithPolicyForTesting({
  1. ISpectShareRequest? request,
  2. required JunnyISpectLogConfig logConfig,
  3. required ISpectShareCallback onShare,
  4. List<ISpectLogData>? logs,
  5. ISpectMetadata? metadata,
  6. JunnyISpectLogFileSharer? shareFile,
})

按 dev_kit 运行时策略处理 ISpect 分享请求。

ISpect 内置导出面板会在内容生成阶段固定执行一次默认脱敏。 因此 raw 模式不能复用 request 中的附件,而要重新从当前 history 生成 JSON;非 raw 模式则继续使用 productionSafe 安全副本,保持普通分享入口默认安全。

Implementation

@visibleForTesting
Future<void> shareJunnyISpectRequestWithPolicyForTesting({
  ISpectShareRequest? request,
  required JunnyISpectLogConfig logConfig,
  required ISpectShareCallback onShare,
  List<ISpectLogData>? logs,
  ISpectMetadata? metadata,
  JunnyISpectLogFileSharer? shareFile,
}) async {
  final bool shouldExportRawPayload =
      logConfig.payloadVisibility == JunnyISpectPayloadVisibility.rawPayload;
  if (shouldExportRawPayload) {
    final List<ISpectLogData> effectiveLogs = logs ?? ISpect.logger.history;
    if (effectiveLogs.isEmpty) {
      if (request == null) {
        return;
      }
      // 没有可重新导出的 history 时不能伪造 raw 文件;此时退回安全分享,
      // 避免把上游可能已脱敏或来源不明的附件误标成原始日志。
      final ISpectShareRequest safeRequest =
          await sanitizeJunnyISpectShareRequest(
        request,
        logConfig: logConfig,
      );
      await onShare(safeRequest);
      return;
    }

    // 上游附件可能已经被脱敏;raw 模式必须以当前 history 为数据源重新导出。
    await shareJunnyISpectLogFileForTesting(
      logs: effectiveLogs,
      metadata: _buildRawPayloadExportMetadata(metadata),
      shareFile: shareFile,
      fileName: 'ispect_raw_logs',
      onShare: onShare,
    );
    return;
  }

  // 非 raw 模式保留 productionSafe 兜底,避免详细日志被普通分享路径带出应用。
  if (request != null && (request.hasFiles || logs == null)) {
    final ISpectShareRequest safeRequest =
        await sanitizeJunnyISpectShareRequest(
      request,
      logConfig: logConfig,
    );
    await onShare(safeRequest);
    return;
  }

  await shareJunnyISpectLogFileForTesting(
    logs: logs,
    metadata: metadata,
    shareFile: shareFile,
    onShare: (ISpectShareRequest generatedRequest) async {
      final ISpectShareRequest safeRequest =
          await sanitizeJunnyISpectShareRequest(
        generatedRequest,
        logConfig: logConfig,
      );
      await onShare(safeRequest);
    },
  );
}