Skip to content

Commit c1e2f21

Browse files
committed
fix
1 parent 027229d commit c1e2f21

5 files changed

Lines changed: 147 additions & 136 deletions

File tree

apps/sim/lib/execution/sandbox/bundles/docx.cjs

Lines changed: 21 additions & 21 deletions
Large diffs are not rendered by default.

apps/sim/lib/execution/sandbox/bundles/pdf-lib.cjs

Lines changed: 21 additions & 21 deletions
Large diffs are not rendered by default.

apps/sim/lib/execution/sandbox/bundles/pptxgenjs.cjs

Lines changed: 63 additions & 62 deletions
Large diffs are not rendered by default.

apps/sim/lib/knowledge/documents/service.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,18 @@ export class KnowledgeBaseFileOwnershipError extends Error {
132132
* referenced bindings are resolved in one query (no N+1 inside the `FOR UPDATE`
133133
* window). Single-document callers pass a one-element array.
134134
*/
135+
function isKnowledgeBaseOwnedStorageKey(key: string): boolean {
136+
return key.startsWith('kb/') || key.startsWith('knowledge-base/')
137+
}
138+
135139
function getKnowledgeBaseStorageKeys(fileUrls: readonly string[]): string[] {
136140
return [
137141
...new Set(
138142
fileUrls
139143
.map((url) => getKnowledgeBaseStorageKey(url))
140-
.filter((key): key is string => typeof key === 'string' && key.startsWith('kb/'))
144+
.filter(
145+
(key): key is string => typeof key === 'string' && isKnowledgeBaseOwnedStorageKey(key)
146+
)
141147
),
142148
]
143149
}

apps/sim/lib/knowledge/documents/storage-billing.test.ts

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -167,39 +167,43 @@ describe('knowledge document storage attribution', () => {
167167
)
168168
})
169169

170-
it('uses server-known file metadata size for quota, ledger, and document row', async () => {
171-
const fileUrl = '/api/files/serve/kb%2Fverified-file?context=knowledge-base'
172-
mockGetFileMetadataByKeys.mockResolvedValue([
173-
{
174-
key: 'kb/verified-file',
175-
workspaceId: 'workspace-1',
176-
userId: 'external-collaborator',
177-
size: 8,
178-
},
179-
])
180-
mockIncrementStorageUsageForBillingContextInTx.mockResolvedValue(13)
170+
it.each(['kb', 'knowledge-base'])(
171+
'uses server-known %s file metadata size for quota, ledger, and document row',
172+
async (keyPrefix) => {
173+
const storageKey = `${keyPrefix}/verified-file`
174+
const fileUrl = `/api/files/serve/${encodeURIComponent(storageKey)}?context=knowledge-base`
175+
mockGetFileMetadataByKeys.mockResolvedValue([
176+
{
177+
key: storageKey,
178+
workspaceId: 'workspace-1',
179+
userId: 'external-collaborator',
180+
size: 8,
181+
},
182+
])
183+
mockIncrementStorageUsageForBillingContextInTx.mockResolvedValue(13)
181184

182-
const result = await createSingleDocument(
183-
{
184-
filename: 'note.txt',
185-
fileUrl,
186-
fileSize: 5,
187-
mimeType: 'text/plain',
188-
},
189-
'knowledge-base-1',
190-
'request-1',
191-
'external-collaborator'
192-
)
185+
const result = await createSingleDocument(
186+
{
187+
filename: 'note.txt',
188+
fileUrl,
189+
fileSize: 5,
190+
mimeType: 'text/plain',
191+
},
192+
'knowledge-base-1',
193+
'request-1',
194+
'external-collaborator'
195+
)
193196

194-
expect(mockCheckStorageQuotaForBillingContext).toHaveBeenCalledWith(STORAGE_CONTEXT, 8)
195-
expect(mockIncrementStorageUsageForBillingContextInTx).toHaveBeenCalledWith(
196-
expect.anything(),
197-
STORAGE_CONTEXT,
198-
8
199-
)
200-
expect(result.fileSize).toBe(8)
201-
expect(dbChainMockFns.values).toHaveBeenCalledWith(expect.objectContaining({ fileSize: 8 }))
202-
})
197+
expect(mockCheckStorageQuotaForBillingContext).toHaveBeenCalledWith(STORAGE_CONTEXT, 8)
198+
expect(mockIncrementStorageUsageForBillingContextInTx).toHaveBeenCalledWith(
199+
expect.anything(),
200+
STORAGE_CONTEXT,
201+
8
202+
)
203+
expect(result.fileSize).toBe(8)
204+
expect(dbChainMockFns.values).toHaveBeenCalledWith(expect.objectContaining({ fileSize: 8 }))
205+
}
206+
)
203207

204208
it('decrements only exact bytes for document rows actually deleted', async () => {
205209
dbChainMockFns.where.mockResolvedValueOnce([

0 commit comments

Comments
 (0)