Skip to content

Add focused unit tests for core PR-Agent flows#2373

Open
PeterDaveHello wants to merge 1 commit intoThe-PR-Agent:mainfrom
PeterDaveHelloKitchen:add-core-unit-tests
Open

Add focused unit tests for core PR-Agent flows#2373
PeterDaveHello wants to merge 1 commit intoThe-PR-Agent:mainfrom
PeterDaveHelloKitchen:add-core-unit-tests

Conversation

@PeterDaveHello
Copy link
Copy Markdown
Contributor

Cover routing, PR processing, reviewer labels, code suggestions, GitHub Action behavior, webhook helpers, GitLab URL handling, LiteLLM request shaping, provider configuration errors, and PR description helpers.

These tests target behavior that is important and likely to change, while keeping production code untouched.

This work was developed through human-led AI collaboration using codex-cli v0.128.0 with GPT-5.5, GitHub Copilot CLI 1.0.40 with GPT-5.5, and Claude Opus 4.7.

@qodo-free-for-open-source-projects
Copy link
Copy Markdown
Contributor

Review Summary by Qodo

Add focused unit tests for core PR-Agent flows

🧪 Tests

Grey Divider

Walkthroughs

Description
• Add comprehensive unit tests for core PR-Agent flows
• Cover routing, PR processing, reviewer labels, code suggestions
• Test GitHub Action behavior, webhook helpers, GitLab URL handling
• Test LiteLLM request shaping and provider configuration errors
Diagram
flowchart LR
  A["Test Coverage"] --> B["Routing & Processing"]
  A --> C["Tools & Suggestions"]
  A --> D["Webhooks & Providers"]
  B --> E["PR Agent routing"]
  B --> F["PR processing logic"]
  C --> G["Code suggestions"]
  C --> H["PR description"]
  D --> I["GitHub Action runner"]
  D --> J["GitLab provider"]
  D --> K["Webhook logic"]
Loading

Grey Divider

File Changes

1. tests/unittest/test_git_provider_utils.py 🧪 Tests +140/-0

Test configuration error handling for git providers

tests/unittest/test_git_provider_utils.py


2. tests/unittest/test_github_action_runner_core.py 🧪 Tests +105/-0

Test GitHub Action runner core functionality

tests/unittest/test_github_action_runner_core.py


3. tests/unittest/test_gitlab_provider.py 🧪 Tests +43/-3

Enhance GitLab provider tests with additional scenarios

tests/unittest/test_gitlab_provider.py


View more (7)
4. tests/unittest/test_litellm_chat_completion_core.py 🧪 Tests +92/-0

Test LiteLLM chat completion request shaping

tests/unittest/test_litellm_chat_completion_core.py


5. tests/unittest/test_pr_agent_routing.py 🧪 Tests +190/-0

Test PR Agent command routing and request handling

tests/unittest/test_pr_agent_routing.py


6. tests/unittest/test_pr_code_suggestions_core.py 🧪 Tests +182/-0

Test PR code suggestions filtering and publishing

tests/unittest/test_pr_code_suggestions_core.py


7. tests/unittest/test_pr_description.py 🧪 Tests +92/-0

Add PR description file labels and marker tests

tests/unittest/test_pr_description.py


8. tests/unittest/test_pr_processing_core.py 🧪 Tests +137/-0

Test PR processing patch generation and model selection

tests/unittest/test_pr_processing_core.py


9. tests/unittest/test_pr_reviewer_core.py 🧪 Tests +92/-0

Test PR reviewer labels and answer collection logic

tests/unittest/test_pr_reviewer_core.py


10. tests/unittest/test_webhook_logic_core.py 🧪 Tests +185/-0

Test webhook payload processing and filtering logic

tests/unittest/test_webhook_logic_core.py


Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects
Copy link
Copy Markdown
Contributor

qodo-free-for-open-source-projects Bot commented May 5, 2026

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (2)

Grey Divider


Action required

1. GitLab webhook import crashes 🐞 Bug ☼ Reliability
Description
The gitlab_webhook_module fixture imports pr_agent.servers.gitlab_webhook without ensuring
GITLAB.URL is set, but the module raises ValueError at import time when that setting is missing.
This can make the new unit tests fail in environments that run with default settings (no GitLab URL
configured).
Code

tests/unittest/test_webhook_logic_core.py[R9-17]

+@pytest.fixture
+def gitlab_webhook_module():
+    settings = get_settings()
+    original_git_provider = settings.config.get("git_provider", None)
+    module = importlib.import_module("pr_agent.servers.gitlab_webhook")
+    try:
+        yield module
+    finally:
+        settings.config.git_provider = original_git_provider
Evidence
The test fixture imports pr_agent.servers.gitlab_webhook unconditionally, while the webhook module
performs a required configuration check at module import and raises if GITLAB.URL is not
configured; default settings don’t define it, so the import is environment-dependent and can fail.

tests/unittest/test_webhook_logic_core.py[9-17]
pr_agent/servers/gitlab_webhook.py[303-306]
pr_agent/settings/configuration.toml[5-15]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`tests/unittest/test_webhook_logic_core.py` imports `pr_agent.servers.gitlab_webhook` inside a fixture, but `pr_agent.servers.gitlab_webhook` raises `ValueError` at import time if `GITLAB.URL` is not configured. This makes the test suite fail depending on environment defaults.
## Issue Context
`pr_agent/servers/gitlab_webhook.py` validates `GITLAB.URL` at module import (`raise ValueError("GITLAB.URL is not set")`). The test fixture currently only saves/restores `config.git_provider` and does not set/restore `GITLAB.URL`.
## Fix Focus Areas
- tests/unittest/test_webhook_logic_core.py[9-17]
## Suggested change
In the `gitlab_webhook_module` fixture:
- Save the original `GITLAB.URL` value.
- Set `GITLAB.URL` to a safe dummy value (e.g., `https://gitlab.com`) before importing.
- Optionally `importlib.reload()` the module if it may already be imported.
- Restore the original `GITLAB.URL` in `finally` (unset if it was absent).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. gitlab_webhook_module cached import 📘 Rule violation ☼ Reliability ⭐ New
Description
The fixture sets settings and then calls importlib.import_module(...), which will return a cached
module if it was imported earlier in the test run, making the tests order-dependent and potentially
flaky. This violates the requirement to stabilize tests that depend on process-global state (module
import side effects + global settings).
Code

tests/unittest/test_webhook_logic_core.py[R10-26]

+@pytest.fixture
+def gitlab_webhook_module():
+    settings = get_settings()
+    original_git_provider = settings.config.get("git_provider", None)
+    had_gitlab_settings = "GITLAB" in settings
+    original_gitlab_settings = copy.deepcopy(settings.get("GITLAB", None))
+    settings.set("GITLAB.URL", "https://gitlab.com")
+    try:
+        module = importlib.import_module("pr_agent.servers.gitlab_webhook")
+        yield module
+    finally:
+        settings.config.git_provider = original_git_provider
+        if had_gitlab_settings:
+            settings.set("GITLAB", original_gitlab_settings)
+        else:
+            settings.unset("GITLAB", force=True)
+
Evidence
The new fixture imports pr_agent.servers.gitlab_webhook after mutating global settings, but
importlib.import_module may reuse an already-imported module, so module-level initialization that
reads settings runs only once and can depend on prior tests' global state. The imported module
performs settings-dependent initialization at import time (e.g., setup_logger(...) and
secret_provider = ...), amplifying the order-dependence risk.

tests/unittest/test_webhook_logic_core.py[10-26]
pr_agent/servers/gitlab_webhook.py[24-29]
Best Practice: Learned patterns

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The `gitlab_webhook_module` fixture mutates global settings and then imports `pr_agent.servers.gitlab_webhook` using `importlib.import_module`, which can return a cached module and skip settings-dependent module initialization, making tests order-dependent/flaky.

## Issue Context
`pr_agent.servers.gitlab_webhook` performs settings-dependent work at import time (e.g., `setup_logger(...)` and `secret_provider = ...`). If the module was imported earlier in the session with different settings, this fixture will not re-run that initialization.

## Fix Focus Areas
- tests/unittest/test_webhook_logic_core.py[10-26]
- pr_agent/servers/gitlab_webhook.py[24-29]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Single-quoted /answer request 📘 Rule violation ⚙ Maintainability
Description
A newly added test uses a single-quoted string literal for the /answer command, diverging from the
repo convention preferring double quotes. This may trigger style inconsistencies across the test
suite.
Code

tests/unittest/test_pr_agent_routing.py[158]

+    handled = await PRAgent()._handle_request("https://example/pr/1", '/answer "because prod is broken"')
Evidence
PR Compliance ID 8 requires Ruff-consistent formatting and prefers double quotes for strings. The
new test passes a single-quoted command string to _handle_request.

AGENTS.md
tests/unittest/test_pr_agent_routing.py[158-158]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A newly added test uses a single-quoted string literal for the `/answer` command, conflicting with the repo’s double-quote preference.
## Issue Context
Ruff/project convention prefers double quotes; using consistent quoting reduces churn and lint noise.
## Fix Focus Areas
- tests/unittest/test_pr_agent_routing.py[158-158]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Previous review results

Review updated until commit ca4ebd1

Results up to commit e253273


🐞 Bugs (1) 📘 Rule violations (1)


Action required
1. GitLab webhook import crashes 🐞 Bug ☼ Reliability
Description
The gitlab_webhook_module fixture imports pr_agent.servers.gitlab_webhook without ensuring
GITLAB.URL is set, but the module raises ValueError at import time when that setting is missing.
This can make the new unit tests fail in environments that run with default settings (no GitLab URL
configured).
Code

tests/unittest/test_webhook_logic_core.py[R9-17]

+@pytest.fixture
+def gitlab_webhook_module():
+    settings = get_settings()
+    original_git_provider = settings.config.get("git_provider", None)
+    module = importlib.import_module("pr_agent.servers.gitlab_webhook")
+    try:
+        yield module
+    finally:
+        settings.config.git_provider = original_git_provider
Evidence
The test fixture imports pr_agent.servers.gitlab_webhook unconditionally, while the webhook module
performs a required configuration check at module import and raises if GITLAB.URL is not
configured; default settings don’t define it, so the import is environment-dependent and can fail.

tests/unittest/test_webhook_logic_core.py[9-17]
pr_agent/servers/gitlab_webhook.py[303-306]
pr_agent/settings/configuration.toml[5-15]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`tests/unittest/test_webhook_logic_core.py` imports `pr_agent.servers.gitlab_webhook` inside a fixture, but `pr_agent.servers.gitlab_webhook` raises `ValueError` at import time if `GITLAB.URL` is not configured. This makes the test suite fail depending on environment defaults.

## Issue Context
`pr_agent/servers/gitlab_webhook.py` validates `GITLAB.URL` at module import (`raise ValueError("GITLAB.URL is not set")`). The test fixture currently only saves/restores `config.git_provider` and does not set/restore `GITLAB.URL`.

## Fix Focus Areas
- tests/unittest/test_webhook_logic_core.py[9-17]

## Suggested change
In the `gitlab_webhook_module` fixture:
- Save the original `GITLAB.URL` value.
- Set `GITLAB.URL` to a safe dummy value (e.g., `https://gitlab.com`) before importing.
- Optionally `importlib.reload()` the module if it may already be imported.
- Restore the original `GITLAB.URL` in `finally` (unset if it was absent).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended
2. Single-quoted /answer request 📘 Rule violation ⚙ Maintainability
Description
A newly added test uses a single-quoted string literal for the /answer command, diverging from the
repo convention preferring double quotes. This may trigger style inconsistencies across the test
suite.
Code

tests/unittest/test_pr_agent_routing.py[158]

+    handled = await PRAgent()._handle_request("https://example/pr/1", '/answer "because prod is broken"')
Evidence
PR Compliance ID 8 requires Ruff-consistent formatting and prefers double quotes for strings. The
new test passes a single-quoted command string to _handle_request.

AGENTS.md
tests/unittest/test_pr_agent_routing.py[158-158]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A newly added test uses a single-quoted string literal for the `/answer` command, conflicting with the repo’s double-quote preference.

## Issue Context
Ruff/project convention prefers double quotes; using consistent quoting reduces churn and lint noise.

## Fix Focus Areas
- tests/unittest/test_pr_agent_routing.py[158-158]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Qodo Logo

Comment thread tests/unittest/test_litellm_chat_completion_core.py Fixed
Comment thread tests/unittest/test_litellm_chat_completion_core.py Fixed
Comment thread tests/unittest/test_pr_agent_routing.py Fixed
Comment thread tests/unittest/test_pr_processing_core.py Fixed
Comment on lines +9 to +17
@pytest.fixture
def gitlab_webhook_module():
settings = get_settings()
original_git_provider = settings.config.get("git_provider", None)
module = importlib.import_module("pr_agent.servers.gitlab_webhook")
try:
yield module
finally:
settings.config.git_provider = original_git_provider
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.

Action required

1. Gitlab webhook import crashes 🐞 Bug ☼ Reliability

The gitlab_webhook_module fixture imports pr_agent.servers.gitlab_webhook without ensuring
GITLAB.URL is set, but the module raises ValueError at import time when that setting is missing.
This can make the new unit tests fail in environments that run with default settings (no GitLab URL
configured).
Agent Prompt
## Issue description
`tests/unittest/test_webhook_logic_core.py` imports `pr_agent.servers.gitlab_webhook` inside a fixture, but `pr_agent.servers.gitlab_webhook` raises `ValueError` at import time if `GITLAB.URL` is not configured. This makes the test suite fail depending on environment defaults.

## Issue Context
`pr_agent/servers/gitlab_webhook.py` validates `GITLAB.URL` at module import (`raise ValueError("GITLAB.URL is not set")`). The test fixture currently only saves/restores `config.git_provider` and does not set/restore `GITLAB.URL`.

## Fix Focus Areas
- tests/unittest/test_webhook_logic_core.py[9-17]

## Suggested change
In the `gitlab_webhook_module` fixture:
- Save the original `GITLAB.URL` value.
- Set `GITLAB.URL` to a safe dummy value (e.g., `https://gitlab.com`) before importing.
- Optionally `importlib.reload()` the module if it may already be imported.
- Restore the original `GITLAB.URL` in `finally` (unset if it was absent).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Handled by setting GITLAB.URL before import and restoring GITLAB/git_provider afterward. avoiding reload() here because these tests only cover helper behavior, and forced module reinitialization would be more invasive than needed.

Cover routing, PR processing, reviewer labels, code suggestions,
GitHub Action behavior, webhook helpers, GitLab URL handling,
LiteLLM request shaping, provider configuration errors, and PR
description helpers.

These tests target behavior that is important and likely to change,
while keeping production code untouched.

This work was developed through human-led AI collaboration using
codex-cli v0.128.0 with GPT-5.5, GitHub Copilot CLI 1.0.40 with
GPT-5.5, and Claude Opus 4.7.
@PeterDaveHello PeterDaveHello force-pushed the add-core-unit-tests branch from e253273 to ca4ebd1 Compare May 5, 2026 16:56
@qodo-free-for-open-source-projects
Copy link
Copy Markdown
Contributor

qodo-free-for-open-source-projects Bot commented May 5, 2026

Persistent review updated to latest commit ca4ebd1

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.

2 participants