jcia 0.2.0__tar.gz
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.
- jcia-0.2.0/LICENSE +21 -0
- jcia-0.2.0/PKG-INFO +281 -0
- jcia-0.2.0/README.md +235 -0
- jcia-0.2.0/jcia/__init__.py +13 -0
- jcia-0.2.0/jcia/adapters/__init__.py +1 -0
- jcia-0.2.0/jcia/adapters/ai/__init__.py +7 -0
- jcia-0.2.0/jcia/adapters/ai/llm_adapter.py +37 -0
- jcia-0.2.0/jcia/adapters/ai/openai_adapter.py +800 -0
- jcia-0.2.0/jcia/adapters/ai/skywalking_adapter.py +563 -0
- jcia-0.2.0/jcia/adapters/ai/volcengine_adapter.py +472 -0
- jcia-0.2.0/jcia/adapters/database/__init__.py +1 -0
- jcia-0.2.0/jcia/adapters/database/sqlite_database_adapter.py +100 -0
- jcia-0.2.0/jcia/adapters/git/__init__.py +1 -0
- jcia-0.2.0/jcia/adapters/git/pydriller_adapter.py +287 -0
- jcia-0.2.0/jcia/adapters/maven/__init__.py +1 -0
- jcia-0.2.0/jcia/adapters/maven/maven_adapter.py +157 -0
- jcia-0.2.0/jcia/adapters/test_runners/__init__.py +7 -0
- jcia-0.2.0/jcia/adapters/test_runners/maven_surefire_test_executor.py +593 -0
- jcia-0.2.0/jcia/adapters/tools/__init__.py +15 -0
- jcia-0.2.0/jcia/adapters/tools/codeql_adapter.py +808 -0
- jcia-0.2.0/jcia/adapters/tools/codeql_models.py +303 -0
- jcia-0.2.0/jcia/adapters/tools/java_all_call_graph_adapter.py +908 -0
- jcia-0.2.0/jcia/adapters/tools/mock_call_chain_analyzer.py +124 -0
- jcia-0.2.0/jcia/adapters/tools/reflection_models.py +127 -0
- jcia-0.2.0/jcia/adapters/tools/reflection_patterns.py +442 -0
- jcia-0.2.0/jcia/adapters/tools/remote_call/__init__.py +22 -0
- jcia-0.2.0/jcia/adapters/tools/remote_call/composite_adapter.py +180 -0
- jcia-0.2.0/jcia/adapters/tools/remote_call/dubbo_adapter.py +117 -0
- jcia-0.2.0/jcia/adapters/tools/remote_call/feign_adapter.py +114 -0
- jcia-0.2.0/jcia/adapters/tools/remote_call/grpc_adapter.py +128 -0
- jcia-0.2.0/jcia/adapters/tools/remote_call/http_adapter.py +115 -0
- jcia-0.2.0/jcia/adapters/tools/remote_call/mq_adapter.py +145 -0
- jcia-0.2.0/jcia/adapters/tools/remote_call_patterns.py +565 -0
- jcia-0.2.0/jcia/adapters/tools/service_registry/__init__.py +5 -0
- jcia-0.2.0/jcia/adapters/tools/service_registry/mock_registry.py +78 -0
- jcia-0.2.0/jcia/adapters/tools/skywalking_call_chain_adapter.py +727 -0
- jcia-0.2.0/jcia/adapters/tools/source_code_call_graph_adapter.py +560 -0
- jcia-0.2.0/jcia/adapters/tools/starts_test_selector_adapter.py +465 -0
- jcia-0.2.0/jcia/cli/__init__.py +10 -0
- jcia-0.2.0/jcia/cli/main.py +383 -0
- jcia-0.2.0/jcia/core/__init__.py +1 -0
- jcia-0.2.0/jcia/core/entities/__init__.py +77 -0
- jcia-0.2.0/jcia/core/entities/change_set.py +276 -0
- jcia-0.2.0/jcia/core/entities/impact_graph.py +295 -0
- jcia-0.2.0/jcia/core/entities/remote_call.py +220 -0
- jcia-0.2.0/jcia/core/entities/test_case.py +156 -0
- jcia-0.2.0/jcia/core/entities/test_run.py +410 -0
- jcia-0.2.0/jcia/core/interfaces/__init__.py +93 -0
- jcia-0.2.0/jcia/core/interfaces/ai_service.py +216 -0
- jcia-0.2.0/jcia/core/interfaces/analyzer.py +111 -0
- jcia-0.2.0/jcia/core/interfaces/call_chain_analyzer.py +156 -0
- jcia-0.2.0/jcia/core/interfaces/file_system.py +41 -0
- jcia-0.2.0/jcia/core/interfaces/remote_call_analyzer.py +116 -0
- jcia-0.2.0/jcia/core/interfaces/repository.py +146 -0
- jcia-0.2.0/jcia/core/interfaces/service_registry.py +98 -0
- jcia-0.2.0/jcia/core/interfaces/test_runner.py +178 -0
- jcia-0.2.0/jcia/core/interfaces/tool_wrapper.py +173 -0
- jcia-0.2.0/jcia/core/services/__init__.py +35 -0
- jcia-0.2.0/jcia/core/services/analysis_fusion_service.py +895 -0
- jcia-0.2.0/jcia/core/services/call_chain_builder.py +248 -0
- jcia-0.2.0/jcia/core/services/change_comparison_service.py +280 -0
- jcia-0.2.0/jcia/core/services/impact_analysis_service.py +310 -0
- jcia-0.2.0/jcia/core/services/remote_call_detection_service.py +283 -0
- jcia-0.2.0/jcia/core/services/severity_calculator.py +547 -0
- jcia-0.2.0/jcia/core/services/severity_enhancer.py +183 -0
- jcia-0.2.0/jcia/core/services/test_generator_service.py +238 -0
- jcia-0.2.0/jcia/core/services/test_selection_service.py +363 -0
- jcia-0.2.0/jcia/core/use_cases/__init__.py +37 -0
- jcia-0.2.0/jcia/core/use_cases/analyze_impact.py +314 -0
- jcia-0.2.0/jcia/core/use_cases/generate_report.py +431 -0
- jcia-0.2.0/jcia/core/use_cases/generate_tests.py +211 -0
- jcia-0.2.0/jcia/core/use_cases/run_regression.py +351 -0
- jcia-0.2.0/jcia/infrastructure/__init__.py +1 -0
- jcia-0.2.0/jcia/infrastructure/config/__init__.py +5 -0
- jcia-0.2.0/jcia/infrastructure/config/config_manager.py +76 -0
- jcia-0.2.0/jcia/infrastructure/database/__init__.py +1 -0
- jcia-0.2.0/jcia/infrastructure/database/sqlite_adapter.py +179 -0
- jcia-0.2.0/jcia/infrastructure/database/sqlite_repository.py +614 -0
- jcia-0.2.0/jcia/infrastructure/fs/__init__.py +5 -0
- jcia-0.2.0/jcia/infrastructure/fs/file_system.py +59 -0
- jcia-0.2.0/jcia/infrastructure/logging/__init__.py +5 -0
- jcia-0.2.0/jcia/infrastructure/logging/logger.py +56 -0
- jcia-0.2.0/jcia/reports/__init__.py +17 -0
- jcia-0.2.0/jcia/reports/base.py +173 -0
- jcia-0.2.0/jcia/reports/html_reporter.py +611 -0
- jcia-0.2.0/jcia/reports/json_reporter.py +94 -0
- jcia-0.2.0/jcia/reports/markdown_reporter.py +352 -0
- jcia-0.2.0/jcia.egg-info/PKG-INFO +281 -0
- jcia-0.2.0/jcia.egg-info/SOURCES.txt +94 -0
- jcia-0.2.0/jcia.egg-info/dependency_links.txt +1 -0
- jcia-0.2.0/jcia.egg-info/entry_points.txt +2 -0
- jcia-0.2.0/jcia.egg-info/requires.txt +24 -0
- jcia-0.2.0/jcia.egg-info/top_level.txt +1 -0
- jcia-0.2.0/pyproject.toml +393 -0
- jcia-0.2.0/setup.cfg +4 -0
- jcia-0.2.0/setup.py +16 -0
jcia-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-2026 JCIA Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
jcia-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: jcia
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Java Code Impact Analyzer - 代码变更影响分析工具
|
|
5
|
+
Author: JCIA Team
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/boyingliu01/jcia
|
|
8
|
+
Project-URL: Documentation, https://github.com/boyingliu01/jcia#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/boyingliu01/jcia
|
|
10
|
+
Project-URL: Issues, https://github.com/boyingliu01/jcia/issues
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: Software Development :: Testing
|
|
19
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: click>=8.0.0
|
|
24
|
+
Requires-Dist: pydriller>=2.6.0
|
|
25
|
+
Requires-Dist: pyyaml>=6.0.1
|
|
26
|
+
Requires-Dist: jinja2>=3.1.2
|
|
27
|
+
Requires-Dist: requests>=2.31.0
|
|
28
|
+
Requires-Dist: beautifulsoup4>=4.12.0
|
|
29
|
+
Requires-Dist: rich>=13.7.0
|
|
30
|
+
Requires-Dist: pydantic>=2.5.0
|
|
31
|
+
Requires-Dist: defusedxml>=0.7.1
|
|
32
|
+
Provides-Extra: dev
|
|
33
|
+
Requires-Dist: pytest>=7.4.0; extra == "dev"
|
|
34
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
|
|
35
|
+
Requires-Dist: pytest-mock>=3.12.0; extra == "dev"
|
|
36
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
|
|
37
|
+
Requires-Dist: ruff==0.15.5; extra == "dev"
|
|
38
|
+
Requires-Dist: import-linter>=2.0; extra == "dev"
|
|
39
|
+
Requires-Dist: pyright>=1.1.340; extra == "dev"
|
|
40
|
+
Requires-Dist: bandit[toml]>=1.7.6; extra == "dev"
|
|
41
|
+
Requires-Dist: pre-commit>=3.6.0; extra == "dev"
|
|
42
|
+
Requires-Dist: mypy>=1.7.0; extra == "dev"
|
|
43
|
+
Provides-Extra: ai
|
|
44
|
+
Requires-Dist: openai>=1.0.0; extra == "ai"
|
|
45
|
+
Dynamic: license-file
|
|
46
|
+
|
|
47
|
+
# JCIA - Java Code Impact Analyzer
|
|
48
|
+
|
|
49
|
+
[]
|
|
50
|
+
[]
|
|
51
|
+
[]
|
|
52
|
+
|
|
53
|
+
**JCIA** 是一个 Python 工具,用于分析 Java 代码变更的影响范围,智能选择需要运行的测试用例,并提供回归分析能力。
|
|
54
|
+
|
|
55
|
+
## 特性
|
|
56
|
+
|
|
57
|
+
- 🔍 **变更代码影响分析** - 自动分析 Git 提交,识别变更的文件和方法
|
|
58
|
+
- 📊 **影响图构建** - 构建调用链图,计算受影响的类和方法
|
|
59
|
+
- 🌐 **跨服务远程调用检测** - 识别 Dubbo/Feign/HTTP/MQ 远程调用并融合进影响图,评估跨服务变更风险(`--detect-remote-calls`)
|
|
60
|
+
- 🎯 **智能测试选择** - 基于 STARTS 算法和影响范围选择测试用例
|
|
61
|
+
- 🤖 **AI 测试生成** - 集成 LLM 服务,自动生成测试用例建议
|
|
62
|
+
- 📈 **多格式报告** - 支持 HTML、JSON、Markdown 格式报告
|
|
63
|
+
- 🔄 **回归分析** - 对比基线测试和回归测试结果,识别回归问题
|
|
64
|
+
|
|
65
|
+
## 快速开始
|
|
66
|
+
|
|
67
|
+
### 安装
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
# 克隆仓库
|
|
71
|
+
git clone https://github.com/boyingliu01/jcia.git
|
|
72
|
+
cd jcia
|
|
73
|
+
|
|
74
|
+
# 创建虚拟环境
|
|
75
|
+
python -m venv .venv
|
|
76
|
+
.venv\Scripts\Activate.ps1 # Windows PowerShell
|
|
77
|
+
|
|
78
|
+
# 安装依赖
|
|
79
|
+
pip install -e ".[dev]"
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### 配置
|
|
83
|
+
|
|
84
|
+
创建配置文件 `jcia.yaml`(可选):
|
|
85
|
+
|
|
86
|
+
```yaml
|
|
87
|
+
repository:
|
|
88
|
+
path: /path/to/your/java/project
|
|
89
|
+
|
|
90
|
+
analyzer:
|
|
91
|
+
max_depth: 10
|
|
92
|
+
include_test_files: false
|
|
93
|
+
|
|
94
|
+
report:
|
|
95
|
+
format: html
|
|
96
|
+
output_dir: ./reports
|
|
97
|
+
|
|
98
|
+
ai:
|
|
99
|
+
provider: volcengine
|
|
100
|
+
model: gpt-4
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### 使用
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
# 分析变更影响
|
|
107
|
+
jcia analyze --repo-path /path/to/repo --from-commit abc123 --to-commit def456
|
|
108
|
+
|
|
109
|
+
# 分析变更影响并检测跨服务远程调用(Dubbo/Feign/HTTP/MQ)
|
|
110
|
+
jcia analyze --repo-path /path/to/repo --commit-range abc123..def456 --detect-remote-calls
|
|
111
|
+
|
|
112
|
+
# 生成测试用例
|
|
113
|
+
jcia test --repo-path /path/to/project --target-class com.example.Service
|
|
114
|
+
|
|
115
|
+
# 生成报告
|
|
116
|
+
jcia report --output-dir ./reports --format html
|
|
117
|
+
|
|
118
|
+
# 配置管理
|
|
119
|
+
jcia config --show
|
|
120
|
+
jcia config --set analyzer.max_depth=15
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## 核心概念
|
|
124
|
+
|
|
125
|
+
### 变更分析
|
|
126
|
+
|
|
127
|
+
JCIA 使用 PyDriller 解析 Git 仓库,识别:
|
|
128
|
+
|
|
129
|
+
- 文件级变更(新增、修改、删除、重命名)
|
|
130
|
+
- 方法级变更(方法签名变更)
|
|
131
|
+
- 提交信息(作者、时间、消息)
|
|
132
|
+
|
|
133
|
+
### 影响图
|
|
134
|
+
|
|
135
|
+
影响图展示代码变更的传播路径:
|
|
136
|
+
|
|
137
|
+
- **直接影响** - 直接调用变更方法的代码
|
|
138
|
+
- **间接影响** - 通过调用链间接影响的代码
|
|
139
|
+
- **严重程度** - HIGH/MEDIUM/LOW
|
|
140
|
+
- **影响深度** - 变更传播的最大深度
|
|
141
|
+
|
|
142
|
+
### 测试选择
|
|
143
|
+
|
|
144
|
+
JCIA 支持多种测试选择策略:
|
|
145
|
+
|
|
146
|
+
- **ALL** - 运行所有测试
|
|
147
|
+
- **STARTS** - 使用 STARTS 算法选择
|
|
148
|
+
- **IMPACT_BASED** - 基于影响范围选择
|
|
149
|
+
- **HYBRID** - 混合策略
|
|
150
|
+
|
|
151
|
+
## 架构
|
|
152
|
+
|
|
153
|
+
JCIA 采用**清洁架构**(Clean Architecture):
|
|
154
|
+
|
|
155
|
+
```
|
|
156
|
+
Adapters Layer (Git, Maven, AI, Database)
|
|
157
|
+
↓
|
|
158
|
+
Infrastructure Layer (Repositories, Config, Logging)
|
|
159
|
+
↓
|
|
160
|
+
Use Cases Layer (Business Orchestration)
|
|
161
|
+
↓
|
|
162
|
+
Services Layer (Domain Logic)
|
|
163
|
+
↓
|
|
164
|
+
Entities Layer (Domain Models)
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### 依赖规则
|
|
168
|
+
|
|
169
|
+
- 外部依赖(Git、Maven、AI)在适配器层
|
|
170
|
+
- 业务逻辑在核心层
|
|
171
|
+
- 核心层不依赖适配器层
|
|
172
|
+
- 通过接口(ABC)解耦
|
|
173
|
+
|
|
174
|
+
## 开发
|
|
175
|
+
|
|
176
|
+
### 设置开发环境
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
# 安装开发依赖
|
|
180
|
+
pip install -e ".[dev]"
|
|
181
|
+
|
|
182
|
+
# 配置 pre-commit hooks
|
|
183
|
+
make setup-hooks
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### 运行测试
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
# 运行所有测试
|
|
190
|
+
make test
|
|
191
|
+
|
|
192
|
+
# 运行单元测试
|
|
193
|
+
pytest tests/unit -v
|
|
194
|
+
|
|
195
|
+
# 运行集成测试
|
|
196
|
+
pytest tests/integration -v
|
|
197
|
+
|
|
198
|
+
# 运行带覆盖率的测试
|
|
199
|
+
pytest tests/unit --cov=jcia --cov-report=html
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### 代码质量
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
# Lint 检查
|
|
206
|
+
make lint
|
|
207
|
+
|
|
208
|
+
# 格式化代码
|
|
209
|
+
make format
|
|
210
|
+
|
|
211
|
+
# 类型检查
|
|
212
|
+
pyright jcia tests
|
|
213
|
+
|
|
214
|
+
# 安全扫描
|
|
215
|
+
make security
|
|
216
|
+
|
|
217
|
+
# 完整检查
|
|
218
|
+
make check
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## 配置选项
|
|
222
|
+
|
|
223
|
+
### CLI 选项
|
|
224
|
+
|
|
225
|
+
| 命令 | 选项 | 说明 |
|
|
226
|
+
|-------|------|------|
|
|
227
|
+
| `analyze` | `--repo-path` | Git 仓库路径 |
|
|
228
|
+
| | `--from-commit` | 起始提交哈希 |
|
|
229
|
+
| | `--to-commit` | 结束提交哈希 |
|
|
230
|
+
| | `--commit-range` | 提交范围(如 abc123..def456)|
|
|
231
|
+
| | `--max-depth` | 最大追溯深度 |
|
|
232
|
+
| `test` | `--repo-path` | 项目路径 |
|
|
233
|
+
| | `--target-class` | 目标类(可多次使用)|
|
|
234
|
+
| | `--coverage-file` | 覆盖率报告文件 |
|
|
235
|
+
| | `--min-confidence` | 最低置信度阈值 |
|
|
236
|
+
| `report` | `--output-dir` | 报告输出目录(必填)|
|
|
237
|
+
| | `--format` | 报告格式(json/html/markdown/console,默认 json)|
|
|
238
|
+
| | `--include-details` | 包含详细信息 |
|
|
239
|
+
| `config` | `--show` | 显示当前配置项 |
|
|
240
|
+
| | `--set` | 设置配置项(如 analyzer.max_depth=15)|
|
|
241
|
+
|
|
242
|
+
### 环境变量
|
|
243
|
+
|
|
244
|
+
| 变量 | 说明 |
|
|
245
|
+
|-------|------|
|
|
246
|
+
| `VOLCENGINE_ACCESS_KEY` | Volcengine 访问密钥 |
|
|
247
|
+
| `VOLCENGINE_SECRET_KEY` | Volcengine 密钥 |
|
|
248
|
+
| `VOLCENGINE_APP_ID` | Volcengine 应用 ID |
|
|
249
|
+
|
|
250
|
+
## 性能
|
|
251
|
+
|
|
252
|
+
- 单次提交分析:< 10 秒
|
|
253
|
+
- 影响图构建:< 5 秒
|
|
254
|
+
- 测试选择:< 3 秒
|
|
255
|
+
- 支持 1000+ 测试用例
|
|
256
|
+
- 选择性测试加速:≥ 50%
|
|
257
|
+
|
|
258
|
+
## 许可证
|
|
259
|
+
|
|
260
|
+
[MIT License](LICENSE)
|
|
261
|
+
|
|
262
|
+
## 贡献
|
|
263
|
+
|
|
264
|
+
欢迎贡献!请查看 [CONTRIBUTING.md](CONTRIBUTING.md) 了解详细信息。
|
|
265
|
+
|
|
266
|
+
## 支持
|
|
267
|
+
|
|
268
|
+
- 🐛 Issues: [GitHub Issues](https://github.com/boyingliu01/jcia/issues)
|
|
269
|
+
- 📖 Docs: [项目文档](https://github.com/boyingliu01/jcia#readme)
|
|
270
|
+
|
|
271
|
+
## 更新日志
|
|
272
|
+
|
|
273
|
+
查看 [CHANGELOG.md](CHANGELOG.md) 了解版本历史。
|
|
274
|
+
|
|
275
|
+
## 致谢
|
|
276
|
+
|
|
277
|
+
感谢所有贡献者和开源项目的支持:
|
|
278
|
+
|
|
279
|
+
- [PyDriller](https://github.com/ishepard/pydriller) - Git 仓库分析
|
|
280
|
+
- [Click](https://click.palletsprojects.com/) - 命令行界面
|
|
281
|
+
- [Pytest](https://docs.pytest.org/) - 测试框架
|
jcia-0.2.0/README.md
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
# JCIA - Java Code Impact Analyzer
|
|
2
|
+
|
|
3
|
+
[]
|
|
4
|
+
[]
|
|
5
|
+
[]
|
|
6
|
+
|
|
7
|
+
**JCIA** 是一个 Python 工具,用于分析 Java 代码变更的影响范围,智能选择需要运行的测试用例,并提供回归分析能力。
|
|
8
|
+
|
|
9
|
+
## 特性
|
|
10
|
+
|
|
11
|
+
- 🔍 **变更代码影响分析** - 自动分析 Git 提交,识别变更的文件和方法
|
|
12
|
+
- 📊 **影响图构建** - 构建调用链图,计算受影响的类和方法
|
|
13
|
+
- 🌐 **跨服务远程调用检测** - 识别 Dubbo/Feign/HTTP/MQ 远程调用并融合进影响图,评估跨服务变更风险(`--detect-remote-calls`)
|
|
14
|
+
- 🎯 **智能测试选择** - 基于 STARTS 算法和影响范围选择测试用例
|
|
15
|
+
- 🤖 **AI 测试生成** - 集成 LLM 服务,自动生成测试用例建议
|
|
16
|
+
- 📈 **多格式报告** - 支持 HTML、JSON、Markdown 格式报告
|
|
17
|
+
- 🔄 **回归分析** - 对比基线测试和回归测试结果,识别回归问题
|
|
18
|
+
|
|
19
|
+
## 快速开始
|
|
20
|
+
|
|
21
|
+
### 安装
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# 克隆仓库
|
|
25
|
+
git clone https://github.com/boyingliu01/jcia.git
|
|
26
|
+
cd jcia
|
|
27
|
+
|
|
28
|
+
# 创建虚拟环境
|
|
29
|
+
python -m venv .venv
|
|
30
|
+
.venv\Scripts\Activate.ps1 # Windows PowerShell
|
|
31
|
+
|
|
32
|
+
# 安装依赖
|
|
33
|
+
pip install -e ".[dev]"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### 配置
|
|
37
|
+
|
|
38
|
+
创建配置文件 `jcia.yaml`(可选):
|
|
39
|
+
|
|
40
|
+
```yaml
|
|
41
|
+
repository:
|
|
42
|
+
path: /path/to/your/java/project
|
|
43
|
+
|
|
44
|
+
analyzer:
|
|
45
|
+
max_depth: 10
|
|
46
|
+
include_test_files: false
|
|
47
|
+
|
|
48
|
+
report:
|
|
49
|
+
format: html
|
|
50
|
+
output_dir: ./reports
|
|
51
|
+
|
|
52
|
+
ai:
|
|
53
|
+
provider: volcengine
|
|
54
|
+
model: gpt-4
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### 使用
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
# 分析变更影响
|
|
61
|
+
jcia analyze --repo-path /path/to/repo --from-commit abc123 --to-commit def456
|
|
62
|
+
|
|
63
|
+
# 分析变更影响并检测跨服务远程调用(Dubbo/Feign/HTTP/MQ)
|
|
64
|
+
jcia analyze --repo-path /path/to/repo --commit-range abc123..def456 --detect-remote-calls
|
|
65
|
+
|
|
66
|
+
# 生成测试用例
|
|
67
|
+
jcia test --repo-path /path/to/project --target-class com.example.Service
|
|
68
|
+
|
|
69
|
+
# 生成报告
|
|
70
|
+
jcia report --output-dir ./reports --format html
|
|
71
|
+
|
|
72
|
+
# 配置管理
|
|
73
|
+
jcia config --show
|
|
74
|
+
jcia config --set analyzer.max_depth=15
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## 核心概念
|
|
78
|
+
|
|
79
|
+
### 变更分析
|
|
80
|
+
|
|
81
|
+
JCIA 使用 PyDriller 解析 Git 仓库,识别:
|
|
82
|
+
|
|
83
|
+
- 文件级变更(新增、修改、删除、重命名)
|
|
84
|
+
- 方法级变更(方法签名变更)
|
|
85
|
+
- 提交信息(作者、时间、消息)
|
|
86
|
+
|
|
87
|
+
### 影响图
|
|
88
|
+
|
|
89
|
+
影响图展示代码变更的传播路径:
|
|
90
|
+
|
|
91
|
+
- **直接影响** - 直接调用变更方法的代码
|
|
92
|
+
- **间接影响** - 通过调用链间接影响的代码
|
|
93
|
+
- **严重程度** - HIGH/MEDIUM/LOW
|
|
94
|
+
- **影响深度** - 变更传播的最大深度
|
|
95
|
+
|
|
96
|
+
### 测试选择
|
|
97
|
+
|
|
98
|
+
JCIA 支持多种测试选择策略:
|
|
99
|
+
|
|
100
|
+
- **ALL** - 运行所有测试
|
|
101
|
+
- **STARTS** - 使用 STARTS 算法选择
|
|
102
|
+
- **IMPACT_BASED** - 基于影响范围选择
|
|
103
|
+
- **HYBRID** - 混合策略
|
|
104
|
+
|
|
105
|
+
## 架构
|
|
106
|
+
|
|
107
|
+
JCIA 采用**清洁架构**(Clean Architecture):
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
Adapters Layer (Git, Maven, AI, Database)
|
|
111
|
+
↓
|
|
112
|
+
Infrastructure Layer (Repositories, Config, Logging)
|
|
113
|
+
↓
|
|
114
|
+
Use Cases Layer (Business Orchestration)
|
|
115
|
+
↓
|
|
116
|
+
Services Layer (Domain Logic)
|
|
117
|
+
↓
|
|
118
|
+
Entities Layer (Domain Models)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### 依赖规则
|
|
122
|
+
|
|
123
|
+
- 外部依赖(Git、Maven、AI)在适配器层
|
|
124
|
+
- 业务逻辑在核心层
|
|
125
|
+
- 核心层不依赖适配器层
|
|
126
|
+
- 通过接口(ABC)解耦
|
|
127
|
+
|
|
128
|
+
## 开发
|
|
129
|
+
|
|
130
|
+
### 设置开发环境
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
# 安装开发依赖
|
|
134
|
+
pip install -e ".[dev]"
|
|
135
|
+
|
|
136
|
+
# 配置 pre-commit hooks
|
|
137
|
+
make setup-hooks
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### 运行测试
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
# 运行所有测试
|
|
144
|
+
make test
|
|
145
|
+
|
|
146
|
+
# 运行单元测试
|
|
147
|
+
pytest tests/unit -v
|
|
148
|
+
|
|
149
|
+
# 运行集成测试
|
|
150
|
+
pytest tests/integration -v
|
|
151
|
+
|
|
152
|
+
# 运行带覆盖率的测试
|
|
153
|
+
pytest tests/unit --cov=jcia --cov-report=html
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### 代码质量
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
# Lint 检查
|
|
160
|
+
make lint
|
|
161
|
+
|
|
162
|
+
# 格式化代码
|
|
163
|
+
make format
|
|
164
|
+
|
|
165
|
+
# 类型检查
|
|
166
|
+
pyright jcia tests
|
|
167
|
+
|
|
168
|
+
# 安全扫描
|
|
169
|
+
make security
|
|
170
|
+
|
|
171
|
+
# 完整检查
|
|
172
|
+
make check
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## 配置选项
|
|
176
|
+
|
|
177
|
+
### CLI 选项
|
|
178
|
+
|
|
179
|
+
| 命令 | 选项 | 说明 |
|
|
180
|
+
|-------|------|------|
|
|
181
|
+
| `analyze` | `--repo-path` | Git 仓库路径 |
|
|
182
|
+
| | `--from-commit` | 起始提交哈希 |
|
|
183
|
+
| | `--to-commit` | 结束提交哈希 |
|
|
184
|
+
| | `--commit-range` | 提交范围(如 abc123..def456)|
|
|
185
|
+
| | `--max-depth` | 最大追溯深度 |
|
|
186
|
+
| `test` | `--repo-path` | 项目路径 |
|
|
187
|
+
| | `--target-class` | 目标类(可多次使用)|
|
|
188
|
+
| | `--coverage-file` | 覆盖率报告文件 |
|
|
189
|
+
| | `--min-confidence` | 最低置信度阈值 |
|
|
190
|
+
| `report` | `--output-dir` | 报告输出目录(必填)|
|
|
191
|
+
| | `--format` | 报告格式(json/html/markdown/console,默认 json)|
|
|
192
|
+
| | `--include-details` | 包含详细信息 |
|
|
193
|
+
| `config` | `--show` | 显示当前配置项 |
|
|
194
|
+
| | `--set` | 设置配置项(如 analyzer.max_depth=15)|
|
|
195
|
+
|
|
196
|
+
### 环境变量
|
|
197
|
+
|
|
198
|
+
| 变量 | 说明 |
|
|
199
|
+
|-------|------|
|
|
200
|
+
| `VOLCENGINE_ACCESS_KEY` | Volcengine 访问密钥 |
|
|
201
|
+
| `VOLCENGINE_SECRET_KEY` | Volcengine 密钥 |
|
|
202
|
+
| `VOLCENGINE_APP_ID` | Volcengine 应用 ID |
|
|
203
|
+
|
|
204
|
+
## 性能
|
|
205
|
+
|
|
206
|
+
- 单次提交分析:< 10 秒
|
|
207
|
+
- 影响图构建:< 5 秒
|
|
208
|
+
- 测试选择:< 3 秒
|
|
209
|
+
- 支持 1000+ 测试用例
|
|
210
|
+
- 选择性测试加速:≥ 50%
|
|
211
|
+
|
|
212
|
+
## 许可证
|
|
213
|
+
|
|
214
|
+
[MIT License](LICENSE)
|
|
215
|
+
|
|
216
|
+
## 贡献
|
|
217
|
+
|
|
218
|
+
欢迎贡献!请查看 [CONTRIBUTING.md](CONTRIBUTING.md) 了解详细信息。
|
|
219
|
+
|
|
220
|
+
## 支持
|
|
221
|
+
|
|
222
|
+
- 🐛 Issues: [GitHub Issues](https://github.com/boyingliu01/jcia/issues)
|
|
223
|
+
- 📖 Docs: [项目文档](https://github.com/boyingliu01/jcia#readme)
|
|
224
|
+
|
|
225
|
+
## 更新日志
|
|
226
|
+
|
|
227
|
+
查看 [CHANGELOG.md](CHANGELOG.md) 了解版本历史。
|
|
228
|
+
|
|
229
|
+
## 致谢
|
|
230
|
+
|
|
231
|
+
感谢所有贡献者和开源项目的支持:
|
|
232
|
+
|
|
233
|
+
- [PyDriller](https://github.com/ishepard/pydriller) - Git 仓库分析
|
|
234
|
+
- [Click](https://click.palletsprojects.com/) - 命令行界面
|
|
235
|
+
- [Pytest](https://docs.pytest.org/) - 测试框架
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""JCIA - Java Code Impact Analyzer.
|
|
2
|
+
|
|
3
|
+
代码变更影响分析工具,支持Maven项目的一键式代码变更影响分析、测试生成与回归验证。
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
__version__ = "0.2.0"
|
|
7
|
+
__author__ = "JCIA Team"
|
|
8
|
+
|
|
9
|
+
from jcia.core.entities.change_set import ChangeSet
|
|
10
|
+
from jcia.core.entities.impact_graph import ImpactGraph
|
|
11
|
+
from jcia.core.entities.test_case import TestCase
|
|
12
|
+
|
|
13
|
+
__all__ = ["ChangeSet", "ImpactGraph", "TestCase"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""外部适配器层."""
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""AI 服务适配器."""
|
|
2
|
+
|
|
3
|
+
from jcia.adapters.ai.openai_adapter import OpenAIAdapter
|
|
4
|
+
from jcia.adapters.ai.skywalking_adapter import SkyWalkingAdapter
|
|
5
|
+
from jcia.adapters.ai.volcengine_adapter import VolcengineAdapter
|
|
6
|
+
|
|
7
|
+
__all__ = ["OpenAIAdapter", "SkyWalkingAdapter", "VolcengineAdapter"]
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""LLM 适配器工厂.
|
|
2
|
+
|
|
3
|
+
提供对不同 AI 服务提供商的统一访问。
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from jcia.adapters.ai.volcengine_adapter import VolcengineAdapter
|
|
9
|
+
from jcia.core.interfaces.ai_service import AIAnalyzer, AIProvider, AITestGenerator
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class LLMAdapterFactory:
|
|
13
|
+
"""LLM 适配器工厂类."""
|
|
14
|
+
|
|
15
|
+
@staticmethod
|
|
16
|
+
def create_adapter(
|
|
17
|
+
provider: AIProvider | str,
|
|
18
|
+
**kwargs: Any,
|
|
19
|
+
) -> AITestGenerator | AIAnalyzer:
|
|
20
|
+
"""根据提供商创建对应的适配器实例.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
provider: AI 服务提供商
|
|
24
|
+
**kwargs: 适配器初始化参数
|
|
25
|
+
|
|
26
|
+
Returns:
|
|
27
|
+
AITestGenerator | AIAnalyzer: 适配器实例
|
|
28
|
+
|
|
29
|
+
Raises:
|
|
30
|
+
ValueError: 不支持的提供商
|
|
31
|
+
"""
|
|
32
|
+
provider_val = provider.value if isinstance(provider, AIProvider) else str(provider).lower()
|
|
33
|
+
|
|
34
|
+
if provider_val == AIProvider.VOLCENGINE.value:
|
|
35
|
+
return VolcengineAdapter(**kwargs)
|
|
36
|
+
|
|
37
|
+
raise ValueError(f"Unsupported AI provider: {provider_val}")
|