Overview
The file pkg/cli/logs_orchestrator.go has grown to 1284 lines, making it difficult to maintain and test. It mixes orchestration logic, filter logic, type definitions, output rendering, and stdin-based processing into a single file. A significant portion of the run-filter and ProcessedRun-build logic is duplicated between DownloadWorkflowLogs and DownloadWorkflowLogsFromStdin.
Current State
- File:
pkg/cli/logs_orchestrator.go
- Size: 1284 lines
- Test Coverage:
pkg/cli/logs_orchestrator_test.go — 451 lines (~35% test-to-source ratio)
- Complexity: Two large public functions share nearly identical run-filter blocks (~150 lines each), plus a 600-line main loop in
DownloadWorkflowLogs
Full File Analysis
Function / Type Distribution
| Symbol |
Lines |
Domain |
DownloadWorkflowLogs |
~590 |
Core orchestration + pagination loop |
DownloadWorkflowLogsFromStdin |
~310 |
Stdin path — duplicates filter + build logic |
renderLogsOutput |
~130 |
Output rendering (console/JSON/markdown/TSV) |
renderLogsArtifactHint |
~6 |
Render helper |
LogsDownloadOptions |
~28 |
Type definition |
StdinLogsOptions |
~24 |
Type definition |
continuationOptions |
~10 |
Type definition |
renderLogsOutputOptions |
~13 |
Type definition |
buildContinuationIfNeeded |
~28 |
Pagination helper |
shouldStopPagination / selectPaginationCursorDate |
~12 |
Pagination helpers |
matchEngineFilter |
~6 |
Filter helper |
| Small utilities |
~40 |
parseFilterDate, noRunsMessage, isDeadlineExceeded, etc. |
Key Duplication Hotspot
Lines 506–687 (DownloadWorkflowLogs) and lines 1103–1259 (DownloadWorkflowLogsFromStdin) contain near-identical blocks for:
- Parsing
aw_info.json
- Filtering by engine, staged, firewall, safe-output type, DIFC integrity
- Building the
ProcessedRun struct from DownloadResult
Extracting these into a shared applyRunFilters + buildProcessedRun helper eliminates ~250 lines of duplication.
Refactoring Strategy
Proposed File Splits
-
logs_orchestrator_types.go
- Types:
LogsDownloadOptions, StdinLogsOptions, continuationOptions, renderLogsOutputOptions
- Responsibility: Pure type declarations with no logic
- Estimated LOC: ~80
-
logs_orchestrator_filters.go
- Functions:
matchEngineFilter, applyRunFilters (new — deduplicate filter logic), buildProcessedRun (new — deduplicate ProcessedRun construction)
- Responsibility: Decide whether a downloaded run should be included in results
- Estimated LOC: ~180
-
logs_orchestrator_render.go
- Functions:
renderLogsOutput, renderLogsArtifactHint
- Responsibility: Transform
[]ProcessedRun → console/JSON/markdown/TSV/pretty output
- Estimated LOC: ~160
-
logs_orchestrator_stdin.go
- Functions:
DownloadWorkflowLogsFromStdin
- Responsibility: Stdin-driven run discovery and processing path
- Estimated LOC: ~180 (after duplication is extracted)
-
logs_orchestrator.go (trimmed)
- Functions:
DownloadWorkflowLogs, pagination helpers (shouldStopPagination, selectPaginationCursorDate, buildContinuationIfNeeded), small utilities (isDeadlineExceeded, applyMetricsTurnsToRun, noRunsMessage, parseFilterDate, getMaxConcurrentDownloads)
- Responsibility: Primary entry point, pagination loop
- Estimated LOC: ~500
Shared Utilities to Extract
applyRunFilters(result DownloadResult, opts runFilterOpts, verbose bool) (skip bool) — replaces the repeated engine / staged / firewall / safe-output / DIFC filter blocks
buildProcessedRun(result DownloadResult) ProcessedRun — replaces the repeated ProcessedRun{...} struct literal construction
Interface Abstractions
Consider a runProcessor interface (or simple functional type) to unify the two download paths and reduce future drift between them.
Test Coverage Plan
New / Updated Test Files
-
logs_orchestrator_filters_test.go
- Test cases: engine filter match/miss/unknown, staged skip, firewall-only skip, no-firewall skip, safe-output-type filtering, DIFC filtering, combined filters
- Target coverage: >80%
-
logs_orchestrator_render_test.go
- Test cases: console format, JSON output, TSV output, markdown format, pretty format, report-file write, nil continuation, non-nil continuation
- Target coverage: >80%
-
logs_orchestrator_stdin_test.go
- Test cases: empty stdin, URL parse failure, metadata fetch failure, filter application, parse flag, JSON output
- Target coverage: >80%
-
logs_orchestrator_test.go (existing — update)
- Keep existing tests; add tests for
buildProcessedRun and applyRunFilters now that they are testable in isolation
Implementation Guidelines
- Preserve Behavior: Ensure all existing functionality works identically
- Maintain Exports: Keep public API unchanged (
DownloadWorkflowLogs, DownloadWorkflowLogsFromStdin, LogsDownloadOptions, StdinLogsOptions)
- Extract helpers first: Start with
applyRunFilters + buildProcessedRun to eliminate duplication before splitting files
- Incremental Changes: Split one module at a time; keep the build green at each step
- Run Tests Frequently: Verify
make test-unit passes after each split
- Update Imports: All new files are in the same
cli package — no import path changes needed
Acceptance Criteria
Additional Context
- Repository Guidelines: Follow patterns in
.github/agents/developer.instructions.agent.md
- Code Organization: Prefer many small files grouped by functionality (see
create_*.go pattern)
- Testing: Match existing test patterns in
pkg/cli/*_test.go
- Same package: All new files stay in
package cli — no import changes needed
Priority: Medium
Effort: Medium (~3–5 focused PRs)
Expected Impact: Eliminates ~250 lines of duplication, improves testability of filter logic, reduces cognitive load when navigating log orchestration code
Generated by 🧹 Daily File Diet · 60.7 AIC · ⌖ 19 AIC · ⊞ 6.8K · ◷
Overview
The file
pkg/cli/logs_orchestrator.gohas grown to 1284 lines, making it difficult to maintain and test. It mixes orchestration logic, filter logic, type definitions, output rendering, and stdin-based processing into a single file. A significant portion of the run-filter andProcessedRun-build logic is duplicated betweenDownloadWorkflowLogsandDownloadWorkflowLogsFromStdin.Current State
pkg/cli/logs_orchestrator.gopkg/cli/logs_orchestrator_test.go— 451 lines (~35% test-to-source ratio)DownloadWorkflowLogsFull File Analysis
Function / Type Distribution
DownloadWorkflowLogsDownloadWorkflowLogsFromStdinrenderLogsOutputrenderLogsArtifactHintLogsDownloadOptionsStdinLogsOptionscontinuationOptionsrenderLogsOutputOptionsbuildContinuationIfNeededshouldStopPagination/selectPaginationCursorDatematchEngineFilterparseFilterDate,noRunsMessage,isDeadlineExceeded, etc.Key Duplication Hotspot
Lines 506–687 (
DownloadWorkflowLogs) and lines 1103–1259 (DownloadWorkflowLogsFromStdin) contain near-identical blocks for:aw_info.jsonProcessedRunstruct fromDownloadResultExtracting these into a shared
applyRunFilters+buildProcessedRunhelper eliminates ~250 lines of duplication.Refactoring Strategy
Proposed File Splits
logs_orchestrator_types.goLogsDownloadOptions,StdinLogsOptions,continuationOptions,renderLogsOutputOptionslogs_orchestrator_filters.gomatchEngineFilter,applyRunFilters(new — deduplicate filter logic),buildProcessedRun(new — deduplicate ProcessedRun construction)logs_orchestrator_render.gorenderLogsOutput,renderLogsArtifactHint[]ProcessedRun→ console/JSON/markdown/TSV/pretty outputlogs_orchestrator_stdin.goDownloadWorkflowLogsFromStdinlogs_orchestrator.go(trimmed)DownloadWorkflowLogs, pagination helpers (shouldStopPagination,selectPaginationCursorDate,buildContinuationIfNeeded), small utilities (isDeadlineExceeded,applyMetricsTurnsToRun,noRunsMessage,parseFilterDate,getMaxConcurrentDownloads)Shared Utilities to Extract
applyRunFilters(result DownloadResult, opts runFilterOpts, verbose bool) (skip bool)— replaces the repeated engine / staged / firewall / safe-output / DIFC filter blocksbuildProcessedRun(result DownloadResult) ProcessedRun— replaces the repeatedProcessedRun{...}struct literal constructionInterface Abstractions
Consider a
runProcessorinterface (or simple functional type) to unify the two download paths and reduce future drift between them.Test Coverage Plan
New / Updated Test Files
logs_orchestrator_filters_test.gologs_orchestrator_render_test.gologs_orchestrator_stdin_test.gologs_orchestrator_test.go(existing — update)buildProcessedRunandapplyRunFiltersnow that they are testable in isolationImplementation Guidelines
DownloadWorkflowLogs,DownloadWorkflowLogsFromStdin,LogsDownloadOptions,StdinLogsOptions)applyRunFilters+buildProcessedRunto eliminate duplication before splitting filesmake test-unitpasses after each splitclipackage — no import path changes neededAcceptance Criteria
logs_orchestrator.gois split into 5 focused filesProcessedRunbuild logic is extracted into shared helpersmake test-unit)make lint)make build)Additional Context
.github/agents/developer.instructions.agent.mdcreate_*.gopattern)pkg/cli/*_test.gopackage cli— no import changes neededPriority: Medium
Effort: Medium (~3–5 focused PRs)
Expected Impact: Eliminates ~250 lines of duplication, improves testability of filter logic, reduces cognitive load when navigating log orchestration code