Skip to content

[code-simplifier] Simplify duplicate alt-path blocks in fetch.go; fix add_command test broken by #20375#20410

Merged
pelikhan merged 1 commit intomainfrom
code-simplifier/fetch-alt-path-loop-26ad9280ebb54098
Mar 10, 2026
Merged

[code-simplifier] Simplify duplicate alt-path blocks in fetch.go; fix add_command test broken by #20375#20410
pelikhan merged 1 commit intomainfrom
code-simplifier/fetch-alt-path-loop-26ad9280ebb54098

Conversation

@github-actions
Copy link
Contributor

This PR simplifies recently modified code (from §22919210941) to improve clarity and fix a broken test.

Files Changed

Improvements Made

1. Reduced Duplication in fetch.go

fetchRemoteWorkflow had two near-identical blocks for retrying a short workflow name under common directory prefixes (workflows/ and .github/workflows/). Both blocks performed the same steps: build the alt path, ensure .md suffix, log, attempt download, return on success. The only difference was the prefix string.

Consolidated into a single loop over []string{"workflows/", ".github/workflows/"}, reducing ~25 lines to ~13 with no behavioral change:

// Before: two separate identical blocks
altPath := "workflows/" + spec.WorkflowPath
...
if altContent, altErr := parser.DownloadFileFromGitHub(...); altErr == nil { return ... }

altPath = ".github/workflows/" + spec.WorkflowPath
...
if altContent, altErr := parser.DownloadFileFromGitHub(...); altErr == nil { return ... }

// After: one loop
for _, prefix := range []string{"workflows/", ".github/workflows/"} {
    altPath := prefix + spec.WorkflowPath
    ...
    if altContent, altErr := parser.DownloadFileFromGitHub(...); altErr == nil { return ... }
}

2. Fixed Broken Test in add_command_test.go

PR #20375 changed the add command's long description from "Add one or more workflows" to "Add one or more agentic workflows", but the corresponding test assertion was not updated. This caused TestNewAddCommand to fail on every run.

Changes Based On

Recent changes from:

Testing

  • TestNewAddCommand now passes
  • ✅ Build succeeds (make build)
  • go test ./pkg/cli/ passes
  • TestWasmGolden_CompileFixtures failures are pre-existing (unrelated to these changes)

References:

Generated by Code Simplifier ·

Warning

⚠️ Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • releaseassets.githubusercontent.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "releaseassets.githubusercontent.com"

See Network Configuration for more information.

  • expires on Mar 11, 2026, 7:09 PM UTC

…oop; fix add_command test broken by #20375

- pkg/cli/fetch.go: The fetchRemoteWorkflow function had two nearly identical
  blocks for trying fallback paths ("workflows/" and ".github/workflows/").
  Consolidate them into a single loop over candidate prefixes, removing ~12
  lines of duplicate code while preserving identical behavior.

- pkg/cli/add_command_test.go: TestNewAddCommand was asserting the old text
  "Add one or more workflows" which was changed to "Add one or more agentic
  workflows" by PR #20375. Update the assertion to match the new wording.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pelikhan pelikhan merged commit cf3969b into main Mar 10, 2026
@pelikhan pelikhan deleted the code-simplifier/fetch-alt-path-loop-26ad9280ebb54098 branch March 10, 2026 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant