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
23 changes: 19 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install -e ".[dev]"
- run: python -m pip install -e ".[dev]"
- run: ruff check skilldiff tests examples fixtures
- run: ruff format --check skilldiff tests examples fixtures
- run: mypy
Expand All @@ -32,6 +32,21 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- run: pip install -e ".[dev]"
- run: python -m pytest -v --tb=short
- run: skilldiff demo
- run: python -m pip install -e ".[dev]"
- name: Run pytest
run: |
set +e
python -m pytest -vv --tb=short | tee pytest.log
status=${PIPESTATUS[0]}
{
echo "## Pytest (Python ${{ matrix.python-version }})"
echo
echo '```'
cat pytest.log
echo '```'
} >> "$GITHUB_STEP_SUMMARY"
if [ "$status" -ne 0 ]; then
python -c 'from pathlib import Path; text=Path("pytest.log").read_text(errors="replace")[-4000:]; print("::error title=pytest failed::" + text.replace("%", "%25").replace("\r", "%0D").replace("\n", "%0A"))'
fi
exit "$status"
- run: python -m skilldiff demo
5 changes: 1 addition & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ Changelog = "https://github.com/shunvel/skilldiff/blob/main/CHANGELOG.md"
[project.optional-dependencies]
dev = [
"pytest>=7.0",
"pytest-asyncio>=0.23",
"ruff>=0.6",
"mypy>=1.8",
]
Expand All @@ -55,9 +54,7 @@ packages = ["skilldiff"]

[tool.pytest.ini_options]
testpaths = ["tests"]
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "function"
addopts = "-q --tb=short"
addopts = "--tb=short"
pythonpath = ["."]

[tool.ruff]
Expand Down
8 changes: 5 additions & 3 deletions tests/test_agent_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,24 @@

from skilldiff.tools_schema import build_tool_specs, load_tools_from_script

REPO_ROOT = Path(__file__).resolve().parents[1]


def test_load_baseline_tools_from_examples() -> None:
tools = load_tools_from_script(Path("examples/baseline_tools.py"))
tools = load_tools_from_script(REPO_ROOT / "examples/baseline_tools.py")
assert "fetch_url" in tools
assert "read_text_file" in tools
assert "_fetch_url" not in tools


def test_load_variant_tools_from_examples() -> None:
tools = load_tools_from_script(Path("examples/variant_tools.py"))
tools = load_tools_from_script(REPO_ROOT / "examples/variant_tools.py")
assert "fetch_and_extract_title" in tools
assert "summarize_text" in tools


def test_build_function_declarations_has_parameters() -> None:
tools = load_tools_from_script(Path("examples/baseline_tools.py"))
tools = load_tools_from_script(REPO_ROOT / "examples/baseline_tools.py")
declarations = build_tool_specs(tools)
names = {decl.name for decl in declarations}
assert "fetch_url" in names
Expand Down
7 changes: 4 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
def test_demo_exits_zero_and_writes_json(tmp_path: Path, monkeypatch) -> None:
monkeypatch.chdir(tmp_path)
result = runner.invoke(app, ["demo", "--output-dir", ".agent_diff"])
assert result.exit_code == 0, result.output
assert "skilldiff Results" in result.output
assert "Win Rate" in result.output
combined = f"{result.output}\n{result.stdout}\n{getattr(result, 'stderr', '')}"
assert result.exit_code == 0, combined
assert "skilldiff Results" in combined
assert "Win Rate" in combined

output_dir = tmp_path / ".agent_diff"
files = list(output_dir.glob("results_*.json"))
Expand Down
3 changes: 2 additions & 1 deletion tests/test_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from skilldiff.models import Task
from skilldiff.tools_schema import load_tools_from_script

FIXTURE = Path("fixtures/demo-repo")
REPO_ROOT = Path(__file__).resolve().parents[1]
FIXTURE = REPO_ROOT / "fixtures/demo-repo"


def test_fixture_tasks_cover_sanity_and_eval() -> None:
Expand Down
36 changes: 20 additions & 16 deletions tests/test_gemini_history.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
"""Tests for Gemini thought_signature history preservation."""

import pytest
from google.genai import types

from skilldiff.llm import AgentTurn, ToolCall, _messages_to_gemini_contents, append_assistant_message


def _model_content(*, name: str, args: dict, signature: bytes) -> types.Content:
try:
part = types.Part(
function_call=types.FunctionCall(name=name, args=args),
thought_signature=signature,
)
except (TypeError, ValueError) as exc:
pytest.skip(f"google-genai Part() rejected thought_signature: {exc}")
return types.Content(role="model", parts=[part])


def test_append_assistant_message_preserves_gemini_model_content() -> None:
model_content = types.Content(
role="model",
parts=[
types.Part(
function_call=types.FunctionCall(name="fetch_url", args={"url": "https://x.com"}),
thought_signature=b"sig-bytes",
)
],
model_content = _model_content(
name="fetch_url",
args={"url": "https://x.com"},
signature=b"sig-bytes",
)
turn = AgentTurn(
text="",
Expand All @@ -28,14 +36,10 @@ def test_append_assistant_message_preserves_gemini_model_content() -> None:


def test_messages_to_gemini_contents_replays_raw_model_content() -> None:
model_content = types.Content(
role="model",
parts=[
types.Part(
function_call=types.FunctionCall(name="read_text_file", args={"path": "a.txt"}),
thought_signature=b"keep-me",
)
],
model_content = _model_content(
name="read_text_file",
args={"path": "a.txt"},
signature=b"keep-me",
)
contents = _messages_to_gemini_contents(
[
Expand Down
4 changes: 3 additions & 1 deletion tests/test_http_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

from skilldiff.tools_schema import load_tools_from_script

REPO_ROOT = Path(__file__).resolve().parents[1]


def test_fetch_url_text_uses_certifi_context() -> None:
tools = load_tools_from_script(Path("examples/http_utils.py"))
tools = load_tools_from_script(REPO_ROOT / "examples/http_utils.py")
fetch_url_text = tools["fetch_url_text"]
module = sys.modules[fetch_url_text.__module__]

Expand Down
Loading