Skip to content

fix: trial command missing remote dependency fetching for imports#23165

Open
dsyme wants to merge 7 commits intomainfrom
fix/trial-fetch-remote-imports
Open

fix: trial command missing remote dependency fetching for imports#23165
dsyme wants to merge 7 commits intomainfrom
fix/trial-fetch-remote-imports

Conversation

@dsyme
Copy link
Collaborator

@dsyme dsyme commented Mar 26, 2026

githubnext/agentics#266

Problem

gh aw trial fails with import file not found errors when the workflow uses frontmatter imports: (e.g. shared/formatting.md), while the equivalent gh aw add works fine.

✗ .github/workflows/code-simplifier.md:22:5: error: import file not found
21 | imports:
22 |   - shared/formatting.md
         ^^^^^^^^^^^^^^^^^^^^

Root Cause

installWorkflowInTrialMode in trial_repository.go only called fetchAndSaveRemoteIncludes (for @include directives in the markdown body) but was missing three other dependency fetchers that AddWorkflows in add_command.go called:

  • fetchAndSaveRemoteFrontmatterImports — frontmatter imports: field
  • fetchAndSaveRemoteDispatchWorkflowssafe-outputs.dispatch-workflow references
  • fetchAndSaveRemoteResourcesresources: frontmatter field

Fix

Extract a shared fetchAllRemoteDependencies() function in includes.go that both add_command.go and trial_repository.go now call. This ensures parity between the two code paths and prevents future drift when new dependency types are added.

Changes

  • pkg/cli/includes.go: New fetchAllRemoteDependencies() function
  • pkg/cli/add_command.go: Replaced inline dependency fetching with shared function
  • pkg/cli/trial_repository.go: Replaced incomplete dependency fetching with shared function


✨ PR Review Safe Output Test - Run 23617381060

💥 [THE END] — Illustrated by Smoke Claude ·

dsyme and others added 5 commits March 26, 2026 19:25
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…spatch workflows, and resources

The trial command only called fetchAndSaveRemoteIncludes but not
fetchAndSaveRemoteFrontmatterImports, fetchAndSaveRemoteDispatchWorkflows,
or fetchAndSaveRemoteResources. This caused 'import file not found'
errors when running 'gh aw trial' with workflows that use frontmatter
imports (e.g. shared/formatting.md), while 'gh aw add' worked fine.

Extract a shared fetchAllRemoteDependencies function in includes.go
that both add_command.go and trial_repository.go now call, ensuring
parity and preventing future drift.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes gh aw trial failing with import file not found for workflows that use frontmatter imports: by aligning trial-mode dependency fetching with the add command’s behavior.

Changes:

  • Added a shared fetchAllRemoteDependencies() helper to fetch includes, frontmatter imports, dispatch-workflow references, and resources.
  • Updated add to call the shared helper instead of duplicating dependency-fetch logic inline.
  • Updated trial install flow to call the shared helper so remote workflows fetch the same dependency types as add.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
pkg/cli/includes.go Introduces fetchAllRemoteDependencies() to centralize remote dependency fetching.
pkg/cli/add_command.go Replaces inline dependency-fetch calls with fetchAllRemoteDependencies().
pkg/cli/trial_repository.go Uses fetchAllRemoteDependencies() in trial installs to prevent dependency-fetch drift.
actions/setup/js/extra_empty_commit.cjs Improves logging for git fetch/reset failures by including the underlying error.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +153 to 155
const syncErrorMessage = error instanceof Error ? error.message : String(error);
core.warning(`Could not sync local branch with remote ${branchName} - will attempt push with local HEAD. Underlying error: ${syncErrorMessage}`);
}
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

The warning logs the underlying git fetch/reset error message while the temporary remote URL contains the auth token (https://x-access-token:@...). Some git/exec errors can include the remote URL or other sensitive output, which would risk leaking the token into Actions logs. Please redact the token/remote URL from the error before logging, or avoid logging the raw error message here (e.g., log a generic warning and only include sanitized details).

Copilot uses AI. Check for mistakes.
Comment on lines +446 to +455
// fetchAllRemoteDependencies fetches all remote dependencies for a workflow:
// includes (@include directives), frontmatter imports, dispatch workflows, and resources.
// This is the single entry point shared by both the add and trial commands.
func fetchAllRemoteDependencies(ctx context.Context, content string, spec *WorkflowSpec, targetDir string, verbose bool, force bool, tracker *FileTracker) error {
// Fetch and save @include directive dependencies
if err := fetchAndSaveRemoteIncludes(content, spec, targetDir, verbose, force, tracker); err != nil {
if verbose {
fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Failed to fetch include dependencies: %v", err)))
}
}
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

The docstring says this function “fetches all remote dependencies”, but the implementation intentionally swallows errors from includes and frontmatter imports (only emitting a warning when verbose). This mismatch can confuse callers (e.g., trial wraps the returned error as if all dependency fetch failures would surface). Either update the comment/name to make the best-effort semantics explicit, or change the function to propagate/aggregate include/import errors when they occur.

Copilot uses AI. Check for mistakes.
dsyme and others added 2 commits March 26, 2026 20:24
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
The test was timing out at 10s default. Increase to 30s to handle
slow API responses.
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

💥 Automated smoke test review - all systems nominal!

💥 [THE END] — Illustrated by Smoke Claude

fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Failed to fetch resource dependencies: %v", err)))
}
return fmt.Errorf("failed to fetch resource dependencies: %w", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This function provides a clean, unified entry point for all remote dependency fetching. Smoke test review comment — Run 23617381060.

if err := fetchAllRemoteDependencies(ctx, string(content), parsedSpec, result.WorkflowsDir, opts.Verbose, true, nil); err != nil {
return fmt.Errorf("failed to fetch remote dependencies: %w", err)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Good refactor — using fetchAllRemoteDependencies here ensures trial mode stays in sync with add command parity. Smoke test review comment — Run 23617381060.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

Hey @dsyme 👋 — great catch on the gh aw trial / gh aw add parity gap! The root cause analysis is clear, the fetchAllRemoteDependencies refactor is clean, and the PR description is excellent. A couple of things would help get this across the finish line:

  • Add tests for fetchAllRemoteDependencies — the new shared function in pkg/cli/includes.go has no unit-test coverage yet. The codebase has rich test patterns nearby (pkg/cli/imports_test.go, pkg/cli/trial_command_test.go, pkg/cli/add_integration_test.go) that show how to stub out HTTP fetches and assert on error propagation. In particular, the error-wrapping branches for fetchAndSaveRemoteDispatchWorkflows and fetchAndSaveRemoteResources (the two that now return err) and the soft-fail paths for includes/frontmatter imports should all be covered. A regression test that exercises installWorkflowInTrialMode with a workflow that uses imports: frontmatter would directly prove the original bug is fixed.

  • Split the unrelated JS changes — the tweaks in actions/setup/js/extra_empty_commit.cjs (error object capture + core.warning) and actions/setup/js/frontmatter_hash_github_api.test.cjs (timeout annotation) are unrelated to the trial-import fix. They're small but they make the diff harder to reason about. Consider landing them in a separate PR so reviewers can focus on the Go CLI change.

If you'd like a hand, you can assign this prompt to your coding agent:

Add tests for the new `fetchAllRemoteDependencies` function introduced in `pkg/cli/includes.go`.

Follow the test patterns in `pkg/cli/imports_test.go` and `pkg/cli/trial_command_test.go`.

1. Create `pkg/cli/fetch_all_remote_dependencies_test.go` with the following cases:
   a. All sub-fetchers succeed → `fetchAllRemoteDependencies` returns nil.
   b. `fetchAndSaveRemoteDispatchWorkflows` returns an error → the error is wrapped as "failed to fetch dispatch workflow dependencies: ..." and returned.
   c. `fetchAndSaveRemoteResources` returns an error → the error is wrapped as "failed to fetch resource dependencies: ..." and returned.
   d. `fetchAndSaveRemoteIncludes` returns an error (non-fatal) → function continues and returns nil.
   e. `fetchAndSaveRemoteFrontmatterImports` returns an error (non-fatal) → function continues and returns nil.

2. In `pkg/cli/trial_command_test.go` (or a new `pkg/cli/trial_imports_test.go`), add a test that verifies `installWorkflowInTrialMode` correctly fetches a file listed under `imports:` frontmatter when the workflow is remote. This is the regression test for the original bug (import file not found during `gh aw trial`).

Run `make test` after writing the tests to verify they pass.

Generated by Contribution Check ·

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.

2 participants