dify/dify-agent/tests/local/test_packaging.py
Yunlu Wen 302d7b1e1b
feat(agent): shellctl rewritten in go (#38841)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-07-15 01:58:36 +00:00

79 lines
2.4 KiB
Python

from __future__ import annotations
import tomllib
from pathlib import Path
PROJECT_ROOT = Path(__file__).resolve().parents[2]
CLIENT_SHARED_DTO_DEPENDENCIES = {
"httpx==0.28.1",
"httpx2>=2.5.0,<3.0.0",
"pydantic>=2.12.5,<2.13",
"pydantic-ai-slim>=1.102.0,<2.0.0",
"typing-extensions>=4.12.2,<5.0.0",
}
SERVER_RUNTIME_DEPENDENCIES = {
"fastapi==0.136.0",
"graphon==0.5.2",
"jsonschema>=4.23.0,<5.0.0",
"jwcrypto>=1.5.6,<2",
"logfire[fastapi,httpx,redis]>=4.37.0,<5.0.0",
"pydantic-ai-slim[anthropic,google,openai]>=1.85.1,<2.0.0",
"pydantic-settings>=2.12.0,<3.0.0",
"redis>=7.4.0,<8.0.0",
"uvicorn[standard]==0.46.0",
}
GRPC_RUNTIME_DEPENDENCIES = {
"grpclib[protobuf]>=0.4.9,<0.5.0",
"protobuf>=6.33.5,<7.0.0",
}
DEV_DEPENDENCIES = {
"basedpyright>=1.39.3",
"coverage[toml]>=7.10.7",
"grpcio-tools>=1.81.0,<2.0.0",
"pytest>=9.0.3",
"pytest-examples>=0.0.18",
"pytest-mock>=3.14.0",
"ruff>=0.15.11",
}
def _read_pyproject():
return tomllib.loads((PROJECT_ROOT / "pyproject.toml").read_text(encoding="utf-8"))
def test_project_dependencies_split_client_and_server_requirements() -> None:
pyproject = _read_pyproject()
project = pyproject["project"]
assert set(project["dependencies"]) == CLIENT_SHARED_DTO_DEPENDENCIES
assert set(project["optional-dependencies"]["grpc"]) == GRPC_RUNTIME_DEPENDENCIES
assert set(project["optional-dependencies"]["server"]) == SERVER_RUNTIME_DEPENDENCIES
assert set(pyproject["dependency-groups"]["dev"]) == DEV_DEPENDENCIES
def test_default_package_discovery_excludes_example_packages() -> None:
pyproject = _read_pyproject()
find_config = pyproject["tool"]["setuptools"]["packages"]["find"]
assert find_config["where"] == ["src"]
assert "shellctl*" in find_config["include"]
assert "shellctl_runtime*" not in find_config["include"]
assert "agenton_examples*" not in find_config["include"]
assert "dify_agent_examples*" not in find_config["include"]
def test_project_declares_console_scripts() -> None:
pyproject = _read_pyproject()
scripts = pyproject["project"]["scripts"]
assert scripts["dify-agent-stub-server"] == "dify_agent.agent_stub.server.cli:main"
assert "dify-agent" not in scripts
assert "shellctl" not in scripts
assert "shellctl-sanitize-pty" not in scripts
assert "shellctl-runner-exit" not in scripts