Repository navigation
fix: wrap async mock factory errors in MockFactoryError and separate arity check (#79) - #88
Merged
Conversation
…ity check - In wrapper.py, await async mock factory coroutines during resolution and wrap exceptions in MockFactoryError so async factories follow the same handling path as sync factories. - In mock_registry.py and validation.py, determine mock factory arity using sig.bind() before calling the factory function to avoid catching factory-internal TypeErrors as arity mismatches. - Add unit tests for 2-arg factory TypeError reporting and an async twin of TestMockFactoryErrors. Fixes intuit#79
Fire162
requested review from
Bbenchaya,
ChiefArchitect and
sboorlagadda
as code owners
October 2, 2026 18:12
This branch was successfully deployed
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.
Summary
Fixes two issues with mock factory resolution identified in #79:
wrapper.py, coroutines returned by async mock factories were awaited inside the mock execution block. If the async factory raised an exception during resolution, strict mode raised raw exceptions instead ofMockFactoryError, and lenient mode did not format the failure message throughMockFactoryError. Awaiting the coroutine is now handled during resolution, wrapping exceptions withraise MockFactoryError(tool_name, e) from e.MockToolsRegistry.resolve()andvalidate_mock_signature()previously calledmock_fn(scenario_metadata, config)inside the sametry/except TypeErrorused to test 2-argument signature compatibility withsig.bind({}, {}). If a 2-argument factory raised aTypeErrorfrom its own body, it triggered a fallback to 1-argument invocation, causing a misleading arity error to mask the real exception. The arity determination viasig.bind()is now performed before callingmock_fn.Testing
test_two_arg_factory_type_error_cause_preservedintests/test_mocking.py.test_two_arg_factory_type_error_message_preservedintests/test_validation.py.test_async_factory_error_reraises_in_strict_modeintests/test_wrapper.py.TestAsyncMockFactoryErrorstest suite intests/test_wrapper.py.uv run pytest), e2e tests (uv run pytest tests-e2e/), linter (uv run ruff check .), formatter check (uv run ruff format --check .), and type checker (uv run mypy src/). All passed.Fixes #79