Repository navigation
Fix(trailers): Keep one trailer block when adding - #562
ModeSevenIndustrialSolutions merged 4 commits into
Conversation
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>
There was a problem hiding this comment.
🟢 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
There was a problem hiding this comment.
🤖 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
left a comment
There was a problem hiding this comment.
🤖 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.
ccb245f
into
lfreleng-actions:main
Closes #559
Authored by an AI agent; human review required
claude-opus-5.5via GitHub Copilot CLIfdb5cb35ec76f13e0e36622aae7df41c0b185721uv run pytestprek 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.pyAISLOP_NO_TELEMETRY=1 aislop scan --changes --base fdb5cb35ec76f13e0e36622aae7df41c0b185721 --jsonuv run python scripts/demo_trailer_functionality.pygit log --raw --format=%h fdb5cb35ec76f13e0e36622aae7df41c0b185721..HEADThe
github-code-monkey-botworkflow 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_trailersalways opened a new paragraph for the trailers it added. When the message already ended in a trailer block, that split the block in two, andparse_trailers(which reads only the last paragraph) lost the earlier trailers, so an existingChange-Idwas no longer found.Four commits:
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 markedxfail(strict=True). Also adds tests (passing onmain) for the no-block cases (a subject alone, a subject with a colon, a subject and body, a last paragraph that is not allKey: valuelines) and for the no-duplicate rule.Orchestrator._find_trailer_boundaryintotrailers.find_trailer_boundary.trailers.pyimports nothing from the package, so this adds no import cycle.core._build_commit_message_with_trailersandgitutils._parse_trailersnow both call it.gitutils._parse_trailershad 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.add_trailersusesfind_trailer_boundaryto 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.Orchestrator._append_missing_trailershas no caller undersrc/. Its only users were two tests intests/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_trailersand stay. The module docstring now describes what is left.parse_trailersand the production message builder are unchanged, as the issue scopes.Validation
uv run pytest(full suite, coverage gate included): exit 0 after each commitprek run --files <all changed files>: exit 0. The commit hooks (ruff, mypy, basedpyright, reuse, aislop, pytest, gitlint) also passed on every commitAISLOP_NO_TELEMETRY=1 aislop scan --changes --base fdb5cb3 --json: emptydiagnostics, no engine skippeduv run python scripts/demo_trailer_functionality.py: exit 0parse_trailers(out)now findsChange-Id,Signed-off-byandGitHub-PR, andextract_change_ids(out)returns the Change-IdPoints a reviewer may question
_append_missing_trailersputs 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_fixstays. It calls no production appender, only_build_pr_metadata_trailers, and is left alone as out of scope.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.parse_trailers, so it inherits that reader's view of the last paragraph (for example, a subject alone such asfix: somethingcounts as a trailer there). Reconciling the readers is out of scope here (Test: Fuzz the commit and comment parsers #560).scripts/demo_trailer_functionality.pyis executable, so this workflow cannot edit it. It needed no change and still runs.