Skip to main content

JCIA - Java Code Impact Analyzer

[Python Version] [License] [Code Coverage]

JCIA 是一个 Python 工具,用于分析 Java 代码变更的影响范围,智能选择需要运行的测试用例,并提供回归分析能力。

特性

  • 🔍 变更代码影响分析 - 自动分析 Git 提交,识别变更的文件和方法
  • 📊 影响图构建 - 构建调用链图,计算受影响的类和方法
  • 🌐 跨服务远程调用检测 - 识别 Dubbo/Feign/HTTP/MQ 远程调用并融合进影响图,评估跨服务变更风险(--detect-remote-calls)
  • 🎯 智能测试选择 - 基于 STARTS 算法和影响范围选择测试用例
  • 🤖 AI 测试生成 - 集成 LLM 服务,自动生成测试用例建议
  • 📈 多格式报告 - 支持 HTML、JSON、Markdown 格式报告
  • 🔄 回归分析 - 对比基线测试和回归测试结果,识别回归问题

快速开始

安装

# 克隆仓库
git clone https://github.com/boyingliu01/jcia.git
cd jcia

# 创建虚拟环境
python -m venv .venv
.venv\Scripts\Activate.ps1  # Windows PowerShell

# 安装依赖
pip install -e ".[dev]"

配置

创建配置文件 jcia.yaml(可选):

repository:
  path: /path/to/your/java/project

analyzer:
  max_depth: 10
  include_test_files: false

report:
  format: html
  output_dir: ./reports

ai:
  provider: volcengine
  model: gpt-4

使用

# 分析变更影响
jcia analyze --repo-path /path/to/repo --from-commit abc123 --to-commit def456

# 分析变更影响并检测跨服务远程调用(Dubbo/Feign/HTTP/MQ)
jcia analyze --repo-path /path/to/repo --commit-range abc123..def456 --detect-remote-calls

# 生成测试用例
jcia test --repo-path /path/to/project --target-class com.example.Service

# 生成报告
jcia report --output-dir ./reports --format html

# 配置管理
jcia config --show
jcia config --set analyzer.max_depth=15

核心概念

变更分析

JCIA 使用 PyDriller 解析 Git 仓库,识别:

  • 文件级变更(新增、修改、删除、重命名)
  • 方法级变更(方法签名变更)
  • 提交信息(作者、时间、消息)

影响图

影响图展示代码变更的传播路径:

  • 直接影响 - 直接调用变更方法的代码
  • 间接影响 - 通过调用链间接影响的代码
  • 严重程度 - HIGH/MEDIUM/LOW
  • 影响深度 - 变更传播的最大深度

测试选择

JCIA 支持多种测试选择策略:

  • ALL - 运行所有测试
  • STARTS - 使用 STARTS 算法选择
  • IMPACT_BASED - 基于影响范围选择
  • HYBRID - 混合策略

架构

JCIA 采用清洁架构(Clean Architecture):

Adapters Layer (Git, Maven, AI, Database)
    ↓
Infrastructure Layer (Repositories, Config, Logging)
    ↓
Use Cases Layer (Business Orchestration)
    ↓
Services Layer (Domain Logic)
    ↓
Entities Layer (Domain Models)

依赖规则

  • 外部依赖(Git、Maven、AI)在适配器层
  • 业务逻辑在核心层
  • 核心层不依赖适配器层
  • 通过接口(ABC)解耦

开发

设置开发环境

# 安装开发依赖
pip install -e ".[dev]"

# 配置 pre-commit hooks
make setup-hooks

运行测试

# 运行所有测试
make test

# 运行单元测试
pytest tests/unit -v

# 运行集成测试
pytest tests/integration -v

# 运行带覆盖率的测试
pytest tests/unit --cov=jcia --cov-report=html

代码质量

# Lint 检查
make lint

# 格式化代码
make format

# 类型检查
pyright jcia tests

# 安全扫描
make security

# 完整检查
make check

配置选项

CLI 选项

命令 选项 说明
analyze --repo-path Git 仓库路径
--from-commit 起始提交哈希
--to-commit 结束提交哈希
--commit-range 提交范围(如 abc123..def456)
--max-depth 最大追溯深度
test --repo-path 项目路径
--target-class 目标类(可多次使用)
--coverage-file 覆盖率报告文件
--min-confidence 最低置信度阈值
report --output-dir 报告输出目录(必填)
--format 报告格式(json/html/markdown/console,默认 json)
--include-details 包含详细信息
config --show 显示当前配置项
--set 设置配置项(如 analyzer.max_depth=15)

环境变量

变量 说明
VOLCENGINE_ACCESS_KEY Volcengine 访问密钥
VOLCENGINE_SECRET_KEY Volcengine 密钥
VOLCENGINE_APP_ID Volcengine 应用 ID

性能

  • 单次提交分析:< 10 秒
  • 影响图构建:< 5 秒
  • 测试选择:< 3 秒
  • 支持 1000+ 测试用例
  • 选择性测试加速:≥ 50%

许可证

MIT License

贡献

欢迎贡献!请查看 CONTRIBUTING.md 了解详细信息。

支持

更新日志

查看 CHANGELOG.md 了解版本历史。

致谢

感谢所有贡献者和开源项目的支持:

Metadata

Release files for jcia 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jcia 0.2.1
File Size Uploaded
jcia-0.2.1.tar.gz 139.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jcia 0.2.1
File Interpreter ABI Platform
jcia-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 313.5 kB

Release files / jcia-0.2.1.tar.gz

Download URL jcia-0.2.1.tar.gz
Size 139.4 kB
Tags Source
SHA-256 checksum
How to use checksums
18553a6a15e8b5970d761129c29e4c2f738f18c8b6988472249ccf892d93e1bd
BLAKE2b-256 checksum
How to use checksums
b75e4ccf2a8a10ea0bd9ace6be8da61661894b1d9743250d6ba771a305899234
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 22, 2026.

Transparency log

Release files / jcia-0.2.1-py3-none-any.whl

Download URL jcia-0.2.1-py3-none-any.whl
Size 174.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0585642fa1ecf010474337977b9d9f249b5ef24fda68796324a388b3322f6508
BLAKE2b-256 checksum
How to use checksums
85a98af0672a0cf9d09741a4d65fdab4d3242f2f2dfc1995a50ddf5c9f305eb7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 22, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page