loadRunSummaryForDiff loads or builds a RunSummary for a given run for use in diffing. It first tries to load from a cached RunSummary (which includes MCP tool usage and run metrics); otherwise it downloads artifacts and analyzes firewall logs, returning a partial summary with only FirewallAnalysis
(ctx context.Context, runID int64, outputDir string, owner, repo, hostname string, verbose bool, artifactFilter []string)
| 920 | // summary with only FirewallAnalysis populated. |
| 921 | // artifactFilter restricts which artifacts are downloaded; nil means download all. |
| 922 | func loadRunSummaryForDiff(ctx context.Context, runID int64, outputDir string, owner, repo, hostname string, verbose bool, artifactFilter []string) (*RunSummary, error) { |
| 923 | auditDiffLog.Printf("Loading run summary for diff: run_id=%d, owner=%q, repo=%q, artifact_filter=%v", runID, owner, repo, artifactFilter) |
| 924 | runOutputDir := filepath.Join(outputDir, fmt.Sprintf("run-%d", runID)) |
| 925 | if absDir, err := filepath.Abs(runOutputDir); err == nil { |
| 926 | runOutputDir = absDir |
| 927 | } |
| 928 | |
| 929 | // Try cached summary first (full data including MCP tool usage, token usage, etc.) |
| 930 | if summary, ok := loadRunSummary(runOutputDir, verbose); ok { |
| 931 | auditDiffLog.Printf("Using cached run summary for run %d", runID) |
| 932 | return summary, nil |
| 933 | } |
| 934 | |
| 935 | // Download artifacts if needed |
| 936 | if err := downloadRunArtifacts(ctx, runID, runOutputDir, verbose, owner, repo, hostname, artifactFilter); err != nil { |
| 937 | if !errors.Is(err, ErrNoArtifacts) { |
| 938 | auditDiffLog.Printf("Failed to download artifacts for run %d: %v", runID, err) |
| 939 | return nil, fmt.Errorf("failed to download artifacts for run %d: %w", runID, err) |
| 940 | } |
| 941 | auditDiffLog.Printf("No artifacts found for run %d, proceeding with partial summary", runID) |
| 942 | } |
| 943 | |
| 944 | // Analyze firewall logs only when the agent artifact was included in the filter. |
| 945 | // Firewall audit logs are now included in the unified agent artifact. |
| 946 | // Skip silently when the artifact was intentionally excluded to avoid spurious warnings. |
| 947 | var analysis *FirewallAnalysis |
| 948 | if artifactMatchesFilter(constants.AgentArtifactName, artifactFilter) { |
| 949 | var err error |
| 950 | analysis, err = analyzeFirewallLogs(runOutputDir, verbose) |
| 951 | if err != nil { |
| 952 | return nil, fmt.Errorf("failed to analyze firewall logs for run %d: %w", runID, err) |
| 953 | } |
| 954 | } |
| 955 | |
| 956 | // Analyze GitHub API rate limit consumption |
| 957 | rateLimitUsage, err := analyzeGitHubRateLimits(runOutputDir, verbose) |
| 958 | if err != nil { |
| 959 | auditDiffLog.Printf("Failed to analyze GitHub rate limits for run %d: %v", runID, err) |
| 960 | // Non-fatal: proceed without rate limit data |
| 961 | } |
| 962 | |
| 963 | return &RunSummary{ |
| 964 | RunID: runID, |
| 965 | FirewallAnalysis: analysis, |
| 966 | GitHubRateLimitUsage: rateLimitUsage, |
| 967 | }, nil |
| 968 | } |
no test coverage detected