Fix security vulnerability, broken tests, and code quality issues#3
Fix security vulnerability, broken tests, and code quality issues#3
Conversation
Co-authored-by: amitdevx <110670491+amitdevx@users.noreply.github.com>
Co-authored-by: amitdevx <110670491+amitdevx@users.noreply.github.com>
Co-authored-by: amitdevx <110670491+amitdevx@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses security, functional, and code quality issues identified in a repository audit. The security fix adds usedforsecurity=False to MD5 hashing (used for non-cryptographic ID generation). Functional fixes include adding missing @pytest.mark.asyncio decorators to enable test execution, fixing demo cleanup logic, and adding proper error handling for missing dependencies. Code quality improvements include removing unused imports, fixing whitespace issues, and improving line length compliance.
Changes:
- Security: Added
usedforsecurity=Falseparameter to MD5 hash in memory.py for non-cryptographic use - Testing: Added
@pytest.mark.asynciodecorators to 5 async test functions to enable proper test execution - Cleanup: Replaced incorrect file deletion in demo.py with
clear_user_memories()method call - Dependencies: Added try/except wrapper for reportlab imports with user-friendly error messages
- Code quality: Removed unused imports, fixed trailing whitespace, and improved PEP 8 compliance
Reviewed changes
Copilot reviewed 11 out of 38 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_agent.py | Added @pytest.mark.asyncio decorators to enable async test execution; converted some f-strings to .format() |
| profiler_agent/tools.py | Removed unused imports (Dict, Any, pandas); converted f-strings to .format() |
| profiler_agent/sub_agents/taxonomist.py | Split long instruction string across multiple lines for PEP 8 compliance |
| profiler_agent/sub_agents/strategist.py | Split long instruction string across multiple lines for PEP 8 compliance |
| profiler_agent/paths.py | Removed unused os import; fixed trailing whitespace |
| profiler_agent/observability.py | Removed unused LOGS_DIR import; fixed trailing whitespace throughout |
| profiler_agent/memory.py | Added usedforsecurity=False to MD5 hash; added clear_user_memories() method; fixed whitespace |
| profiler_agent/config.py | Minor comment simplification; added blank lines for PEP 8 |
| profiler_agent/agent_utils.py | Added blank line for PEP 8 compliance |
| profiler_agent/pycache/*.pyc | CRITICAL: Python bytecode files should not be committed |
| profiler_agent/sub_agents/pycache/*.pyc | CRITICAL: Python bytecode files should not be committed |
| google/adk/**/*.pyc | CRITICAL: Python bytecode files should not be committed |
| google/adk/tools/function_tool.py | Fixed trailing whitespace throughout |
| google/adk/sessions/in_memory_session_service.py | Fixed trailing whitespace throughout |
| google/adk/runners/runner.py | Fixed trailing whitespace throughout |
| google/adk/agents/callback_context.py | Fixed trailing whitespace |
| google/adk/agents/agent.py | Fixed trailing whitespace throughout |
| demo.py | Replaced file deletion with clear_user_memories(); converted many f-strings to .format(); removed unused import |
| create_sample_exams.py | Added try/except for reportlab imports with REPORTLAB_AVAILABLE flag; converted f-strings to .format() |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| logger = setup_logging(level="INFO", structured=True) | ||
|
|
||
| # Setup structured logging (logger returned for potential future use) |
There was a problem hiding this comment.
The comment "logger returned for potential future use" is misleading. The setup_logging function is called without capturing its return value, which is correct since the logger is not used in this function. However, the comment suggests it might be used later, which could confuse future maintainers. Consider either:
- Removing the comment entirely (since not using the return value is the correct behavior here)
- Changing it to: "# Setup structured logging (return value not needed)"
| # Setup structured logging (logger returned for potential future use) | |
| # Setup structured logging (return value not needed) |
| "message": "Found {count} PDF file(s) in input/ directory".format(count=len(pdf_files)) | ||
| } | ||
| except Exception as e: | ||
| return {"error": f"Failed to list files: {str(e)}"} No newline at end of file | ||
| return {"error": "Failed to list files: {error}".format(error=str(e))} |
There was a problem hiding this comment.
These f-strings were converted to .format() method, but they both have placeholders, contradicting the PR description which states "Fixed f-strings without placeholders (F541)". The Ruff rule F541 specifically targets f-strings WITHOUT any placeholders (e.g., f"Hello world" instead of "Hello world"), not f-strings with placeholders like these.
These changes make the code less readable and are inconsistent with other parts of the codebase that still use f-strings. F-strings are generally preferred in modern Python for their clarity and performance. Unless there's a specific requirement for .format() (like Python version compatibility), these conversions should be reverted.
| print(f"✅ Root agent: {root_agent.name}") | ||
| print(f"✅ Sub-agents: {[a.name for a in root_agent.sub_agents]}") | ||
| print(f"✅ Tools: {[t.name for t in root_agent.tools]}") | ||
| print("✅ Sub-agents: {sub_agents}".format(sub_agents=[a.name for a in root_agent.sub_agents])) | ||
| print("✅ Tools: {tools}".format(tools=[t.name for t in root_agent.tools])) |
There was a problem hiding this comment.
The conversion of f-strings to .format() method is inconsistent and appears unnecessary. Line 34 retains the f-string format print(f"✅ Root agent: {root_agent.name}"), but lines 35-36 were converted to .format() for similar simple substitutions.
F-strings are generally preferred in modern Python (3.6+) for their readability and performance. Unless there's a specific reason to use .format() (like supporting older Python versions or specific formatting requirements), these conversions should either be reverted or applied consistently. The PR description mentions fixing "f-strings without placeholders (F541)", but these f-strings DO have placeholders, so the conversion seems inappropriate.
Audit of repository identified security, functional, and quality issues across the codebase.
Critical
usedforsecurity=Falsetohashlib.md5()inmemory.py- hash is only used for ID generation, not cryptographic purposesFunctional Bugs
@pytest.mark.asynciodecoratorsdemo.pycleanup tried to removedemo_memory.jsonfrom wrong path; replaced withmemory_bank.clear_user_memories()reportlabunavailable increate_sample_exams.pyCode Quality
Dict,Any,pandas,os,LOGS_DIR,PageBreak,TA_LEFT)All 5 tests now pass. Bandit and CodeQL report no issues.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.