Skip to content

chore: add support for contextcheck#5565

Open
remyleone wants to merge 2 commits into
mainfrom
contextcheck
Open

chore: add support for contextcheck#5565
remyleone wants to merge 2 commits into
mainfrom
contextcheck

Conversation

@remyleone
Copy link
Copy Markdown
Member

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Relates OR Closes #0000

Release note for CHANGELOG:


@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 12, 2026

❌ 2 Tests Failed:

Tests completed Failed Passed Skipped
2394 2 2392 17
View the top 2 failed test(s) by shortest run time
::TestMain
Stack Traces | 0s run time
panic: test timed out after 10m0s
	running tests:
		TestCleanupOnContext (10m0s)

goroutine 50 [running]:
testing.(*M).startAlarm.func1()
	.../hostedtoolcache/go/1.26.3.../src/testing/testing.go:2802 +0x354
created by time.goFunc
	.../hostedtoolcache/go/1.26.3.../src/time/sleep.go:215 +0x2d

goroutine 1 [chan receive]:
testing.(*T).Run(0x8dccbce1688, {0xe8230f?, 0x0?}, 0xec4e18)
	.../hostedtoolcache/go/1.26.3.../src/testing/testing.go:2109 +0x4e5
testing.runTests.func1(0x8dccbce1688)
	.../hostedtoolcache/go/1.26.3.../src/testing/testing.go:2585 +0x3e
testing.tRunner(0x8dccbce1688, 0x8dccbedfc58)
	.../hostedtoolcache/go/1.26.3.../src/testing/testing.go:2036 +0xea
testing.runTests({0xe91549, 0x23}, {0xea13a1, 0x32}, 0x8dccbc0d1d0, {0x164b520, 0x4, 0x4}, {0xc27d2ec3ca2ed811, 0x8bb300328c, ...})
	.../hostedtoolcache/go/1.26.3.../src/testing/testing.go:2583 +0x505
testing.(*M).Run(0x8dccbef2be0)
	.../hostedtoolcache/go/1.26.3.../src/testing/testing.go:2443 +0x6ac
main.main()
	_testmain.go:64 +0x9b

goroutine 36 [chan send]:
github..../v2/internal/tasks.(*Logger).Write(...)
	.../internal/tasks/logger.go:66
github..../v2/internal/tasks.(*Logger).AddEntry.func3({0xed0320, 0x8dccbf3a4d0})
	.../internal/tasks/logger.go:140 +0x288
github..../v2/internal/tasks.(*Tasks).Execute(0x8dccbc79f00, {0xeda828, 0x8dccbceb5e0}, {0x0, 0x0})
	.../internal/tasks/tasks.go:160 +0x4c9
github..../v2/internal/tasks_test.TestCleanupOnContext(0x8dccbce1b08)
	.../internal/tasks/tasks_test.go:187 +0x1ee
testing.tRunner(0x8dccbce1b08, 0xec4e18)
	.../hostedtoolcache/go/1.26.3.../src/testing/testing.go:2036 +0xea
created by testing.(*T).Run in goroutine 1
	.../hostedtoolcache/go/1.26.3.../src/testing/testing.go:2101 +0x4c5

goroutine 18 [syscall]:
os/signal.signal_recv()
	.../hostedtoolcache/go/1.26.3.../src/runtime/sigqueue.go:152 +0x98
os/signal.loop()
	.../hostedtoolcache/go/1.26.3.../os/signal/signal_unix.go:23 +0x13
created by os/signal.Notify.func1.1 in goroutine 8
	.../hostedtoolcache/go/1.26.3.../os/signal/signal.go:152 +0x1f
FAIL	github..../v2/internal/tasks	600.092s
github.com/scaleway/scaleway-cli/v2/internal/tasks::TestCleanupOnContext
Stack Traces | 0s run time
=== RUN   TestCleanupOnContext
#0 Running workflow

#1 TaskFunc 1
#1 DONE 0.0s

#2 TaskFunc 2
#2 DONE 0.0s

#3 TaskFunc 3
coverage: 86.4% of statements

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@remyleone remyleone marked this pull request as ready for review May 25, 2026 12:14
Copilot AI review requested due to automatic review settings May 25, 2026 12:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR introduces golangci-lint’s contextcheck and updates several call sites to use inherited contexts instead of creating new background contexts, aligning context propagation across tasks, Cobra, and HTTP operations.

Changes:

  • Enable contextcheck in .golangci.yml and add an exclusion rule for Cobra-related signatures.
  • Propagate inherited context.Context in tasks logging, MCP server shutdown, Cobra usage/run hooks, and build version checks.
  • Refactor getLatestVersion to accept a context.Context and extract the HTTP client from it.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
internal/tasks/tasks.go Use the task’s cancelable context when creating the tasks logger.
internal/namespaces/mcp/server/streamable_http.go Attempt to inherit context for graceful shutdown timeout.
core/cobra_utils.go Remove unused context parameter and always source ctx from cobraCmd.Context().
core/cobra_usage_builder.go Pass command context into annotation building; extract helper.
core/cobra_builder.go Adjust usage builder callback signature and update cobraRun usage.
core/build_info.go Make version checks context-driven; derive timeout from passed context.
core/bootstrap.go Remove nil-context fallback handling.
.golangci.yml Enable contextcheck and add an exclusion rule targeting Cobra patterns.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 45 to 51
<-ctx.Done()

// Graceful shutdown with timeout
shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 10*time.Second)
shutdownCtx, shutdownCancel := context.WithTimeout(ctx, 10*time.Second)
defer shutdownCancel()

return server.Shutdown(shutdownCtx)
Comment thread core/bootstrap.go
@@ -199,9 +199,6 @@ func Bootstrap(ctx context.Context, config *BootstrapConfig) (exitCode int, resu
meta.OverrideExec = defaultOverrideExec
}

Comment thread .golangci.yml

# cobra API requires func(*cobra.Command) error signature; context extracted from command
- linters:
- contextcheck
Comment on lines +167 to +171
func executeWithCtx(
ctx context.Context,
cmd *cobra.Command,
annotationBuilder func(context.Context),
) {
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.

3 participants