Skip to content

Commit 8ca824b

Browse files
committed
test(cleanup): delete the source chat before checking its files' references
The reference-check test never seeded or deleted the chat whose files were being cleaned, so it could not tell a key kept by another chat from one kept by the purged chat itself. It now collects the files of a real source chat, deletes that row, and expects only the key a surviving same-scope fork still attaches to be kept.
1 parent b54e6a4 commit 8ca824b

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

‎apps/sim/lib/cleanup/chat-cleanup.integration.ts‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,22 +141,27 @@ describe('deletable chat files against PostgreSQL message rows', () => {
141141
})
142142

143143
it('keeps a key another chat of its scope still attaches, and deletes the rest', async () => {
144-
const shared = `copilot/${generateId()}/shared.png`
144+
const shared = `assistant/${organizationId}/${userId}/u1/shared.png`
145+
const own = `assistant/${organizationId}/${userId}/u2/own.png`
145146
const elsewhere = `copilot/${generateId()}/elsewhere.png`
146-
const own = `copilot/${generateId()}/own.png`
147+
const source = await seedChat(
148+
[{ role: 'user', content: 'look', fileAttachments: [attachment(shared), attachment(own)] }],
149+
[],
150+
organizationId
151+
)
147152
await seedChat(
148153
[{ role: 'user', content: 'fork', fileAttachments: [attachment(shared), 'x', { key: 7 }] }],
149154
[],
150155
organizationId
151156
)
152157
// Attached only by a chat outside the scope, which cannot be a fork of the deleted one.
153158
await seedChat([{ role: 'user', content: 'other', fileAttachments: [attachment(elsewhere)] }])
154-
const scope = { kind: 'organization', id: organizationId } as const
159+
const files = await collectChatFiles([source])
160+
await db.delete(copilotChats).where(eq(copilotChats.id, source))
155161

156162
const deletable = await deletableChatFiles([
157-
ref(shared, scope),
158-
ref(elsewhere, scope),
159-
ref(own, scope),
163+
...files,
164+
ref(elsewhere, { kind: 'organization', id: organizationId }),
160165
])
161166

162167
expect(deletable.map((file) => file.key).sort(compareStrings)).toEqual(

0 commit comments

Comments
 (0)