Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: didcomm message handler should attempt to pass message to other handlers #1064

Merged
merged 3 commits into from
Nov 10, 2022

Conversation

nickreynolds
Copy link
Contributor

What issue is this PR fixing

fixes #944

What is being changed

DIDComm Message Handler should attempt to forward message to downstream handlers (but should not fail if none handle message)

Quality

Check all that apply:

  • I want these changes to be integrated
  • I successfully ran yarn, yarn build, yarn test, yarn test:browser locally.
  • I allow my PR to be updated by the reviewers (to speed up the review process).
  • I added unit tests.
  • I added integration tests.
  • I did not add automated tests because _________, and I am aware that a PR without tests will likely get rejected.

Copy link
Member

@mirceanis mirceanis left a comment

Choose a reason for hiding this comment

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

This is a very nice fix that also doesn't introduce a breaking change, which I would have expected for #944. Great work!

The test cases can be improved a little bit; please see my comments.

// shouldn't throw an error if other handlers fail
let superHandled
try {
superHandled = await super.handle(message, context)
Copy link
Member

Choose a reason for hiding this comment

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

What I'm seeing here is that a message is parsed by this handler and it could be returned directly (which would also emit the validatedMessage event) but it can also be forwarded to other handlers in case they might be able to extract more value from it.
I like this idea a lot.
I wonder how we can incorporate it as the default way to handle all messages at some point.

Maybe message handlers can flag things as "good enough" so that the top-level handler knows not to throw an error at the end of the pipeline.

@@ -59,6 +59,7 @@ export default (testContext: {
const allMessages = await agent.dataStoreORMGetMessages()
const count = await agent.dataStoreORMGetMessagesCount()
expect(allMessages.length).toEqual(count)
expect(count).toEqual(1)
Copy link
Member

Choose a reason for hiding this comment

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

This creates some coupling between the tests and the order in which they are executed.
Perhaps the expectation should be that the count is not zero, if another test in this suite produces a message, but not give it a specific value in case other suites create messages of their own.

recipientDidUrl: sender.did,
})
const messages = await agent.dataStoreORMGetMessagesCount({})
expect(messages).toEqual(2)
Copy link
Member

Choose a reason for hiding this comment

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

testing message flow by count is prone to some weird test failures when multiple tests produce messages.

It would be better to use message IDs, or something else to check if they get processed correctly.

@nickreynolds nickreynolds merged commit 5e18427 into next Nov 10, 2022
@nickreynolds nickreynolds deleted the nickreynolds/test-didcomm-handler branch November 10, 2022 16:33
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.

DIDComm message handler breaks out of message handler flow
2 participants