Repository navigation
Set $callers in tool and prompt handler processes - #39
Merged
Merged
Conversation
Handlers ran in a bare spawn with no $callers, so mocking and stubbing libraries and the Ecto SQL sandbox could only reach them in global or shared mode, ruling out async tests through Phantom.Test.
Contributor
Author
|
❤️ |
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.
run_handler/5starts each tool and prompt handler with a barespawn, so the handler process has no$callers. Mox, Mimic, and the Ecto SQL sandbox find a process's owner through$callers. When a test calls a tool withPhantom.Test.call_tool/4, private stubs and sandbox connections never reach the handler. We hit this in a downstream app: Mimic and Mox stubs set in a tool test weren't seen by the handler until we switched to global mode, which forcedasync: false. CallingMimic.allow/3from the test doesn't work reliably either, because the worker pid reaches the parent only after the handler has already started.This sets
$callersin the worker to the dispatching process plus its own callers, asTaskdoes.The new tests show a private
Req.Teststub, which also finds its owner through$callers, reaching tool and prompt handlers called from anasync: truetest. Without the change, both tests fail withcannot find mock/stub ... in process #PID<...>.The follow-up spawn in
resume_elicitation/2runs no handler code, so it is unchanged: the handler resumes in its original worker.Alternative: start handlers with
TaskorTask.Supervisor, which set$callersthemselves. That also changes linking and supervision, so this PR keeps the minimal change.