fix: restore Dynaconf fresh vars support
User description
The changes in PR https://github.com/qodo-ai/pr-agent/pull/2087 which are included in v0.31 prevent Dynaconf fresh vars from working properly.
For context, here's my setup with the codiumai/pr-agent:0.31-gitlab_webhook image:
In kubernetes pod, this environment variable is set:
FRESH_VARS_FOR_DYNACONF='["GITLAB"]'
Note: that this has to be uppercase as mentioned here.
In /app/pr_agent/settings_prod/.secrets.toml which is mounted from a kubernetes secret:
[gitlab]
personal_access_token = "xxx"
shared_secret = "xxx"
With v0.30, every time the secret is updated (every day in our case as we use short lived Gitlab tokens), the file is refreshed, and Dynaconf picks the changes perfectly without restarting neither the pod nor the pr-agent process.
The first commit in this PR only introduces unit tests to demonstrate the issue in Github workflow execution.
The fix is in second commit pushed after the first workflow execution: https://github.com/qodo-ai/pr-agent/pull/2104/commits/312134ae97825dd5c689b75dc2aa3c0e2ab16763
PR Type
Tests, Bug fix
Description
-
Add comprehensive unit tests for Dynaconf fresh_vars functionality
-
Tests verify fresh_vars works with custom_merge_loader configuration
-
Detect regression where fresh_vars stopped working after PR #2087
-
Cover GitLab credentials reload scenario with file modifications
Diagram Walkthrough
flowchart LR
A["Test Suite"] --> B["Fresh Vars Functionality"]
B --> C["GitLab Scenario Tests"]
B --> D["Custom Loader Integration"]
B --> E["Basic Functionality Tests"]
C --> F["Token Reload Detection"]
D --> G["Core Loaders Disabled"]
E --> H["Environment Variable Config"]
File Walkthrough
| Relevant files | |||
|---|---|---|---|
| Tests |
|
PR Compliance Guide 🔍
Below is a summary of compliance checks for this PR:
| Security Compliance | |
| 🟢 | No security concerns identifiedNo security vulnerabilities detected by AI analysis. Human verification advised for critical code. |
| Ticket Compliance | |
| ⚪ | 🎫 No ticket provided
|
| Codebase Duplication Compliance | |
| ⚪ | Codebase context is not definedFollow the guide to enable codebase context checks. |
| Custom Compliance | |
| 🟢 |
Consistent Naming ConventionsObjective: All new variables, functions, and classes must follow the project's established naming Status: Passed |
Single Responsibility for FunctionsObjective: Each function should have a single, well-defined responsibility Status: Passed | |
When relevant, utilize early returnObjective: In a code snippet containing multiple logic conditions (such as 'if-else'), prefer an Status: Passed | |
| 🔴 | No Dead or Commented-Out CodeObjective: Keep the codebase clean by ensuring all submitted code is active and necessary Status: Referred Code
|
| ⚪ | Robust Error HandlingObjective: Ensure potential errors and edge cases are anticipated and handled gracefully throughout Status: Referred Code
|
| |
Compliance status legend
🟢 - Fully Compliant🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label
First test workflow execution:
=========================== short test summary info ============================
FAILED tests/unittest/test_fresh_vars_functionality.py::TestFreshVarsGitLabScenario::test_gitlab_personal_access_token_reload
FAILED tests/unittest/test_fresh_vars_functionality.py::TestFreshVarsGitLabScenario::test_gitlab_shared_secret_reload
FAILED tests/unittest/test_fresh_vars_functionality.py::TestFreshVarsGitLabScenario::test_gitlab_multiple_fields_reload
FAILED tests/unittest/test_fresh_vars_functionality.py::TestFreshVarsCustomLoaderIntegration::test_fresh_vars_without_core_loaders
FAILED tests/unittest/test_fresh_vars_functionality.py::TestFreshVarsCustomLoaderIntegration::test_custom_loader_respects_fresh_vars
FAILED tests/unittest/test_fresh_vars_functionality.py::TestFreshVarsBasicFunctionality::test_fresh_vars_from_environment_variable
FAILED tests/unittest/test_fresh_vars_functionality.py::TestFreshVarsBasicFunctionality::test_gitlab_credentials_not_cached_when_fresh
============ 7 failed, 192 passed, 6 skipped, 24 warnings in 5.71s =============
https://github.com/qodo-ai/pr-agent/actions/runs/19370299280/job/55424179340?pr=2104#step:5:579
PR Code Suggestions ✨
Explore these optional code suggestions:
| Category | Suggestion | Impact |
| Possible issue |
Use correct helper method for testsIn tests/unittest/test_fresh_vars_functionality.py [150-168]
Suggestion importance[1-10]: 10__ Why: The suggestion correctly identifies a critical bug where tests in | High |
Fix broken file timestamp updateUncomment the tests/unittest/test_fresh_vars_functionality.py [28-44]
Suggestion importance[1-10]: 9__ Why: The suggestion correctly identifies that the | High | |
| Learned best practice |
Add exception handling in teardownWrap the cleanup operation in a try-except block to handle potential permission tests/unittest/test_fresh_vars_functionality.py [93-98]
Suggestion importance[1-10]: 6__ Why: Relevant best practice - Improve exception handling by preserving context (raise from), capturing exceptions into variables, sanitizing logs to avoid secrets leakage, and converting returns of exception objects into proper raises. | Low |
| ||
- [ ] Author self-review: I have reviewed the PR code suggestions, and addressed the relevant ones.
Second test workflow with the fix:
================= 199 passed, 6 skipped, 24 warnings in 6.17s ==================
https://github.com/qodo-ai/pr-agent/actions/runs/19370355959/job/55424387444?pr=2104#step:5:302
Note: I cannot check the boxes in the qodo-merge-for-open-source comment, they are disabled:
PR Reviewer Guide 🔍
Here are some key observations to aid the review process:
| ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪ |
| 🧪 PR contains tests |
| 🔒 No security concerns identified |
⚡ Recommended focus areas for reviewFresh Vars Matching
|
@sharoneyal please have a look here.
🤖 Automated PR Review
Summary
✅ Code review complete. Analyzed 2 files. No major issues found. The code looks good!
✅ No issues found!
Generated by AI-powered PR Review Agent
🤖 Automated PR Review
Summary
✅ Code Review Complete PR #2104: fix: restore Dynaconf fresh vars support Analyzed: 2 files Issues Found: 0 total ✅ No major issues detected. Code looks good!
Detailed Findings
📄 pr_agent/custom_merge_loader.py
📄 tests/unittest/test_fresh_vars_functionality.py
Generated by AI-powered PR Review Agent
🤖 Automated PR Review
Summary
✅ Code Review Complete PR #2104: fix: restore Dynaconf fresh vars support Analyzed: 2 files Issues Found: 0 total ✅ No major issues detected. Code looks good!
Detailed Findings
📄 pr_agent/custom_merge_loader.py
📄 tests/unittest/test_fresh_vars_functionality.py
Generated by AI-powered PR Review Agent
🤖 Automated PR Review
Summary
✅ Code Review Complete PR #2104: fix: restore Dynaconf fresh vars support Analyzed: 2 files Issues Found: 0 total ✅ No major issues detected. Code looks good!
Detailed Findings
📄 pr_agent/custom_merge_loader.py
📄 tests/unittest/test_fresh_vars_functionality.py
Generated by AI-powered PR Review Agent
🤖 Automated PR Review
Summary
✅ Code Review Complete PR #2104: fix: restore Dynaconf fresh vars support Analyzed: 2 files Issues Found: 0 total ✅ No major issues detected. Code looks good!
Detailed Findings
📄 pr_agent/custom_merge_loader.py
📄 tests/unittest/test_fresh_vars_functionality.py
Generated by AI-powered PR Review Agent
🤖 Automated PR Review
Summary
✅ Code Review Complete PR #2104: fix: restore Dynaconf fresh vars support Analyzed: 2 files Issues Found: 0 total ✅ No major issues detected. Code looks good!
Detailed Findings
📄 pr_agent/custom_merge_loader.py
📄 tests/unittest/test_fresh_vars_functionality.py
Generated by AI-powered PR Review Agent