Skip to content

Fix(trailers): Keep one trailer block when adding - #562

Merged
ModeSevenIndustrialSolutions merged 4 commits into
lfreleng-actions:mainfrom
lfreleng-bot-forks:code-monkey/issue-559
Nov 19, 2026
Merged

ModeSevenIndustrialSolutions merged 4 commits into
lfreleng-actions:mainfrom
lfreleng-bot-forks:code-monkey/issue-559

Conversation

@lf-releng-code-monkey-bot

Copy link
Copy Markdown
Contributor

Closes #559

Authored by an AI agent; human review required
Command Exit
uv run pytest 0
prek run --files src/github2gerrit/core.py src/github2gerrit/gitutils.py src/github2gerrit/trailers.py tests/test_metadata_trailer_separation_bug.py tests/test_trailers_additional.py 0
AISLOP_NO_TELEMETRY=1 aislop scan --changes --base fdb5cb35ec76f13e0e36622aae7df41c0b185721 --json 0
uv run python scripts/demo_trailer_functionality.py 0
git log --raw --format=%h fdb5cb35ec76f13e0e36622aae7df41c0b185721..HEAD 0

The github-code-monkey-bot workflow opened this pull request.
Nobody has merged it; a maintainer must review it first.
Review findings on this pull request are answered by a later revision round of this workflow, up to ten rounds per antagonistic review round; after that a maintainer, or the next antagonistic review, takes on any finding that remains, and a maintainer reviews every round before merge.


What changed

trailers.add_trailers always opened a new paragraph for the trailers it added. When the message already ended in a trailer block, that split the block in two, and parse_trailers (which reads only the last paragraph) lost the earlier trailers, so an existing Change-Id was no longer found.

Four commits:

  1. Test(trailers): Add expected-fail block join tests: makes the two relaxed tests (test_add_trailers_deduplicates_and_appends, test_parse_then_add_trailers_integration) assert the parsed result and drops their comments about avoiding it. Adds the reproduction from the issue. All three are marked xfail(strict=True). Also adds tests (passing on main) for the no-block cases (a subject alone, a subject with a colon, a subject and body, a last paragraph that is not all Key: value lines) and for the no-duplicate rule.
  2. Refactor(trailers): Share the trailer block rule: moves the rule for where a trailer block starts out of Orchestrator._find_trailer_boundary into trailers.find_trailer_boundary. trailers.py imports nothing from the package, so this adds no import cycle. core._build_commit_message_with_trailers and gitutils._parse_trailers now both call it. gitutils._parse_trailers had an inline copy of the same loop, which goes too, so one definition is left instead of two. Behaviour does not change: both copies returned the same index for every input.
  3. Fix(trailers): Keep one trailer block when adding: add_trailers uses find_trailer_boundary to decide whether the message ends in a trailer block. If it does, the added trailers join that block with no blank line. If not, they start a new block after one blank line, as before. Duplicates are still skipped. The xfail markers come off in this commit.
  4. Refactor(core): Drop unused trailer appender: Orchestrator._append_missing_trailers has no caller under src/. Its only users were two tests in tests/test_metadata_trailer_separation_bug.py, so I removed it rather than fixing it, along with those two tests (test_metadata_trailers_properly_separated, test_metadata_injection_with_various_issue_ids). The other tests in that file cover _build_pr_metadata_trailers and stay. The module docstring now describes what is left.

parse_trailers and the production message builder are unchanged, as the issue scopes.

Validation

  • uv run pytest (full suite, coverage gate included): exit 0 after each commit
  • prek run --files <all changed files>: exit 0. The commit hooks (ruff, mypy, basedpyright, reuse, aislop, pytest, gitlint) also passed on every commit
  • AISLOP_NO_TELEMETRY=1 aislop scan --changes --base fdb5cb3 --json: empty diagnostics, no engine skipped
  • uv run python scripts/demo_trailer_functionality.py: exit 0
  • Ran the reproduction from the issue: parse_trailers(out) now finds Change-Id, Signed-off-by and GitHub-PR, and extract_change_ids(out) returns the Change-Id

Points a reviewer may question

  • Removing tests. The two removed tests asserted that _append_missing_trailers puts a blank line between the old trailers and the GitHub metadata, which is the split-block shape the issue calls a defect. test_buggy_behavior_before_fix stays. It calls no production appender, only _build_pr_metadata_trailers, and is left alone as out of scope.
  • Empty message. add_trailers("", {...}) used to return "\nA: 1\n" and now returns "A: 1\n", with no leading blank line. No caller passes an empty message.
  • Duplicate detection still uses parse_trailers, so it inherits that reader's view of the last paragraph (for example, a subject alone such as fix: something counts as a trailer there). Reconciling the readers is out of scope here (Test: Fuzz the commit and comment parsers #560).
  • scripts/demo_trailer_functionality.py is executable, so this workflow cannot edit it. It needed no change and still runs.

lf-releng-code-monkey-bot Bot and others added 4 commits November 19, 2026 17:00
add_trailers always opens a new paragraph, so adding to a message
that already ends in a trailer block splits it and parse_trailers
loses the earlier trailers. Assert the parsed result in the two
tests that avoided it, and add a reproduction, marked as strict
expected failures until the fix lands.

Also pin the cases that must keep a fresh block after one blank
line (a subject alone, a subject with a colon, a subject and body)
and the no-duplicate rule.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
Orchestrator._find_trailer_boundary and gitutils._parse_trailers each
carried their own copy of the rule that says where a trailer block
starts: a run of "Key: value" lines preceded by a blank line. Move it
to trailers.find_trailer_boundary, a leaf module both can import
without a cycle, so add_trailers can apply the same rule next.

No behaviour change: the two copies returned the same index for every
input, and the existing tests pass unchanged.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
add_trailers always opened a new paragraph for the trailers it added.
When the message already ended in a trailer block, that split the
block in two, and parse_trailers, which reads only the last
paragraph, lost the earlier trailers: an existing Change-Id was no
longer found.

Decide with find_trailer_boundary whether the message ends in a
trailer block. When it does, the new trailers join it with no blank
line; when it does not, they start a new block after one blank line,
as before. A trailer already present is still not added twice.

Remove the expected-fail markers the tests carried.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
Orchestrator._append_missing_trailers had no caller under src/; only
two tests in test_metadata_trailer_separation_bug.py used it. It
always opened a new paragraph, the same split-block defect add_trailers
had. Production builds messages through
_build_commit_message_with_trailers, which emits one trailer block, so
remove the helper and the two tests that existed only to exercise it.
The tests of the metadata trailers themselves stay.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the trailer-block preservation change.

No open issues 🎉

What changed in this PR

Fixes #559 by keeping added trailers in a single footer block, so existing Change-Id and sign-off trailers remain discoverable by the trailer parser.

Changes:

  • Joins existing trailer blocks while preserving blank-line separation for messages without one.
  • Shares trailer-boundary detection across utilities and the production message builder without changing the builder’s behavior.
  • Strengthens regression assertions and removes the unused trailer appender and its obsolete tests.
File Description
tests/​test_trailers_additional.py Verifies parsed trailer preservation, block joining, separation, and deduplication.
tests/​test_metadata_trailer_separation_bug.py Removes obsolete appender tests and updates the module documentation.
src/​github2gerrit/​trailers.py Adds shared boundary detection and joins new trailers to existing blocks.
src/​github2gerrit/​gitutils.py Replaces duplicated boundary detection with the shared helper.
src/​github2gerrit/​core.py Uses the shared boundary helper and removes the unused appender.

Review effort: Balanced

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Antagonistic review by agent: no line-level findings; the summary below is the verdict.

No actionable defects found. The change joins added trailers to an existing footer, strengthens regression assertions, and preserves the existing boundary logic in production callers; the removed private appender has no remaining references.

Antagonistic round 1 of 3.


Automated antagonistic review by lf-releng-antagonistic-review-bot[bot] using model gpt-6-astra; see the run. This is not a human review and never an approval: a maintainer must still review and approve this pull request.

@zxiiro zxiiro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Auto-approved by agent: reviewed workflow/code change for security and CI/CD impact, found low risk. add_trailers now joins an existing trailer block instead of splitting it; the boundary rule moves unchanged into trailers.find_trailer_boundary, and an unused appender is dropped. add_trailers has no production caller, the production message builder keeps the same behaviour, and no workflow, permission or secret changes.

@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions merged commit ccb245f into lfreleng-actions:main Nov 19, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix(trailers): Keep one trailer block when adding

3 participants