-
Notifications
You must be signed in to change notification settings - Fork 495
Improve test quality for activation checkout tests with testify #52698
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
Open
Copilot
wants to merge
6
commits into
main
Choose a base branch
from
copilot/testify-expert-improve-test-quality-again
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c971fa6
Initial plan
Copilot f46c394
Improve test quality for activation checkout tests with testify
Copilot 322ba26
Clarify checkout invariant comment after review feedback
Copilot 5478fc9
Merge branch 'main' into copilot/testify-expert-improve-test-quality-…
github-actions[bot] 66172ca
Strengthen checkout and default-events assertions per review
Copilot c2257a4
Merge branch 'main' into copilot/testify-expert-improve-test-quality-…
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| //go:build integration | ||
|
|
||
| package workflow | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/github/gh-aw/pkg/stringutil" | ||
|
|
||
| "github.com/github/gh-aw/pkg/testutil" | ||
| ) | ||
|
|
||
| // TestActivationJobNoCheckoutStep tests that the activation job uses GitHub API | ||
| // instead of checking out the repository for the timestamp check | ||
| func TestActivationJobNoCheckoutStep(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| frontmatter string | ||
| }{ | ||
| { | ||
| name: "basic workflow has no checkout in activation", | ||
| frontmatter: `--- | ||
| on: | ||
| issues: | ||
| types: [opened] | ||
| permissions: | ||
| contents: read | ||
| issues: read | ||
| engine: claude | ||
| strict: false | ||
| ---`, | ||
| }, | ||
| { | ||
| name: "workflow without contents permission has no checkout in activation", | ||
| frontmatter: `--- | ||
| on: | ||
| issues: | ||
| types: [opened] | ||
| permissions: | ||
| issues: read | ||
| engine: claude | ||
| strict: false | ||
| ---`, | ||
| }, | ||
| { | ||
| name: "workflow with reaction has no checkout in activation", | ||
| frontmatter: `--- | ||
| on: | ||
| issues: | ||
| types: [opened] | ||
| reaction: eyes | ||
| permissions: | ||
| issues: read | ||
| engine: claude | ||
| strict: false | ||
| ---`, | ||
| }, | ||
| { | ||
| // Top-level workflow permissions cannot grant write scopes directly (enforced by | ||
| // 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", | ||
| frontmatter: `--- | ||
| on: | ||
| issues: | ||
| types: [opened] | ||
| permissions: | ||
| contents: read | ||
| issues: read | ||
| engine: claude | ||
| strict: false | ||
| safe-outputs: | ||
| create-pull-request: | ||
| ---`, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| tmpDir := testutil.TempDir(t, "activation-checkout-test") | ||
|
|
||
| testContent := tt.frontmatter + "\n\n# Test Workflow\n\nTest workflow content." | ||
| testFile := filepath.Join(tmpDir, "test-workflow.md") | ||
| require.NoError(t, os.WriteFile(testFile, []byte(testContent), 0644)) | ||
|
|
||
| compiler := NewCompiler(WithVersion("dev")) | ||
| // Use dev mode to use local action paths | ||
| compiler.SetActionMode(ActionModeDev) | ||
|
|
||
| // Compile the workflow | ||
| require.NoError(t, compiler.CompileWorkflow(testFile), "Failed to compile workflow") | ||
|
|
||
| // Calculate the lock file path | ||
| lockFile := stringutil.MarkdownToLockFile(testFile) | ||
|
|
||
| // Read the generated lock file | ||
| lockContent, err := os.ReadFile(lockFile) | ||
| require.NoError(t, err, "Failed to read lock file") | ||
|
|
||
| lockContentStr := string(lockContent) | ||
|
|
||
| // Verify activation job exists | ||
| require.Contains(t, lockContentStr, "activation:", "Expected activation job to be present") | ||
|
|
||
| // Extract the activation job section using the shared job-boundary helper | ||
| 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") | ||
|
|
||
| // 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") | ||
|
|
||
| // Verify timestamp check step is present | ||
| assert.Contains(t, activationJobSection, "Check workflow lock file", "Should contain timestamp check step") | ||
|
|
||
| // Verify scripts are loaded via require() (not inlined) | ||
| assert.Contains(t, activationJobSection, "require(", "Should load scripts via require()") | ||
| }) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Addressed in 66172ca: the subtest now asserts the sparse checkout step (
name: Checkout .github and .agents folders,sparse-checkout: |,sparse-checkout-cone-mode: true) and explicitly asserts the activation job does not containname: Checkout repository.