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.
This commit is contained in:
Deluan Quintão 2026-07-01 13:58:33 -04:00 committed by GitHub
parent 2d53360f89
commit 08cfc55d52
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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,
})
})