From 19619b1cd29c6585c773e41d48da32683cc4a96f Mon Sep 17 00:00:00 2001 From: clawbot <35+clawbot@noreply.example.org> Date: Wed, 23 Sep 2026 03:04:31 +0200 Subject: [PATCH] Wait for webhook deployments in handlers tests instead of sleeping (closes #211) `TestHandleWebhookProcessesValidWebhook` waited for the background deployment with a 100 ms sleep, so its temp directory could be removed while the deployment was still writing its log there, and the test failed now and then. It now waits with the webhook service's `WaitForDeployments`, the fix already applied to the webhook service tests for https://git.eeqj.de/sneak/upaas/issues/198. The test context keeps the webhook service it already built. No other handlers test can start a deployment. No production code change. Model: opus-5-5 --- TODO.md | 4 ++++ internal/handlers/handlers_test.go | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/TODO.md b/TODO.md index bf456fe..5f47fa4 100644 --- a/TODO.md +++ b/TODO.md @@ -20,6 +20,10 @@ regress. # Completed Steps +- 2026-09-23: Fixed the flaky `t.TempDir` cleanup race in `internal/handlers` + (the one fixed in `internal/service/webhook` by #198): + `TestHandleWebhookProcessesValidWebhook` now waits with the webhook service's + `WaitForDeployments` instead of sleeping (#211). - 2026-09-22: Vendored the canonical prettier/format toolchain from the `sneak/prompts` scaffold: added `.prettierrc` (tabWidth 4, proseWrap always), pinned `package.json` + `yarn.lock` (prettier 3.8.1), taught diff --git a/internal/handlers/handlers_test.go b/internal/handlers/handlers_test.go index 68e116e..6aa2037 100644 --- a/internal/handlers/handlers_test.go +++ b/internal/handlers/handlers_test.go @@ -8,7 +8,6 @@ import ( "strconv" "strings" "testing" - "time" "github.com/go-chi/chi/v5" "github.com/stretchr/testify/assert" @@ -43,6 +42,7 @@ type testContext struct { authSvc *auth.Service appSvc *app.Service deploySvc *deploy.Service + webhookSvc *webhook.Service middleware *middleware.Middleware } @@ -188,6 +188,7 @@ func setupTestHandlers(t *testing.T) *testContext { authSvc: authSvc, appSvc: appSvc, deploySvc: deploySvc, + webhookSvc: webhookSvc, middleware: mw, } } @@ -1213,8 +1214,7 @@ func TestHandleWebhookProcessesValidWebhook(t *testing.T) { assert.Equal(t, http.StatusOK, recorder.Code) - // Allow async deployment goroutine to complete before test cleanup. - // The deployment will fail quickly (docker not connected) but we need - // to wait for it to finish to avoid temp directory cleanup race. - time.Sleep(100 * time.Millisecond) + // Wait for the async deployment goroutine to finish so its writes + // under the temp dir complete before test cleanup. + testCtx.webhookSvc.WaitForDeployments() }