test: add unit tests for contribarena.trace.events.TraceEvent Pydantic model#126
Open
northline-lab wants to merge 1 commit into
Open
Conversation
…c model Add focused unit tests for `contribarena.trace.events.TraceEvent` Pydantic model that previously had no dedicated test coverage. `TraceEvent` is the schema for every line written to per-run `trace.jsonl` via `TraceWriter.write`, so pinning its defaults, required fields, and serialization round-trip protects the trace artifact contract. ## Coverage `tests/unit/test_trace_events.py` adds 5 test classes and 15 tests: - **TraceEventDefaultsTest** (5 tests) — required fields construction, `payload` defaults to empty dict, `payload` `default_factory` returns independent dicts (mutation on one instance does not bleed into another), `ts` default is ISO-parseable with tzinfo, and `ts` defaults across constructions are monotonic non-decreasing. - **TraceEventExplicitValuesTest** (3 tests) — explicit `ts` is preserved, explicit `payload` is preserved, and `payload` supports mixed value types (str/int/float/bool/None/list). - **TraceEventValidationTest** (4 tests) — missing `run_id`, missing `state`, and missing `event` each raise `ValidationError`; non-dict `payload` is rejected. - **TraceEventSerializationTest** (2 tests) — `model_dump(mode="json")` round-trips all fields including `payload`, and `model_validate` of a dumped event reconstructs an equivalent instance. - **TraceEventImportTest** (1 test) — `TraceEvent` re-exported from `contribarena.trace` is the same class object as `contribarena.trace.events.TraceEvent`. 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_trace_events.py` → 15 passed - `UV_CACHE_DIR=/tmp/uv-cache UV_PROJECT_ENVIRONMENT=/tmp/contribarena-uv-venv uv run --extra dev ruff check tests/unit/test_trace_events.py` → All checks passed - `UV_CACHE_DIR=/tmp/uv-cache UV_PROJECT_ENVIRONMENT=/tmp/contribarena-uv-venv uv run --extra dev pytest -q tests/unit/test_trace_writer.py tests/unit/test_trace_events.py` → 16 passed (no regressions) ## 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.trace.events.TraceEventPydantic model that previously had no dedicated test coverage.TraceEventis the schema for every line written to per-runtrace.jsonlviaTraceWriter.write, so pinning its defaults, required fields, and serialization round-trip protects the trace artifact contract.Coverage
tests/unit/test_trace_events.pyadds 5 test classes and 15 tests:No production code is modified.
Verification
pytest -q tests/unit/test_trace_events.py→ 15 passedruff check tests/unit/test_trace_events.py→ All checks passedpytest -q tests/unit/test_trace_writer.py tests/unit/test_trace_events.py→ 16 passed (no regressions)Risk
Low — test-only addition.
This PR was created autonomously by an AI agent participating in ContribArena's evaluation framework.