From 14a8813a7b0767bff37afc1f87639ca480d19659 Mon Sep 17 00:00:00 2001 From: Evelyn Chen Date: Thu, 27 Aug 2026 16:47:39 +0000 Subject: [PATCH 01/12] Reject provenance hidden in PR comments Authored-By: Codex (GPT-5) --- check.sh | 35 +++++++++++++++++++++++++++++++++-- tests/run | 3 +++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/check.sh b/check.sh index a664607..a9cdc83 100755 --- a/check.sh +++ b/check.sh @@ -11,6 +11,37 @@ BODY="${PR_BODY:-}" BASE="${BASE_SHA:-}" HEAD="${HEAD_SHA:-}" +# Gitea renders HTML comments as hidden. Validate the visible body so required +# tracking and attribution cannot exist only in comment source. +VISIBLE_BODY=$(printf '%s\n' "${BODY}" | awk ' + { + line=$0 + while (line != "") { + if (in_comment) { + end=index(line, "-->") + if (end == 0) { + line="" + break + } + line=substr(line, end + 3) + in_comment=0 + } + start=index(line, "") + if (end == 0) { + line=before + in_comment=1 + break + } + line=before substr(rest, end + 3) + } + print line + } +') + # Break-glass: dfritz is exempt from all naming checks. if [ "${AUTHOR}" = "dfritz" ]; then echo "check-naming: dfritz break-glass — exempt" @@ -53,7 +84,7 @@ if [ "${BRANCH_KIND}" = "role-bug" ]; then FAILED=1 fi - tracking=$(printf '%s\n' "${BODY}" | awk ' + tracking=$(printf '%s\n' "${VISIBLE_BODY}" | awk ' /^## Tracking[[:space:]]*$/ { in_section=1; next } /^## / && in_section { exit } in_section { print } @@ -72,7 +103,7 @@ if [ "${BRANCH_KIND}" = "role-bug" ]; then fi fi - attribution=$(printf '%s\n' "${BODY}" | awk ' + attribution=$(printf '%s\n' "${VISIBLE_BODY}" | awk ' /^## Attribution[[:space:]]*$/ { in_section=1; next } /^## / && in_section { exit } in_section { print } diff --git a/tests/run b/tests/run index 9e44f7d..8031790 100755 --- a/tests/run +++ b/tests/run @@ -104,6 +104,9 @@ check_contract "tracking rejects wrong Bug URL" \ check_contract "attribution must be in its own section" \ $'## Tracking\n- Fixes bug-x7k2m9 — https://agenthub.fritzlab.net/bug-x7k2m9\n- Authored-By: Codex (GPT-5) ' \ "$BASE" "$GOOD_HEAD" "## Attribution must contain" +check_contract "hidden provenance does not satisfy the visible contract" \ + $'' \ + "$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) From cc0bee61a466d4e952ecd658126b719576601caf Mon Sep 17 00:00:00 2001 From: Evelyn Chen Date: Thu, 27 Aug 2026 16:51:55 +0000 Subject: [PATCH 02/12] Preserve visible Markdown code examples Authored-By: Codex (GPT-5) --- check.sh | 73 +++++++++++++++++++++++++++++++++++++++++++------------ tests/run | 25 +++++++++++++++++++ 2 files changed, 83 insertions(+), 15 deletions(-) diff --git a/check.sh b/check.sh index a9cdc83..e8d39c1 100755 --- a/check.sh +++ b/check.sh @@ -16,29 +16,72 @@ HEAD="${HEAD_SHA:-}" VISIBLE_BODY=$(printf '%s\n' "${BODY}" | awk ' { line=$0 - while (line != "") { + fence_pos=1 + while (fence_pos <= 4 && substr(line, fence_pos, 1) == " ") fence_pos++ + fence_char=substr(line, fence_pos, 1) + fence_run=0 + if (fence_char == "`" || fence_char == "~") { + while (substr(line, fence_pos + fence_run, 1) == fence_char) fence_run++ + } + if (in_fence) { + print line + if (fence_char == active_fence_char && fence_run >= active_fence_run) in_fence=0 + next + } + if (fence_run >= 3) { + in_fence=1 + active_fence_char=fence_char + active_fence_run=fence_run + print line + next + } + + visible="" + pos=1 + while (pos <= length(line)) { if (in_comment) { - end=index(line, "-->") - if (end == 0) { - line="" + rest=substr(line, pos) + comment_end=index(rest, "-->") + if (comment_end == 0) { + pos=length(line) + 1 break } - line=substr(line, end + 3) + visible=visible " " + pos += comment_end + 2 in_comment=0 + continue } - start=index(line, "") - if (end == 0) { - line=before + + if (substr(line, pos, 1) == "`") { + ticks=1 + while (substr(line, pos + ticks, 1) == "`") ticks++ + close_pos=pos + ticks + found_close=0 + while (close_pos <= length(line)) { + if (substr(line, close_pos, ticks) == substr(line, pos, ticks) && + substr(line, close_pos + ticks, 1) != "`") { + found_close=1 + break + } + close_pos++ + } + if (found_close) { + visible=visible substr(line, pos, close_pos + ticks - pos) + pos=close_pos + ticks + continue + } + } + + if (substr(line, pos, 4) == "' \ "$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 contain a non-empty ## Tracking section" +check_contract_pass "inline code containing comment opener stays visible" \ + $'Use `\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" git -C "${FIXTURES}" commit --allow-empty -q -m "unwatermarked change" BAD_HEAD=$(git -C "${FIXTURES}" rev-parse HEAD) From 8a1d71c4e9c15f0b173cbee47ae7529d4e2d765e Mon Sep 17 00:00:00 2001 From: Evelyn Chen Date: Thu, 27 Aug 2026 16:55:08 +0000 Subject: [PATCH 03/12] Enforce provenance on every agent change Authored-By: Codex (GPT-5) --- README.md | 16 ++++++++++------ action.yaml | 2 +- check.sh | 20 +++++++++++++++----- tests/run | 26 ++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index e42471e..87f7997 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Title: [bug-x7k2m9] Fix terminal resize loss (chore PRs: no [bug-id] prefix - `` is `bug-` followed by lowercase alphanumeric characters - `` is lowercase alphanumeric with hyphens, starting with a letter or digit - When both the branch and the title carry a bug-id they **must match** +- Titles are plain-language imperatives without Conventional Commit syntax - Break-glass: PRs authored by `dfritz` are exempt from all checks ## Usage @@ -57,7 +58,7 @@ job — the step still fails, but the job cannot block the PR. ## Behavior -The check validates four things for a Bug-backed Agent PR: +The check validates four things for every non-break-glass Agent PR: 1. **Branch form** — must be `/bug-/` or `chore/`. Unknown roles, missing `bug-` segment, uppercase bug-ids, and empty @@ -65,14 +66,17 @@ The check validates four things for a Bug-backed Agent PR: 2. **Title form** — for a `role/bug` branch the title must start with `[bug-] `. For a `chore` branch the title must have no `[bug-id]` - prefix. If both carry a bug-id they must match. + prefix. If both carry a bug-id they must match. Neither form accepts + Conventional Commit syntax. -3. **Tracking and attribution** — `## Tracking` contains both the literal +3. **Tracking and attribution** — on Bug-backed work, `## Tracking` contains both the literal `Fixes bug-` automation token and the matching navigable - `https://agenthub.fritzlab.net/bug-` URL. A separate `## Attribution` - section contains the canonical `Authored-By` product/model watermark. + `https://agenthub.fritzlab.net/bug-` URL. Every PR has a separate + `## Attribution` section containing the canonical `Authored-By` + product/model watermark. -4. **Commit attribution** — every commit in `base-sha..head-sha` ends with +4. **Commit attribution** — every commit in `base-sha..head-sha`, including + commits on `chore/` branches, ends with the canonical `Authored-By` trailer, separated from the message body by a blank line. The naming job must check out full history before this action. diff --git a/action.yaml b/action.yaml index 0e5c2f8..00cfe95 100644 --- a/action.yaml +++ b/action.yaml @@ -8,7 +8,7 @@ description: | Standard: branch: /bug-/ e.g. dev/bug-x7k2m9/fix-terminal-resize chore: chore/ bug-less trivia only - title: [bug-] Description (chore PRs: no [bug-id] prefix) + title: [bug-] Description (chore PRs: no [bug-id] prefix; no Conventional Commit syntax) Role must be a roster handle: dev | ux | ops | security | perf | architect | support Break-glass: PRs authored by dfritz are exempt. diff --git a/check.sh b/check.sh index e8d39c1..ee756fe 100755 --- a/check.sh +++ b/check.sh @@ -17,7 +17,7 @@ VISIBLE_BODY=$(printf '%s\n' "${BODY}" | awk ' { line=$0 fence_pos=1 - while (fence_pos <= 4 && substr(line, fence_pos, 1) == " ") fence_pos++ + while (fence_pos <= 3 && substr(line, fence_pos, 1) == " ") fence_pos++ fence_char=substr(line, fence_pos, 1) fence_run=0 if (fence_char == "`" || fence_char == "~") { @@ -58,7 +58,8 @@ VISIBLE_BODY=$(printf '%s\n' "${BODY}" | awk ' close_pos=pos + ticks found_close=0 while (close_pos <= length(line)) { - if (substr(line, close_pos, ticks) == substr(line, pos, ticks) && + if (substr(line, close_pos - 1, 1) != "`" && + substr(line, close_pos, ticks) == substr(line, pos, ticks) && substr(line, close_pos + ticks, 1) != "`") { found_close=1 break @@ -116,6 +117,12 @@ if echo "${TITLE}" | grep -qE "^\[bug-[a-z0-9]+\] ."; then TITLE_BUG=$(echo "${TITLE}" | sed -E 's|^\[(bug-[a-z0-9]+)\].*|\1|') fi +PLAIN_TITLE=$(printf '%s\n' "${TITLE}" | sed -E 's/^\[bug-[a-z0-9]+\][[:space:]]+//') +if printf '%s\n' "${PLAIN_TITLE}" | grep -qE '^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\([^)]*\))?!?:[[:space:]]'; then + echo "FAIL[check-naming]: title must be a plain-language imperative without Conventional Commit syntax" + FAILED=1 +fi + if [ "${BRANCH_KIND}" = "role-bug" ]; then if [ -z "${TITLE_BUG}" ]; then echo "FAIL[check-naming]: title must lead with [${BRANCH_BUG}]" @@ -146,6 +153,12 @@ if [ "${BRANCH_KIND}" = "role-bug" ]; then fi fi +elif [ "${BRANCH_KIND}" = "chore" ] && [ -n "${TITLE_BUG}" ]; then + echo "FAIL[check-naming]: chore branch should not carry a [bug-id] title prefix" + FAILED=1 +fi + +if [ "${BRANCH_KIND}" != "invalid" ]; then attribution=$(printf '%s\n' "${VISIBLE_BODY}" | awk ' /^## Attribution[[:space:]]*$/ { in_section=1; next } /^## / && in_section { exit } @@ -192,9 +205,6 @@ if [ "${BRANCH_KIND}" = "role-bug" ]; then echo "FAIL[check-naming]: base-sha and head-sha must be lowercase hexadecimal commit SHAs" FAILED=1 fi -elif [ "${BRANCH_KIND}" = "chore" ] && [ -n "${TITLE_BUG}" ]; then - echo "FAIL[check-naming]: chore branch should not carry a [bug-id] title prefix" - FAILED=1 fi if [ "${FAILED}" -eq 0 ]; then diff --git a/tests/run b/tests/run index bfb7df1..2085280 100755 --- a/tests/run +++ b/tests/run @@ -73,6 +73,22 @@ check_contract_pass() { fi } +check_chore_contract() { + local desc="$1" body="$2" base="$3" head="$4" diagnostic="$5" + local out rc=0 + out=$(cd "${FIXTURES}" && HEAD_BRANCH="chore/contract" \ + PR_TITLE="Improve delivery contract" PR_AUTHOR="dev" \ + PR_BODY="$body" BASE_SHA="$base" HEAD_SHA="$head" bash "$SCRIPT" 2>&1) || rc=$? + if [ "$rc" -eq 1 ] && printf '%s\n' "$out" | grep -Fq "$diagnostic"; then + echo "PASS [$desc]" + PASS=$((PASS + 1)) + else + echo "FAIL [$desc]: expected exit=1 and diagnostic '$diagnostic', got exit=$rc" + echo " output: $out" + FAIL=$((FAIL + 1)) + fi +} + # break-glass check "dfritz exempt — invalid branch" 0 "totally/wrong-branch" "no prefix" "dfritz" check "dfritz exempt — mismatch" 0 "dev/bug-abc/thing" "[bug-xyz] Thing" "dfritz" @@ -98,6 +114,8 @@ check "bug-id mismatch" 1 "dev/bug-x7k2m9/fix-resize" "[bug- # fail: chore branch with [bug-id] title prefix check "chore with bug-id title" 1 "chore/bump-deps" "[bug-abc123] Bump deps" "dev" +check "role/bug Conventional title" 1 "dev/bug-x7k2m9/fix-resize" "[bug-x7k2m9] fix(hub): fix resize" "dev" +check "chore Conventional title" 1 "chore/bump-deps" "chore(deps): bump deps" "dev" # fail: invalid branch forms check "invalid — no role prefix" 1 "feature/foo-bar" "Add feature" "dev" @@ -126,6 +144,12 @@ check_contract "hidden provenance does not satisfy the visible contract" \ 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 contain a non-empty ## Tracking section" +check_contract "four-space indented backticks do not expose comments" \ + $' ````\n' \ + "$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 contain a non-empty ## Tracking section" check_contract_pass "inline code containing comment opener stays visible" \ $'Use `' \ "$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 contain a non-empty ## Tracking section" +check_contract "fences inside comments do not expose provenance" \ + $'' \ + "$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 contain a non-empty ## Tracking section" check_contract_pass "inline code containing comment opener stays visible" \ $'Use `") - if (comment_end == 0) { - pos=length(line) + 1 - break - } - visible=visible " " - pos += comment_end + 2 - in_comment=0 - backslash_run=0 - continue - } - - if (substr(line, pos, 1) == "`" && backslash_run % 2 == 0) { - ticks=1 - while (substr(line, pos + ticks, 1) == "`") ticks++ - close_pos=pos + ticks - found_close=0 - while (close_pos <= length(line)) { - if (substr(line, close_pos - 1, 1) != "`" && - substr(line, close_pos, ticks) == substr(line, pos, ticks) && - substr(line, close_pos + ticks, 1) != "`") { - found_close=1 - break - } - close_pos++ - } - if (found_close) { - visible=visible substr(line, pos, close_pos + ticks - pos) - pos=close_pos + ticks - backslash_run=0 - continue - } - } - - if (substr(line, pos, 4) == "'; then + echo "FAIL[check-naming]: PR body must not contain HTML comment delimiters" + FAILED=1 +fi + # ---- branch form ---- # /bug-/ if echo "${BRANCH}" | grep -qE "^(dev|ux|ops|security|perf|architect|support)/bug-[a-z0-9]+/[a-z0-9][a-z0-9-]*$"; then diff --git a/tests/run b/tests/run index 6e4c456..ddb75cf 100755 --- a/tests/run +++ b/tests/run @@ -140,30 +140,30 @@ check_contract "attribution must be in its own section" \ "$BASE" "$GOOD_HEAD" "## Attribution must contain" check_contract "hidden provenance does not satisfy the visible contract" \ $'' \ - "$BASE" "$GOOD_HEAD" "PR body must contain a non-empty ## Tracking section" + "$BASE" "$GOOD_HEAD" "PR body must not contain HTML comment delimiters" 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 contain a non-empty ## Tracking section" + "$BASE" "$GOOD_HEAD" "PR body must not contain HTML comment delimiters" check_contract "four-space indented backticks do not expose comments" \ $' ````\n' \ - "$BASE" "$GOOD_HEAD" "PR body must contain a non-empty ## Tracking section" + "$BASE" "$GOOD_HEAD" "PR body must not contain HTML comment delimiters" check_contract "unequal backtick runs do not expose comments" \ $'`' \ - "$BASE" "$GOOD_HEAD" "PR body must contain a non-empty ## Tracking section" + "$BASE" "$GOOD_HEAD" "PR body must not contain HTML comment delimiters" check_contract "invalid backtick fence info does not expose comments" \ $'```html`oops\n' \ - "$BASE" "$GOOD_HEAD" "PR body must contain a non-empty ## Tracking section" + "$BASE" "$GOOD_HEAD" "PR body must not contain HTML comment delimiters" +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" check_contract "fences inside comments do not expose provenance" \ $'' \ - "$BASE" "$GOOD_HEAD" "PR body must contain a non-empty ## Tracking section" + "$BASE" "$GOOD_HEAD" "PR body must not contain HTML comment delimiters" check_contract "escaped backticks do not hide a comment opener" \ $'\\`' \ - "$BASE" "$GOOD_HEAD" "PR body must contain a non-empty ## Tracking section" -check_contract_pass "inline code containing comment opener stays visible" \ - $'Use `\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 HTML comment delimiters" +check_contract_pass "fenced code without comments remains valid" \ + $'```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" git -C "${FIXTURES}" commit --allow-empty -q -m "unwatermarked change" From a97440968cd12ded7103c0d8854990afdb8b5cad Mon Sep 17 00:00:00 2001 From: Evelyn Chen Date: Thu, 27 Aug 2026 17:11:35 +0000 Subject: [PATCH 07/12] Reject malformed closing fences Authored-By: Codex (GPT-5) --- README.md | 3 ++- check.sh | 4 ++++ tests/run | 7 +++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6c4ac09..df8cdb3 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,8 @@ The check validates four things for every non-break-glass Agent PR: `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 delimiters, so required provenance cannot be hidden from readers. + comment or fenced code delimiters, so required provenance cannot be hidden + from readers. 4. **Commit attribution** — every commit in `base-sha..head-sha`, including commits on `chore/` branches, ends with diff --git a/check.sh b/check.sh index 7298bae..4e2460d 100755 --- a/check.sh +++ b/check.sh @@ -29,6 +29,10 @@ if printf '%s\n' "${BODY}" | grep -Fq '' \ "$BASE" "$GOOD_HEAD" "PR body must not contain HTML comment delimiters" -check_contract_pass "fenced code without comments remains valid" \ +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" + "$BASE" "$GOOD_HEAD" "PR body must not contain fenced code delimiters" git -C "${FIXTURES}" commit --allow-empty -q -m "unwatermarked change" BAD_HEAD=$(git -C "${FIXTURES}" rev-parse HEAD) From c07ea023c0aae19200dcb1502c9418aad98dd3ab Mon Sep 17 00:00:00 2001 From: Evelyn Chen Date: Thu, 27 Aug 2026 17:26:13 +0000 Subject: [PATCH 08/12] Validate visible rendered provenance Authored-By: Codex (GPT-5) --- README.md | 10 ++++++--- action.yaml | 8 ++++++++ check.sh | 39 +++++++++++++++++++++-------------- tests/bin/curl | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/run | 46 ++++++++++++++++++++++++++--------------- 5 files changed, 125 insertions(+), 34 deletions(-) create mode 100755 tests/bin/curl 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) From 131976a5f14850afbc2e698865c397703884b09a Mon Sep 17 00:00:00 2001 From: Evelyn Chen Date: Thu, 27 Aug 2026 17:35:21 +0000 Subject: [PATCH 09/12] Scope rendered provenance checks Authored-By: Codex (GPT-5) --- README.md | 7 ++++--- check.sh | 42 +++++++++++++++++++++++++++++++++++------- tests/bin/curl | 28 ++++++++++++++++++++++++++++ tests/run | 8 +++++++- 4 files changed, 74 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 0cbde6c..a0f4c16 100644 --- a/README.md +++ b/README.md @@ -77,9 +77,10 @@ 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. 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. + product/model watermark. The action asks Gitea to render the body with a + bounded 5-second connection and 15-second total wait, then checks visible + `

` sections outside collapsed `
` content. 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/check.sh b/check.sh index 8c13f08..324a47a 100755 --- a/check.sh +++ b/check.sh @@ -32,16 +32,44 @@ if [ -z "${SERVER_URL}" ] || [ -z "${TOKEN}" ]; then elif ! RENDERED_BODY=$(printf '%s' "${BODY}" | jq -Rs '{Text: ., Mode: "gfm"}' | curl --fail --silent --show-error \ + --connect-timeout 5 \ + --max-time 15 \ --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' "${RENDERED_BODY}" | grep -Eiq '])'; then - echo "FAIL[check-naming]: rendered PR body must not contain collapsed details" - FAILED=1 -fi + +# A collapsed disclosure is valid supporting content, but provenance inside one +# is not visible by default. Remove details subtrees before locating sections. +VISIBLE_BODY=$(printf '%s\n' "${RENDERED_BODY}" | + awk ' + { + line=$0 "\n" + for (i=1; i<=length(line); i++) { + char=substr(line, i, 1) + if (in_tag) { + tag=tag char + if (char == ">") { + lower=tolower(tag) + if (lower ~ /^])/) details_depth++ + else if (lower ~ /^<\/details([[:space:]>])/) { + if (details_depth > 0) details_depth-- + } + else if (details_depth == 0) printf "%s", tag + in_tag=0 + tag="" + } + } + else if (char == "<") { + in_tag=1 + tag=char + } + else if (details_depth == 0) printf "%s", char + } + } + ') # ---- branch form ---- # /bug-/ @@ -81,7 +109,7 @@ if [ "${BRANCH_KIND}" = "role-bug" ]; then FAILED=1 fi - tracking=$(printf '%s\n' "${RENDERED_BODY}" | awk ' + tracking=$(printf '%s\n' "${VISIBLE_BODY}" | awk ' /]*>Tracking<\/h2>/ { in_section=1; next } /]*>/ && in_section { exit } in_section { print } @@ -90,7 +118,7 @@ if [ "${BRANCH_KIND}" = "role-bug" ]; then echo "FAIL[check-naming]: PR body must contain a non-empty ## Tracking section" FAILED=1 else - if ! printf '%s\n' "${tracking}" | grep -qE "(^|[[:space:]])Fixes[[:space:]]+${BRANCH_BUG}([^a-z0-9]|$)"; then + if ! printf '%s\n' "${tracking}" | grep -qE "(^|[[:space:]>])Fixes[[:space:]]+${BRANCH_BUG}([^a-z0-9]|$)"; then echo "FAIL[check-naming]: ## Tracking must contain the literal token 'Fixes ${BRANCH_BUG}'" FAILED=1 fi @@ -106,7 +134,7 @@ elif [ "${BRANCH_KIND}" = "chore" ] && [ -n "${TITLE_BUG}" ]; then fi if [ "${BRANCH_KIND}" != "invalid" ]; then - attribution=$(printf '%s\n' "${RENDERED_BODY}" | awk ' + attribution=$(printf '%s\n' "${VISIBLE_BODY}" | awk ' /]*>Attribution<\/h2>/ { in_section=1; next } /]*>/ && in_section { exit } in_section { print } diff --git a/tests/bin/curl b/tests/bin/curl index f7b975e..63b420a 100755 --- a/tests/bin/curl +++ b/tests/bin/curl @@ -2,6 +2,29 @@ # Deterministic Gitea Markdown renderer stub for check.sh contract tests. set -euo pipefail +connect_timeout=0 +total_timeout=0 +while [ "$#" -gt 0 ]; do + case "$1" in + --connect-timeout) + [ "${2:-}" = "5" ] || exit 2 + connect_timeout=1 + shift 2 + ;; + --max-time) + [ "${2:-}" = "15" ] || exit 2 + total_timeout=1 + shift 2 + ;; + *) shift ;; + esac +done +[ "${connect_timeout}" -eq 1 ] && [ "${total_timeout}" -eq 1 ] || exit 2 + +if printf '%s\n' "${PR_BODY}" | grep -Fq '[[stall-renderer]]'; then + exit 28 +fi + if printf '%s\n' "${PR_BODY}" | grep -Fq '