Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 177 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
name: CI

on:
# 仅在 push 时触发测试
push:
Comment on lines +4 to +5
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment states "仅在 push 时触发测试" (only triggered on push), but this will run on every push to any branch. Consider adding branch filters or documenting whether this is intentional, especially since the workflow includes automated package publishing which might not be desired for all branches.

Suggested change
# 仅在 push 时触发测试
push:
# 仅在 main 分支 push 时触发测试和发布
push:
branches:
- main

Copilot uses AI. Check for mistakes.

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10']

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # 获取完整历史用于增量覆盖率检查

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
make setup PYTHON_VERSION=${{ matrix.python-version }}
- name: Run type check (mypy)
run: |
make mypy-check
- name: Run unit tests
run: |
make test-unit
- name: Run coverage
run: |
make coverage
# 检测文件更改并决定是否构建测试包
- name: Check for changes in agentrun directory
id: changes
run: |
echo "Checking if agentrun directory has changes..."
# 获取最近两次提交之间的差异;如果没有父提交,则将所有跟踪文件视为已更改
if git rev-parse HEAD^ >/dev/null 2>&1; then
git diff --name-only HEAD^ HEAD > changed_files.txt
else
echo "No parent commit; treating all tracked files as changed."
git ls-files > changed_files.txt
fi
echo "Changed files:"
cat changed_files.txt || echo "No changed files detected"
# 检查是否有任何以 agentrun/ 开头的文件
if grep -q "^agentrun/" changed_files.txt 2>/dev/null; then
echo "agentrun directory has changes"
echo "agentrun_changed=true" >> $GITHUB_OUTPUT
else
echo "agentrun directory has no changes"
echo "agentrun_changed=false" >> $GITHUB_OUTPUT
fi
# 测试通过后自动构建测试包(仅在 agentrun 目录有变化时触发)
- name: Get latest version from PyPI and calculate next version
id: version
if: steps.changes.outputs.agentrun_changed == 'true'
run: |
# 从 PyPI 获取 agentrun-inner-test 的最新版本
PYPI_RESPONSE=$(curl -s https://pypi.org/pypi/agentrun-inner-test/json 2>/dev/null || echo "")
if [ -z "$PYPI_RESPONSE" ] || echo "$PYPI_RESPONSE" | grep -q "Not Found"; then
# 如果包不存在,从 0.0.0 开始
CURRENT_VERSION="0.0.0"
echo "Package not found on PyPI, starting from 0.0.0"
else
# 从 PyPI 响应中提取最新版本
CURRENT_VERSION=$(echo "$PYPI_RESPONSE" | python3 -c "import sys, json; print(json.load(sys.stdin)['info']['version'])")
echo "Latest version on PyPI: $CURRENT_VERSION"
fi
# 解析版本号
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
# 默认为 patch
BUMP_TYPE="patch"
case "$BUMP_TYPE" in
major)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
minor)
MINOR=$((MINOR + 1))
PATCH=0
Comment on lines +81 to +96
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The BUMP_TYPE variable is set to "patch" but never uses any other value since it's hard-coded. The subsequent case statement checking for major/minor/patch is unnecessary. Either remove the unused branches or make BUMP_TYPE configurable.

Suggested change
fi
# 解析版本号
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
# 默认为 patch
BUMP_TYPE="patch"
case "$BUMP_TYPE" in
major)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
minor)
MINOR=$((MINOR + 1))
PATCH=0
# 始终执行 patch 版本号递增
PATCH=$((PATCH + 1))

Copilot uses AI. Check for mistakes.
;;
patch)
PATCH=$((PATCH + 1))
;;
esac
Comment on lines +86 to +101
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded constant: The BUMP_TYPE is always set to "patch" and the subsequent case statement is unnecessary. Consider removing the case statement entirely and just implementing the patch logic directly, or make BUMP_TYPE configurable if different bump types are needed in the future.

Suggested change
# 默认为 patch
BUMP_TYPE="patch"
case "$BUMP_TYPE" in
major)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
minor)
MINOR=$((MINOR + 1))
PATCH=0
;;
patch)
PATCH=$((PATCH + 1))
;;
esac
# 始终进行 patch 版本号递增
PATCH=$((PATCH + 1))

Copilot uses AI. Check for mistakes.
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
NEW_TAG="agentrun-inner-test-v${NEW_VERSION}"
echo "VERSION=${NEW_VERSION}" >> $GITHUB_OUTPUT
echo "TAG=${NEW_TAG}" >> $GITHUB_OUTPUT
echo "New version: ${NEW_VERSION}"
echo "New tag: ${NEW_TAG}"
- name: Update package name and version in pyproject.toml
if: steps.changes.outputs.agentrun_changed == 'true'
run: |
VERSION="${{ steps.version.outputs.VERSION }}"
# 修改包名为 agentrun-inner-test
sed -i 's/name = "agentrun-sdk"/name = "agentrun-inner-test"/' pyproject.toml
# 修改版本号
sed -i 's/version = "[^"]*"/version = "'${VERSION}'"/' pyproject.toml
echo "Updated pyproject.toml:"
head -10 pyproject.toml
- name: Update __version__ in __init__.py
if: steps.changes.outputs.agentrun_changed == 'true'
run: |
VERSION="${{ steps.version.outputs.VERSION }}"
if grep -q "__version__" agentrun/__init__.py; then
sed -i 's/__version__ = "[^"]*"/__version__ = "'${VERSION}'"/' agentrun/__init__.py
else
sed -i '1a __version__ = "'${VERSION}'"' agentrun/__init__.py
fi
echo "Updated __init__.py version to ${VERSION}"
grep "__version__" agentrun/__init__.py
- name: Build package
if: steps.changes.outputs.agentrun_changed == 'true'
run: |
python -m pip install --upgrade pip
pip install build twine
python -m build
echo "Package built successfully"
ls -la dist/
- name: Verify package
if: steps.changes.outputs.agentrun_changed == 'true'
run: |
python -m twine check dist/*
echo "Package verification completed"
- name: Publish to PyPI
Comment on lines +144 to +149
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The workflow automatically publishes packages to PyPI on every push where agentrun/ files change, without requiring manual approval or additional checks. This could lead to unintended package publications. Consider adding a condition to only publish on specific branches (e.g., main) or requiring manual approval for production releases.

Copilot uses AI. Check for mistakes.
if: steps.changes.outputs.agentrun_changed == 'true'
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
verify-metadata: false

- name: Create and push tag
if: steps.changes.outputs.agentrun_changed == 'true'
run: |
TAG="${{ steps.version.outputs.TAG }}"
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git tag -a "$TAG" -m "Release test package version ${{ steps.version.outputs.VERSION }}"
git push origin "$TAG"
echo "Created and pushed tag: $TAG"
- name: Summary
if: steps.changes.outputs.agentrun_changed == 'true'
run: |
echo "## 🎉 Test Package Released!" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Package Name:** agentrun-inner-test" >> $GITHUB_STEP_SUMMARY
echo "- **Version:** ${{ steps.version.outputs.VERSION }}" >> $GITHUB_STEP_SUMMARY
echo "- **Tag:** ${{ steps.version.outputs.TAG }}" >> $GITHUB_STEP_SUMMARY
echo "- **Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Install with: \`pip install agentrun-inner-test==${{ steps.version.outputs.VERSION }}\`" >> $GITHUB_STEP_SUMMARY
13 changes: 11 additions & 2 deletions .github/workflows/release-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ on:
- patch # 0.0.1 -> 0.0.2
- minor # 0.0.1 -> 0.1.0
- major # 0.0.1 -> 1.0.0

# 支持被其他工作流调用(CI 测试通过后自动触发)
workflow_call:
inputs:
version_bump:
description: '版本递增类型'
required: false
default: 'patch'
type: string

jobs:
release-test:
Expand Down Expand Up @@ -49,8 +58,8 @@ jobs:
# 解析版本号
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"

# 根据用户选择递增版本
BUMP_TYPE="${{ inputs.version_bump }}"
# 根据用户选择递增版本(默认为 patch)
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment states "根据用户选择递增版本(默认为 patch)" but the actual default is set by the workflow_call input definition on line 23, not by this line. The comment could be clearer about where the default comes from.

Suggested change
# 根据用户选择递增版本(默认为 patch)
# 根据用户选择递增版本(默认值由 workflow inputs 定义,此处未提供时回退为 patch)

Copilot uses AI. Check for mistakes.
BUMP_TYPE="${{ inputs.version_bump || 'patch' }}"
case "$BUMP_TYPE" in
major)
MAJOR=$((MAJOR + 1))
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,6 @@ dmypy.json
.pytest_cache
.env

uv.lock
uv.lock
coverage.json
coverage.json
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,29 @@ install-deps:
--dev \
--all-extras \
-i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple

# ============================================================================
# 测试和覆盖率
# ============================================================================

.PHONY: test
test: ## 运行所有测试
@uv run pytest tests/

.PHONY: test-unit
test-unit: ## 运行单元测试
@uv run pytest tests/unittests/

.PHONY: test-e2e
test-e2e: ## 运行端到端测试
@uv run pytest tests/e2e/

.PHONY: mypy-check
mypy-check: ## 运行 mypy 类型检查
@uv run mypy --config-file mypy.ini .

.PHONY: coverage
coverage: ## 运行测试并显示覆盖率报告(全量代码 + 增量代码)
@echo "📊 运行覆盖率测试..."
@uv run python scripts/check_coverage.py

113 changes: 113 additions & 0 deletions coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# 覆盖率配置文件
# Coverage Configuration File

# ============================================================================
# 全量代码覆盖率要求
# ============================================================================
full:
# 分支覆盖率要求 (百分比)
branch_coverage: 0
# 行覆盖率要求 (百分比)
line_coverage: 0

# ============================================================================
# 增量代码覆盖率要求 (相对于基准分支的变更代码)
# ============================================================================
incremental:
# 分支覆盖率要求 (百分比)
branch_coverage: 0
# 行覆盖率要求 (百分比)
line_coverage: 0

# ============================================================================
# 特定目录的覆盖率要求
# 可以为特定目录设置不同的覆盖率阈值
# ============================================================================
directory_overrides:
# 为除 server 外的所有文件夹设置 0% 覆盖率要求
# 这样可以逐个文件夹增加测试,暂时跳过未测试的文件夹
agentrun/agent_runtime:
full:
branch_coverage: 0
line_coverage: 0
incremental:
branch_coverage: 0
line_coverage: 0

agentrun/credential:
full:
branch_coverage: 0
line_coverage: 0
incremental:
branch_coverage: 0
line_coverage: 0

agentrun/integration:
full:
branch_coverage: 0
line_coverage: 0
incremental:
branch_coverage: 0
line_coverage: 0

agentrun/model:
full:
branch_coverage: 0
line_coverage: 0
incremental:
branch_coverage: 0
line_coverage: 0

agentrun/sandbox:
full:
branch_coverage: 0
line_coverage: 0
incremental:
branch_coverage: 0
line_coverage: 0

agentrun/toolset:
full:
branch_coverage: 0
line_coverage: 0
incremental:
branch_coverage: 0
line_coverage: 0

agentrun/utils:
full:
branch_coverage: 0
line_coverage: 0
incremental:
branch_coverage: 0
line_coverage: 0

# server 模块保持默认的 95% 覆盖率要求
agentrun/server:
full:
branch_coverage: 0
line_coverage: 0
incremental:
branch_coverage: 0
line_coverage: 0
Comment on lines +85 to +92
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment is misleading: The comment says "server 模块保持默认的 95% 覆盖率要求" (server module maintains default 95% coverage requirement), but the actual values below are set to 0%, not 95%. Either update the comment to match the actual configuration or update the values if the comment is correct.

Copilot uses AI. Check for mistakes.

# ============================================================================
# 排除配置
# ============================================================================

# 排除的目录(不计入覆盖率统计)
exclude_directories:
- "tests/"
- "*__pycache__*"
- "*_async_template.py"
- "codegen/"
- "examples/"
- "build/"
- "*.egg-info"

# 排除的文件模式
exclude_patterns:
- "*_test.py"
- "test_*.py"
- "conftest.py"

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ dev = [
"pyyaml>=6.0.3",
"fastapi>=0.104.0",
"uvicorn>=0.24.0",
"langchain_mcp_adapters>=0.2.1",
]

[tool.pyink]
Expand Down Expand Up @@ -101,7 +102,7 @@ known_third_party = ["alibabacloud_tea_openapi", "alibabacloud_devs20230714", "a
sections = ["FUTURE", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"]

[tool.mypy]
python_version = "0.0.8"
python_version = "3.10"
exclude = "tests/"
plugins = ["pydantic.mypy"]
# Start with non-strict mode, and switch to strict mode later.
Expand Down
Loading