Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/cli/logs_orchestrator_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ func appendProcessedWorkflowRuns(
if shouldSkipProcessedWorkflowRun(result, opts.verbose) || applyRunFilters(activeCtx, result, opts.filters, opts.verbose) {
continue
}
processedRun := buildProcessedRun(result, opts.verbose, true)
processedRun := buildProcessedRun(activeCtx, result, opts.verbose, true)
parseWorkflowRunArtifacts(result, processedRun, opts.parse, opts.verbose)
processedRuns = append(processedRuns, processedRun)
batchProcessed++
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/logs_orchestrator_filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func applyRunFilters(ctx context.Context, result DownloadResult, opts runFilterO

// buildProcessedRun constructs a ProcessedRun from a DownloadResult, computing
// duration, action minutes, effective tokens, and job-failure counts.
func buildProcessedRun(result DownloadResult, verbose, logFailedJobs bool) ProcessedRun {
func buildProcessedRun(ctx context.Context, result DownloadResult, verbose, logFailedJobs bool) ProcessedRun {
run := result.Run
run.TokenUsage = result.Metrics.TokenUsage
applyMetricsTurnsToRun(&run, result.Metrics)
Expand All @@ -164,7 +164,7 @@ func buildProcessedRun(result DownloadResult, verbose, logFailedJobs bool) Proce
}

// Add failed jobs to error count.
if failedJobCount, err := fetchJobStatusesForProcessedRun(context.Background(), run.DatabaseID, verbose); err == nil {
if failedJobCount, err := fetchJobStatusesForProcessedRun(ctx, run.DatabaseID, verbose); err == nil {
run.ErrorCount += failedJobCount
if verbose && logFailedJobs && failedJobCount > 0 {
fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("Added %d failed jobs to error count for run %d", failedJobCount, run.DatabaseID)))
Expand Down
19 changes: 12 additions & 7 deletions pkg/cli/logs_orchestrator_filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func TestBuildProcessedRun(t *testing.T) {
AwContext: awCtx,
}

pr := buildProcessedRun(result, false, false)
pr := buildProcessedRun(context.Background(), result, false, false)

assert.Equal(t, int64(1234), pr.Run.DatabaseID)
assert.Equal(t, tmpDir, pr.Run.LogsPath)
Expand All @@ -246,7 +246,7 @@ func TestBuildProcessedRun(t *testing.T) {
LogsPath: t.TempDir(),
}

pr := buildProcessedRun(result, false, false)
pr := buildProcessedRun(context.Background(), result, false, false)

assert.Equal(t, 90*time.Second, pr.Run.Duration)
assert.InDelta(t, 2.0, pr.Run.ActionMinutes, 0.001) // ceil(1.5) = 2
Expand All @@ -258,7 +258,7 @@ func TestBuildProcessedRun(t *testing.T) {
Run: WorkflowRun{DatabaseID: 7},
LogsPath: t.TempDir(),
}
pr := buildProcessedRun(result, false, false)
pr := buildProcessedRun(context.Background(), result, false, false)
assert.Equal(t, time.Duration(0), pr.Run.Duration)
assert.InDelta(t, 0.0, pr.Run.ActionMinutes, 0.001)
})
Expand All @@ -271,7 +271,7 @@ func TestBuildProcessedRun(t *testing.T) {
LogsPath: t.TempDir(),
TokenUsage: usage,
}
pr := buildProcessedRun(result, false, false)
pr := buildProcessedRun(context.Background(), result, false, false)
assert.Equal(t, 5000, pr.Run.EffectiveTokens)
})

Expand All @@ -283,22 +283,27 @@ func TestBuildProcessedRun(t *testing.T) {
LogsPath: t.TempDir(),
TokenUsage: usage,
}
pr := buildProcessedRun(result, false, false)
pr := buildProcessedRun(context.Background(), result, false, false)
assert.Equal(t, 0, pr.Run.EffectiveTokens)
})

t.Run("failed job count is added via test seam", func(t *testing.T) {
stubFetchJobStatusesForProcessedRun(t, func(_ context.Context, runID int64, verbose bool) (int, error) {
type ctxKey string
const key ctxKey = "request-id"
ctx := context.WithValue(context.Background(), key, "abc123")

stubFetchJobStatusesForProcessedRun(t, func(fetchCtx context.Context, runID int64, verbose bool) (int, error) {
assert.Equal(t, int64(88), runID)
assert.False(t, verbose)
assert.Equal(t, "abc123", fetchCtx.Value(key))
return 2, nil
})
result := DownloadResult{
Run: WorkflowRun{DatabaseID: 88},
LogsPath: t.TempDir(),
}

pr := buildProcessedRun(result, false, false)
pr := buildProcessedRun(ctx, result, false, false)

assert.Equal(t, 2, pr.Run.ErrorCount)
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/logs_orchestrator_stdin.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func DownloadWorkflowLogsFromStdin(ctx context.Context, opts StdinLogsOptions) e
continue
}

processedRun := buildProcessedRun(result, opts.Verbose, false)
processedRun := buildProcessedRun(ctx, result, opts.Verbose, false)

if opts.Parse {
awInfoPath := filepath.Join(result.LogsPath, "aw_info.json")
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/update_extension_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const backupCleanupRetryDelay = 300 * time.Millisecond
// baked in. The caller should re-launch the freshly-installed binary (at
// installPath) so that subsequent work (e.g. lock-file compilation) uses the
// correct new version string.
func upgradeExtensionIfOutdated(verbose bool, includePrereleases bool) (bool, string, error) {
func upgradeExtensionIfOutdated(ctx context.Context, verbose bool, includePrereleases bool) (bool, string, error) {
currentVersion := GetVersion()
updateExtensionCheckLog.Printf("Checking if extension needs upgrade (current: %s)", currentVersion)

Expand All @@ -60,7 +60,7 @@ func upgradeExtensionIfOutdated(verbose bool, includePrereleases bool) (bool, st
}

// Query GitHub API for latest release
latestVersion, err := getLatestRelease(context.Background(), includePrereleases)
latestVersion, err := getLatestRelease(ctx, includePrereleases)
if err != nil {
// Fail silently - don't block the upgrade command if we can't reach GitHub
updateExtensionCheckLog.Printf("Failed to check for latest release (silently ignoring): %v", err)
Expand Down
5 changes: 3 additions & 2 deletions pkg/cli/update_extension_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package cli

import (
"bytes"
"context"
"errors"
"os"
"path/filepath"
Expand All @@ -27,7 +28,7 @@ func TestUpgradeExtensionIfOutdated_DevBuild(t *testing.T) {
// Verify the function exits before making any API calls.
// If it did make API calls we'd see a network error in test environments,
// but the function must return (false, "", nil) immediately.
upgraded, installPath, err := upgradeExtensionIfOutdated(false, false)
upgraded, installPath, err := upgradeExtensionIfOutdated(context.Background(), false, false)
require.NoError(t, err, "Should not return error for dev builds")
assert.False(t, upgraded, "Should not report upgrade for dev builds")
assert.Empty(t, installPath, "installPath should be empty for dev builds")
Expand All @@ -44,7 +45,7 @@ func TestUpgradeExtensionIfOutdated_SilentFailureOnAPIError(t *testing.T) {
// Use a release version so the API call is attempted
SetVersionInfo("v0.1.0")

upgraded, installPath, err := upgradeExtensionIfOutdated(false, false)
upgraded, installPath, err := upgradeExtensionIfOutdated(context.Background(), false, false)
require.NoError(t, err, "Should fail silently on API errors")
assert.False(t, upgraded, "Should not report upgrade when API is unreachable")
assert.Empty(t, installPath, "installPath should be empty when API is unreachable")
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/upgrade_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func runUpgradeCommand(opts upgradeOptions) error {
// prevents the re-launched process from entering this branch again.
if !opts.skipExtensionUpgrade {
fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Checking gh-aw extension version..."))
upgraded, installPath, err := upgradeExtensionIfOutdated(opts.verbose, opts.preReleases)
upgraded, installPath, err := upgradeExtensionIfOutdated(opts.ctx, opts.verbose, opts.preReleases)
if err != nil {
upgradeLog.Printf("Extension upgrade failed: %v", err)
return err
Expand Down
Loading