diff --git a/.github/workflows/fuzz-run-go.yml b/.github/workflows/fuzz-run-go.yml index 6b8bb865df..da41af253b 100644 --- a/.github/workflows/fuzz-run-go.yml +++ b/.github/workflows/fuzz-run-go.yml @@ -112,3 +112,40 @@ jobs: When opening a PR with the fix, please include the test case file in your PR to prevent regressions. EOF + + - name: Create new issue + if: ${{ failure() && steps.new-failure.outputs.file != '' }} + uses: actions/github-script@v7 + with: + script: | + const failureName = "${{ steps.new-failure.outputs.name }}"; + const issueTitle = `${{ inputs.package-path }}: ${{ inputs.test-name }} failed (${failureName})`; + + // Look for existing issue first with the same title. + const issues = await github.rest.search.issuesAndPullRequests({ + q: `is:issue is:open repo:${{ github.repository }} in:title "${failureName}"` + }) + const issue = issues.data.items.find((issue) => issue.title === issue.title); + if (issue) { + return; + } + + // Create a new issue. + await github.rest.issues.create({ + owner: context.repo.owner, + repo: context.repo.repo, + title: issueTitle, + body: ` + A new fuzz test failure was found in ${{ inputs.package-path }}. + + To reproduce the failure locally, run the following command using the GitHub CLI to download the corpus entry: + +
gh run download --repo ${{ github.repository }} ${{ github.run_id }} -n failure-${{ steps.new-failure.outputs.package }}-${{ steps.new-failure.outputs.function }} --dir ${{ inputs.package-path }}/testdata/fuzz/${{ inputs.test-name }}
+ + When opening a PR with the fix, please include in the corpus entry in your commit to prevent regressions. + + [Link to failed run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) + `, + + labels: ['bug'], + }) diff --git a/internal/fuzztests/fake_fuzz_test.go b/internal/fuzztests/fake_fuzz_test.go new file mode 100644 index 0000000000..a89a830230 --- /dev/null +++ b/internal/fuzztests/fake_fuzz_test.go @@ -0,0 +1,27 @@ +package main + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func FuzzFails(f *testing.F) { + f.Add(0, 0) + f.Add(2, 4) + + f.Fuzz(func(t *testing.T, a, b int) { + expect := a + b + actual := myAdd(a, b) + + require.Equal(t, expect, actual, "Expect %d + %d = %d", a, b, expect) + }) +} + +func myAdd(a, b int) int { + // Force myAdd to return the wrong sum if a is an odd number. + if a%2 != 0 { + return a + b + 1 + } + return a + b +}