Skip to content

test: expand test coverage with edge cases, error paths, and shared conftest#61

Merged
dgenio merged 10 commits intomainfrom
issue-6/expand-test-coverage
Mar 4, 2026
Merged

test: expand test coverage with edge cases, error paths, and shared conftest#61
dgenio merged 10 commits intomainfrom
issue-6/expand-test-coverage

Conversation

@dgenio
Copy link
Owner

@dgenio dgenio commented Mar 4, 2026

What changed

Closes #6 — expand test coverage for edge cases, error paths, and context accumulation.

New test cases in tests/test_flow_execution.py

  • TestSingleStepFlow — one-step flow with input_mapping (simplest chaining case)
  • TestContextAccumulation — verifies that outputs from all steps (not just the last) are merged into final_output, including the original initial_input keys
  • TestToolZeroDivisionErrorZeroDivisionError inside a tool fn is wrapped as FlowExecutionError
  • TestBoundaryValues — negative numbers, zero, and large negatives through the double→add→format chain

New test cases in tests/test_registry.py

  • test_empty_registry_returns_nonematch_flow_by_intent on an empty registry returns None
  • TestOverwritePreservesCountlen() stays the same after register_flow(..., overwrite=True)

Structural improvements

  • tests/conftest.py (new) — shared Pydantic schemas (NumberInput, ValueOutput, ValueInput, FormattedOutput), helper functions (_double_fn, _add_ten_fn, _format_fn), and pytest fixtures (double_tool, add_ten_tool, format_tool, linear_flow, executor) extracted from test_flow_execution.py
  • tests/__init__.py removed — allows pytest to auto-add the test directory to sys.path so test modules can import from conftest.py
  • pyproject.toml — added pytest-cov>=4.0 to [project.optional-dependencies] dev

Note on issue scope

The issue listed test_empty_flow_succeeds — this test already existed in TestEmptyFlow so no duplicate was added.

Why

Missing coverage for edge cases (single-step, boundary values, context accumulation) and specific exception types (ZeroDivisionError) reduced confidence for the v0.1.0 release. Shared fixtures reduce duplication across test files.

How verified

pytest tests/ -v --cov=chainweaver --cov-report=term-missing  → 46 passed, 0 failed
ruff check chainweaver/ tests/ examples/                       → All checks passed
ruff format --check chainweaver/ tests/ examples/              → 12 files already formatted

Coverage: 99% (213 statements, 3 missed)

Module Cover Missing
__init__.py 100%
exceptions.py 100%
executor.py 99% L204
flow.py 100%
log_utils.py 100%
registry.py 96% L100
tools.py 94% L88

Tradeoffs / risks

  • Removing tests/__init__.py changes how pytest discovers tests (rootdir-based instead of package-based). This is the standard pytest recommendation and has no practical impact for this project.
  • No existing tests were modified beyond import deduplication (schemas/fixtures moved to conftest).

dgenio added 5 commits March 3, 2026 23:57
Move duplicated Pydantic schemas (NumberInput, ValueOutput, ValueInput,
FormattedOutput), helper functions (_double_fn, _add_ten_fn, _format_fn),
and pytest fixtures (double_tool, add_ten_tool, format_tool, linear_flow,
executor) from test_flow_execution.py into tests/conftest.py.

Remove tests/__init__.py so pytest auto-adds the test directory to
sys.path, enabling direct imports from conftest.

Part of #6.
Remove the empty tests/__init__.py so that pytest adds the test directory
to sys.path, allowing test modules to import from conftest.py directly.
…tion

- Replace inline schemas/fixtures with imports from conftest.py.
- Add TestSingleStepFlow: one-step flow with input_mapping.
- Add TestContextAccumulation: verify all step outputs in final_output.
- Add TestToolZeroDivisionError: ZeroDivisionError wrapped as FlowExecutionError.
- Add TestBoundaryValues: negative numbers, zero, and large negatives.

Closes #6 (test_flow_execution.py portion).
- Add test_empty_registry_returns_none to TestMatchFlowByIntent.
- Add TestOverwritePreservesCount: verify len() stays the same after overwrite.

Closes #6 (test_registry.py portion).
Add pytest-cov>=4.0 to [project.optional-dependencies] dev for coverage
reporting during local development.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands test coverage for the chainweaver package by adding new test cases for edge cases and error paths, and refactors shared test infrastructure into a central conftest.py.

Changes:

  • New test cases in test_flow_execution.py for single-step flows, context accumulation, ZeroDivisionError wrapping, and boundary values (negative numbers, zero, large negatives)
  • New test cases in test_registry.py for empty-registry intent matching and overwrite-preserves-count behavior
  • Shared Pydantic schemas, helper functions, and pytest fixtures extracted from test_flow_execution.py into a new tests/conftest.py; tests/__init__.py removed; pytest-cov>=4.0 added to dev dependencies

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/test_flow_execution.py Removes in-file fixtures/schemas (moved to conftest); adds TestSingleStepFlow, TestContextAccumulation, TestToolZeroDivisionError, and TestBoundaryValues
tests/test_registry.py Adds test_empty_registry_returns_none to TestMatchFlowByIntent and a new TestOverwritePreservesCount class
tests/conftest.py New file with shared Pydantic schemas, tool functions, and pytest fixtures for all test files
tests/__init__.py Removed to enable rootdir-based pytest discovery (allows from conftest import in test files)
pyproject.toml Adds pytest-cov>=4.0 to dev optional dependencies

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@dgenio dgenio merged commit 5eca9ba into main Mar 4, 2026
4 checks passed
@dgenio dgenio deleted the issue-6/expand-test-coverage branch March 4, 2026 06:26
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.

Expand test coverage: edge cases, error paths, and context accumulation

2 participants