coding-client 1.21.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- coding_client/__init__.py +1 -0
- coding_client/api/__init__.py +19 -0
- coding_client/api/exception_handlers.py +158 -0
- coding_client/api/logging_setup.py +44 -0
- coding_client/api/metrics.py +40 -0
- coding_client/api/openapi_config.py +124 -0
- coding_client/api/request_logging.py +60 -0
- coding_client/api/validation.py +150 -0
- coding_client/auth/__init__.py +78 -0
- coding_client/auth/_default_tenant.py +132 -0
- coding_client/auth/_header_trust.py +98 -0
- coding_client/auth/_onbehalf.py +315 -0
- coding_client/auth/_trusted_networks.py +94 -0
- coding_client/auth/dependencies.py +61 -0
- coding_client/auth/middleware.py +445 -0
- coding_client/auth/models.py +83 -0
- coding_client/auth/outbound.py +137 -0
- coding_client/auth/rbac.py +21 -0
- coding_client/auth/rbac_coding.py +5 -0
- coding_client/auth/tenant.py +650 -0
- coding_client/auth/websocket.py +148 -0
- coding_client/clients/__init__.py +24 -0
- coding_client/clients/base.py +131 -0
- coding_client/clients/coding_ai.py +33 -0
- coding_client/clients/coding_analysis.py +36 -0
- coding_client/clients/coding_containers.py +45 -0
- coding_client/clients/coding_github.py +127 -0
- coding_client/clients/coding_realtime.py +127 -0
- coding_client/clients/coding_security.py +51 -0
- coding_client/clients/coding_testing.py +31 -0
- coding_client/clients/coding_workspaces.py +265 -0
- coding_client/config/__init__.py +12 -0
- coding_client/config/base_settings.py +61 -0
- coding_client/config/yaml_config_loader.py +172 -0
- coding_client/db/__init__.py +42 -0
- coding_client/db/db_types.py +122 -0
- coding_client/db/exceptions.py +59 -0
- coding_client/db/postgres_connection.py +572 -0
- coding_client/db/tenant_query_helper.py +417 -0
- coding_client/db_init.py +49 -0
- coding_client/exceptions/__init__.py +67 -0
- coding_client/exceptions/api_exceptions.py +395 -0
- coding_client/exceptions/pydantic_ai_exceptions.py +533 -0
- coding_client/interfaces/__init__.py +22 -0
- coding_client/interfaces/cache_interface.py +179 -0
- coding_client/interfaces/container_interface.py +49 -0
- coding_client/interfaces/docker_interface.py +283 -0
- coding_client/interfaces/graph_interface.py +28 -0
- coding_client/interfaces/security_interface.py +72 -0
- coding_client/interfaces/webhook_interface.py +67 -0
- coding_client/llm/__init__.py +54 -0
- coding_client/llm/base_agent.py +195 -0
- coding_client/llm/context.py +121 -0
- coding_client/llm/responses.py +102 -0
- coding_client/llm/routing.py +82 -0
- coding_client/llm/settings.py +102 -0
- coding_client/models/__init__.py +62 -0
- coding_client/models/agent.py +38 -0
- coding_client/models/ai_test_failure.py +745 -0
- coding_client/models/analysis.py +330 -0
- coding_client/models/architecture.py +685 -0
- coding_client/models/bug.py +128 -0
- coding_client/models/code_graph.py +317 -0
- coding_client/models/container.py +241 -0
- coding_client/models/core.py +878 -0
- coding_client/models/docker_container.py +104 -0
- coding_client/models/github.py +293 -0
- coding_client/models/logging.py +29 -0
- coding_client/models/package_manager.py +257 -0
- coding_client/models/pr_validation.py +440 -0
- coding_client/models/pydantic_ai.py +395 -0
- coding_client/models/repo_scanner.py +249 -0
- coding_client/models/responses.py +431 -0
- coding_client/models/security.py +185 -0
- coding_client/models/static_analysis.py +508 -0
- coding_client/models/system.py +48 -0
- coding_client/models/test_executor.py +204 -0
- coding_client/models/testing.py +673 -0
- coding_client/models/testing_config.py +200 -0
- coding_client/models/validation.py +127 -0
- coding_client/models_init.py +272 -0
- coding_client/telemetry.py +195 -0
- coding_client/testing.py +180 -0
- coding_client/types/__init__.py +130 -0
- coding_client/types/constraint_types.py +276 -0
- coding_client/types/core_types.py +112 -0
- coding_client/types/state_machine.py +443 -0
- coding_client/utils/__init__.py +86 -0
- coding_client/utils/archive_utils.py +387 -0
- coding_client/utils/ast_debug.py +45 -0
- coding_client/utils/async_timeout.py +364 -0
- coding_client/utils/constants.py +518 -0
- coding_client/utils/content_processing.py +326 -0
- coding_client/utils/database.py +916 -0
- coding_client/utils/encoding_helper.py +222 -0
- coding_client/utils/enum_helpers.py +166 -0
- coding_client/utils/file_operations.py +177 -0
- coding_client/utils/filesystem_ops.py +528 -0
- coding_client/utils/http_client.py +562 -0
- coding_client/utils/path_utils.py +471 -0
- coding_client/utils/profiling.py +421 -0
- coding_client/utils/response_builder.py +240 -0
- coding_client/utils/retry_helper.py +712 -0
- coding_client/utils/security_validation.py +423 -0
- coding_client-1.21.2.dist-info/METADATA +234 -0
- coding_client-1.21.2.dist-info/RECORD +109 -0
- coding_client-1.21.2.dist-info/WHEEL +5 -0
- coding_client-1.21.2.dist-info/licenses/LICENSE +201 -0
- coding_client-1.21.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
"""Static analysis models for comprehensive code analysis and validation.
|
|
2
|
+
|
|
3
|
+
This module provides sophisticated Pydantic models for static code analysis operations
|
|
4
|
+
including call graph analysis, function signature analysis, and advanced validation
|
|
5
|
+
techniques. The models support AI-driven code analysis workflows with comprehensive
|
|
6
|
+
validation capabilities across multiple programming languages.
|
|
7
|
+
|
|
8
|
+
The static analysis system enables:
|
|
9
|
+
- Call graph generation with visual representations and metrics
|
|
10
|
+
- Function signature analysis with type inference and documentation extraction
|
|
11
|
+
- Advanced validation using symbolic execution, taint analysis, and formal verification
|
|
12
|
+
- Documentation generation with architectural diagrams and API references
|
|
13
|
+
- Multi-language support for Python, JavaScript, and TypeScript
|
|
14
|
+
|
|
15
|
+
Key Model Categories:
|
|
16
|
+
Request Models: CallGraphRequest, SignatureAnalysisRequest, AdvancedValidationRequest
|
|
17
|
+
Response Models: CallGraphResponse, SignatureAnalysisResponse, AdvancedValidationResponse
|
|
18
|
+
Data Models: CallGraphNode, FunctionSignature, SecurityIssue for analysis results
|
|
19
|
+
Validation Models: SymbolicExecutionResult, TaintAnalysisResult, FormalVerificationResult
|
|
20
|
+
Documentation Models: DocumentationRequest, DocumentationResponse for doc generation
|
|
21
|
+
|
|
22
|
+
Analysis Types:
|
|
23
|
+
- Call Graph: Function call relationships and execution paths
|
|
24
|
+
- Signature Analysis: Function signatures with type inference
|
|
25
|
+
- Symbolic Execution: Edge case discovery and assertion validation
|
|
26
|
+
- Taint Analysis: Security vulnerability detection through data flow
|
|
27
|
+
- Formal Verification: Mathematical proof of code properties
|
|
28
|
+
- Documentation: Automated generation of technical documentation
|
|
29
|
+
|
|
30
|
+
Security Features:
|
|
31
|
+
- Multi-level security validation (LOW, MEDIUM, HIGH, CRITICAL)
|
|
32
|
+
- Taint analysis for vulnerability detection
|
|
33
|
+
- Security issue reporting with severity levels
|
|
34
|
+
- Formal verification for critical code paths
|
|
35
|
+
|
|
36
|
+
Example:
|
|
37
|
+
```python
|
|
38
|
+
from static_analysis_models import (
|
|
39
|
+
CallGraphRequest, SignatureAnalysisRequest,
|
|
40
|
+
OutputFormat, StaticAnalysisSecurityLevel, Language
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
# Call graph analysis request
|
|
44
|
+
call_graph_request = CallGraphRequest(
|
|
45
|
+
container_name="my-analysis-container",
|
|
46
|
+
analysis_scope=["src/", "lib/"],
|
|
47
|
+
output_format=OutputFormat.SVG,
|
|
48
|
+
include_external=True,
|
|
49
|
+
max_depth=15
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
# Function signature analysis request
|
|
53
|
+
signature_request = SignatureAnalysisRequest(
|
|
54
|
+
container_name="my-analysis-container",
|
|
55
|
+
language=Language.PYTHON,
|
|
56
|
+
include_type_inference=True,
|
|
57
|
+
extract_docstrings=True,
|
|
58
|
+
analyze_usage_patterns=True
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
# Advanced validation request
|
|
62
|
+
validation_request = AdvancedValidationRequest(
|
|
63
|
+
code_changes=[
|
|
64
|
+
CodeChange(
|
|
65
|
+
file_path="src/main.py",
|
|
66
|
+
original_code="def process(data): return data",
|
|
67
|
+
modified_code="def process(data: List[Dict]) -> Dict: return transform(data)",
|
|
68
|
+
change_type=ChangeType.MODIFICATION
|
|
69
|
+
)
|
|
70
|
+
],
|
|
71
|
+
validation_types=[ValidationType.SYMBOLIC_EXECUTION, ValidationType.TAINT_ANALYSIS],
|
|
72
|
+
security_level=StaticAnalysisSecurityLevel.HIGH
|
|
73
|
+
)
|
|
74
|
+
```
|
|
75
|
+
"""
|
|
76
|
+
|
|
77
|
+
from __future__ import annotations
|
|
78
|
+
|
|
79
|
+
from enum import StrEnum
|
|
80
|
+
from typing import Any
|
|
81
|
+
|
|
82
|
+
from pydantic import BaseModel, Field, field_validator
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class OutputFormat(StrEnum):
|
|
86
|
+
"""Output format options for call graph analysis.
|
|
87
|
+
|
|
88
|
+
Defines the available output formats for call graph visualization and data export.
|
|
89
|
+
Each format serves different purposes for analysis and presentation.
|
|
90
|
+
|
|
91
|
+
Attributes:
|
|
92
|
+
DOT: Graphviz DOT format for programmatic graph manipulation
|
|
93
|
+
SVG: Scalable Vector Graphics format for web display and documentation
|
|
94
|
+
JSON: JavaScript Object Notation format for data exchange and API responses
|
|
95
|
+
"""
|
|
96
|
+
|
|
97
|
+
DOT = "dot"
|
|
98
|
+
SVG = "svg"
|
|
99
|
+
JSON = "json"
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class StaticAnalysisSecurityLevel(StrEnum):
|
|
103
|
+
"""Security level options for advanced validation.
|
|
104
|
+
|
|
105
|
+
Defines the security validation levels that determine the strictness and depth
|
|
106
|
+
of security analysis performed during code validation.
|
|
107
|
+
|
|
108
|
+
Attributes:
|
|
109
|
+
LOW: Basic security checks with minimal performance impact
|
|
110
|
+
MEDIUM: Standard security analysis with balanced performance
|
|
111
|
+
HIGH: Comprehensive security validation with thorough analysis
|
|
112
|
+
CRITICAL: Maximum security scrutiny for security-critical code paths
|
|
113
|
+
"""
|
|
114
|
+
|
|
115
|
+
LOW = "low"
|
|
116
|
+
MEDIUM = "medium"
|
|
117
|
+
HIGH = "high"
|
|
118
|
+
CRITICAL = "critical"
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
class DocumentationType(StrEnum):
|
|
122
|
+
"""Documentation type options for automated documentation generation.
|
|
123
|
+
|
|
124
|
+
Defines the types of documentation that can be automatically generated
|
|
125
|
+
from code analysis results.
|
|
126
|
+
|
|
127
|
+
Attributes:
|
|
128
|
+
ARCHITECTURE: High-level architectural documentation with component diagrams
|
|
129
|
+
API_REFERENCE: Detailed API documentation with function signatures and usage
|
|
130
|
+
CHANGE_SUMMARY: Summary of code changes with impact analysis
|
|
131
|
+
"""
|
|
132
|
+
|
|
133
|
+
ARCHITECTURE = "architecture"
|
|
134
|
+
API_REFERENCE = "api_reference"
|
|
135
|
+
CHANGE_SUMMARY = "change_summary"
|
|
136
|
+
USER_GUIDE = "user_guide"
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
class DocumentationFormat(StrEnum):
|
|
140
|
+
"""Documentation format options for output generation.
|
|
141
|
+
|
|
142
|
+
Defines the available output formats for generated documentation,
|
|
143
|
+
each optimized for different use cases and presentation requirements.
|
|
144
|
+
|
|
145
|
+
Attributes:
|
|
146
|
+
MARKDOWN: Markdown format for README files and GitHub documentation
|
|
147
|
+
HTML: HTML format for web-based documentation and portals
|
|
148
|
+
SPHINX: Sphinx format for Python documentation with advanced features
|
|
149
|
+
"""
|
|
150
|
+
|
|
151
|
+
MARKDOWN = "markdown"
|
|
152
|
+
HTML = "html"
|
|
153
|
+
SPHINX = "sphinx"
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
class Language(StrEnum):
|
|
157
|
+
"""Supported programming languages for static analysis.
|
|
158
|
+
|
|
159
|
+
Defines the programming languages supported by the static analysis system,
|
|
160
|
+
each with specialized analysis capabilities and language-specific features.
|
|
161
|
+
|
|
162
|
+
Attributes:
|
|
163
|
+
PYTHON: Python language support with AST analysis and type inference
|
|
164
|
+
JAVASCRIPT: JavaScript language support with ES6+ features
|
|
165
|
+
TYPESCRIPT: TypeScript language support with type annotations
|
|
166
|
+
"""
|
|
167
|
+
|
|
168
|
+
PYTHON = "python"
|
|
169
|
+
JAVASCRIPT = "javascript"
|
|
170
|
+
TYPESCRIPT = "typescript"
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
class StaticAnalysisChangeType(StrEnum):
|
|
174
|
+
"""Type of code changes for validation analysis.
|
|
175
|
+
|
|
176
|
+
Defines the types of code changes that can be analyzed during validation,
|
|
177
|
+
each requiring different validation strategies and risk assessments.
|
|
178
|
+
|
|
179
|
+
Attributes:
|
|
180
|
+
ADDED: New code that has been added to the codebase
|
|
181
|
+
DELETED: Code that has been removed from the codebase
|
|
182
|
+
MODIFIED: Existing code that has been modified or updated
|
|
183
|
+
RENAMED: Code that has been moved or renamed
|
|
184
|
+
"""
|
|
185
|
+
|
|
186
|
+
ADDED = "ADDED"
|
|
187
|
+
DELETED = "DELETED"
|
|
188
|
+
MODIFIED = "MODIFIED"
|
|
189
|
+
RENAMED = "RENAMED"
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
# Alias for backward compatibility
|
|
193
|
+
ChangeType = StaticAnalysisChangeType
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
class ValidationType(StrEnum):
|
|
197
|
+
"""Types of advanced validation techniques available.
|
|
198
|
+
|
|
199
|
+
Defines the advanced validation techniques that can be applied to code
|
|
200
|
+
for comprehensive analysis and security assessment.
|
|
201
|
+
|
|
202
|
+
Attributes:
|
|
203
|
+
SYMBOLIC_EXECUTION: Symbolic execution for edge case discovery and path analysis
|
|
204
|
+
TAINT_ANALYSIS: Data flow analysis for security vulnerability detection
|
|
205
|
+
FORMAL_VERIFICATION: Mathematical verification of code properties and contracts
|
|
206
|
+
"""
|
|
207
|
+
|
|
208
|
+
SYMBOLIC_EXECUTION = "symbolic_execution"
|
|
209
|
+
TAINT_ANALYSIS = "taint_analysis"
|
|
210
|
+
FORMAL_VERIFICATION = "formal_verification"
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
# Call Graph Analysis Models
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
class CallGraphRequest(BaseModel):
|
|
217
|
+
"""Request model for call graph analysis."""
|
|
218
|
+
|
|
219
|
+
container_name: str = Field(..., description="Name of provisioned container to analyze")
|
|
220
|
+
analysis_scope: list[str] = Field(
|
|
221
|
+
default=["src/"], description="Directories to include in analysis"
|
|
222
|
+
)
|
|
223
|
+
output_format: OutputFormat = Field(
|
|
224
|
+
default=OutputFormat.JSON, description="Output format for call graph"
|
|
225
|
+
)
|
|
226
|
+
include_external: bool = Field(default=False, description="Include external library calls")
|
|
227
|
+
max_depth: int = Field(default=10, description="Maximum call depth to analyze")
|
|
228
|
+
|
|
229
|
+
@field_validator("container_name")
|
|
230
|
+
@classmethod
|
|
231
|
+
def validate_container_name(cls, v):
|
|
232
|
+
"""Validate that the container name is not empty."""
|
|
233
|
+
if not v or not v.strip():
|
|
234
|
+
raise ValueError("container_name cannot be empty")
|
|
235
|
+
return v.strip()
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
class StaticAnalysisCallGraphNode(BaseModel):
|
|
239
|
+
"""Individual node in call graph."""
|
|
240
|
+
|
|
241
|
+
function: str = Field(..., description="Function name")
|
|
242
|
+
module: str = Field(..., description="Module path")
|
|
243
|
+
complexity: int = Field(..., description="Function complexity score")
|
|
244
|
+
line_number: int | None = Field(None, description="Line number in source")
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
class StaticAnalysisCallGraphEdge(BaseModel):
|
|
248
|
+
"""Edge representing function call relationship."""
|
|
249
|
+
|
|
250
|
+
from_function: str = Field(..., alias="from", description="Calling function")
|
|
251
|
+
to_function: str = Field(..., alias="to", description="Called function")
|
|
252
|
+
call_type: str = Field(..., description="Type of call (direct, indirect, etc.)")
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
class CallGraphMetrics(BaseModel):
|
|
256
|
+
"""Metrics about the call graph."""
|
|
257
|
+
|
|
258
|
+
total_functions: int = Field(..., description="Total number of functions")
|
|
259
|
+
max_call_depth: int = Field(..., description="Maximum call depth found")
|
|
260
|
+
cyclic_dependencies: list[str] = Field(
|
|
261
|
+
default=[], description="List of cyclic dependencies found"
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
class CallGraphResponse(BaseModel):
|
|
266
|
+
"""Response model for call graph analysis."""
|
|
267
|
+
|
|
268
|
+
analysis_id: str = Field(..., description="Unique analysis identifier")
|
|
269
|
+
call_graph: dict[str, Any] = Field(..., description="Call graph data structure")
|
|
270
|
+
visual_output: str | None = Field(None, description="Base64 encoded visual representation")
|
|
271
|
+
critical_paths: list[str] = Field(default=[], description="Critical execution paths")
|
|
272
|
+
orphaned_functions: list[str] = Field(default=[], description="Functions with no callers")
|
|
273
|
+
metrics: CallGraphMetrics = Field(..., description="Call graph metrics")
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
# Signature Analysis Models
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
class SignatureAnalysisRequest(BaseModel):
|
|
280
|
+
"""Request model for function signature analysis."""
|
|
281
|
+
|
|
282
|
+
container_name: str = Field(..., description="Name of provisioned container to analyze")
|
|
283
|
+
language: Language = Field(..., description="Programming language")
|
|
284
|
+
include_type_inference: bool = Field(default=True, description="Run type inference analysis")
|
|
285
|
+
extract_docstrings: bool = Field(default=True, description="Extract function docstrings")
|
|
286
|
+
analyze_usage_patterns: bool = Field(
|
|
287
|
+
default=True, description="Analyze function usage patterns"
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
@field_validator("container_name")
|
|
291
|
+
@classmethod
|
|
292
|
+
def validate_container_name(cls, v):
|
|
293
|
+
"""Validate that the container name is not empty."""
|
|
294
|
+
if not v or not v.strip():
|
|
295
|
+
raise ValueError("container_name cannot be empty")
|
|
296
|
+
return v.strip()
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
class FunctionParameter(BaseModel):
|
|
300
|
+
"""Function parameter details."""
|
|
301
|
+
|
|
302
|
+
name: str = Field(..., description="Parameter name")
|
|
303
|
+
type: str | None = Field(None, description="Parameter type annotation")
|
|
304
|
+
required: bool = Field(..., description="Whether parameter is required")
|
|
305
|
+
default: str | None = Field(None, description="Default value if any")
|
|
306
|
+
description: str | None = Field(None, description="Parameter description")
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
class FunctionComplexityMetrics(BaseModel):
|
|
310
|
+
"""Function complexity metrics."""
|
|
311
|
+
|
|
312
|
+
cyclomatic: int = Field(..., description="Cyclomatic complexity")
|
|
313
|
+
cognitive: int = Field(..., description="Cognitive complexity")
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
class StaticAnalysisFunctionSignature(BaseModel):
|
|
317
|
+
"""Comprehensive function signature information."""
|
|
318
|
+
|
|
319
|
+
name: str = Field(..., description="Function name")
|
|
320
|
+
module: str = Field(..., description="Module path")
|
|
321
|
+
signature: str = Field(..., description="Complete function signature")
|
|
322
|
+
parameters: list[FunctionParameter] = Field(default=[], description="Function parameters")
|
|
323
|
+
return_type: str | None = Field(None, description="Return type annotation")
|
|
324
|
+
docstring: str | None = Field(None, description="Function docstring")
|
|
325
|
+
usage_examples: list[str] = Field(default=[], description="Example usage patterns")
|
|
326
|
+
called_by: list[str] = Field(default=[], description="Functions that call this function")
|
|
327
|
+
calls: list[str] = Field(default=[], description="Functions called by this function")
|
|
328
|
+
complexity_metrics: FunctionComplexityMetrics = Field(..., description="Complexity metrics")
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
class SignatureAnalysisResponse(BaseModel):
|
|
332
|
+
"""Response model for signature analysis."""
|
|
333
|
+
|
|
334
|
+
analysis_id: str = Field(..., description="Unique analysis identifier")
|
|
335
|
+
functions: list[StaticAnalysisFunctionSignature] = Field(
|
|
336
|
+
default=[], description="List of analyzed functions"
|
|
337
|
+
)
|
|
338
|
+
type_coverage: float = Field(..., description="Type annotation coverage (0-1)")
|
|
339
|
+
external_dependencies: list[str] = Field(
|
|
340
|
+
default=[], description="External dependencies referenced"
|
|
341
|
+
)
|
|
342
|
+
total_functions: int = Field(..., description="Total number of functions analyzed")
|
|
343
|
+
typed_functions: int = Field(..., description="Number of functions with type annotations")
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
# Advanced Validation Models
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
class CodeChange(BaseModel):
|
|
350
|
+
"""Individual code change for validation."""
|
|
351
|
+
|
|
352
|
+
file_path: str = Field(..., description="Path to the file")
|
|
353
|
+
original_code: str | None = Field(None, description="Original code")
|
|
354
|
+
modified_code: str = Field(..., description="Modified code")
|
|
355
|
+
change_type: StaticAnalysisChangeType = Field(..., description="Type of change")
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
class AdvancedValidationRequest(BaseModel):
|
|
359
|
+
"""Request model for advanced code validation."""
|
|
360
|
+
|
|
361
|
+
container_name: str = Field(..., description="Container name to scope file paths")
|
|
362
|
+
code_changes: list[CodeChange] = Field(..., description="List of code changes to validate")
|
|
363
|
+
validation_types: list[ValidationType] = Field(
|
|
364
|
+
..., description="Types of validation to perform"
|
|
365
|
+
)
|
|
366
|
+
security_level: StaticAnalysisSecurityLevel = Field(
|
|
367
|
+
default=StaticAnalysisSecurityLevel.MEDIUM,
|
|
368
|
+
description="Security validation level",
|
|
369
|
+
)
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
class SymbolicExecutionResult(BaseModel):
|
|
373
|
+
"""Results from symbolic execution."""
|
|
374
|
+
|
|
375
|
+
status: str = Field(..., description="Execution status")
|
|
376
|
+
edge_cases_found: list[str] = Field(default=[], description="Edge cases discovered")
|
|
377
|
+
assertion_violations: list[str] = Field(default=[], description="Assertion violations found")
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
class SecurityIssue(BaseModel):
|
|
381
|
+
"""Security issue found during taint analysis."""
|
|
382
|
+
|
|
383
|
+
severity: str = Field(..., description="Issue severity")
|
|
384
|
+
type: str = Field(..., description="Type of security issue")
|
|
385
|
+
location: str = Field(..., description="Location in code")
|
|
386
|
+
flow_path: list[str] = Field(..., description="Data flow path")
|
|
387
|
+
recommendation: str = Field(..., description="Resolve recommendation")
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
class TaintAnalysisResult(BaseModel):
|
|
391
|
+
"""Results from taint analysis."""
|
|
392
|
+
|
|
393
|
+
status: str = Field(..., description="Analysis status")
|
|
394
|
+
security_issues: list[SecurityIssue] = Field(default=[], description="Security issues found")
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
class FormalVerificationResult(BaseModel):
|
|
398
|
+
"""Results from formal verification."""
|
|
399
|
+
|
|
400
|
+
status: str = Field(..., description="Verification status")
|
|
401
|
+
properties_verified: list[str] = Field(default=[], description="Properties that were verified")
|
|
402
|
+
coverage: float = Field(..., description="Verification coverage")
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
class StaticAnalysisValidationResult(BaseModel):
|
|
406
|
+
"""Validation results for a single file."""
|
|
407
|
+
|
|
408
|
+
file_path: str = Field(..., description="Path to validated file")
|
|
409
|
+
symbolic_execution: SymbolicExecutionResult | None = Field(
|
|
410
|
+
None, description="Symbolic execution results"
|
|
411
|
+
)
|
|
412
|
+
taint_analysis: TaintAnalysisResult | None = Field(None, description="Taint analysis results")
|
|
413
|
+
formal_verification: FormalVerificationResult | None = Field(
|
|
414
|
+
None, description="Formal verification results"
|
|
415
|
+
)
|
|
416
|
+
safety_score: float | None = Field(
|
|
417
|
+
None, description="Individual safety score for this file (0-1)"
|
|
418
|
+
)
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
class AdvancedValidationResponse(BaseModel):
|
|
422
|
+
"""Response model for advanced validation."""
|
|
423
|
+
|
|
424
|
+
analysis_id: str = Field(..., description="Unique analysis identifier")
|
|
425
|
+
validation_results: list[StaticAnalysisValidationResult] = Field(
|
|
426
|
+
..., description="Validation results per file"
|
|
427
|
+
)
|
|
428
|
+
overall_safety_score: float = Field(..., description="Overall safety score (0-1)")
|
|
429
|
+
blocking_issues: list[str] = Field(default=[], description="Issues that block deployment")
|
|
430
|
+
recommendations: list[str] = Field(default=[], description="General recommendations")
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
# Documentation Generation Models
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
class DocumentationRequest(BaseModel):
|
|
437
|
+
"""Request model for documentation generation."""
|
|
438
|
+
|
|
439
|
+
container_name: str = Field(..., description="Name of provisioned container to analyze")
|
|
440
|
+
doc_types: list[DocumentationType] = Field(
|
|
441
|
+
..., description="Types of documentation to generate"
|
|
442
|
+
)
|
|
443
|
+
include_diagrams: bool = Field(default=True, description="Include architectural diagrams")
|
|
444
|
+
format: DocumentationFormat = Field(
|
|
445
|
+
default=DocumentationFormat.MARKDOWN, description="Output format"
|
|
446
|
+
)
|
|
447
|
+
|
|
448
|
+
@field_validator("container_name")
|
|
449
|
+
@classmethod
|
|
450
|
+
def validate_container_name(cls, v):
|
|
451
|
+
"""Validate that the container name is not empty."""
|
|
452
|
+
if not v or not v.strip():
|
|
453
|
+
raise ValueError("container_name cannot be empty")
|
|
454
|
+
return v.strip()
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
class DocumentationSection(BaseModel):
|
|
458
|
+
"""Individual documentation section."""
|
|
459
|
+
|
|
460
|
+
content: str = Field(..., description="Documentation content")
|
|
461
|
+
diagrams: list[str] = Field(default=[], description="Associated diagram files")
|
|
462
|
+
coverage: float | None = Field(None, description="Documentation coverage")
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
class DocumentationResponse(BaseModel):
|
|
466
|
+
"""Response model for documentation generation."""
|
|
467
|
+
|
|
468
|
+
analysis_id: str = Field(..., description="Unique analysis identifier")
|
|
469
|
+
documentation: dict[str, DocumentationSection] = Field(
|
|
470
|
+
..., description="Generated documentation sections"
|
|
471
|
+
)
|
|
472
|
+
generated_files: list[str] = Field(default=[], description="List of generated files")
|
|
473
|
+
quality_score: float = Field(..., description="Documentation quality score (0-1)")
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
# Database Models for Persistence
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
class CallGraphAnalysis(BaseModel):
|
|
480
|
+
"""Database model for call graph analysis results."""
|
|
481
|
+
|
|
482
|
+
id: str = Field(..., description="Analysis ID")
|
|
483
|
+
repository_url: str = Field(..., description="Repository URL")
|
|
484
|
+
analysis_config: dict[str, Any] = Field(..., description="Analysis configuration")
|
|
485
|
+
call_graph_data: dict[str, Any] = Field(..., description="Call graph data")
|
|
486
|
+
visual_outputs: dict[str, Any] = Field(..., description="Visual outputs")
|
|
487
|
+
created_at: str = Field(..., description="Creation timestamp")
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
class SignatureAnalysis(BaseModel):
|
|
491
|
+
"""Database model for signature analysis results."""
|
|
492
|
+
|
|
493
|
+
id: str = Field(..., description="Analysis ID")
|
|
494
|
+
repository_url: str = Field(..., description="Repository URL")
|
|
495
|
+
language: str = Field(..., description="Programming language")
|
|
496
|
+
functions_data: dict[str, Any] = Field(..., description="Functions data")
|
|
497
|
+
type_coverage: float = Field(..., description="Type coverage")
|
|
498
|
+
created_at: str = Field(..., description="Creation timestamp")
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
class ValidationAnalysis(BaseModel):
|
|
502
|
+
"""Database model for validation analysis results."""
|
|
503
|
+
|
|
504
|
+
id: str = Field(..., description="Analysis ID")
|
|
505
|
+
code_changes: dict[str, Any] = Field(..., description="Code changes")
|
|
506
|
+
validation_results: dict[str, Any] = Field(..., description="Validation results")
|
|
507
|
+
safety_score: float = Field(..., description="Safety score")
|
|
508
|
+
created_at: str = Field(..., description="Creation timestamp")
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""System-level models for package management and dependencies."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from enum import Enum
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class PackageManager(Enum):
|
|
10
|
+
"""Supported system package managers."""
|
|
11
|
+
|
|
12
|
+
APT = "apt" # Debian/Ubuntu
|
|
13
|
+
YUM = "yum" # RHEL/CentOS (older)
|
|
14
|
+
DNF = "dnf" # RHEL/CentOS/Fedora (newer)
|
|
15
|
+
BREW = "brew" # macOS
|
|
16
|
+
PACMAN = "pacman" # Arch Linux
|
|
17
|
+
APK = "apk" # Alpine Linux
|
|
18
|
+
ZYPPER = "zypper" # openSUSE
|
|
19
|
+
CHOCO = "choco" # Windows
|
|
20
|
+
|
|
21
|
+
@property
|
|
22
|
+
def command(self) -> str:
|
|
23
|
+
"""Get the actual command to run for this package manager."""
|
|
24
|
+
if self == PackageManager.APT:
|
|
25
|
+
return "apt-get"
|
|
26
|
+
return self.value
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class DependencyType(Enum):
|
|
30
|
+
"""Types of dependencies."""
|
|
31
|
+
|
|
32
|
+
BUILD = "build"
|
|
33
|
+
RUNTIME = "runtime"
|
|
34
|
+
OPTIONAL = "optional"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@dataclass
|
|
38
|
+
class SystemDependency:
|
|
39
|
+
"""Represents a system-level dependency."""
|
|
40
|
+
|
|
41
|
+
name: str
|
|
42
|
+
packages: dict[PackageManager, list[str]]
|
|
43
|
+
description: str
|
|
44
|
+
dependency_type: DependencyType = DependencyType.RUNTIME
|
|
45
|
+
test_command: str | None = None
|
|
46
|
+
test_import: str | None = None
|
|
47
|
+
version_command: str | None = None
|
|
48
|
+
min_version: str | None = None
|