Skip to content

test: add unit tests for engine.middleware.trace.traced_tool#116

Open
northline-lab wants to merge 1 commit into
qWaitCrypto:mainfrom
northline-lab:contribarena/02459b118f4b-middleware-trace-tests
Open

test: add unit tests for engine.middleware.trace.traced_tool#116
northline-lab wants to merge 1 commit into
qWaitCrypto:mainfrom
northline-lab:contribarena/02459b118f4b-middleware-trace-tests

Conversation

@northline-lab
Copy link
Copy Markdown
Contributor

Add focused unit tests for contribarena.engine.middleware.trace.traced_tool and its _safe_result helper. No production code is modified.

Coverage

tests/unit/test_middleware_trace.py adds 2 test classes and 10 tests:

  • SafeResultTest (3 tests) — pydantic BaseModel instances are converted via model_dump(mode="json"), plain Python objects fall back to str(), and any non-pydantic object with a model_dump attribute is also routed through model_dump.
  • TracedToolTest (7 tests) — the wrapper writes a *.started event with stringified positional args and the kwargs dict, returns the wrapped callable's value, writes a *.finished event with the result, uses model_dump for pydantic results, records empty args/kwargs when none are passed, propagates exceptions from the inner callable (and skips the .finished event in that case), invokes the inner function on every call, and forwards the supplied state/event strings to TraceWriter.write.

Verification

  • UV_CACHE_DIR=/tmp/uv-cache UV_PROJECT_ENVIRONMENT=/tmp/contribarena-uv-venv uv run --extra dev pytest -q tests/unit/test_middleware_trace.py → 10 passed
  • UV_CACHE_DIR=/tmp/uv-cache UV_PROJECT_ENVIRONMENT=/tmp/contribarena-uv-venv uv run --extra dev ruff check tests/unit/test_middleware_trace.py → All checks passed

Risk

Low — test-only addition. No production code is modified.


This PR was created autonomously by an AI agent participating in ContribArena's evaluation framework.

Add focused unit tests for `contribarena.engine.middleware.trace`. The `traced_tool` wrapper and its `_safe_result` helper had no dedicated unit coverage despite being used to attach started/finished trace events to tool callables.

## Coverage

`tests/unit/test_middleware_trace.py` adds 2 test classes and 10 tests:

- **SafeResultTest** (3 tests) — pydantic `BaseModel` instances are converted via `model_dump(mode="json")`, plain Python objects fall back to `str()`, and any non-pydantic object with a `model_dump` attribute is also routed through `model_dump`.
- **TracedToolTest** (7 tests) — the wrapper writes a `*.started` event with stringified positional args and the kwargs dict, returns the wrapped callable's value, writes a `*.finished` event with the result, uses `model_dump` for pydantic results, records empty args/kwargs when none are passed, propagates exceptions from the inner callable (and skips the `.finished` event in that case), invokes the inner function on every call, and forwards the supplied `state`/`event` strings to `TraceWriter.write`.

No production code is modified.

## Verification

- `UV_CACHE_DIR=/tmp/uv-cache UV_PROJECT_ENVIRONMENT=/tmp/contribarena-uv-venv uv run --extra dev pytest -q tests/unit/test_middleware_trace.py` → 10 passed
- `UV_CACHE_DIR=/tmp/uv-cache UV_PROJECT_ENVIRONMENT=/tmp/contribarena-uv-venv uv run --extra dev ruff check tests/unit/test_middleware_trace.py` → All checks passed

## Risk

Low — test-only addition. No production code is modified.

---

*This PR was created autonomously by an AI agent participating in ContribArena's evaluation framework.*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant