Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/code.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,17 @@ vars. Key differences from single-forge setup:
tracker comes from `FULLSEND_TRACKER`, or from `FULLSEND_WORK_ITEM_SOURCE`
(exported by `fullsend run`) when that is unset. If both are set and
disagree, the run stops.
- **Jira origin metadata** — newly created Jira-originated PRs and MRs
include a `fullsend:work-item` HTML comment in the managed post-script
verification footer. Its JSON records `source: "jira"`, `key`, and `url`
from the code run. The run stops before pushing the branch when the key,
URL, and `JIRA_BASE_URL` disagree. Fix-agent description updates preserve
this record, and `fullsend:work-item` comments in agent-written descriptions
are dropped, except literal examples inside Markdown code spans or closed
fenced blocks. If an existing origin record falls outside the preserved footer,
the description update is skipped with a warning rather than moving the record.
A Jira link in an otherwise forge-originated PR does not add the record;
existing PRs are not backfilled by this creation path.
- **Jira results** — after a Jira-sourced run creates or updates the PR/MR,
the post-script posts a short code-stage update with the PR/MR URL to the
Jira issue through `fullsend issues post-comment --tracker jira`. The
Expand Down
12 changes: 11 additions & 1 deletion docs/fix.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,19 @@ The fix agent follows a similar pipeline to the [code agent](code.md), with an a
A fix can leave the PR title or description inaccurate, for example after content moves to a different file or a test count changes. When that happens the agent proposes a replacement in the optional `pr_title` / `pr_body` fields of `agent-result.json`, and the post-script applies it. GitHub uses `gh pr edit` with the body passed through `--body-file -`. GitLab uses the merge request update API (`title` / `description`). The update happens only when all of these hold:

- the output passed schema validation and the post-script's secret scan of `agent-result.json`;
- the final description, after the normalization below, passes a second secret scan. Removing a `fullsend:work-item` comment can join text that was separate when `agent-result.json` was scanned, so a credential split by such a comment is caught here. If the scan finds a secret or cannot run, only the body update is skipped with a warning;
- the live value still matches the SHA-256 the agent recorded for the value it read (`pr_title_base_sha256` / `pr_body_base_sha256`). A human edit made after the agent read the value and before the post-script's check is not overwritten; the field is skipped with a warning instead. The check and the write are separate API calls, because neither `gh pr edit` nor the GitLab MR update offers a conditional write, so an edit landing in the short window between them can still be overwritten.

A field the agent did not propose is left unchanged. When the body is replaced, the existing issue-closing reference and the `### Post-script verification` section are kept. Before the body is written, the post-script checks that the merged body still shows them outside fenced code and HTML comments. If a proposal's Markdown could hide them (for example an unclosed code fence or HTML comment), only the body update is skipped with a warning; the post-script does not close or change the agent's Markdown, and a valid title update still applies. The outcome is noted in the summary comment. A failed update is logged as a warning and does not fail the run or block the summary.
A field the agent did not propose is left unchanged. When the body is replaced, the existing issue-closing reference and the `### Post-script verification` section are kept. Before the body is written, the post-script checks that the merged body still shows them outside fenced code and HTML comments. If a proposal's Markdown could hide them (for example an unclosed code fence or HTML comment), only the body update is skipped with a warning; the post-script does not close or change the agent's Markdown, and a valid title update still applies. The outcome is noted in the summary comment.

The body update also preserves origin metadata. A Jira-originated PR/MR created by the [code agent](code.md#multi-forge-support) carries a `<!-- fullsend:work-item {...} -->` comment under the `### Post-script verification` heading. This record belongs to the post-script, so a body update keeps the existing record in that footer, and the agent cannot add, change or promote one:

- every `fullsend:work-item` comment in the proposed text is removed, including multiline, differently spaced or cased, and nested forms, and an unclosed opener that would hide the footer. The comment is removed before closing keywords (`Fixes`, `Closes`, ...) are stripped, and the whole normalization repeats until the text stops changing. A keyword split by a comment, or separated from its issue reference by one, is therefore still removed;
- an example of the comment inside Markdown code (an inline code span or a fenced block) is literal text, not a record, so it is kept and does not block the update. Only comments outside code are removed or counted. A fence the proposal never closes would hide the footer, so that update is skipped. The code agent's creation path shelters inline spans and closed fences only, so it also removes a comment in indented code;
- if the current body holds an origin record that the update cannot keep in the selected footer (for example a record in the description, under an earlier heading, or duplicated), the body update is skipped with a warning and the record is not moved. The summary comment reports the body as not updated because the origin metadata is ambiguous, and a valid title update still applies;
- a PR/MR without an origin record gets none from a body update. A Jira link in the description does not create one.

This applies on GitHub and GitLab. A failed update is logged as a warning and does not fail the run or block the summary.

### Finding threads

Expand Down
154 changes: 143 additions & 11 deletions scripts/post-code-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3802,6 +3802,9 @@ cat > "${JIRA_INT_MOCK_BIN}/git" <<MOCKEOF
if [[ "\$1" == "remote" && "\$2" == "set-url" ]]; then
exit 0
fi
if [[ "\$1" == "push" ]]; then
echo "git push" >> "${JIRA_INT_FORGE_LOG}"
fi
if [[ "\$1" == "push" && -n "\${MOCK_JIRA_PUSH_FAIL:-}" ]]; then
echo "\${MOCK_JIRA_PUSH_ERROR:-forced local push failure}" >&2
exit 1
Expand Down Expand Up @@ -4067,13 +4070,18 @@ jira_int_fail() {
JIRA_CODE_MARKER="--marker <!-- fullsend:code-agent -->"
JIRA_OUTCOME_MARKER="--marker <!-- fullsend:code-agent-outcome -->"
JIRA_FAILURE_MARKER="--marker <!-- fullsend:code-agent-failure -->"
JIRA_ORIGIN_MARKER='<!-- fullsend:work-item {"source":"jira","key":"TESTPROJ-42","url":"https://test.atlassian.net/browse/TESTPROJ-42"} -->'

# GitHub target: PR on GitHub, stage update with the PR URL on the Jira issue.
run_jira_int "jira-github-target" github
if [ "${JIRA_INT_RC}" -ne 0 ]; then
jira_int_fail "jira-github-target-pr-url-to-jira" "post-code failed"
elif ! grep -q "^gh pr create" "${JIRA_INT_FORGE_LOG}"; then
jira_int_fail "jira-github-target-pr-url-to-jira" "PR not created on GitHub"
elif ! grep -qxF "git push" "${JIRA_INT_FORGE_LOG}"; then
jira_int_fail "jira-github-target-branch-pushed" "push was not recorded"
elif ! grep -qxF "${JIRA_ORIGIN_MARKER}" "${JIRA_INT_FORGE_LOG}"; then
jira_int_fail "jira-github-target-pr-url-to-jira" "PR body missing Jira origin metadata"
elif ! grep -qF -- "--tracker jira --fullsend-dir ${JIRA_INT_FULLSEND_DIR} --project TESTPROJ --number 42" "${JIRA_INT_FULLSEND_LOG}" \
|| ! grep -qF -- "${JIRA_CODE_MARKER}" "${JIRA_INT_FULLSEND_LOG}" \
|| ! grep -qF "opened pull request https://github.com/test-org/test-repo/pull/1 for TESTPROJ-42" "${JIRA_INT_FULLSEND_LOG}"; then
Expand Down Expand Up @@ -4226,6 +4234,10 @@ if [ "${JIRA_INT_RC}" -ne 0 ]; then
jira_int_fail "jira-gitlab-target-mr-url-to-jira" "post-code failed"
elif ! grep -qE "^curl .*--request POST .*https://gitlab.com/api/v4/projects/test-group%2Ftest-project/merge_requests" "${JIRA_INT_FORGE_LOG}"; then
jira_int_fail "jira-gitlab-target-mr-url-to-jira" "MR not created on GitLab"
elif ! grep -qxF "git push" "${JIRA_INT_FORGE_LOG}"; then
jira_int_fail "jira-gitlab-target-branch-pushed" "push was not recorded"
elif ! grep -qxF "${JIRA_ORIGIN_MARKER}" "${JIRA_INT_FORGE_LOG}"; then
jira_int_fail "jira-gitlab-target-mr-url-to-jira" "MR description missing Jira origin metadata"
elif grep -qF "atlassian.net/api/v4" "${JIRA_INT_FORGE_LOG}"; then
jira_int_fail "jira-gitlab-target-mr-url-to-jira" "GitLab API call went to the Jira host"
elif ! grep -qF -- "${JIRA_CODE_MARKER}" "${JIRA_INT_FULLSEND_LOG}" \
Expand All @@ -4245,6 +4257,124 @@ else
echo "PASS: jira-gitlab-target-requires-ci-server-host (expected failure, got exit ${JIRA_INT_RC})"
fi

# The origin record is post-script-owned: a work-item comment in the
# agent-written description is dropped and only the real record is published.
for _jira_forge in github gitlab; do
_jira_forged_name="jira-${_jira_forge}-agent-origin-comment-dropped"
JIRA_INT_RESULT_JSON='{"pr_body":"Fix.\n<!-- fullsend:work-item {\"source\":\"jira\",\"key\":\"EVIL-1\",\"url\":\"https://evil.atlassian.net/browse/EVIL-1\"} -->\n<!--fullsend:work-item {\"key\":\"EVIL-2\"}-->\nMore."}' \
run_jira_int "${_jira_forged_name}" "${_jira_forge}"
if [ "${JIRA_INT_RC}" -ne 0 ]; then
jira_int_fail "${_jira_forged_name}" "post-code failed"
elif ! grep -qxF "${JIRA_ORIGIN_MARKER}" "${JIRA_INT_FORGE_LOG}" \
|| [ "$(grep -c 'fullsend:work-item' "${JIRA_INT_FORGE_LOG}")" -ne 1 ] \
|| grep -qE 'EVIL-[12]' "${JIRA_INT_FORGE_LOG}"; then
jira_int_fail "${_jira_forged_name}" "agent-written origin comment reached the PR/MR"
else
echo "PASS: ${_jira_forged_name}"
fi
# A multiline comment goes whole: no payload line and no closing delimiter
# survives, so only the post-script record (one delimiter) remains.
_jira_multiline_name="jira-${_jira_forge}-agent-multiline-origin-comment-dropped"
JIRA_INT_RESULT_JSON='{"pr_body":"Fix.\n<!-- fullsend:work-item\n{\"source\":\"jira\",\"key\":\"EVIL-3\"}\nPAYLOAD-TAIL\n-->\nMore."}' \
run_jira_int "${_jira_multiline_name}" "${_jira_forge}"
if [ "${JIRA_INT_RC}" -ne 0 ]; then
jira_int_fail "${_jira_multiline_name}" "post-code failed"
elif ! grep -qxF "${JIRA_ORIGIN_MARKER}" "${JIRA_INT_FORGE_LOG}" \
|| grep -qE 'EVIL-3|PAYLOAD-TAIL' "${JIRA_INT_FORGE_LOG}" \
|| [ "$(grep -c -e '-->' "${JIRA_INT_FORGE_LOG}")" -ne 1 ] \
|| ! grep -qxF 'More.' "${JIRA_INT_FORGE_LOG}"; then
jira_int_fail "${_jira_multiline_name}" "multiline origin comment was not removed whole"
else
echo "PASS: ${_jira_multiline_name}"
fi
# An example of the comment in Markdown code is literal text and stays; a
# live comment beside it still goes, and the post-script record is unique.
_jira_example_name="jira-${_jira_forge}-origin-comment-example-in-code-kept"
JIRA_INT_RESULT_JSON='{"pr_body":"Fix.\nUse `<!-- fullsend:work-item {} -->` in docs, not <!-- fullsend:work-item {\"key\":\"EVIL-4\"} --> here.\n\n```html\n<!-- fullsend:work-item {\"key\":\"EXAMPLE-1\"} -->\n```\n\nMore."}' \
run_jira_int "${_jira_example_name}" "${_jira_forge}"
if [ "${JIRA_INT_RC}" -ne 0 ]; then
jira_int_fail "${_jira_example_name}" "post-code failed"
elif [ "$(grep -cxF "${JIRA_ORIGIN_MARKER}" "${JIRA_INT_FORGE_LOG}")" -ne 1 ] \
|| grep -qF 'EVIL-4' "${JIRA_INT_FORGE_LOG}" \
|| ! grep -qF 'Use `<!-- fullsend:work-item {} -->` in docs, not here.' "${JIRA_INT_FORGE_LOG}" \
|| ! grep -qxF '<!-- fullsend:work-item {"key":"EXAMPLE-1"} -->' "${JIRA_INT_FORGE_LOG}" \
|| ! grep -qxF 'More.' "${JIRA_INT_FORGE_LOG}"; then
jira_int_fail "${_jira_example_name}" "code example removed, or a live origin comment kept"
else
echo "PASS: ${_jira_example_name}"
fi
# A backtick inside an HTML comment, tag or autolink opens no code span, so
# it cannot shelter the live comment after it; a real span still can.
_jira_shelter_name="jira-${_jira_forge}-origin-comment-not-sheltered-by-markup-backtick"
JIRA_INT_RESULT_JSON='{"pr_body":"Fix.\n<!-- ` --> <!-- fullsend:work-item {\"key\":\"EVIL-5\"} --> and `x`\nSee <https://e.com/`> <!-- fullsend:work-item {\"key\":\"EVIL-6\"} --> and `y`\nSee <a title=\"`\"> <!-- fullsend:work-item {\"key\":\"EVIL-8\"} --> `z`\n<b>`<!-- fullsend:work-item {} -->`</b>\nMore."}' \
run_jira_int "${_jira_shelter_name}" "${_jira_forge}"
if [ "${JIRA_INT_RC}" -ne 0 ]; then
jira_int_fail "${_jira_shelter_name}" "post-code failed"
elif [ "$(grep -cxF "${JIRA_ORIGIN_MARKER}" "${JIRA_INT_FORGE_LOG}")" -ne 1 ] \
|| grep -qE 'EVIL-[568]' "${JIRA_INT_FORGE_LOG}" \
|| ! grep -qF '<!-- ` -->' "${JIRA_INT_FORGE_LOG}" \
|| ! grep -qF 'See <https://e.com/`> and `y`' "${JIRA_INT_FORGE_LOG}" \
|| ! grep -qxF '<b>`<!-- fullsend:work-item {} -->`</b>' "${JIRA_INT_FORGE_LOG}" \
|| ! grep -qxF 'More.' "${JIRA_INT_FORGE_LOG}"; then
jira_int_fail "${_jira_shelter_name}" "markup backtick sheltered a live origin comment, or code example lost"
else
echo "PASS: ${_jira_shelter_name}"
fi
# Pairing follows CommonMark: a fence closer takes only spaces or tabs after
# it, so "```~" / "~~~`" close nothing and the comment after them is live; a
# code span crosses a single newline, so the backtick after "b" closes the
# span opened on the previous line and the comment after it is live.
_jira_pair_name="jira-${_jira_forge}-origin-comment-not-sheltered-by-cmark-pairing-mismatch"
JIRA_INT_RESULT_JSON='{"pr_body":"Fix.\nintro\n```\nx\n```~\n```\n\n<!-- fullsend:work-item {\"key\":\"EVIL-1\"} -->\n\n```\ny\n```\n\nintro\n~~~\nx\n~~~`\n~~~\n\n<!-- fullsend:work-item {\"key\":\"EVIL-9\"} -->\n\n~~~\ny\n~~~\n\nx `a\nb` <!-- fullsend:work-item {\"key\":\"EVIL-2\"} --> `c`\nMore."}' \
run_jira_int "${_jira_pair_name}" "${_jira_forge}"
if [ "${JIRA_INT_RC}" -ne 0 ]; then
jira_int_fail "${_jira_pair_name}" "post-code failed"
elif [ "$(grep -cxF "${JIRA_ORIGIN_MARKER}" "${JIRA_INT_FORGE_LOG}")" -ne 1 ] \
|| [ "$(grep -c 'fullsend:work-item' "${JIRA_INT_FORGE_LOG}")" -ne 1 ] \
|| grep -qE 'EVIL-[129]' "${JIRA_INT_FORGE_LOG}" \
|| ! grep -qxF '```~' "${JIRA_INT_FORGE_LOG}" \
|| ! grep -qxF '~~~`' "${JIRA_INT_FORGE_LOG}" \
|| ! grep -qxF 'b` `c`' "${JIRA_INT_FORGE_LOG}" \
|| ! grep -qxF 'More.' "${JIRA_INT_FORGE_LOG}"; then
jira_int_fail "${_jira_pair_name}" "fence closer or multiline span sheltered a live origin comment"
else
echo "PASS: ${_jira_pair_name}"
fi
# A code span may cross a single newline, so a literal example split over two
# lines stays; it may not cross a blank line.
_jira_span_name="jira-${_jira_forge}-origin-comment-example-in-multiline-span-kept"
JIRA_INT_RESULT_JSON='{"pr_body":"Fix.\nUse `first\nsecond <!-- fullsend:work-item {} -->` here.\nMore."}' \
run_jira_int "${_jira_span_name}" "${_jira_forge}"
if [ "${JIRA_INT_RC}" -ne 0 ]; then
jira_int_fail "${_jira_span_name}" "post-code failed"
elif [ "$(grep -cxF "${JIRA_ORIGIN_MARKER}" "${JIRA_INT_FORGE_LOG}")" -ne 1 ] \
|| ! grep -qxF 'second <!-- fullsend:work-item {} -->` here.' "${JIRA_INT_FORGE_LOG}" \
|| ! grep -qxF 'More.' "${JIRA_INT_FORGE_LOG}"; then
jira_int_fail "${_jira_span_name}" "multiline code example removed"
else
echo "PASS: ${_jira_span_name}"
fi
done

# An inconsistent Jira identity must stop before any push or PR/MR creation.
for _jira_forge in github gitlab; do
for _jira_bad_dest in \
'url|FULLSEND_WORK_ITEM_URL=https://other.example/browse/TESTPROJ-42' \
'key|FULLSEND_WORK_ITEM_KEY=TESTPROJ-7' \
'host|JIRA_BASE_URL=https://other.atlassian.net'; do
_jira_bad_name="jira-${_jira_forge}-create-rejects-${_jira_bad_dest%%|*}"
run_jira_int "${_jira_bad_name}" "${_jira_forge}" "${_jira_bad_dest#*|}"
if [ "${JIRA_INT_RC}" -eq 0 ] \
|| grep -qE '^git push|^gh pr create|^curl .*--request POST .*merge_requests' "${JIRA_INT_FORGE_LOG}" \
|| grep -qF 'fullsend:work-item' "${JIRA_INT_FORGE_LOG}" \
|| [ -s "${JIRA_INT_FULLSEND_LOG}" ]; then
jira_int_fail "${_jira_bad_name}" "expected failure before any push, PR/MR creation or Jira write"
else
echo "PASS: ${_jira_bad_name}"
fi
done
done

# Retry: the PR already exists, so the run updates it and rewrites the same
# sticky Jira comment (same marker) instead of adding a second one.
run_jira_int "jira-existing-pr" github MOCK_EXISTING_PR=1
Expand Down Expand Up @@ -4727,8 +4857,8 @@ for _jira_refusal_write in success failure; do
fi
done

# New no-op and failure callers must reject mismatched destinations before
# issuing any tracker or forge write, while preserving their own exit status.
# Invalid identity is a setup error even on no-op and failure paths; no
# push, tracker write or forge write may happen before it is rejected.
for _jira_bad_dest in \
'url|FULLSEND_WORK_ITEM_URL=https://other.example/browse/TESTPROJ-42' \
'key|FULLSEND_WORK_ITEM_KEY=TESTPROJ-7' \
Expand All @@ -4737,19 +4867,15 @@ for _jira_bad_dest in \
_jira_bad_name="jira-${_jira_bad_path}-rejects-${_jira_bad_dest%%|*}"
if [ "${_jira_bad_path}" = noop ]; then
JIRA_INT_NO_BRANCH=1 run_jira_int "${_jira_bad_name}" github "${_jira_bad_dest#*|}"
_jira_bad_rc=0
_jira_bad_warning='Failed to post no-op comment'
else
JIRA_INT_RESULT_JSON="${JIRA_BRANCH_FAIL_RESULT}" run_jira_int "${_jira_bad_name}" github \
CODE_ALLOWED_TARGET_BRANCHES=main "${_jira_bad_dest#*|}"
_jira_bad_rc=1
_jira_bad_warning='see workflow logs'
fi
if [ "${JIRA_INT_RC}" -ne "${_jira_bad_rc}" ] \
if [ "${JIRA_INT_RC}" -ne 1 ] \
|| [ -s "${JIRA_INT_FULLSEND_LOG}" ] \
|| grep -qE '^gh (issue comment|pr create|pr comment)' "${JIRA_INT_FORGE_LOG}" \
|| ! grep -qF "${_jira_bad_warning}" "${JIRA_INT_OUT}"; then
jira_int_fail "${_jira_bad_name}" "expected zero writes, warning and preserved status"
|| [ -s "${JIRA_INT_FORGE_LOG}" ] \
|| ! grep -qE '^::error::(FULLSEND_WORK_ITEM_URL is not a Jira Cloud issue URL|FULLSEND_WORK_ITEM_KEY does not match|JIRA_BASE_URL does not match)' "${JIRA_INT_OUT}"; then
jira_int_fail "${_jira_bad_name}" "expected setup failure before any push or write"
else
echo "PASS: ${_jira_bad_name}"
fi
Expand Down Expand Up @@ -4844,7 +4970,9 @@ else
fi

# Forge-originated run (fullsend run still exports FULLSEND_WORK_ITEM_SOURCE):
# GitHub issue flow, no Jira write.
# GitHub issue flow, no Jira write or origin metadata, even with a Jira link
# in the agent-provided description.
JIRA_INT_RESULT_JSON='{"pr_body":"See https://test.atlassian.net/browse/TESTPROJ-42 for related context."}' \
run_jira_int "forge-originated" github FULLSEND_TRACKER= FULLSEND_WORK_ITEM_SOURCE=github \
FULLSEND_WORK_ITEM_KEY= FULLSEND_WORK_ITEM_URL= ISSUE_NUMBER=42 \
ISSUE_URL=https://github.com/test-org/test-repo/issues/42 JIRA_TOKEN= JIRA_USER_EMAIL= CODE_JIRA_PR_READY_TRANSITION=Review
Expand All @@ -4854,6 +4982,10 @@ elif [ -s "${JIRA_INT_FULLSEND_LOG}" ]; then
jira_int_fail "forge-originated-run-no-jira-write" "wrote to Jira for a GitHub issue"
elif ! grep -q "^gh pr create" "${JIRA_INT_FORGE_LOG}"; then
jira_int_fail "forge-originated-run-no-jira-write" "PR not created"
elif ! grep -qF 'See https://test.atlassian.net/browse/TESTPROJ-42 for related context.' "${JIRA_INT_FORGE_LOG}"; then
jira_int_fail "forge-originated-run-no-jira-write" "PR body missing the incidental Jira link"
elif grep -qF '<!-- fullsend:work-item ' "${JIRA_INT_FORGE_LOG}"; then
jira_int_fail "forge-originated-run-no-jira-write" "incidental Jira link was marked as Jira origin"
else
echo "PASS: forge-originated-run-no-jira-write"
fi
Expand Down
Loading
Loading