Skip to content

fix(spec): group patch-add tags with existing Patch tags - #366

Open
Izan (IzanVil) wants to merge 5 commits into
microsoft:mainfrom
IzanVil:fix/patch-add-group-patch-tags
Open

Izan (IzanVil) wants to merge 5 commits into
microsoft:mainfrom
IzanVil:fix/patch-add-group-patch-tags

Conversation

@IzanVil

Copy link
Copy Markdown

Fixes #284

Problem

When a spec has no %patchlist section, the patch-add overlay appends the new PatchN: tag at the very end of the preamble (typically right before %description) instead of next to the existing Patch tags. AddPatchEntry fell back to AddTag, which always appends to the end of the section.

Changes

Following the same style as #235 / #345, this reuses the family-based insertion that InsertTag already uses for Source tags:

  • refactor(spec): move the body of InsertTag into insertTagAfterFamily, with a flag controlling whether it falls back to the last tag of any kind when no tag of the same family exists. InsertTag keeps its current behavior.
  • fix(spec): AddPatchEntry now inserts the new PatchN: after the last Patch tag of the target package, moving past an enclosing %if/%endif so the new tag stays unconditional. Without a same-family match it does not fall back to "any tag", so it keeps today's AddTag behavior.

Against the acceptance criteria:

  • New patches added via patch-add are placed next to existing Patch/PatchN tags.
  • Specs with a %patchlist section continue to append there.
  • Specs with no existing patch tags behave as today (output pinned by a test).

Note: already-rendered specs that use patch-add on top of existing Patch tags will see the PatchN: line move next to the other Patch tags the next time they are rendered. This is the intended cosmetic change.

Testing

  • New table-driven TestAddPatchEntry in internal/rpm/spec/edit_test.go: unnumbered Patch: followed by a conditional BuildRequires block (the libsolv shape from the issue), multiple numbered Patch tags, last Patch tag inside a conditional, %patchlist present, and no existing Patch tags. The three grouping cases fail before the fix and pass after it.
  • Existing TestInsertTag and TestAddPatchEntry_EmptySpec pass unchanged.
  • mage unit and mage check lint pass, on each commit.

Copilot AI lite review requested due to automatic review settings September 27, 2026 11:46

Copilot AI 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.

Copilot review overview

🟢 Approval recommended

No unresolved review issues were identified.

Review effort: Lite
Findings: None

What changed in this PR

Fixes RPM spec patch-add placement so new patch tags stay grouped with existing patch tags.

Changes:

  • Refactors family-based tag insertion.
  • Applies grouped insertion to AddPatchEntry.
  • Adds regression tests for grouping and fallback scenarios.
File Summary
internal/​rpm/​spec/​edit.go Implements family-aware patch insertion.
internal/​rpm/​spec/​edit_test.go Adds regression coverage for patch placement scenarios.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@trungams

Copy link
Copy Markdown
Member

Thank you Izan (@IzanVil) for opening this PR! We are currently reviewing our usage of the overlay engine so cosmetic changes may take a bit of time to get in. We will keep you posted.

Move the body of InsertTag into insertTagAfterFamily with a flag that
controls whether insertion falls back to the last tag of any kind when no
tag of the same family exists. InsertTag keeps its current behavior.

Signed-off-by: IzanVil <soyoquienmas@outlook.com>
When a spec has no %patchlist section, AddPatchEntry appended the new
PatchN tag at the end of the preamble, typically right before
%description, instead of next to the existing Patch tags.

Insert the new tag after the last Patch tag of the target package, moving
past any enclosing conditional block. Specs with a %patchlist section still
append there, and specs without Patch tags keep appending to the end of the
preamble.

Fixes microsoft#284

Signed-off-by: IzanVil <soyoquienmas@outlook.com>
…sertTag

Signed-off-by: IzanVil <soyoquienmas@outlook.com>
Signed-off-by: IzanVil <soyoquienmas@outlook.com>
@IzanVil

Copy link
Copy Markdown
Author

Rebased onto current main, which now has two spec editors (legacy and the opt-in structural). The same fix is applied to both, each as a refactor commit plus a fix commit, and TestAddPatchEntry now runs against both editors. If you would rather keep this PR limited to the default legacy editor while the overlay engine is under review, the last two commits can be dropped cleanly.

@IzanVil
Izan (IzanVil) force-pushed the fix/patch-add-group-patch-tags branch from b6f7cf9 to 75983a4 Compare October 19, 2026 15:57
Copilot AI lite review requested due to automatic review settings October 19, 2026 15:57

Copilot AI 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.

🟢 Approval recommended

No unresolved issues were identified, and all reviewed scenarios are covered.

No open issues 🎉

Review effort: Lite

Copilot AI lite review requested due to automatic review settings October 29, 2026 18:47

Copilot AI 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.

🟢 Approval recommended

No active review issues are reported, and the patch-grouping changes are accompanied by targeted table-driven coverage across both spec editors and fallback scenarios.

No open issues 🎉

Review effort: Lite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

patch-add overlay appends PatchN: tag at end of preamble instead of grouping with existing Patch tags

4 participants