-
-
Notifications
You must be signed in to change notification settings - Fork 835
fix: 修复 file_path 始终为 null 的问题 #217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Windelly
wants to merge
6
commits into
lintsinghua:v3.0.0
Choose a base branch
from
Windelly:fix/filepath-null
base: v3.0.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7763d0a
fix: 修复 file_path 始终为 null 的问题
Windelly e10fb57
fix: address Qodo review feedback for PR #217
Windelly 5b9d3e0
chore: trigger Qodo re-review
Windelly f3d0b74
fix: address Qodo review - normalize None guard, stats consistency, t…
Windelly 9c77394
fix: Qodo round 3 - type-safe stats, guarded cross-file merge
Windelly e56dcfd
fix: define files_with_findings_set and populate filtered_findings
Windelly File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
backend/alembic/versions/009_add_verdict_to_agent_findings.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| """Add verdict column to agent_findings | ||
|
|
||
| Revision ID: 009_add_verdict_to_agent_findings | ||
| Revises: 008_add_files_with_findings | ||
| Create Date: 2026-05-04 | ||
|
|
||
| """ | ||
| from alembic import op | ||
| import sqlalchemy as sa | ||
|
|
||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = '009_add_verdict_to_agent_findings' | ||
| down_revision = '008_add_files_with_findings' | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| op.add_column('agent_findings', sa.Column('verdict', sa.String(length=30), nullable=True)) | ||
| op.create_index('ix_agent_findings_verdict', 'agent_findings', ['verdict']) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| op.drop_index('ix_agent_findings_verdict', table_name='agent_findings') | ||
| op.drop_column('agent_findings', 'verdict') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -194,6 +194,7 @@ class AgentFindingResponse(BaseModel): | |
| status: str | ||
|
|
||
| suggestion: Optional[str] = None | ||
| verdict: Optional[str] = None | ||
| poc: Optional[dict] = None | ||
|
|
||
| created_at: datetime | ||
|
|
@@ -566,35 +567,43 @@ def check_global_cancel(): | |
| # files_with_findings = 有漏洞发现的唯一文件数 | ||
| task.analyzed_files = task.total_files # Agent 扫描了所有符合条件的文件 | ||
|
|
||
| # 🔥 FIX: 先过滤 findings,再用过滤后的列表做统计 | ||
| # 与 _save_findings 的过滤逻辑保持一致(排除无 file_path 的 finding) | ||
| filtered_findings = [] | ||
| files_with_findings_set = set() | ||
| for f in findings: | ||
| if isinstance(f, dict): | ||
| file_path = f.get("file_path") or f.get("file") or f.get("location", "").split(":")[0] | ||
| raw_file_path = f.get("file_path") or f.get("file") | ||
| file_path = raw_file_path if isinstance(raw_file_path, str) else "" | ||
| if not file_path: | ||
| raw_location = f.get("location", "") | ||
| location = raw_location if isinstance(raw_location, str) else "" | ||
| file_path = location.split(":")[0] | ||
| if file_path: | ||
| files_with_findings_set.add(file_path) | ||
| filtered_findings.append(f) | ||
| task.files_with_findings = len(files_with_findings_set) | ||
|
|
||
| # 统计严重程度和验证状态 | ||
| # 统计严重程度和验证状态(使用过滤后的列表) | ||
| verified_count = 0 | ||
| for f in findings: | ||
| if isinstance(f, dict): | ||
| sev = str(f.get("severity", "low")).lower() | ||
| if sev == "critical": | ||
| task.critical_count += 1 | ||
| elif sev == "high": | ||
| task.high_count += 1 | ||
| elif sev == "medium": | ||
| task.medium_count += 1 | ||
| elif sev == "low": | ||
| task.low_count += 1 | ||
| # 🔥 统计已验证的发现 | ||
| if f.get("is_verified") or f.get("verdict") == "confirmed": | ||
| verified_count += 1 | ||
| for f in filtered_findings: | ||
| sev = str(f.get("severity", "low")).lower() | ||
| if sev == "critical": | ||
| task.critical_count += 1 | ||
| elif sev == "high": | ||
| task.high_count += 1 | ||
| elif sev == "medium": | ||
| task.medium_count += 1 | ||
| elif sev == "low": | ||
| task.low_count += 1 | ||
| # 🔥 统计已验证的发现 | ||
| if f.get("is_verified") or f.get("verdict") == "confirmed": | ||
| verified_count += 1 | ||
| task.verified_count = verified_count | ||
|
|
||
| # 计算安全评分 | ||
| task.security_score = _calculate_security_score(findings) | ||
| task.quality_score = _calculate_security_score(findings) | ||
| # 计算安全评分(使用过滤后的列表) | ||
| task.security_score = _calculate_security_score(filtered_findings) | ||
| task.quality_score = _calculate_security_score(filtered_findings) | ||
| # 🔥 注意: progress_percentage 是计算属性,不需要手动设置 | ||
| # 当 status = COMPLETED 时会自动返回 100.0 | ||
|
|
||
|
|
@@ -1261,11 +1270,20 @@ async def _save_findings( | |
| type_enum = VulnerabilityType.DESERIALIZATION | ||
|
|
||
| # 🔥 Handle file path (support multiple field names) | ||
| file_path = ( | ||
| finding.get("file_path") or | ||
| finding.get("file") or | ||
| finding.get("location", "").split(":")[0] if ":" in finding.get("location", "") else finding.get("location") | ||
| ) | ||
| raw_file_path = finding.get("file_path") or finding.get("file") | ||
| file_path = raw_file_path if isinstance(raw_file_path, str) else "" | ||
| if not file_path: | ||
| raw_location = finding.get("location", "") | ||
| location = raw_location if isinstance(raw_location, str) else "" | ||
| file_path = location.split(":")[0] if ":" in location else location | ||
|
|
||
| # 🔥 v2.2: file_path 为空直接跳过 | ||
| if not file_path or not file_path.strip(): | ||
| logger.warning( | ||
| f"[SaveFindings] 🚫 跳过无 file_path 的 finding: " | ||
| f"title={finding.get('title', 'N/A')[:50]}, type={finding.get('vulnerability_type', '?')}" | ||
| ) | ||
| continue | ||
|
qodo-free-for-open-source-projects[bot] marked this conversation as resolved.
|
||
|
|
||
| # 🔥 v2.1: 文件路径验证 - 过滤幻觉发现 | ||
| if project_root and file_path: | ||
|
|
@@ -1284,9 +1302,11 @@ async def _save_findings( | |
|
|
||
| # 🔥 Handle line numbers (support multiple formats) | ||
| line_start = finding.get("line_start") or finding.get("line") | ||
| if not line_start and ":" in finding.get("location", ""): | ||
| raw_location = finding.get("location", "") | ||
| location = raw_location if isinstance(raw_location, str) else "" | ||
| if not line_start and ":" in location: | ||
| try: | ||
| line_start = int(finding.get("location", "").split(":")[1]) | ||
| line_start = int(location.split(":")[1]) | ||
| except (ValueError, IndexError): | ||
| line_start = None | ||
|
|
||
|
|
@@ -1336,7 +1356,8 @@ async def _save_findings( | |
|
|
||
| # 🔥 Handle verification status | ||
| is_verified = finding.get("is_verified", False) | ||
| if finding.get("verdict") == "confirmed": | ||
| verdict = finding.get("verdict") # confirmed / likely / uncertain / false_positive | ||
| if verdict == "confirmed": | ||
| is_verified = True | ||
|
|
||
| # 🔥 Handle PoC information | ||
|
|
@@ -1381,6 +1402,7 @@ async def _save_findings( | |
| code_snippet=code_snippet[:10000] if code_snippet else None, | ||
| suggestion=suggestion[:5000] if suggestion else None, | ||
| is_verified=is_verified, | ||
| verdict=verdict, # 🔥 新增:保存 verdict 到数据库 | ||
| ai_confidence=confidence, # 🔥 FIX: Use ai_confidence, not confidence | ||
|
Comment on lines
1402
to
1406
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. Verdict migration missing AgentFinding 新增了 verdict 字段且保存时会写入该列,但 Alembic 迁移里 agent_findings 表定义不包含 verdict,运行时插入会失败并触发回滚,导致任务可能“完成”但 findings 实际未入库。 Agent Prompt
|
||
| status=FindingStatus.VERIFIED if is_verified else FindingStatus.NEW, | ||
| # 🔥 Additional fields | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.