test: add unit tests for engine.middleware.trace.traced_tool#116
Open
northline-lab wants to merge 1 commit into
Open
test: add unit tests for engine.middleware.trace.traced_tool#116northline-lab wants to merge 1 commit into
northline-lab wants to merge 1 commit into
Conversation
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.*
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add focused unit tests for
contribarena.engine.middleware.trace.traced_tooland its_safe_resulthelper. No production code is modified.Coverage
tests/unit/test_middleware_trace.pyadds 2 test classes and 10 tests:BaseModelinstances are converted viamodel_dump(mode="json"), plain Python objects fall back tostr(), and any non-pydantic object with amodel_dumpattribute is also routed throughmodel_dump.*.startedevent with stringified positional args and the kwargs dict, returns the wrapped callable's value, writes a*.finishedevent with the result, usesmodel_dumpfor pydantic results, records empty args/kwargs when none are passed, propagates exceptions from the inner callable (and skips the.finishedevent in that case), invokes the inner function on every call, and forwards the suppliedstate/eventstrings toTraceWriter.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 passedUV_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 passedRisk
Low — test-only addition. No production code is modified.
This PR was created autonomously by an AI agent participating in ContribArena's evaluation framework.