Skip to content

[duplicate-code] refactor(cli): deduplicate logs render option construction - #75992

Merged
pelikhan merged 2 commits into
mainfrom
refactor/dedupe-logs-render-options-ca8b6d83f36337be
Nov 8, 2026
Merged

pelikhan merged 2 commits into
mainfrom
refactor/dedupe-logs-render-options-ca8b6d83f36337be

Conversation

@github-actions

@github-actions github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

🔍 Duplicate Code Detected: renderLogsOutputOptions construction in logs rendering

Implementation: Extracted newRenderLogsOutputOptions(opts LogsDownloadOptions, artifactFilter []string) in pkg/cli/logs_orchestrator_types.go. Both call sites now call it and set only their path-specific fields. Behavior is intended to be unchanged.

Summary

Two discovery-mode rendering paths each built a ~25-line renderLogsOutputOptions literal. 13 of those fields were copied one-for-one from LogsDownloadOptions.

Duplication Details
  • Severity: Medium
  • Occurrences: 2 (about 13 identical field mappings each)
  • Locations:
    • pkg/cli/logs_orchestrator.go renderCollectedWorkflowLogs
    • pkg/cli/logs_multi.go DownloadWorkflowLogsForTargets
  • Shared fields: outputDir, summaryFile, format, reportFile, jsonOutput, episodes, toolGraph, train, drain3Weights, audit, verbose, artifactFilter, includeWorkQueue
  • DownloadWorkflowLogsFromStdin in pkg/cli/logs_orchestrator_stdin.go has a similar literal. It takes StdinLogsOptions, a different type, so it was left alone.

Impact Analysis

  • Maintainability: Adding a logs output flag previously meant editing each literal in step.
  • Bug risk: A field forgotten in one path would silently change that path's output.
  • Code bloat: Net -4 lines (+46/-50); the repeated mappings now live in one helper.

Validation

  • gofmt -l pkg/cli: clean.
  • Serena (gopls) diagnostics on the three changed files: no errors. The only message is a pre-existing errors.As hint in logs_multi.go, unrelated to this change. The diagnostics also caught a type mismatch in my first attempt to use the helper from the stdin path, and I reverted that part.
  • Field-by-field comparison of the old and new literals shows every field is still set.
  • Not run: go build, go vet and go test ./pkg/cli could not run in the analysis sandbox. Module downloads from proxy.golang.org failed with a TLS certificate error. Please let CI run make test-unit, particularly the logs_* tests.
Analysis Metadata
  • Detection Method: Serena semantic analysis plus a normalized sliding-window duplicate scan over pkg/**/*.go (non-test)
  • Commit: ccff033

Generated by 🔍 Duplicate Code Detector · pi · routed: sonnet55 high · ~31 AIC · ⌖ ~2 AIC · ⊞ 7.2K · ◷

  • expires on Nov 10, 2026, 1:57 PM UTC-08:00

@github-actions github-actions Bot added automated-analysis code-quality cookie Issue Monster Loves Cookies! labels Nov 8, 2026
@pelikhan
pelikhan marked this pull request as ready for review November 8, 2026 22:08
Copilot AI adaptive review requested due to automatic review settings November 8, 2026 22:08
@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ PR Specification Reviewer completed successfully!

PR Specification Reviewer

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from PR Specification Reviewer · gpt56 · ~1 AIC · ⌖ ~1 AIC · ◇ ~1 AIC · ⊞ 1.7K · ◷

Generated by PR Specification Reviewer for #75992

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor Author

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Test Quality Sentinel · routed: haiku55 xhigh · ~2 AIC · ⌖ ~2 AIC · ◇ ~1 AIC · ⊞ 7.2K · ◷

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Ponytail Reviewer completed successfully!

Generated by Ponytail Reviewer for #75992

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft.

Design Decision Gate 🏗️

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Design Decision Gate 🏗️ · routed: haiku55 xhigh · ~1 AIC · ⌖ ~2 AIC · ◇ ~1 AIC · ⊞ 8.6K · ◷

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What this change does: It shares the common rendering options between single-target and multi-target log downloads. The callers still set their result-specific values.

One small duplication remains in the shared discovery-mode options; see the inline comment.

Verdict: Ship.
Lean: -5 lines possible.

Generated by ✂️ Ponytail Reviewer for #75992 · codex · routed: gpt61 medium · ~5 AIC · ⌖ ~1 AIC · ⊞ 181
Comment /ponytail to run again

Comment thread pkg/cli/logs_multi.go
outcomeReports: outcomeReports,
})
renderOpts := newRenderLogsOutputOptions(opts, artifactFilter)
renderOpts.startDate = opts.StartDate

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should fix: Both discovery paths repeat startDate, endDate, checkStaleness, suppressRender, and cachedJSONLWriter; set these five values in newRenderLogsOutputOptions and remove both sets of assignments so future changes only need one edit (about 5 fewer lines).

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the three changed files and the refactor preserves the previous field mappings and path-specific behavior. No actionable correctness, performance, or maintainability issues found in the changed lines. The grumpy-coder specialist completed its pass; its suggestions were non-blocking and did not identify a regression.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~2 AIC · ⌖ ~1 AIC · ⊞ 1.6K
Comment /review to run again

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain, and the change consistently centralizes shared render-option construction while preserving path-specific behavior.

No open issues 🎉

What changed in this PR

This pull request deduplicates shared renderLogsOutputOptions construction across single-target and multi-target discovery log rendering while preserving path-specific behavior.

Changes:

  • Added newRenderLogsOutputOptions to centralize shared option mapping.
  • Updated single-target and multi-target rendering paths to use the helper.
  • Left stdin rendering unchanged because it uses a different options type.
File Description
pkg/​cli/​logs_orchestrator.go Uses the shared helper for single-target discovery rendering.
pkg/​cli/​logs_orchestrator_types.go Defines the shared render-option construction helper.
pkg/​cli/​logs_multi.go Uses the shared helper for multi-target rendering.

Review effort: Lite (auto)

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skills-Based Review 🧠

Applied /codebase-design and /tdd. Verdict: the refactor is behavior-preserving, but the shared helper is only partly shared.

📋 Key Themes & Highlights

Verification run

  • gofmt -l on the three changed files: clean.
  • go vet ./pkg/cli/: clean.
  • go test ./pkg/cli/ -run Logs|logs|RenderLogs: passes. The PR could not run these, so this closes that gap.
  • All 22 renderLogsOutputOptions fields are still set on both paths.

Key themes

  • Half-extracted helper: startDate, endDate, checkStaleness, suppressRender, and cachedJSONLWriter are still repeated at both call sites. The doc comment on the helper calls the date range path-specific, but both callers set it the same way.
  • No direct test: the helper that now holds the mapping has no unit test, so a dropped field would only surface through indirect tests.

Positive highlights

  • ✅ Good use of a constructor that takes the options struct and returns a value, so callers keep control of path-specific fields.
  • ✅ Net -4 lines and a single place to add future output flags.
  • ✅ The PR describes its own validation gaps honestly.

@copilot please address the review comments above.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~3 AIC · ⌖ ~2 AIC · ⊞ 6.3K
Comment /matt to run again

// fields shared by the discovery-mode logs rendering paths (single-target and
// multi-target). Callers set the path-specific fields (continuations, rate limits,
// date range, etc.) on the returned value.
func newRenderLogsOutputOptions(opts LogsDownloadOptions, artifactFilter []string) renderLogsOutputOptions {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/codebase-design] This helper is meant to hold the fields shared by the discovery-mode render paths, but startDate, endDate, checkStaleness, suppressRender, and cachedJSONLWriter are set identically at both call sites (logs_orchestrator.go lines 355-362 and logs_multi.go lines 313-323). Those mappings are still duplicated. The doc comment also calls the date range path-specific, which the code contradicts.

💡 Suggested change

Move those five fields into newRenderLogsOutputOptions, with checkStaleness: true set there too. That matches the struct comment, which says checkStaleness is for discovery-mode only. apiRateLimit and outcomeReports are also identical at both sites, so they can move too if the helper takes them as parameters. Callers would then set only continuation/continuations, countLimitReached, countLimitTargets, and apiRateLimits.

@copilot please address this.

audit: opts.Audit,
verbose: opts.Verbose,
artifactFilter: artifactFilter,
includeWorkQueue: workQueueEvidenceRequested(opts.ArtifactSets),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/tdd] Nothing tests newRenderLogsOutputOptions directly. The PR names the main risk itself: a field forgotten on one path would silently change that path output. The helper now centralizes that mapping, but nothing checks it.

💡 Suggested test

Add a unit test that sets a distinct non-zero value on every copied LogsDownloadOptions field, calls newRenderLogsOutputOptions, and asserts each matching renderLogsOutputOptions field. Use Arrange, Act, Assert, and name it as a spec, for example TestNewRenderLogsOutputOptionsCopiesSharedFields. This catches a mapping that gets dropped or mis-wired in future edits.

@copilot please address this.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot

Copilot assignment requested for the following outstanding work:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.
  2. Fix failing check impacted-go-tests (FAILURE): https://github.com/github/gh-aw/actions/runs/42528717144/job/128878077856.

Once you start work, post this work summary as a PR comment without the leading Copilot mention, including the Sous-chef head, work, and state lines below, to record that the assignment is running. Apply the necessary fixes on this PR's existing branch, reply to each listed review thread and resolve it when addressed. Ignore feedback already answered or resolved; stop when only human review or CI remains. Do not merge or trigger CI.

Sous-chef requested-head: 7bac19b
Sous-chef requested-work: 42e5d572d9d75b7168fe7d0aeda0717cc07e65ed240f6d299e6fec661214f1ac
Sous-chef requested-state: a4ba22dd9cf86de4d41304285a676b5fd0b5bb6658a5c154b0d83b82cce08120

Generated by 👨🍳 PR Sous Chef · pi · haiku45 · ~11 AIC · ⌖ ~12 AIC · ⊞ 1.2K · ◷
Comment /souschef to run again

Copilot AI commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

@copilot

Copilot assignment requested for the following outstanding work:...

Assignment running:

  1. Update this branch with the latest main using make merge-main, resolving conflicts and preserving the intended changes.
  2. Investigate and fix failing check impacted-go-tests: https://github.com/github/gh-aw/actions/runs/42528717144/job/128878077856.

Sous-chef requested-head: 7bac19b
Sous-chef requested-work: 42e5d572d9d75b7168fe7d0aeda0717cc07e65ed240f6d299e6fec661214f1ac
Sous-chef requested-state: a4ba22dd9cf86de4d41304285a676b5fd0b5bb6658a5c154b0d83b82cce08120

I will not merge the PR or trigger CI.

…render-options-ca8b6d83f36337be

Co-authored-by: gh-aw-bot <[email protected]>
Copilot AI requested a review from gh-aw-bot November 8, 2026 23:06
@pelikhan
pelikhan merged commit b757b53 into main Nov 8, 2026
46 checks passed
@pelikhan
pelikhan deleted the refactor/dedupe-logs-render-options-ca8b6d83f36337be branch November 8, 2026 23:41
@github-actions

Copy link
Copy Markdown
Contributor Author

🎉 This pull request is included in a new release.

Release: v1.2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants