From d187f8e818d6d621ed7d6bb71e65b78e894a24fd Mon Sep 17 00:00:00 2001 From: Cristian Magherusan-Stanciu Date: Thu, 28 May 2026 20:47:14 +0200 Subject: [PATCH 1/3] fix(purchases): cite #625 in cancelled-KPI regression tests summarizePurchaseHistory already excludes cancelled rows from dollar totals (landed in #737 against #736). Issue #625 describes the same bug -- this commit updates the two existing regression-test comments and assertion messages to cite both issues so the PR can formally close #625. Closes #625 --- internal/api/handler_history_test.go | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/internal/api/handler_history_test.go b/internal/api/handler_history_test.go index c77369afe..38be52837 100644 --- a/internal/api/handler_history_test.go +++ b/internal/api/handler_history_test.go @@ -1694,7 +1694,7 @@ func TestHandler_getHistory_CompletedExecutionNotDuplicated(t *testing.T) { } // TestSummarizePurchaseHistory_CancelledExcludedFromKPIs is the regression -// test for issue #736. Canceling a pending purchase must not add its upfront +// test for issues #625 and #736. Canceling a pending purchase must not add its upfront // cost or savings to the KPI totals. Specifically: // - TotalUpfront, TotalMonthlySavings, TotalAnnualSavings must reflect only // the approved/completed rows. @@ -1721,17 +1721,17 @@ func TestSummarizePurchaseHistory_CancelledExcludedFromKPIs(t *testing.T) { assert.Equal(t, 1, summary.TotalPending) assert.InDelta(t, 350.0, summary.TotalUpfront, 0.001, - "canceled upfront cost must not be included in TotalUpfront (issue #736)") + "canceled upfront cost must not be included in TotalUpfront (issues #625, #736)") assert.InDelta(t, 35.0, summary.TotalMonthlySavings, 0.001, - "canceled savings must not be included in TotalMonthlySavings (issue #736)") + "canceled savings must not be included in TotalMonthlySavings (issues #625, #736)") assert.InDelta(t, 420.0, summary.TotalAnnualSavings, 0.001, - "TotalAnnualSavings = TotalMonthlySavings * 12 and must exclude canceled (issue #736)") + "TotalAnnualSavings = TotalMonthlySavings * 12 and must exclude canceled (issues #625, #736)") } // TestSummarizePurchaseHistory_CancelPendingDoesNotChangeKPIs mirrors the -// QA reproduction scenario from issue #736: start with N approved purchases, -// observe KPI totals, then add a canceled execution and assert the totals -// are unchanged. +// QA reproduction scenario from issues #625 and #736: start with N approved +// purchases, observe KPI totals, then add a canceled execution and assert the +// totals are unchanged. // TestHandler_getHistory_LimitParsing is the 01-M1 regression guard. // Prior to the fix, parseHistoryFilters used fmt.Sscanf to parse the limit // query param, which silently swallows non-integer input (callers get the @@ -1811,7 +1811,6 @@ func TestHandler_getHistory_LimitParsing(t *testing.T) { }) } } - func TestSummarizePurchaseHistory_CancelPendingDoesNotChangeKPIs(t *testing.T) { // Baseline: three approved (completed) rows. baseline := []config.PurchaseHistoryRecord{ //nolint:prealloc // composite literal with fixed elements; append below adds 1 more @@ -1830,11 +1829,11 @@ func TestSummarizePurchaseHistory_CancelPendingDoesNotChangeKPIs(t *testing.T) { after := summarizePurchaseHistory(withCancelled) assert.Equal(t, before.TotalUpfront, after.TotalUpfront, - "canceling a pending purchase must not change TotalUpfront (issue #736)") + "canceling a pending purchase must not change TotalUpfront (issues #625, #736)") assert.Equal(t, before.TotalMonthlySavings, after.TotalMonthlySavings, - "canceling a pending purchase must not change TotalMonthlySavings (issue #736)") + "canceling a pending purchase must not change TotalMonthlySavings (issues #625, #736)") assert.Equal(t, before.TotalAnnualSavings, after.TotalAnnualSavings, - "canceling a pending purchase must not change TotalAnnualSavings (issue #736)") + "canceling a pending purchase must not change TotalAnnualSavings (issues #625, #736)") assert.Equal(t, before.TotalCompleted, after.TotalCompleted, - "canceling a pending purchase must not change TotalCompleted (issue #736)") + "canceling a pending purchase must not change TotalCompleted (issues #625, #736)") } From 662e2bcc03b930a95df84182358ffbee698a5e65 Mon Sep 17 00:00:00 2001 From: Cristian Magherusan-Stanciu Date: Fri, 19 Jun 2026 23:09:30 +0200 Subject: [PATCH 2/3] test(purchases): fix misspell/prealloc/govet in handler_history_test - cancelled->canceled, Cancelling->Canceling, cancelling->canceling, synthesised->synthesized, honour->honor in comments/test messages; Status:"cancelled" DB enum values suppressed with //nolint:misspell - prealloc: preallocate baseline slice with cap 4 in TestSummarizePurchaseHistory_CancelPendingDoesNotChangeKPIs - govet fieldalignment: suppress anonymous test-table struct in TestHandler_getHistory_FilterValidation with //nolint:govet --- internal/api/handler_history_test.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/internal/api/handler_history_test.go b/internal/api/handler_history_test.go index 38be52837..ba7fe28e6 100644 --- a/internal/api/handler_history_test.go +++ b/internal/api/handler_history_test.go @@ -1710,8 +1710,8 @@ func TestSummarizePurchaseHistory_CancelledExcludedFromKPIs(t *testing.T) { {Status: "pending", UpfrontCost: 999.0, EstimatedSavings: 99.0}, // Two canceled rows — the regression case from issue #736. // Neither must appear in the dollar KPIs or TotalCompleted. - {Status: "canceled", UpfrontCost: 500.0, EstimatedSavings: 50.0}, - {Status: "canceled", UpfrontCost: 750.0, EstimatedSavings: 75.0}, + {Status: "cancelled", UpfrontCost: 500.0, EstimatedSavings: 50.0}, //nolint:misspell // DB schema value 'cancelled' -- see migration 000001_initial_schema.up.sql + {Status: "cancelled", UpfrontCost: 750.0, EstimatedSavings: 75.0}, //nolint:misspell // DB schema value 'cancelled' -- see migration 000001_initial_schema.up.sql } summary := summarizePurchaseHistory(purchases) @@ -1813,16 +1813,17 @@ func TestHandler_getHistory_LimitParsing(t *testing.T) { } func TestSummarizePurchaseHistory_CancelPendingDoesNotChangeKPIs(t *testing.T) { // Baseline: three approved (completed) rows. - baseline := []config.PurchaseHistoryRecord{ //nolint:prealloc // composite literal with fixed elements; append below adds 1 more - {Status: "completed", UpfrontCost: 100.0, EstimatedSavings: 10.0}, - {Status: "completed", UpfrontCost: 200.0, EstimatedSavings: 20.0}, - {Status: "completed", UpfrontCost: 300.0, EstimatedSavings: 30.0}, - } + baseline := make([]config.PurchaseHistoryRecord, 0, 4) + baseline = append(baseline, + config.PurchaseHistoryRecord{Status: "completed", UpfrontCost: 100.0, EstimatedSavings: 10.0}, + config.PurchaseHistoryRecord{Status: "completed", UpfrontCost: 200.0, EstimatedSavings: 20.0}, + config.PurchaseHistoryRecord{Status: "completed", UpfrontCost: 300.0, EstimatedSavings: 30.0}, + ) before := summarizePurchaseHistory(baseline) // After: same rows plus one canceled execution (the pending that got canceled). - withCancelled := append(baseline, config.PurchaseHistoryRecord{ //nolint:gocritic - Status: "canceled", + withCancelled := append(baseline, config.PurchaseHistoryRecord{ //nolint:gocritic,misspell + Status: "cancelled", //nolint:misspell // DB schema value 'cancelled' -- see migration 000001_initial_schema.up.sql UpfrontCost: 999.0, EstimatedSavings: 99.0, }) From 855a9bfc47ae942813b26c036065a3edf4ad02d7 Mon Sep 17 00:00:00 2001 From: Cristian Magherusan-Stanciu Date: Sat, 20 Jun 2026 13:19:10 +0200 Subject: [PATCH 3/3] fix(lint): fix govet/misspell nolints in handler_history_test - Remove nolint:govet by reordering test-case struct fields to optimal alignment (map+string+string+int = 40 bytes, down from 48). - Annotate three nolint:misspell directives on "cancelled" with the DB-schema-value exception note referencing migration 000001. - Drop redundant misspell suppress from the append line (nolint:gocritic retained for the appendAssign check added in an earlier pass). --- internal/api/handler_history_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/api/handler_history_test.go b/internal/api/handler_history_test.go index ba7fe28e6..31672159d 100644 --- a/internal/api/handler_history_test.go +++ b/internal/api/handler_history_test.go @@ -1822,7 +1822,7 @@ func TestSummarizePurchaseHistory_CancelPendingDoesNotChangeKPIs(t *testing.T) { before := summarizePurchaseHistory(baseline) // After: same rows plus one canceled execution (the pending that got canceled). - withCancelled := append(baseline, config.PurchaseHistoryRecord{ //nolint:gocritic,misspell + withCancelled := append(baseline, config.PurchaseHistoryRecord{ //nolint:gocritic Status: "cancelled", //nolint:misspell // DB schema value 'cancelled' -- see migration 000001_initial_schema.up.sql UpfrontCost: 999.0, EstimatedSavings: 99.0,