diff --git a/README.md b/README.md index df8cdb3..0cbde6c 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,8 @@ jobs: pr-title: ${{ github.event.pull_request.title }} pr-author: ${{ github.event.pull_request.user.login }} pr-body: ${{ github.event.pull_request.body }} + server-url: ${{ github.server_url }} + token: ${{ github.token }} base-sha: ${{ github.event.pull_request.base.sha }} head-sha: ${{ github.event.pull_request.head.sha }} ``` @@ -53,6 +55,8 @@ job — the step still fails, but the job cannot block the PR. | `pr-title` | yes | PR title — `github.event.pull_request.title` | | `pr-author` | no | PR author login — `github.event.pull_request.user.login`; `dfritz` is exempt | | `pr-body` | yes | PR description — `github.event.pull_request.body` | +| `server-url` | yes | Gitea server URL — `github.server_url` | +| `token` | yes | Gitea Actions token — `github.token` | | `base-sha` | yes | Base commit — `github.event.pull_request.base.sha` | | `head-sha` | yes | Head commit — `github.event.pull_request.head.sha` | @@ -73,9 +77,9 @@ The check validates four things for every non-break-glass Agent PR: `Fixes bug-` automation token and the matching navigable `https://agenthub.fritzlab.net/bug-` URL. Every PR has a separate `## Attribution` section containing the canonical `Authored-By` - product/model watermark. Agent-authored PR bodies cannot contain HTML - comment or fenced code delimiters, so required provenance cannot be hidden - from readers. + product/model watermark. The action asks Gitea to render the body and checks + the rendered `

` sections; fenced, commented, scripted, or collapsed + copies do not satisfy the visible provenance contract. 4. **Commit attribution** — every commit in `base-sha..head-sha`, including commits on `chore/` branches, ends with diff --git a/action.yaml b/action.yaml index 00cfe95..70d6c85 100644 --- a/action.yaml +++ b/action.yaml @@ -29,6 +29,12 @@ inputs: pr-body: description: PR description — github.event.pull_request.body. required: true + server-url: + description: Gitea server URL — github.server_url. + required: true + token: + description: Gitea Actions token — github.token. + required: true base-sha: description: Base commit SHA — github.event.pull_request.base.sha. required: true @@ -46,6 +52,8 @@ runs: PR_TITLE: ${{ inputs.pr-title }} PR_AUTHOR: ${{ inputs.pr-author }} PR_BODY: ${{ inputs.pr-body }} + GITEA_SERVER_URL: ${{ inputs.server-url }} + GITEA_TOKEN: ${{ inputs.token }} BASE_SHA: ${{ inputs.base-sha }} HEAD_SHA: ${{ inputs.head-sha }} run: bash "${{ github.action_path }}/check.sh" diff --git a/check.sh b/check.sh index 4e2460d..8c13f08 100755 --- a/check.sh +++ b/check.sh @@ -10,6 +10,8 @@ AUTHOR="${PR_AUTHOR:-}" BODY="${PR_BODY:-}" BASE="${BASE_SHA:-}" HEAD="${HEAD_SHA:-}" +SERVER_URL="${GITEA_SERVER_URL:-}" +TOKEN="${GITEA_TOKEN:-}" # Break-glass: dfritz is exempt from all naming checks. if [ "${AUTHOR}" = "dfritz" ]; then @@ -21,16 +23,23 @@ FAILED=0 BRANCH_KIND="invalid" BRANCH_BUG="" -# Gitea hides HTML comments. Reject their delimiters so required provenance is -# always visible, then parse the raw body without a second Markdown renderer. -VISIBLE_BODY="${BODY}" -if printf '%s\n' "${BODY}" | grep -Fq ''; then - echo "FAIL[check-naming]: PR body must not contain HTML comment delimiters" +# Gitea's renderer is the visibility contract. Validate its output instead of +# maintaining a second Markdown parser in this action. +RENDERED_BODY="" +if [ -z "${SERVER_URL}" ] || [ -z "${TOKEN}" ]; then + echo "FAIL[check-naming]: server-url and token are required to render the PR body" + FAILED=1 +elif ! RENDERED_BODY=$(printf '%s' "${BODY}" | + jq -Rs '{Text: ., Mode: "gfm"}' | + curl --fail --silent --show-error \ + --header "Authorization: token ${TOKEN}" \ + --header "Content-Type: application/json" \ + --data-binary @- "${SERVER_URL%/}/api/v1/markdown"); then + echo "FAIL[check-naming]: Gitea could not render the PR body" FAILED=1 fi -if printf '%s\n' "${BODY}" | grep -Eq '^[[:blank:]]*(```|~~~)'; then - echo "FAIL[check-naming]: PR body must not contain fenced code delimiters" +if printf '%s\n' "${RENDERED_BODY}" | grep -Eiq '])'; then + echo "FAIL[check-naming]: rendered PR body must not contain collapsed details" FAILED=1 fi @@ -72,9 +81,9 @@ if [ "${BRANCH_KIND}" = "role-bug" ]; then FAILED=1 fi - tracking=$(printf '%s\n' "${VISIBLE_BODY}" | awk ' - /^## Tracking[[:space:]]*$/ { in_section=1; next } - /^## / && in_section { exit } + tracking=$(printf '%s\n' "${RENDERED_BODY}" | awk ' + /]*>Tracking<\/h2>/ { in_section=1; next } + /]*>/ && in_section { exit } in_section { print } ') if [ -z "${tracking}" ]; then @@ -97,12 +106,12 @@ elif [ "${BRANCH_KIND}" = "chore" ] && [ -n "${TITLE_BUG}" ]; then fi if [ "${BRANCH_KIND}" != "invalid" ]; then - attribution=$(printf '%s\n' "${VISIBLE_BODY}" | awk ' - /^## Attribution[[:space:]]*$/ { in_section=1; next } - /^## / && in_section { exit } + attribution=$(printf '%s\n' "${RENDERED_BODY}" | awk ' + /]*>Attribution<\/h2>/ { in_section=1; next } + /]*>/ && in_section { exit } in_section { print } ') - watermark_re='^[-*]?[[:space:]]*Authored-By: .+ \(.+\) $' + watermark_re='Authored-By: .+ \(.+\) ]*>noreply@[[:alnum:].-]+' if ! printf '%s\n' "${attribution}" | grep -qE "${watermark_re}"; then echo "FAIL[check-naming]: ## Attribution must contain an Authored-By product/model watermark" FAILED=1 diff --git a/tests/bin/curl b/tests/bin/curl new file mode 100755 index 0000000..f7b975e --- /dev/null +++ b/tests/bin/curl @@ -0,0 +1,56 @@ +#!/usr/bin/env bash +# Deterministic Gitea Markdown renderer stub for check.sh contract tests. +set -euo pipefail + +if printf '%s\n' "${PR_BODY}" | grep -Fq '' \ - "$BASE" "$GOOD_HEAD" "PR body must not contain HTML comment delimiters" + "$BASE" "$GOOD_HEAD" "PR body must contain a non-empty ## Tracking section" check_contract "comment removal cannot synthesize section headings" \ $'## Tracking\n- Fixes bug-x7k2m9 — https://agenthub.fritzlab.net/bug-x7k2m9\n\n## Attribution\n- Authored-By: Codex (GPT-5) ' \ - "$BASE" "$GOOD_HEAD" "PR body must not contain HTML comment delimiters" + "$BASE" "$GOOD_HEAD" "PR body must contain a non-empty ## Tracking section" check_contract "four-space indented backticks do not expose comments" \ $' ````\n' \ - "$BASE" "$GOOD_HEAD" "PR body must not contain HTML comment delimiters" + "$BASE" "$GOOD_HEAD" "PR body must contain a non-empty ## Tracking section" check_contract "unequal backtick runs do not expose comments" \ $'`' \ - "$BASE" "$GOOD_HEAD" "PR body must not contain HTML comment delimiters" + "$BASE" "$GOOD_HEAD" "PR body must contain a non-empty ## Tracking section" check_contract "invalid backtick fence info does not expose comments" \ $'```html`oops\n' \ - "$BASE" "$GOOD_HEAD" "PR body must not contain HTML comment delimiters" + "$BASE" "$GOOD_HEAD" "PR body must contain a non-empty ## Tracking section" check_contract "invalid fence closer does not expose comments" \ $'```html\n```oops\n```\n' \ - "$BASE" "$GOOD_HEAD" "PR body must not contain HTML comment delimiters" + "$BASE" "$GOOD_HEAD" "PR body must contain a non-empty ## Tracking section" check_contract "fences inside comments do not expose provenance" \ $'' \ - "$BASE" "$GOOD_HEAD" "PR body must not contain HTML comment delimiters" + "$BASE" "$GOOD_HEAD" "PR body must contain a non-empty ## Tracking section" check_contract "escaped backticks do not hide a comment opener" \ $'\\`' \ - "$BASE" "$GOOD_HEAD" "PR body must not contain HTML comment delimiters" + "$BASE" "$GOOD_HEAD" "PR body must contain a non-empty ## Tracking section" check_contract "fenced provenance does not satisfy the visible contract" \ $'```\n```oops\n## Tracking\n- Fixes bug-x7k2m9 — https://agenthub.fritzlab.net/bug-x7k2m9\n\n## Attribution\n- Authored-By: Codex (GPT-5) ' \ - "$BASE" "$GOOD_HEAD" "PR body must not contain fenced code delimiters" -check_contract "fenced code delimiters are rejected" \ - $'```text\nvisible example\n```\n\n## Tracking\n- Fixes bug-x7k2m9 — https://agenthub.fritzlab.net/bug-x7k2m9\n\n## Attribution\n- Authored-By: Codex (GPT-5) ' \ - "$BASE" "$GOOD_HEAD" "PR body must not contain fenced code delimiters" + "$BASE" "$GOOD_HEAD" "PR body must contain a non-empty ## Tracking section" +check_contract "indented fence closer does not expose provenance" \ + $'```\n ```\n## Tracking\n- Fixes bug-x7k2m9 — https://agenthub.fritzlab.net/bug-x7k2m9\n\n## Attribution\n- Authored-By: Codex (GPT-5) \n```' \ + "$BASE" "$GOOD_HEAD" "PR body must contain a non-empty ## Tracking section" +check_contract_pass "fenced code examples remain available" \ + $'```html\n\n```\n\n## Tracking\n- Fixes bug-x7k2m9 — https://agenthub.fritzlab.net/bug-x7k2m9\n\n## Attribution\n- Authored-By: Codex (GPT-5) ' \ + "$BASE" "$GOOD_HEAD" +check_contract "details cannot collapse provenance" \ + $'
Release notes\n\n## Tracking\n- Fixes bug-x7k2m9 — https://agenthub.fritzlab.net/bug-x7k2m9\n\n## Attribution\n- Authored-By: Codex (GPT-5) \n
' \ + "$BASE" "$GOOD_HEAD" "rendered PR body must not contain collapsed details" +check_contract "script cannot suppress provenance" \ + $'' \ + "$BASE" "$GOOD_HEAD" "PR body must contain a non-empty ## Tracking section" git -C "${FIXTURES}" commit --allow-empty -q -m "unwatermarked change" BAD_HEAD=$(git -C "${FIXTURES}" rev-parse HEAD)