From 8331ae045232b064b5aa1a0282b3dd86d8504a20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Ign=C3=A1cio=20Fontoura=20Solla?= Date: Sun, 2 Aug 2026 02:37:01 -0300 Subject: [PATCH] fix(int): scope access-memo leadership find to fixture ids Unscoped depth-1 finds could pick up other suites' leaderships with a campaignUser relation and inflate the SQL count without breaking the memo. --- tests/int/campaignAccessRequestMemo.int.spec.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/int/campaignAccessRequestMemo.int.spec.ts b/tests/int/campaignAccessRequestMemo.int.spec.ts index 4d4c867b..13ff18e3 100644 --- a/tests/int/campaignAccessRequestMemo.int.spec.ts +++ b/tests/int/campaignAccessRequestMemo.int.spec.ts @@ -68,13 +68,15 @@ describe('access-control per-request memo', () => { const coordinator = await fixtures.createCampaignUser('coordinator') const municipality = await fixtures.getMunicipality() + const leadershipIds: number[] = [] for (let index = 0; index < 3; index += 1) { const contact = await fixtures.createContact() - await fixtures.createLeadership({ + const leadership = await fixtures.createLeadership({ contact: contact.id, municipalities: [municipality.id], supportStatus: 'engajado', }) + leadershipIds.push(leadership.id) } const { result, count } = await countStatements('from "campaign_user"', () => @@ -84,12 +86,16 @@ describe('access-control per-request memo', () => { // field-level access checks across every populated relation. depth: 1, limit: 25, + // Scope to this test's rows — an unscoped find can pick up other suites' + // leaderships with `user` set and inflate the campaign_user SQL count via + // populate (not via the actor memo). + where: { id: { in: leadershipIds } }, user: coordinator, overrideAccess: false, }), ) - expect(result.docs.length).toBeGreaterThan(0) + expect(result.docs).toHaveLength(3) // One read for the whole operation. Before the fix this was in the hundreds // and grew with rows × populated fields. expect(count).toBe(1)