-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcodetf.py
More file actions
118 lines (87 loc) · 3.07 KB
/
codetf.py
File metadata and controls
118 lines (87 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
from __future__ import annotations
from enum import Enum
from typing import Optional
from pydantic import BaseModel, model_validator
from ..common import Change, CodeTFWriter, Finding, FixQuality
from ..v2.codetf import Finding as V2Finding
class Run(BaseModel):
"""Metadata about the analysis run that produced the results"""
vendor: str
tool: str
version: str
# Optional free-form metadata about the project being analyzed
# e.g. project name, directory, commit SHA, etc.
projectMetadata: Optional[str] = None
# Analysis duration in milliseconds
elapsed: Optional[int] = None
# Optional free-form metadata about the inputs used for the analysis
# e.g. command line, environment variables, etc.
inputMetadata: Optional[dict] = None
# Optional free-form metadata about the analysis itself
# e.g. timeouts, memory usage, etc.
analysisMetadata: Optional[dict] = None
class FixStatusType(str, Enum):
"""Status of a fix"""
fixed = "fixed"
skipped = "skipped"
failed = "failed"
wontfix = "wontfix"
class FixStatus(BaseModel):
"""Metadata describing fix outcome"""
status: FixStatusType
reason: Optional[str] = None
details: Optional[str] = None
class ChangeSet(BaseModel):
path: str
diff: str
changes: list[Change] = []
class Reference(BaseModel):
url: str
description: Optional[str] = None
@model_validator(mode="after")
def validate_description(self):
self.description = self.description or self.url
return self
class Strategy(Enum):
ai = "ai"
hybrid = "hybrid"
deterministic = "deterministic"
class AIMetadata(BaseModel):
provider: Optional[str] = None
models: Optional[list[str]] = None
total_tokens: Optional[int] = None
completion_tokens: Optional[int] = None
prompt_tokens: Optional[int] = None
class GenerationMetadata(BaseModel):
strategy: Strategy
ai: Optional[AIMetadata] = None
provisional: bool
class FixMetadata(BaseModel):
# Fix provider ID, corresponds to legacy codemod ID
id: str
# A brief summary of the fix
summary: str
# A detailed description of the fix
description: str
references: list[Reference] = []
generation: GenerationMetadata
class FixResult(BaseModel):
"""Result corresponding to a single finding"""
finding: Finding | V2Finding
fixStatus: FixStatus
changeSets: list[ChangeSet] = []
fixMetadata: Optional[FixMetadata] = None
fixQuality: Optional[FixQuality] = None
# A description of the reasoning process that led to the fix
reasoningSteps: Optional[list[str]] = None
@model_validator(mode="after")
def validate_fixMetadata(self):
if self.fixStatus.status == FixStatusType.fixed:
if not self.changeSets:
raise ValueError("changeSets must be provided for fixed results")
if not self.fixMetadata:
raise ValueError("fixMetadata must be provided for fixed results")
return self
class CodeTF(CodeTFWriter, BaseModel):
run: Run
results: list[FixResult]