Skip to content

Commit 47f9553

Browse files
committed
test(knowledge): pin the backfill probe's ordered, capped shape
1 parent d023e0e commit 47f9553

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

‎apps/sim/lib/knowledge/search/projection-source-acl-backfill.test.ts‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,21 @@ describe('runProjectionSourceAclBackfill', () => {
7878

7979
it('analyzes and warms the projections on the same connection once both are filled, before closing it', async () => {
8080
await runProjectionSourceAclBackfill({})
81-
/** A row whose document is gone is not the fill's to finish; the probe joins the document. */
82-
expect(
83-
mockUnsafe.mock.calls.some(([query]) =>
84-
String(query).includes('JOIN document d ON d.id = s.document_id WHERE s.acl IS NULL')
81+
/**
82+
* A row whose document is gone is not the fill's to finish; the probe joins the document. It is
83+
* ordered and capped so only the unfilled-rows index can serve it: an `EXISTS` drops both and
84+
* leaves the planner a sequential scan of the projection.
85+
*/
86+
const probes = mockUnsafe.mock.calls
87+
.map(([query]) => String(query).replace(/\s+/g, ' '))
88+
.filter((query) => query.includes('AS unfilled'))
89+
expect(probes).toHaveLength(2)
90+
for (const probe of probes) {
91+
expect(probe).not.toContain('EXISTS')
92+
expect(probe).toContain(
93+
'JOIN document d ON d.id = s.document_id WHERE s.acl IS NULL ORDER BY s.id DESC LIMIT 1 ) IS NOT NULL AS unfilled'
8594
)
86-
).toBe(true)
95+
}
8796
expect(mockUnsafe.mock.calls.map(([query]) => query)).toEqual(
8897
expect.arrayContaining(['ANALYZE embedding_search', 'ANALYZE embedding_keyword_tin'])
8998
)

0 commit comments

Comments
 (0)