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
453 changes: 394 additions & 59 deletions agents/backport_agent.py

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions agents/merge_request_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
MergeRequestInputSchema,
MergeRequestOutputSchema,
)
from common.utils import is_cs_branch
from constants import I_AM_JOTNAR
from observability import setup_observability
from tools.commands import RunShellCommandTool
Expand Down Expand Up @@ -62,14 +63,15 @@ def get_instructions() -> str:

2. If you updated the spec file, use `rpmlint <PACKAGE>.spec` to validate your changes and fix any new issues.

3. Verify any changes to patches by running `centpkg --name=<PACKAGE> --namespace=rpms --release=<DIST_GIT_BRANCH> prep`.
3. Verify any changes to patches by running `<PKG_TOOL> --name=<PACKAGE> --namespace=rpms --release=<DIST_GIT_BRANCH> prep`.
Repeat as necessary. Do not remove any patches unless all their hunks have been already applied
to the upstream sources.
Note: <PKG_TOOL> is `centpkg` for CentOS Stream branches (c9s, c10s) and `rhpkg` for RHEL branches.

4. If you removed any patch file references from the spec file (e.g. because they were already applied upstream),
you must remove all the corresponding patch files from the repository as well.

5. Generate a SRPM using `centpkg --name=<PACKAGE> --namespace=rpms --release=<DIST_GIT_BRANCH> srpm`.
5. Generate a SRPM using `<PKG_TOOL> --name=<PACKAGE> --namespace=rpms --release=<DIST_GIT_BRANCH> srpm`.

6. In your output, provide a "files_to_git_add" list containing all files that have been modified, added or removed.
This typically includes the updated spec file and any new/modified/deleted patch files or other files you've changed
Expand Down Expand Up @@ -245,6 +247,7 @@ async def prepare_dist_git_from_mr(state):
return "run_merge_request_agent"

async def run_merge_request_agent(state):
pkg_tool = "centpkg" if is_cs_branch(state.dist_git_branch) else "rhpkg"
response = await merge_request_agent.run(
render_prompt(
template=get_prompt(),
Expand All @@ -259,6 +262,7 @@ async def run_merge_request_agent(state):
comments=state.merge_request_comments,
fedora_clone=state.fedora_clone,
build_error=state.build_error,
pkg_tool=pkg_tool,
),
),
expected_output=MergeRequestOutputSchema,
Expand Down
11 changes: 7 additions & 4 deletions agents/rebase_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
RebaseOutputSchema,
Task,
)
from common.utils import redis_client, fix_await
from common.utils import redis_client, fix_await, is_cs_branch
from constants import I_AM_JOTNAR, CAREFULLY_REVIEW_CHANGES
from observability import setup_observability
from tools.commands import RunShellCommandTool
Expand Down Expand Up @@ -79,21 +79,22 @@ def get_instructions() -> str:
4. Use `rpmlint <PACKAGE>.spec` to validate your changes and fix any new issues.

5. Download upstream sources using `spectool -g -S <PACKAGE>.spec`.
Run `centpkg --name=<PACKAGE> --namespace=rpms --release=<DIST_GIT_BRANCH> prep`
Run `<PKG_TOOL> --name=<PACKAGE> --namespace=rpms --release=<DIST_GIT_BRANCH> prep`
to see if everything is in order. It is possible that some *.patch files will fail to apply now
that the spec file has been updated. Don't jump to conclusions - if one patch fails to apply, it doesn't mean
all other patches fail to apply as well. Go through the errors one by one, fix them and verify the changes
by running `centpkg --name=<PACKAGE> --namespace=rpms --release=<DIST_GIT_BRANCH> prep` again.
by running `<PKG_TOOL> --name=<PACKAGE> --namespace=rpms --release=<DIST_GIT_BRANCH> prep` again.
Repeat as necessary. Do not remove any patches unless all their hunks have been already applied
to the upstream sources.
Note: <PKG_TOOL> is `centpkg` for CentOS Stream branches (c9s, c10s) and `rhpkg` for RHEL branches.

6. Upload new upstream sources (files that the `spectool` command downloaded in the previous step)
to lookaside cache using the `upload_sources` tool.

7. If you removed any patch file references from the spec file (e.g. because they were already applied upstream),
you must remove all the corresponding patch files from the repository as well.

8. Generate a SRPM using `centpkg --name=<PACKAGE> --namespace=rpms --release=<DIST_GIT_BRANCH> srpm`.
8. Generate a SRPM using `<PKG_TOOL> --name=<PACKAGE> --namespace=rpms --release=<DIST_GIT_BRANCH> srpm`.

9. In your output, provide a "files_to_git_add" list containing all files that should be git added for this rebase.
This typically includes the updated spec file and any new/modified/deleted patch files or other files you've changed
Expand Down Expand Up @@ -241,6 +242,7 @@ async def fork_and_prepare_dist_git(state):

async def run_rebase_agent(state):
package_instructions = await get_package_instructions(state.package, "rebase")
pkg_tool = "centpkg" if is_cs_branch(state.dist_git_branch) else "rhpkg"
response = await rebase_agent.run(
render_prompt(
template=get_prompt(),
Expand All @@ -253,6 +255,7 @@ async def run_rebase_agent(state):
jira_issue=state.jira_issue,
build_error=state.build_error,
package_instructions=package_instructions,
pkg_tool=pkg_tool,
),
),
expected_output=RebaseOutputSchema,
Expand Down
20 changes: 0 additions & 20 deletions agents/tests/unit/test_backporting.py

This file was deleted.

36 changes: 36 additions & 0 deletions agents/tests/unit/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ async def test_add_changelog_entry(minimal_spec):
"fix-memory-leak.patch",
"update-documentation.patch"
]),
("spec_with_macro_patches", "3.5.3", [
"mypackage-3.5.3-Fix-CVE-2026-4111.patch",
]),
("minimal_spec", "0.1", []),
],
)
Expand Down Expand Up @@ -216,6 +219,39 @@ def spec_with_patches(tmp_path):
return spec


@pytest.fixture
def spec_with_macro_patches(tmp_path):
spec = tmp_path / "macro_patches.spec"
source_file = tmp_path / "source.tar.gz"
source_file.touch()
spec.write_text(
dedent(
"""
Name: mypackage
Version: 3.5.3
Release: 1%{?dist}
Summary: Test package

License: MIT

Source0: source.tar.gz
Patch0: %{name}-%{version}-Fix-CVE-2026-4111.patch

%description
Test package with macro-containing patch names

%prep
%autosetup -p1

%changelog
* Thu Jan 13 3770 Test User <test@redhat.com> - 3.5.3-1
- first version
"""
)
)
return spec


@pytest.mark.parametrize(
"rebase",
[False, True],
Expand Down
2 changes: 1 addition & 1 deletion agents/tools/specfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async def _run(
with Specfile(spec_path) as spec:
version = spec.version
with spec.patches() as patches:
patch_files = [p.location for p in patches if p.location]
patch_files = [p.expanded_location for p in patches if p.expanded_location]

return GetPackageInfoToolOutput(
result=PackageInfo(
Expand Down
Loading
Loading