Refactor logs.go: Extract models and cache into separate files #6094
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The 1,620-line
pkg/cli/logs.gomixed type definitions, constants, caching, fetching, processing, and presentation logic in a single file, hindering maintainability and testing.Changes
Extracted
pkg/cli/logs_models.go(212 lines)WorkflowRun,ProcessedRun,RunSummary,MissingToolSummary,MCPFailureSummary,DownloadResult,JobInfo,JobInfoWithDuration,AwInfo,AwInfoStepsdefaultAgentStdioLogPath,runSummaryFileName,defaultLogsOutputDir,MaxIterations,BatchSize,BatchSizeForAllWorkflows,MaxConcurrentDownloadsisFailureConclusion()Extracted
pkg/cli/logs_cache.go(77 lines)loadRunSummary(): Loads cached summaries with CLI version validationsaveRunSummary(): Persists run summaries to diskReduced
pkg/cli/logs.go: 1,620 → 1,339 lines (17% reduction)Result
Clear separation of data models and caching from business logic. Remaining
logs.gostill contains ~1,300 lines that could be further split into fetch, command, presentation, and processing modules.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
https://api.github.com/user/usr/bin/gh gh api user --jq .login up-uv.git g/parser/import_error_test.go e/git GOINSECURE GOMOD GOMODCACHE e/git env f/tags/v6 om/org1/repo1(http block)/usr/bin/gh gh api user --jq .login 35/parse_firewall_logs.js GO111MODULE /opt/hostedtoolcache/go/1.25.0/x64/bin/go GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE e/git GOINSECURE GOMOD GOMODCACHE e/git(http block)/usr/bin/gh gh api user --jq .login it/ref/tags/v5 GO111MODULE f0a6d99496d0465e88d2e773e418b6c5e58/log.json GOINSECURE GOMOD GOMODCACHE /bin/sh -c echo "��� All validations passed" GOPROXY e/git-remote-https GOSUMDB GOWORK g/workflow/node_moby e/git-remote-htt-address(http block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
This section details on the original issue you should resolve
<issue_title>[file-diet] Refactor Large Go File: pkg/cli/logs.go</issue_title>
<issue_description>## Overview
The file
pkg/cli/logs.gohas grown to 1,620 lines, making it difficult to maintain and test. This task involves refactoring it into smaller, focused files with improved structure and targeted test coverage.Current State
pkg/cli/logs.gopkg/cli/logs_test.go)DownloadWorkflowLogsandlistWorkflowRunsWithPaginationcouples pagination, filtering, and progress UI, making changes risky.Refactoring Strategy
Proposed File Splits
logs_command.goNewLogsCommand, flag/arg parsing, workflow name resolution, relative date resolution, engine validation.logs_processing.goDownloadWorkflowLogs, continuation data assembly, count limiting, timeout handling, filter application, cache hit handling orchestration.logs_fetch.golistWorkflowRunsWithPagination,fetchJobStatuses,fetchJobDetails,getAgenticWorkflowNames,contains.logs_presentation.godisplayLogsOverview, rendering helpers invoked byrenderLogsConsole/renderLogsJSON/tool graph generation pathways, plus aggregation helpers (cost/token totals, missing tool and noop displays).logs_models.goWorkflowRun,ProcessedRun,RunSummary,MissingToolSummary,MCPFailureSummary, related constants (paths, defaults).Shared Utilities
loadRunSummary,saveRunSummary, run summary path helpers) into a focused module (e.g.,logs_cache.go) reused by processing and download flows.Interface Abstractions
RunFetcherwrapping the GitHub CLI call) to decouple pagination/filtering from GH CLI invocation for easier testing/mocking.RunProcessororArtifactProcessor) to separate download/parsing from CLI command orchestration and enable targeted unit tests without network calls.Test Coverage Plan
Add or adjust tests to preserve coverage with the new modules:
logs_command_test.gologs_processing_test.gologs_fetch_test.gologs_presentation_test.gologs_models_test.goRunSummarydefaults and constants, ensuring version mismatch invalidates cache.Implementation Guidelines
make test-unitpasses after each splitAcceptance Criteria
make test-unit)✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.