Repository navigation
Fix activation snapshots for symlinked agent configuration #80390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
72a2a5b
26406ec
053eefb
6118e84
e618556
c1e1ce8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -251,10 +251,18 @@ func (cm *CheckoutManager) checkoutManifestEntries() ([]checkoutManifestEntry, [ | |
| // | ||
| // Returns a slice of YAML lines (each ending with \n). | ||
| func (cm *CheckoutManager) GenerateGitHubFolderCheckoutStep(repository, ref, token string, getActionPin func(string) string, extraPaths ...string) []string { | ||
| return cm.generateActivationCheckoutStep(repository, ref, token, getActionPin, false, extraPaths...) | ||
| } | ||
|
|
||
| func (cm *CheckoutManager) generateActivationCheckoutStep(repository, ref, token string, getActionPin func(string) string, fullCheckout bool, extraPaths ...string) []string { | ||
| checkoutManagerLog.Printf("Generating .github/.agents folder checkout: repository=%q ref=%q", repository, ref) | ||
| var sb strings.Builder | ||
|
|
||
| sb.WriteString(" - name: Checkout .github and .agents folders\n") | ||
| if fullCheckout { | ||
| sb.WriteString(" - name: Checkout repository for base branch snapshot\n") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in e618556: the activation checkout has a distinct name. The pre-step and checkout optimization tests pass.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/diagnosing-bugs] This PR changes compiler output for every activation job, but none of the 370 committed 💡 VerificationI compiled all workflows on this head and 370 tracked lock files changed. The PR touches no lock files, so the stored output is stale. @copilot please address this.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regenerated in e618556 and verified again after merging main in c1e1ce84. Full package validation is currently blocked by npm registry DNS; compilation without that external validation succeeded. |
||
| } else { | ||
| sb.WriteString(" - name: Checkout .github and .agents folders\n") | ||
| } | ||
| fmt.Fprintf(&sb, " uses: %s\n", getActionPin("actions/checkout")) | ||
| sb.WriteString(" with:\n") | ||
| sb.WriteString(" persist-credentials: false\n") | ||
|
|
@@ -267,13 +275,15 @@ func (cm *CheckoutManager) GenerateGitHubFolderCheckoutStep(repository, ref, tok | |
| if token != "" && token != "${{ secrets.GITHUB_TOKEN }}" { | ||
| fmt.Fprintf(&sb, " token: %s\n", token) | ||
| } | ||
| sb.WriteString(" sparse-checkout: |\n") | ||
| sb.WriteString(" .github\n") | ||
| sb.WriteString(" .agents\n") | ||
| for _, p := range extraPaths { | ||
| fmt.Fprintf(&sb, " %s\n", p) | ||
| if !fullCheckout { | ||
| sb.WriteString(" sparse-checkout: |\n") | ||
| sb.WriteString(" .github\n") | ||
| sb.WriteString(" .agents\n") | ||
| for _, p := range extraPaths { | ||
| fmt.Fprintf(&sb, " %s\n", p) | ||
| } | ||
| sb.WriteString(" sparse-checkout-cone-mode: true\n") | ||
| } | ||
| sb.WriteString(" sparse-checkout-cone-mode: true\n") | ||
| sb.WriteString(" fetch-depth: 1\n") | ||
|
|
||
| return []string{sb.String()} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ package workflow | |
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
|
|
@@ -65,8 +66,8 @@ strict: false | |
| // validateDangerousPermissions), but safe-outputs such as create-pull-request require | ||
| // contents: write in their own downstream job. This case verifies that even when the | ||
| // workflow needs write-capable safe-outputs, the activation job itself still only | ||
| // performs the sparse .github checkout - it never checks out the full repository. | ||
| name: "workflow with write-capable safe-outputs still has no full checkout in activation", | ||
| // uses a read-only activation checkout. | ||
| name: "workflow with write-capable safe-outputs uses read-only activation checkout", | ||
| frontmatter: `--- | ||
| on: | ||
| issues: | ||
|
|
@@ -113,20 +114,11 @@ safe-outputs: | |
| activationJobSection := extractJobSection(lockContentStr, "activation") | ||
| require.NotEmpty(t, activationJobSection, "Activation job section should not be empty") | ||
|
|
||
| // The activation job always sparse-checks-out .github/.agents (and, in dev mode, | ||
| // actions/setup) so it can load helper scripts and engine config - this is | ||
| // unaffected by the workflow's permissions or triggers (including contents: write, | ||
| // via write-capable safe-outputs). What must never happen is a full checkout of | ||
| // the repository, or a checkout of .github/workflows for timestamp checking - | ||
| // that always uses the GitHub API instead. | ||
|
|
||
| // Verify the activation checkout is the sparse .github/.agents checkout | ||
| assert.Contains(t, activationJobSection, "name: Checkout .github and .agents folders", "Should use the sparse .github/.agents checkout step") | ||
| assert.Contains(t, activationJobSection, "sparse-checkout: |", "Sparse checkout should be configured") | ||
| assert.Contains(t, activationJobSection, "sparse-checkout-cone-mode: true", "Sparse checkout cone mode should be enabled") | ||
|
|
||
| // Verify it does NOT perform a full repository checkout | ||
| assert.NotContains(t, activationJobSection, "name: Checkout repository", "Should not have a full repository checkout step") | ||
| // The trusted snapshot needs the complete base tree to resolve symlink targets. | ||
| require.Contains(t, activationJobSection, "name: Checkout repository for base branch snapshot") | ||
| checkout := strings.SplitN(strings.SplitN(activationJobSection, "name: Checkout repository for base branch snapshot", 2)[1], "\n - name:", 2)[0] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/tdd] Splitting the job text on the step-name marker and the next Parse the activation job YAML and select the step by its name instead. @copilot please address this.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in e618556: the test parses the workflow YAML and selects the activation step by name. |
||
| assert.NotContains(t, checkout, "sparse-checkout:") | ||
| assert.Contains(t, checkout, "persist-credentials: false") | ||
|
|
||
| // Verify it does NOT checkout .github/workflows for timestamp checking | ||
| assert.NotContains(t, activationJobSection, "Checkout workflows", "Should not have 'Checkout workflows' step - uses GitHub API for timestamp checking") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -386,12 +386,12 @@ func (c *Compiler) generateResolveHostRepoStep(data *WorkflowData) string { | |
| return step.String() | ||
| } | ||
|
|
||
| // generateCheckoutGitHubFolderForActivation generates the checkout step for .github and .agents folders | ||
| // specifically for the activation job. Unlike generateCheckoutGitHubFolder, this method doesn't skip | ||
| // generateCheckoutGitHubFolderForActivation generates the activation checkout. | ||
| // Unlike generateCheckoutGitHubFolder, this method doesn't skip | ||
| // the checkout when the agent job will have a full repository checkout, because the activation job | ||
| // runs before the agent job and needs independent access to workflow files for runtime imports during | ||
| // prompt generation. | ||
| func (c *Compiler) generateCheckoutGitHubFolderForActivation(data *WorkflowData) []string { | ||
| func (c *Compiler) generateCheckoutGitHubFolderForActivation(data *WorkflowData, fullCheckout bool) []string { | ||
| // Check if action-tag is specified - if so, skip checkout | ||
| if activationCheckoutDisabledByActionTag(data) { | ||
| compilerActivationJobLog.Print("Skipping .github checkout in activation: action-tag specified") | ||
|
|
@@ -426,11 +426,12 @@ func (c *Compiler) generateCheckoutGitHubFolderForActivation(data *WorkflowData) | |
| } else if prCheckoutRef := activationCheckoutRef(data, "steps.resolve-host-repo.outputs.target_checkout_ref"); prCheckoutRef != "" { | ||
| checkoutRef = prCheckoutRef | ||
| } | ||
| checkoutSteps := cm.GenerateGitHubFolderCheckoutStep( | ||
| checkoutSteps := cm.generateActivationCheckoutStep( | ||
| cm.GetCrossRepoTargetRepo(), | ||
| checkoutRef, | ||
| activationToken, | ||
| c.getActionPin, | ||
| fullCheckout, | ||
| extraPaths..., | ||
| ) | ||
| // When no custom token is configured, GITHUB_TOKEN is scoped to the calling | ||
|
|
@@ -446,19 +447,16 @@ func (c *Compiler) generateCheckoutGitHubFolderForActivation(data *WorkflowData) | |
| return checkoutSteps | ||
| } | ||
|
|
||
| // For activation job, sparse checkout .github, .agents, and engine-specific config directories | ||
| // (plus actions/setup in dev mode). Root instruction files are excluded as they are not needed | ||
| // during activation. sparse-checkout-cone-mode: true ensures subdirectories are recursively included. | ||
| compilerActivationJobLog.Print("Adding .github, .agents, and engine-specific dirs to sparse checkout for activation job") | ||
| return cm.GenerateGitHubFolderCheckoutStep("", activationCheckoutRef(data, "github.sha"), activationToken, c.getActionPin, extraPaths...) | ||
| compilerActivationJobLog.Printf("Adding activation checkout: full=%t", fullCheckout) | ||
| return cm.generateActivationCheckoutStep("", activationCheckoutRef(data, "github.sha"), activationToken, c.getActionPin, fullCheckout, extraPaths...) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/codebase-design] 💡 Suggested fixEither route symlink-bearing configs through the full checkout, or extend the scan to every symlink under the sparse-checked folders. If activation never reads those targets on this path, document that in the comment. @copilot please address this.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in e618556: sparse checkout scans nested symlinks in configuration and extra paths, with repository confinement and regression coverage. |
||
| } | ||
|
|
||
| func needsActivationHostRepoCheckout(data *WorkflowData) bool { | ||
| return data != nil && hasWorkflowCallTrigger(data.On) && (!data.InlinedImports || (data.EngineConfig != nil && data.EngineConfig.CopilotSDK)) | ||
| } | ||
|
|
||
| // activationCheckoutDisabledByActionTag reports whether action-tag supplies setup | ||
| // assets outside the workspace, making the activation sparse checkout unnecessary. | ||
| // assets outside the workspace, making the activation checkout unnecessary. | ||
| func activationCheckoutDisabledByActionTag(data *WorkflowData) bool { | ||
| if data == nil || data.Features == nil { | ||
| return false | ||
|
|
@@ -506,7 +504,7 @@ func (c *Compiler) activationSparseCheckoutExtraPaths(data *WorkflowData) []stri | |
| return resolveSymlinkExtraPaths(repoRoot, extraPaths) | ||
| } | ||
|
|
||
| // activationCheckoutRef returns the ref expression for activation sparse checkout. | ||
| // activationCheckoutRef returns the ref expression for activation checkout. | ||
| // It returns an empty string when the workflow has no pull-request event whose payload | ||
| // includes a pull request. fallbackExpression must be a raw GitHub Actions expression | ||
| // without a ${{ }} wrapper. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[/tdd] This test drives only
save_base_github_folders.sh, and this PR does not change that script. It would also pass against the base commit, so it does not guard the Go checkout change. The Go testTestActivationSnapshotCheckoutIncludesSymlinkTargetsis the real regression test.💡 Suggested fix
Remove this test, or rename it so it reads as a save-script behavior spec and does not claim to cover checkout ordering.
@copilot please address this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in e618556: the shell test is named as a save-and-restore behavior test; checkout regression coverage remains in the Go test.