fix: always attach the function bot access token to the context if available#2513
fix: always attach the function bot access token to the context if available#2513
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2513 +/- ##
==========================================
- Coverage 92.97% 92.96% -0.01%
==========================================
Files 36 36
Lines 7441 7437 -4
Branches 652 649 -3
==========================================
- Hits 6918 6914 -4
Misses 518 518
Partials 5 5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
WilliamBergamin
left a comment
There was a problem hiding this comment.
This is an awesome catch 🥇 🚀
I agree the expected behavior should be to always set the context.functionBotAccessToken as the workflow token if it is found in a payload
We only want to set it to the token for the client if this.attachFunctionToken = true
|
@zimeg any chance we can add a unit tests to ensure this behavior is maintained in the future 🙏 |
Co-authored-by: Eden Zimbelman <[email protected]>
Co-authored-by: Eden Zimbelman <[email protected]>
Co-authored-by: Eden Zimbelman <[email protected]>
Co-authored-by: Eden Zimbelman <[email protected]>
Co-authored-by: Eden Zimbelman <[email protected]>
Co-authored-by: Eden Zimbelman <[email protected]>
Co-authored-by: Eden Zimbelman <[email protected]>
Co-authored-by: Eden Zimbelman <[email protected]>
Co-authored-by: Eden Zimbelman <[email protected]>
Co-authored-by: Eden Zimbelman <[email protected]>
… into zimeg-fix-context-function-token
|
@WilliamBergamin Thanks so much once again for the changes of #2424 - that unlocked this Before merging I agree it'd be best to add tests for this to avoid regressions. I hope to visit this soon! |
zimeg
left a comment
There was a problem hiding this comment.
@WilliamBergamin Thanks for bumping this! 🤖
I added a test to cover both the function and action listeners which brought one more question that I'm curious about before merging this, but I appreciate that this is surfaced from these tests!
| assert.strictEqual(context.functionExecutionId, functionExecutionId); | ||
| assert.strictEqual(context.functionBotAccessToken, functionBotAccessToken); |
There was a problem hiding this comment.
| assert.strictEqual(context.functionExecutionId, functionExecutionId); | |
| assert.strictEqual(context.functionBotAccessToken, functionBotAccessToken); | |
| assert.strictEqual(context.functionExecutionId, functionExecutionId); | |
| assert.strictEqual(context.functionBotAccessToken, functionBotAccessToken); | |
| assert.deepStrictEqual(context.functionInputs, inputs); |
📣 Here we are not testing that functionInputs are added to context but I'm not sure if this is something we want to change in this PR?
It's not clear to me if this should be included following L1624 from body.event.inputs for convenience:
Lines 1616 to 1635 in 76140ed
There was a problem hiding this comment.
If adding a test for functionInputs in the context is a small change then we can do it in this PR 💯 but if it is larger then maybe we do it in another PR
There was a problem hiding this comment.
Good thinking. I'm finding this change involves an update to another file which does seem outside the scope of this PR 🫡
WilliamBergamin
left a comment
There was a problem hiding this comment.
Nice 💯
Ship it as is or add a test for the inputs in the context 🚀
| assert.strictEqual(context.functionExecutionId, functionExecutionId); | ||
| assert.strictEqual(context.functionBotAccessToken, functionBotAccessToken); |
There was a problem hiding this comment.
If adding a test for functionInputs in the context is a small change then we can do it in this PR 💯 but if it is larger then maybe we do it in another PR
zimeg
left a comment
There was a problem hiding this comment.
@WilliamBergamin Thanks for both sharing thoughts on these changes and tests, and the review once again 🙏 ✨
I'll merge these changes and follow up with a few more focused PRs soon!
| assert.strictEqual(context.functionExecutionId, functionExecutionId); | ||
| assert.strictEqual(context.functionBotAccessToken, functionBotAccessToken); |
There was a problem hiding this comment.
Good thinking. I'm finding this change involves an update to another file which does seem outside the scope of this PR 🫡
Summary
This PR adds to the refactors of #2424 to always attach the function bot access token to the context if it's available.
Changes of the linked PR now use a shared
selectTokenfunction that no longer relies on this value incontextto determine whichtokento use - either workflow, bot, or user - and now use theattachFunctionTokenargument:bolt-js/src/App.ts
Lines 1580 to 1591 in d61f2cd
Preview
Before changes we had implicit use of this value to decide which token to use in the
app.functionlistener:bolt-js/src/App.ts
Lines 973 to 978 in 657416f
bolt-js/src/App.ts
Lines 1102 to 1105 in 657416f
bolt-js/src/CustomFunction.ts
Lines 185 to 188 in 657416f
Notes
Including this in
contextgives a choice of using this token in certain circumstances, even ifattachFunctionTokenis false! 🤖 ✨Requirements