From fa765563e8aebde3f2b0a4995c74cfe8b52976a9 Mon Sep 17 00:00:00 2001 From: Cristian Magherusan-Stanciu Date: Fri, 22 May 2026 12:25:26 +0200 Subject: [PATCH] test(purchase): stub late-completion mock so RecoverStrandedApprovals test does not panic When TransitionExecutionStatus returns an error, RecoverStrandedApprovals calls GetExecutionByID to distinguish a race (the row already left "approved") from a real store failure. The test TestManager_RecoverStrandedApprovals_LateCompletionNotClobbered had no expectation for GetExecutionByID, so testify panicked on the unstubbed call (mocks_test.go:277). Add a stub returning Status="completed" so the manager correctly skips the execution and the assertion (recovered==0) still genuinely proves that a row which completed between the stale SELECT and the recovery UPDATE is not clobbered by the sweep. Closes #657 --- internal/purchase/manager_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/purchase/manager_test.go b/internal/purchase/manager_test.go index 77640c0fb..35977fb48 100644 --- a/internal/purchase/manager_test.go +++ b/internal/purchase/manager_test.go @@ -414,6 +414,12 @@ func TestManager_RecoverStrandedApprovals_LateCompletionNotClobbered(t *testing. Return([]config.PurchaseExecution{stranded}, nil) mockStore.On("TransitionExecutionStatus", ctx, "exec-raced", []string{"approved"}, "failed"). Return(nil, errors.New("execution exec-raced cannot transition from \"completed\" to \"failed\"")) + // When TransitionExecutionStatus fails the manager calls GetExecutionByID to + // distinguish a race (row already left "approved") from a real store error. + // Returning a "completed" row causes RecoverStrandedApprovals to skip the + // execution, which is the behaviour this test asserts. + mockStore.On("GetExecutionByID", ctx, "exec-raced"). + Return(&config.PurchaseExecution{ExecutionID: "exec-raced", Status: "completed"}, nil) manager := &Manager{config: mockStore, dashboardURL: "https://dashboard.example.com"}