From 08cfc55d528cc3a898b075947127f115469a13e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Deluan=20Quint=C3=A3o?= Date: Wed, 1 Jul 2026 13:58:33 -0400 Subject: [PATCH] test(db): fix flaky applyLibraryFilter specs on shared DB (#5697) The 'sees all libraries' specs hard-coded the user's libraries as {1, 2} and assumed the shared test DB held exactly two libraries. applyLibraryFilter only skips the filter when granted count == total library count, so when another spec left an extra library behind (Ginkgo randomizes spec order), the count was 3, the filter was applied, and the SQL assertion failed. This surfaced on the Windows CI run but reproduces on any platform. Grant the user exactly the library IDs that actually exist in the DB at runtime instead of hard-coding them. --- persistence/sql_base_repository_test.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/persistence/sql_base_repository_test.go b/persistence/sql_base_repository_test.go index 2cd6ab8a3..9c6c6007f 100644 --- a/persistence/sql_base_repository_test.go +++ b/persistence/sql_base_repository_test.go @@ -296,9 +296,18 @@ var _ = Describe("sqlRepository", func() { Context("Regular User who can see all libraries", func() { BeforeEach(func() { - // Granted every library in the DB, so the filter would exclude nothing. + // Grant every library that currently exists in the (shared) DB, so the filter + // would exclude nothing. Querying the real IDs keeps this correct even if other + // specs left extra libraries behind, which happens under Ginkgo's randomized order. + var ids []int + err := r.db.NewQuery("SELECT id FROM library ORDER BY id").Column(&ids) + Expect(err).ToNot(HaveOccurred()) + libs := make(model.Libraries, 0, len(ids)) + for _, id := range ids { + libs = append(libs, model.Library{ID: id}) + } r.ctx = request.WithUser(context.Background(), model.User{ - ID: "alllibs", IsAdmin: false, Libraries: model.Libraries{{ID: 1}, {ID: 2}}, + ID: "alllibs", IsAdmin: false, Libraries: libs, }) })