Repository navigation
PYTHON-6178 Persist coverage-increasing inputs from the nightly BSON fuzz runs #3215
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
35f60bc
PYTHON-6178 Grow the BSON fuzz corpus from nightly harvests
blink1073 577c271
cleanup and address review
blink1073 042704f
add pr script
blink1073 5a97ce1
rename script
blink1073 7ed2b73
address review
0aaa643
Merge remote-tracking branch 'upstream/main' into PYTHON-6178
a5973bb
remove workaround
e2b404b
merge from main
2d8ba71
Regenerate corrupted evergreen configs; fix ruff ISC004
cf42e7f
Dedup identical candidates within a harvest run
39338eb
Merge remote-tracking branch 'upstream/main' into PYTHON-6178
c31c9f5
address review
75f3194
Rename harvest to capture; keep nightly fuzzing off PRs, manually pat…
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
There are no files selected for viewing
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
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,32 @@ | ||
| #!/bin/bash | ||
| # PYTHON-6178: capture coverage-increasing inputs from a fuzz run and open | ||
| # an automated PR growing fuzz/corpus/. Runs as the last command of the | ||
| # nightly "fuzz" task, while the scratch corpus exists; manual | ||
| # `evergreen patch --variant fuzz-rhel8 --task fuzz` runs capture too. | ||
| set -eu | ||
|
|
||
| # Same environment as just.sh: venv on PATH for a modern Python. | ||
| . "$(dirname "${BASH_SOURCE:-$0}")/setup-dev-env.sh" | ||
|
|
||
| # No new units means no PR, and the github secrets flow is never touched. | ||
| uv run --no-sync python fuzz/capture_corpus.py | ||
| if [ -z "$(ls -A fuzz-scratch/capture 2>/dev/null || true)" ]; then | ||
| echo "No new fuzz corpus units; nothing to do." | ||
| exit 0 | ||
| fi | ||
|
|
||
| # A unit found by a later target never ran through the earlier ones, so | ||
| # replay every unit through all targets before publishing. | ||
| replay=(fuzz-scratch/capture/*) | ||
| for target in fuzz_decode fuzz_decode_all fuzz_is_valid; do | ||
| echo "Replaying captured units against ${target}..." | ||
| if ! uv run --no-sync python "fuzz/${target}.py" "${replay[@]}" \ | ||
| -artifact_prefix="$PWD/fuzz-scratch/" -atheris_runs="${#replay[@]}" | ||
| then | ||
| echo "Captured unit fails ${target}; no corpus PR." >&2 | ||
| exit 1 | ||
| fi | ||
| done | ||
|
|
||
| bash .evergreen/scripts/create-fuzz-corpus-pr.sh \ | ||
| fuzz-scratch/capture fuzz-scratch/capture-summary.md |
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,31 @@ | ||
| #!/usr/bin/env bash | ||
| set -eu | ||
|
|
||
| # Open (or update) the automated pull request that grows fuzz/corpus/ | ||
| # with freshly captured units. Arguments: 1 = captured units directory, | ||
| # 2 = capture summary markdown to use as the PR body. | ||
|
|
||
| capture_dir="$1" | ||
| summary_file="$2" | ||
| today="$(date '+%m-%d-%Y')" | ||
|
|
||
| # Shared github-app authentication, git branch and PR plumbing. | ||
| # shellcheck disable=SC1091 | ||
| . "$(dirname "${BASH_SOURCE[0]}")/github-pr-util.sh" | ||
|
|
||
| acquire_github_token | ||
|
|
||
| echo "Creating the git checkout..." | ||
| branch="fuzz-corpus-${today}" | ||
| prepare_bot_branch "$branch" | ||
|
|
||
| mkdir -p fuzz/corpus | ||
| cp "$capture_dir"/* fuzz/corpus/ | ||
| if ! stage_and_commit "PYTHON-6178 Grow the BSON fuzz corpus (${today})" fuzz/corpus; then | ||
| echo "No new corpus units to commit; skipping PR creation." | ||
| exit 0 | ||
| fi | ||
| echo "Creating the git checkout... done." | ||
|
|
||
| push_branch "$branch" | ||
| create_or_update_pr "$branch" "[Fuzz Corpus] ${today}" "$summary_file" |
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 |
|---|---|---|
| @@ -1,127 +1,30 @@ | ||
| #!/usr/bin/env bash | ||
| set -eu | ||
|
|
||
| # Default to the drivers-evergreen-tools submodule when unset; a | ||
| # caller-provided DRIVERS_TOOLS wins, as in the other consumers. | ||
| tools="$(realpath -s "${DRIVERS_TOOLS:-./drivers-evergreen-tools}")" | ||
| pushd $tools/.evergreen/github_app || exit | ||
| # Open (or update) the automated pull request resyncing the spec tests. | ||
| # Arguments: 1 = resync summary text to use as the PR body. | ||
|
|
||
| owner="mongodb" | ||
| repo="mongo-python-driver" | ||
| summary_file="$1" | ||
| today="$(date '+%m-%d-%Y')" | ||
|
|
||
| # Bootstrap the app. | ||
| echo "bootstrapping" | ||
| source utils.sh | ||
| bootstrap drivers/comment-bot | ||
| # Shared github-app authentication, git branch and PR plumbing. | ||
| # shellcheck disable=SC1091 | ||
| . "$(dirname "${BASH_SOURCE[0]}")/github-pr-util.sh" | ||
|
|
||
| # Run the app. | ||
| source ./secrets-export.sh | ||
| acquire_github_token | ||
|
|
||
| # Get a github access token for the git checkout. | ||
| echo "Getting github token..." | ||
|
|
||
| token=$(bash ./get-access-token.sh $repo $owner) | ||
| if [ -z "${token}" ]; then | ||
| echo "Failed to get github access token!" | ||
| popd || exit | ||
| exit 1 | ||
| fi | ||
| echo "Getting github token... done." | ||
| popd || exit | ||
|
|
||
| # Make the git checkout and create a new branch. | ||
| echo "Creating the git checkout..." | ||
| branch="spec-resync-"$(date '+%m-%d-%Y') | ||
|
|
||
| git remote set-url origin https://x-access-token:${token}@github.com/$owner/$repo.git | ||
| # -B resets the branch if a reused checkout already has it, keeping reruns idempotent. | ||
| git checkout -B "$branch" "origin/main" | ||
| branch="spec-resync-${today}" | ||
| prepare_bot_branch "$branch" | ||
|
|
||
| # Attribute the commit to the bot user; fall back to the host identity. | ||
| bot_login="mongodb-drivers-pr-bot[bot]" | ||
| bot_id=$(curl -gsm 10 "https://api.github.com/users/${bot_login}" | jq -r '.id // empty' || true) | ||
| if [ -n "$bot_id" ]; then | ||
| git config user.name "$bot_login" | ||
| git config user.email "${bot_id}+${bot_login}@users.noreply.github.com" | ||
| fi | ||
|
|
||
| git add ./test | ||
|
|
||
| if git diff --cached --quiet && git diff --quiet --ignore-submodules=dirty; then | ||
| # The spec sync also updates the vendored public suffix list (cp_psl in | ||
| # resync-specs.sh), a tracked file outside test/. | ||
| if ! stage_and_commit "resyncing specs ${today}" ./test pymongo/public_suffix_list.dat; then | ||
| echo "No spec changes to commit; skipping PR creation." | ||
| cat "$1" | ||
| cat "$summary_file" | ||
| exit 0 | ||
| fi | ||
|
|
||
| git commit -am "resyncing specs $(date '+%m-%d-%Y')" | ||
| echo "Creating the git checkout... done." | ||
|
|
||
| # Date-stamped branch: force-push makes same-day reruns idempotent; retry | ||
| # absorbs GitHub's intermittent 403s on the receive-pack endpoint. | ||
| push_ok=false | ||
| for _attempt in 1 2 3; do | ||
| if git push --force origin $branch; then | ||
| push_ok=true | ||
| break | ||
| fi | ||
| if [ "$_attempt" -lt 3 ]; then | ||
| echo "Push attempt ${_attempt} failed; retrying in 30s..." | ||
| sleep 30 | ||
| fi | ||
| done | ||
| if [ "$push_ok" != true ]; then | ||
| echo "Failed to push $branch after 3 attempts!" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Build the payload as a file so the body content is always properly | ||
| # JSON-escaped, rather than interpolated into the command line as text. | ||
| payload_file=$(mktemp) | ||
| trap 'rm -f "$payload_file"' EXIT | ||
| jq -n \ | ||
| --arg title "[Spec Resync] $(date '+%m-%d-%Y')" \ | ||
| --arg head "${branch}" \ | ||
| --rawfile body "$1" \ | ||
| '{title: $title, body: $body, head: $head, base: "main"}' > "$payload_file" | ||
|
|
||
| # Reuse an open PR for this branch (same-day rerun) instead of duplicating it. | ||
| existing_pr_json=$(curl -gs \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| -H "Authorization: Bearer $token" \ | ||
| -H "X-GitHub-Api-Version: 2022-11-28" \ | ||
| --url "https://api.github.com/repos/$owner/$repo/pulls?head=$owner:$branch&state=open") | ||
| existing_pr_url=$(echo "$existing_pr_json" | jq -r '.[0].html_url // empty') | ||
| if [ -n "$existing_pr_url" ]; then | ||
| existing_pr_number=$(echo "$existing_pr_json" | jq -r '.[0].number // empty') | ||
| if ! curl -sfX PATCH \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| -H "Authorization: Bearer $token" \ | ||
| -H "X-GitHub-Api-Version: 2022-11-28" \ | ||
| -d "{\"title\": \"[Spec Resync] $(date '+%m-%d-%Y')\", \"body\": $(jq -Rs . < "$1")}" \ | ||
| --url "https://api.github.com/repos/$owner/$repo/pulls/${existing_pr_number}" > /dev/null | ||
| then | ||
| echo "Failed to update PR summary!" >&2 | ||
| exit 1 | ||
| fi | ||
| echo "$existing_pr_url" | ||
| echo "Creating the PR... done. (PR already existed; branch and summary were updated)" | ||
| rm -rf $tools | ||
| exit 0 | ||
| fi | ||
|
|
||
| resp=$(curl -L \ | ||
| -X POST \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| -H "Authorization: Bearer $token" \ | ||
| -H "X-GitHub-Api-Version: 2022-11-28" \ | ||
| -d "@${payload_file}" \ | ||
| --url https://api.github.com/repos/$owner/$repo/pulls) | ||
|
|
||
| pr_url=$(echo "$resp" | jq -r '.html_url // empty') | ||
| if [ -z "$pr_url" ]; then | ||
| echo "Failed to create PR! API response:" | ||
| echo "$resp" | jq . | ||
| exit 1 | ||
| fi | ||
| echo "$pr_url" | ||
| echo "Creating the PR... done." | ||
| push_branch "$branch" | ||
| create_or_update_pr "$branch" "[Spec Resync] ${today}" "$summary_file" |
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.
Uh oh!
There was an error while loading. Please reload this page.