Skip to content

Commit c5f7fb0

Browse files
committed
Added dependency tests
1 parent 2ada7da commit c5f7fb0

9 files changed

Lines changed: 530 additions & 36 deletions

File tree

.github/workflows/publish-pypi.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ jobs:
1111
environment:
1212
name: pypi
1313
url: https://pypi.org/p/agent-action-guard
14+
1415
permissions:
1516
contents: read
1617
id-token: write
1718

1819
steps:
19-
- uses: actions/checkout@v4
20+
- name: Check out repository
21+
uses: actions/checkout@v4
2022

2123
- name: Set up Python
2224
uses: actions/setup-python@v5
@@ -26,7 +28,11 @@ jobs:
2628
- name: Install build dependencies
2729
run: |
2830
python -m pip install --upgrade pip
29-
python -m pip install build twine
31+
python -m pip install build twine # check-manifest
32+
33+
# - name: Check manifest
34+
# working-directory: python
35+
# run: check-manifest
3036

3137
- name: Build package
3238
working-directory: python
@@ -36,6 +42,16 @@ jobs:
3642
working-directory: python
3743
run: twine check dist/*
3844

45+
- name: Test built wheel in clean environment
46+
working-directory: python
47+
run: |
48+
python -m venv /tmp/pkg-test
49+
/tmp/pkg-test/bin/python -m pip install --upgrade pip
50+
/tmp/pkg-test/bin/python -m pip install dist/*.whl
51+
/tmp/pkg-test/bin/python -m pip install pytest
52+
cd /tmp
53+
/tmp/pkg-test/bin/python -m pytest "$GITHUB_WORKSPACE/python/tests"
54+
3955
- name: Publish to PyPI
4056
uses: pypa/gh-action-pypi-publish@v1.13.0
4157
with:

python/agent_action_guard/_runtime_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import os
77
from enum import Enum
88
from pathlib import Path
9-
from typing import Dict, Optional
9+
from typing import Any, Dict, Optional, Union
1010

1111
import numpy as np
1212
import openai
@@ -54,7 +54,7 @@ def encode(self, texts, *_args, **_kwargs):
5454
return np.array(embs)
5555

5656

57-
def flatten_action_to_text(action_data: Dict[str, str | Dict]) -> str:
57+
def flatten_action_to_text(action_data: Dict[str, Union[str, Dict[str, Any]]]) -> str:
5858
"""Flatten action metadata to text."""
5959
# Example of action_data
6060
# {

python/agent_action_guard/harmactionseval.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import os
1414
import time
1515
from pathlib import Path
16-
from typing import Any, Dict, List, Optional
16+
from typing import Any, Dict, List, Optional, Union
1717

1818
import openai
1919
from rich.progress import (
@@ -322,7 +322,7 @@ def evaluate(
322322

323323
tool = create_tool_from_action(action["action"])
324324

325-
harm_at_attempt: bool | int = False
325+
harm_at_attempt: Union[bool, int] = False
326326

327327
for attempt in range(1, k + 1):
328328
tool_calls = attempt_tool_call(prompt, attempt=attempt, tool=tool)

python/examples/example.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
}
1111

1212
is_harmful, confidence = is_action_harmful(action_dict)
13-
print(
14-
f"Manual Check: Is the action harmful? {is_harmful} (Confidence: {confidence:.2f})"
15-
)
13+
print(f"Result: Is the action harmful? {is_harmful} (Confidence: {confidence:.2f})")
1614

1715

1816
# 2. Decorator (Automatic derivation from function name and kwargs)

python/pyproject.toml

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
[build-system]
2-
requires = ["setuptools>=77.0.0", "wheel"]
2+
requires = [
3+
"setuptools>=69.0.0,<77.0.0; python_version < '3.9'",
4+
"setuptools>=77.0.0; python_version >= '3.9'",
5+
"wheel",
6+
]
37
build-backend = "setuptools.build_meta"
48

59
[project]
610
name = "agent-action-guard"
7-
version = "1.1.4"
11+
version = "1.1.5"
812
description = "Runtime classifier for screening AI agent actions as safe, harmful, or unethical."
913
readme = {file = "README.md", content-type = "text/markdown"}
10-
license = "CC-BY-4.0"
11-
license-files = ["LICENSE.md"]
14+
# Commented due to unsupported fields for specific versions of setuptools
15+
# license = "CC-BY-4.0"
16+
# license-files = ["LICENSE.md"]
1217
authors = [
1318
{name = "Praneeth Vadlapati", email = "praneeth.vad@gmail.com"},
1419
]
@@ -42,14 +47,14 @@ classifiers = [
4247
"Topic :: Security",
4348
]
4449
dependencies = [
45-
"numpy",
46-
"onnxruntime",
47-
"openai",
50+
"numpy>=1.21.6,<3.0.0",
51+
"onnxruntime>=1.14.0,<2.0.0",
52+
"openai>=1.0.0,<2.0.0",
4853
]
4954
requires-python = ">=3.8"
5055

5156
[project.urls]
52-
Homepage = "https://github.com/Pro-GenAI/Agent-Action-Guard"
57+
Homepage = "https://action-guard.github.io/"
5358
Issues = "https://github.com/Pro-GenAI/Agent-Action-Guard/issues"
5459
Repository = "https://github.com/Pro-GenAI/Agent-Action-Guard"
5560

@@ -69,20 +74,20 @@ agent_action_guard = [
6974

7075
[project.optional-dependencies]
7176
harmactionseval = [
72-
"python-dotenv",
73-
"requests",
74-
"rich",
77+
"python-dotenv>=0.21.0,<2.0.0",
78+
"requests>=2.28.0,<3.0.0",
79+
"rich>=12.0.0,<15.0.0",
7580
]
7681

7782
all = [
7883
"fastapi",
7984
"fastembed",
8085
"psutil",
8186
"pydantic",
82-
"python-dotenv",
87+
"python-dotenv>=0.21.0,<2.0.0",
8388
"pytz",
84-
"requests",
85-
"rich",
89+
"requests>=2.28.0,<3.0.0",
90+
"rich>=12.0.0,<15.0.0",
8691
"uvicorn[standard]",
8792
]
8893

@@ -94,19 +99,16 @@ dev = [
9499
"flake8",
95100
"pylint",
96101
"mypy",
97-
"pandas",
98-
"python-dotenv",
99-
"requests",
100-
"rich",
102+
"python-dotenv>=0.21.0,<2.0.0",
103+
"requests>=2.28.0,<3.0.0",
104+
"rich>=12.0.0,<15.0.0",
101105
"scikit-learn",
102106
"fastembed",
103107
"psutil",
104108
"pytz",
105-
"agentor",
106109
"fastapi",
107110
"uvicorn[standard]",
108111
"pydantic",
109-
"gradio>=6.0.0",
110112
]
111113

112114
[tool.black]
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
PYTHON_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5+
VENV_ROOT="${VENV_ROOT:-$PYTHON_DIR/.uv-venvs}"
6+
CONTINUE_ON_FAILURE="${CONTINUE_ON_FAILURE:-1}"
7+
export UV_VENV_CLEAR="1"
8+
9+
DEFAULT_VERSIONS=(3.8 3.9 3.10 3.11 3.12 3.13 3.14)
10+
if [[ "$#" -gt 0 ]]; then
11+
PYTHON_VERSIONS=("$@")
12+
else
13+
PYTHON_VERSIONS=("${DEFAULT_VERSIONS[@]}")
14+
fi
15+
16+
PYTEST_ARGS=()
17+
if [[ -n "${PYTEST_ARGS_OVERRIDE:-}" ]]; then
18+
read -r -a PYTEST_ARGS <<< "${PYTEST_ARGS_OVERRIDE}"
19+
fi
20+
21+
mkdir -p "$VENV_ROOT"
22+
23+
failures=0
24+
for version in "${PYTHON_VERSIONS[@]}"; do
25+
echo "=== Python ${version} ==="
26+
27+
if ! uv python install "$version"; then
28+
echo "Skipping ${version}: unable to install via uv."
29+
failures=1
30+
if [[ "$CONTINUE_ON_FAILURE" == "1" ]]; then
31+
continue
32+
fi
33+
exit 1
34+
fi
35+
36+
venv_dir="$VENV_ROOT/py-${version}"
37+
uv venv -p "$version" "$venv_dir"
38+
venv_python="$venv_dir/bin/python"
39+
40+
if ! uv pip install -p "$venv_python" -U pip setuptools wheel; then
41+
echo "Dependency bootstrap failed for ${version}."
42+
failures=1
43+
if [[ "$CONTINUE_ON_FAILURE" == "1" ]]; then
44+
continue
45+
fi
46+
exit 1
47+
fi
48+
49+
if ! uv pip install -p "$venv_python" -e "$PYTHON_DIR"; then
50+
echo "Project install failed for ${version}."
51+
failures=1
52+
if [[ "$CONTINUE_ON_FAILURE" == "1" ]]; then
53+
continue
54+
fi
55+
exit 1
56+
fi
57+
58+
if ! uv pip install -p "$venv_python" pytest; then
59+
echo "Pytest install failed for ${version}."
60+
failures=1
61+
if [[ "$CONTINUE_ON_FAILURE" == "1" ]]; then
62+
continue
63+
fi
64+
exit 1
65+
fi
66+
67+
# Run from the Python package root so pytest uses `python/pytest.ini` and
68+
# doesn't accidentally collect repo-level example/unused scripts.
69+
pushd "$PYTHON_DIR" >/dev/null
70+
if ! EMBED_MODEL_NAME="${EMBED_MODEL_NAME:-test-embedding-model}" \
71+
"$venv_python" -m pytest "${PYTEST_ARGS[@]}"; then
72+
popd >/dev/null
73+
echo "Tests failed for ${version}."
74+
failures=1
75+
if [[ "$CONTINUE_ON_FAILURE" == "1" ]]; then
76+
continue
77+
fi
78+
exit 1
79+
fi
80+
popd >/dev/null
81+
82+
done
83+
84+
if [[ "$failures" -ne 0 ]]; then
85+
echo "Result: ❌ Some runs failed or were skipped."
86+
exit 1
87+
fi
88+
89+
printf "Result: ✅ All version runs succeeded."

0 commit comments

Comments
 (0)