Skip to content

Commit 8e326cf

Browse files
committed
test(cleanup): port storage-cleanup ownership tests and drop stale mock keys
1 parent 81d5f82 commit 8e326cf

5 files changed

Lines changed: 68 additions & 4 deletions

File tree

‎apps/sim/lib/knowledge/documents/storage-cleanup.test.ts‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,26 @@ const payload = {
4141
workspaceId: binding.workspaceId,
4242
organizationId: null,
4343
}
44+
const SOURCE_WORKSPACE_ID = 'workspace-1'
45+
const SOURCE_KEY = `workspace/${SOURCE_WORKSPACE_ID}/source.pdf`
46+
const SOURCE_URL = `/api/files/serve/${encodeURIComponent(SOURCE_KEY)}?context=workspace`
47+
const SOURCE_UPDATED_AT = new Date('2026-08-05T12:00:00.000Z')
48+
const SOURCE_BINDING = {
49+
id: 'source-file-1',
50+
key: SOURCE_KEY,
51+
userId: 'source-user',
52+
workspaceId: SOURCE_WORKSPACE_ID,
53+
context: 'workspace',
54+
originalName: 'source.pdf',
55+
displayName: 'source.pdf',
56+
contentType: 'application/pdf',
57+
size: 512,
58+
folderId: null,
59+
uploadedAt: SOURCE_UPDATED_AT,
60+
contentUpdatedAt: SOURCE_UPDATED_AT,
61+
deletedAt: null,
62+
secretProvenanceVersion: 1,
63+
}
4464
function context(): OutboxEventContext {
4565
return {
4666
eventId: 'cleanup-1',
@@ -179,4 +199,51 @@ describe('durable knowledge storage cleanup', () => {
179199
expect(dbChainMockFns.transaction).not.toHaveBeenCalled()
180200
expect(mockDeleteFile).not.toHaveBeenCalled()
181201
})
202+
it('never deletes a referenced workspace source as knowledge-base storage', async () => {
203+
await enqueueKnowledgeStorageCleanup(
204+
db,
205+
[{ id: 'document-1', fileUrl: SOURCE_URL, workspaceId: SOURCE_WORKSPACE_ID }],
206+
'request-1'
207+
)
208+
209+
expect(mockGetBindings).not.toHaveBeenCalled()
210+
expect(mockDeleteFile).not.toHaveBeenCalled()
211+
expect(mockDeleteMetadata).not.toHaveBeenCalled()
212+
})
213+
214+
it.each(['org-1', 'org-2', null])(
215+
'only queues an organization cache for its exact owner: %s',
216+
async (organizationId) => {
217+
const storageKey = 'kb/org-source.pdf'
218+
mockGetBindings.mockResolvedValue([
219+
{
220+
...SOURCE_BINDING,
221+
key: storageKey,
222+
context: 'knowledge-base',
223+
workspaceId: null,
224+
organizationId: 'org-1',
225+
},
226+
])
227+
const cleanup = enqueueKnowledgeStorageCleanup(
228+
db,
229+
[
230+
{
231+
id: 'org-doc',
232+
fileUrl: `/api/files/serve/${encodeURIComponent(storageKey)}`,
233+
workspaceId: null,
234+
organizationId,
235+
},
236+
],
237+
'request-1'
238+
)
239+
if (organizationId === 'org-1') {
240+
await cleanup
241+
expect(dbChainMockFns.values).toHaveBeenCalledOnce()
242+
} else {
243+
await expect(cleanup).rejects.toThrow()
244+
expect(dbChainMockFns.values).not.toHaveBeenCalled()
245+
}
246+
expect(mockDeleteFile).not.toHaveBeenCalled()
247+
}
248+
)
182249
})

‎apps/sim/lib/logs/log-views.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, it } from 'vitest'
2+
import { toOverview } from '@/lib/logs/log-views'
23
import type { TraceSpan } from '@/lib/logs/types'
3-
import { toOverview } from './log-views'
44

55
const ref = (preview: unknown) => ({ __sim: 'ref', preview, size: 100 })
66

‎apps/sim/lib/table/bulk-update-concurrency.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ vi.mock('@/lib/table/sql', () => ({
2929
buildFilterClause: vi.fn(() => sql`true`),
3030
buildPredicateClause: vi.fn(() => sql`true`),
3131
buildSortClause: vi.fn(() => sql`true`),
32-
escapeLikePattern: vi.fn((value: string) => value),
3332
uniqueValuePredicate: vi.fn(() => sql`true`),
3433
}))
3534

‎apps/sim/lib/table/find-row-matches.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import type { ColumnDefinition, TableDefinition } from '@/lib/table/types'
1414
vi.mock('@/lib/table/sql', () => ({
1515
buildFilterClause: vi.fn(() => sql`true`),
1616
buildSortClause: vi.fn(() => sql`true`),
17-
escapeLikePattern: vi.fn((s: string) => s),
1817
}))
1918

2019
vi.mock('@/lib/table/trigger', () => tableTriggerMock)

‎apps/sim/lib/table/rows/bulk-update-patch-validation.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ vi.mock('@/lib/table/sql', () => ({
3131
buildFilterClause: vi.fn(() => sql`true`),
3232
buildPredicateClause: vi.fn(() => sql`true`),
3333
buildSortClause: vi.fn(() => sql`true`),
34-
escapeLikePattern: vi.fn((value: string) => value),
3534
uniqueValuePredicate: vi.fn(() => sql`true`),
3635
}))
3736

0 commit comments

Comments
 (0)