Skip to content

refactor: remove context.Background() references from triggers command#47

Merged
mwbrooks merged 1 commit intomainfrom
mbrooks-context-background-trigger
Apr 17, 2025
Merged

refactor: remove context.Background() references from triggers command#47
mwbrooks merged 1 commit intomainfrom
mbrooks-context-background-trigger

Conversation

@mwbrooks
Copy link
Member

Summary

Context delivery, get it while it's hot! 💁🍕

This pull request updates the trigger command to no longer use context.Background(). Not too exciting, but I've separated this into a single PR because its changes span a few files

Requirements

@mwbrooks mwbrooks added code health M-T: Test improvements and anything that improves code health semver:patch Use on pull requests to describe the release version increment labels Apr 17, 2025
@mwbrooks mwbrooks added this to the Next Release milestone Apr 17, 2025
@mwbrooks mwbrooks self-assigned this Apr 17, 2025
@codecov
Copy link

codecov bot commented Apr 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 62.88%. Comparing base (b939841) to head (4d5346c).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #47      +/-   ##
==========================================
- Coverage   62.90%   62.88%   -0.02%     
==========================================
  Files         210      210              
  Lines       22149    22147       -2     
==========================================
- Hits        13932    13928       -4     
- Misses       7129     7132       +3     
+ Partials     1088     1087       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member Author

@mwbrooks mwbrooks left a comment

Choose a reason for hiding this comment

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

A few comments to help guide the reviewer 🥾

}

err = validateCreateCmdFlags(clients, &createFlags)
err = validateCreateCmdFlags(ctx, clients, &createFlags)
Copy link
Member Author

Choose a reason for hiding this comment

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

note: For the most part, this PR updates 2 functions to accept ctx context.Context. So, you'll see a lot of changes that just add ctx as an argument.

Comment on lines -174 to -175
func getFullyQualifiedTriggerFilePaths(clients *shared.ClientFactory, triggerPaths []string) ([]string, error) {
ctx := context.Background()
Copy link
Member Author

Choose a reason for hiding this comment

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

note: This is 1st key change, where we remove ctx := context.Background() and replace wit with a ctx context.Context function argument.

Comment on lines -293 to -294
func maybeSetTriggerDefFlag(clients *shared.ClientFactory, createFlags *createCmdFlags) error {
ctx := context.Background()
Copy link
Member Author

Choose a reason for hiding this comment

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

note: This is the 2nd key change, where we also replace ctx := context.Background() with the ctx context.Context function argument.

Copy link
Member

Choose a reason for hiding this comment

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

🗣️ This is a ramble, but I'm wondering if we want to explore using ctx to timeout certain prompts?

IIRC confusion has appeared when inputs aren't obvious, and a timeout with error might be clear that something was expected. No blocker for this PR though!

Copy link
Member Author

Choose a reason for hiding this comment

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

We can talk about it more, but it may be a fine line between knowing when someone is taking their time thinking vs unaware of the prompt and waiting.

@mwbrooks mwbrooks marked this pull request as ready for review April 17, 2025 22:47
@mwbrooks mwbrooks requested a review from a team as a code owner April 17, 2025 22:47
Copy link
Member

@zimeg zimeg left a comment

Choose a reason for hiding this comment

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

@mwbrooks LGTM and it's nice to find related changes in one set of changes.

All of the updates and even a line removed are solid. I did leave one comment unrelated to these chagnes that ctx has me excited to consider. These improvements I think are making changes like that even possible - cheers aplenty! 🎉


for name, tt := range tests {
t.Run(name, func(t *testing.T) {
ctx := slackcontext.MockContext(t.Context())
Copy link
Member

Choose a reason for hiding this comment

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

🔍 This is good.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm really enjoying the slackcontext.MockContext() function. It's been very handy to consistently sprinkle a mocked context into our tests.

Comment on lines -293 to -294
func maybeSetTriggerDefFlag(clients *shared.ClientFactory, createFlags *createCmdFlags) error {
ctx := context.Background()
Copy link
Member

Choose a reason for hiding this comment

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

🗣️ This is a ramble, but I'm wondering if we want to explore using ctx to timeout certain prompts?

IIRC confusion has appeared when inputs aren't obvious, and a timeout with error might be clear that something was expected. No blocker for this PR though!

@mwbrooks mwbrooks merged commit a1bcf9e into main Apr 17, 2025
6 checks passed
@mwbrooks mwbrooks deleted the mbrooks-context-background-trigger branch April 17, 2025 23:00
@mwbrooks
Copy link
Member Author

Thanks for the quick review @zimeg! I imagine these context PRs are getting a little stale to read through 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code health M-T: Test improvements and anything that improves code health semver:patch Use on pull requests to describe the release version increment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants