-
Notifications
You must be signed in to change notification settings - Fork 2
feat(harness): report categorized post-script failures on issue/PR #38
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
ifireball
wants to merge
1
commit into
fullsend-ai:main
Choose a base branch
from
ifireball:feat/post-script-failure-reporting
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,240 @@ | ||
| #!/usr/bin/env bash | ||
| # post-failure-report.sh — Categorized, sanitized failure comments for post-scripts. | ||
| # | ||
| # Source from post-code.sh / post-fix.sh: | ||
| # source "${SCRIPT_DIR}/lib/post-failure-report.sh" | ||
| # | ||
| # Set POST_FAILURE_CATEGORY / POST_FAILURE_DETAIL before exit, or call post_fail. | ||
|
|
||
| # shellcheck shell=bash | ||
|
|
||
| [[ -n "${POST_FAILURE_REPORT_SH_LOADED:-}" ]] && return 0 | ||
| POST_FAILURE_REPORT_SH_LOADED=1 | ||
|
|
||
| POST_FAILURE_CATEGORY="${POST_FAILURE_CATEGORY:-}" | ||
| POST_FAILURE_DETAIL="${POST_FAILURE_DETAIL:-}" | ||
| POST_FAILURE_REPORTED=false | ||
| POST_FAILURE_SECRET_SCAN_MESSAGE="Secret scan blocked the push. See workflow logs for details." | ||
|
|
||
| # Maximum lines of sanitized detail to include in issue/PR comments. | ||
| POST_FAILURE_DETAIL_MAX_LINES="${POST_FAILURE_DETAIL_MAX_LINES:-30}" | ||
|
|
||
| _redact_multiline_pem() { | ||
| awk ' | ||
| /-----BEGIN [A-Z ]*PRIVATE KEY-----/ { | ||
| print "[REDACTED PRIVATE KEY]" | ||
| in_pem = 1 | ||
| next | ||
| } | ||
| /-----END [A-Z ]*PRIVATE KEY-----/ { | ||
| in_pem = 0 | ||
| next | ||
| } | ||
| in_pem { next } | ||
| { print } | ||
| ' | ||
| } | ||
|
|
||
| # Strip tokens and truncate noisy command output before posting publicly. | ||
| sanitize_failure_detail() { | ||
| local detail="$1" | ||
| local max_lines="${2:-${POST_FAILURE_DETAIL_MAX_LINES}}" | ||
|
|
||
| detail="$(printf '%s\n' "${detail}" \ | ||
| | sed -E \ | ||
| -e 's/gh[pousr]_[A-Za-z0-9_]{20,}/[REDACTED]/g' \ | ||
| -e 's/github_pat_[A-Za-z0-9_]+/[REDACTED]/g' \ | ||
| -e 's/x-access-token:[^@[:space:]]+/x-access-token:[REDACTED]/g' \ | ||
| -e 's/(Bearer|token)[[:space:]]+[A-Za-z0-9._-]+/\1 [REDACTED]/gi' \ | ||
| | _redact_multiline_pem)" | ||
|
|
||
| if [ "${max_lines}" -gt 0 ]; then | ||
| detail="$(printf '%s\n' "${detail}" | tail -n "${max_lines}")" | ||
| fi | ||
|
|
||
| printf '%s' "${detail}" | ||
| } | ||
|
|
||
| set_post_failure() { | ||
| POST_FAILURE_CATEGORY="$1" | ||
| POST_FAILURE_DETAIL="$2" | ||
| } | ||
|
|
||
| categorize_push_failure() { | ||
| local push_output="$1" | ||
|
|
||
| if echo "${push_output}" | grep -qiE \ | ||
| 'workflow.*without.*workflows?[[:space:]]+permission|refusing to allow.*GitHub App.*workflow'; then | ||
| echo "push-workflow-permission" | ||
| return 0 | ||
| fi | ||
|
|
||
| if echo "${push_output}" | grep -qiE \ | ||
| 'non-fast-forward|rejected|fetch first|protected branch|GH006|permission denied'; then | ||
| echo "push-rejected" | ||
| return 0 | ||
| fi | ||
|
|
||
| echo "push-rejected" | ||
| } | ||
|
|
||
| post_failure_category_label() { | ||
| case "$1" in | ||
| secret-scan) echo "Secret scan blocked" ;; | ||
| pre-commit-blocked) echo "Pre-commit blocked" ;; | ||
| signed-off-by) echo "Signed-off-by rejected" ;; | ||
| push-workflow-permission) echo "Push rejected — workflows permission" ;; | ||
| push-rejected) echo "Push rejected" ;; | ||
| pr-creation-failed) echo "PR creation failed" ;; | ||
| branch-validation) echo "Branch validation failed" ;; | ||
| setup-error) echo "Setup error" ;; | ||
| process-output-failed) echo "Structured output processing failed" ;; | ||
| *) echo "Post-script failed" ;; | ||
| esac | ||
| } | ||
|
|
||
| post_failure_environmental_note() { | ||
| case "$1" in | ||
| push-workflow-permission) | ||
| cat <<'EOF' | ||
| > **Environmental limitation:** the GitHub App lacks `workflows` write permission on this repository. The agent's patch is not necessarily wrong — update repo or app permissions (or avoid `.github/workflows/` changes) and retry. | ||
| EOF | ||
| ;; | ||
| *) | ||
| printf '' | ||
| ;; | ||
| esac | ||
| } | ||
|
|
||
| post_failure_workflow_run_url() { | ||
| local repo_full_name="$1" | ||
| local run_repo="${GITHUB_REPOSITORY:-${repo_full_name}}" | ||
| printf '%s/%s/actions/runs/%s' \ | ||
| "${GITHUB_SERVER_URL:-https://github.com}" \ | ||
| "${run_repo}" \ | ||
| "${GITHUB_RUN_ID:-unknown}" | ||
| } | ||
|
|
||
| build_post_failure_comment() { | ||
| local agent_kind="$1" # code | fix | ||
| local exit_code="$2" | ||
| local category="$3" | ||
| local detail="$4" | ||
| local repo_full_name="$5" | ||
| local retry_command="$6" | ||
|
|
||
| local label env_note sanitized_detail run_url detail_block | ||
|
|
||
| label="$(post_failure_category_label "${category}")" | ||
| env_note="$(post_failure_environmental_note "${category}")" | ||
| run_url="$(post_failure_workflow_run_url "${repo_full_name}")" | ||
|
|
||
| if [ "${category}" = "secret-scan" ]; then | ||
| sanitized_detail="${POST_FAILURE_SECRET_SCAN_MESSAGE}" | ||
| else | ||
| sanitized_detail="$(sanitize_failure_detail "${detail}")" | ||
| fi | ||
|
|
||
| if [ -n "${sanitized_detail}" ]; then | ||
| detail_block="$(cat <<EOF | ||
|
|
||
| **Details:** | ||
| \`\`\` | ||
| ${sanitized_detail} | ||
| \`\`\` | ||
| EOF | ||
| )" | ||
| else | ||
| detail_block="" | ||
| fi | ||
|
|
||
| if [ -n "${env_note}" ]; then | ||
| env_note="${env_note} | ||
|
|
||
| " | ||
| fi | ||
|
|
||
| cat <<EOF | ||
| ⚠️ **Post-${agent_kind} script failed** — ${label} (exit code ${exit_code}) | ||
|
|
||
| The ${agent_kind} agent completed, but the post-${agent_kind} script failed before finishing. | ||
|
|
||
| ${env_note}**Workflow run:** ${run_url} | ||
| ${detail_block} | ||
| Please check the workflow logs for full details and retry with \`${retry_command}\` if appropriate. | ||
| EOF | ||
| } | ||
|
|
||
| _post_failure_ensure_token() { | ||
| if [ -z "${GH_TOKEN:-}" ]; then | ||
| export GH_TOKEN="${PUSH_TOKEN:-}" | ||
| fi | ||
| } | ||
|
|
||
| report_post_failure_to_issue() { | ||
| local exit_code="${1:-$?}" | ||
|
|
||
| if [ "${POST_FAILURE_REPORTED}" = "true" ]; then | ||
| return 0 | ||
| fi | ||
| POST_FAILURE_REPORTED=true | ||
|
|
||
| _post_failure_ensure_token | ||
|
|
||
| local category="${POST_FAILURE_CATEGORY:-post-script-error}" | ||
| local detail="${POST_FAILURE_DETAIL:-Post-code script failed before push or PR creation completed.}" | ||
| local body | ||
| # ISSUE_NUMBER and REPO_FULL_NAME are required by post-code.sh before sourcing. | ||
| # shellcheck disable=SC2153 | ||
| body="$(build_post_failure_comment \ | ||
| "code" "${exit_code}" "${category}" "${detail}" \ | ||
| "${REPO_FULL_NAME}" "/fs-code")" | ||
|
|
||
| echo "::warning::Posting failure comment to issue #${ISSUE_NUMBER}..." | ||
| gh issue comment "${ISSUE_NUMBER}" \ | ||
| --repo "${REPO_FULL_NAME}" \ | ||
| --body "${body}" 2>/dev/null || \ | ||
| echo "::warning::Failed to post error comment to issue #${ISSUE_NUMBER}" | ||
| } | ||
|
|
||
| report_post_failure_to_pr() { | ||
| local exit_code="${1:-$?}" | ||
|
|
||
| if [ "${POST_FAILURE_REPORTED}" = "true" ]; then | ||
| return 0 | ||
| fi | ||
| POST_FAILURE_REPORTED=true | ||
|
|
||
| _post_failure_ensure_token | ||
|
|
||
| local category="${POST_FAILURE_CATEGORY:-post-script-error}" | ||
| local detail="${POST_FAILURE_DETAIL:-Post-fix script failed before push or PR update completed.}" | ||
| local body | ||
| # PR_NUMBER and REPO_FULL_NAME are required by post-fix.sh before sourcing. | ||
| # shellcheck disable=SC2153 | ||
| body="$(build_post_failure_comment \ | ||
| "fix" "${exit_code}" "${category}" "${detail}" \ | ||
| "${REPO_FULL_NAME}" "/fs-fix")" | ||
|
|
||
| echo "::warning::Posting failure comment to PR #${PR_NUMBER}..." | ||
| gh pr comment "${PR_NUMBER}" \ | ||
| --repo "${REPO_FULL_NAME}" \ | ||
| --body "${body}" 2>/dev/null || \ | ||
| echo "::warning::Failed to post error comment to PR #${PR_NUMBER}" | ||
|
Comment on lines
+193
to
+223
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. 1. issue_number in ::warning unsanitized The new failure-reporting library emits GitHub Actions workflow commands (::warning::...) with interpolated values that are not sanitized. Unsanitized interpolation can allow workflow-command injection via ::, encoded newlines (%0A/%0D), or control characters. Agent Prompt
|
||
| } | ||
|
|
||
| post_fail_to_issue() { | ||
| local category="$1" | ||
| local detail="${2:-}" | ||
| set_post_failure "${category}" "${detail}" | ||
| report_post_failure_to_issue 1 | ||
| exit 1 | ||
| } | ||
|
|
||
| post_fail_to_pr() { | ||
| local category="$1" | ||
| local detail="${2:-}" | ||
| set_post_failure "${category}" "${detail}" | ||
| report_post_failure_to_pr 1 | ||
| exit 1 | ||
| } | ||
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.
3. Markdown fence injection
🐞 Bug≡ CorrectnessAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools