Skip to content

Commit 2e478d3

Browse files
committed
test(files): align provenance copy query order
1 parent 4a9549c commit 2e478d3

1 file changed

Lines changed: 76 additions & 72 deletions

File tree

apps/sim/lib/uploads/contexts/workspace/workspace-file-secret-provenance.test.ts

Lines changed: 76 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -191,24 +191,25 @@ describe('workspace file secret provenance', () => {
191191

192192
it('copies exact provenance only when it belongs to the source content version', async () => {
193193
const targetContentUpdatedAt = new Date('2026-08-04T00:00:01.000Z')
194-
queueTableRows(workspaceFiles, [
195-
{
196-
key: 'source-key',
197-
userId: 'user-1',
198-
workspaceId: 'workspace-1',
199-
fileContentUpdatedAt: CONTENT_UPDATED_AT,
200-
provenanceContentUpdatedAt: CONTENT_UPDATED_AT,
201-
status: 'exact',
202-
entries: [{ name: 'API_KEY', encryptedValue: 'encrypted' }],
203-
},
204-
])
205-
queueTableRows(workspaceFiles, [
206-
{
207-
userId: 'user-1',
208-
workspaceId: 'workspace-1',
209-
contentUpdatedAt: targetContentUpdatedAt,
210-
},
211-
])
194+
dbChainMockFns.limit
195+
.mockResolvedValueOnce([
196+
{
197+
userId: 'user-1',
198+
workspaceId: 'workspace-1',
199+
contentUpdatedAt: targetContentUpdatedAt,
200+
},
201+
])
202+
.mockResolvedValueOnce([
203+
{
204+
key: 'source-key',
205+
userId: 'user-1',
206+
workspaceId: 'workspace-1',
207+
fileContentUpdatedAt: CONTENT_UPDATED_AT,
208+
provenanceContentUpdatedAt: CONTENT_UPDATED_AT,
209+
status: 'exact',
210+
entries: [{ name: 'API_KEY', encryptedValue: 'encrypted' }],
211+
},
212+
])
212213

213214
await copyWorkspaceFileSecretProvenanceInTx(
214215
dbChainMock.db as unknown as DbOrTx,
@@ -233,24 +234,25 @@ describe('workspace file secret provenance', () => {
233234
it('marks a copied file unknown when source provenance is stale', async () => {
234235
const sourceContentUpdatedAt = new Date('2026-08-04T00:00:01.000Z')
235236
const targetContentUpdatedAt = new Date('2026-08-04T00:00:02.000Z')
236-
queueTableRows(workspaceFiles, [
237-
{
238-
key: 'source-key',
239-
userId: 'user-1',
240-
workspaceId: 'workspace-1',
241-
fileContentUpdatedAt: sourceContentUpdatedAt,
242-
provenanceContentUpdatedAt: CONTENT_UPDATED_AT,
243-
status: 'exact',
244-
entries: [{ name: 'API_KEY', encryptedValue: 'encrypted' }],
245-
},
246-
])
247-
queueTableRows(workspaceFiles, [
248-
{
249-
userId: 'user-1',
250-
workspaceId: 'workspace-1',
251-
contentUpdatedAt: targetContentUpdatedAt,
252-
},
253-
])
237+
dbChainMockFns.limit
238+
.mockResolvedValueOnce([
239+
{
240+
userId: 'user-1',
241+
workspaceId: 'workspace-1',
242+
contentUpdatedAt: targetContentUpdatedAt,
243+
},
244+
])
245+
.mockResolvedValueOnce([
246+
{
247+
key: 'source-key',
248+
userId: 'user-1',
249+
workspaceId: 'workspace-1',
250+
fileContentUpdatedAt: sourceContentUpdatedAt,
251+
provenanceContentUpdatedAt: CONTENT_UPDATED_AT,
252+
status: 'exact',
253+
entries: [{ name: 'API_KEY', encryptedValue: 'encrypted' }],
254+
},
255+
])
254256

255257
await copyWorkspaceFileSecretProvenanceInTx(
256258
dbChainMock.db as unknown as DbOrTx,
@@ -274,24 +276,25 @@ describe('workspace file secret provenance', () => {
274276

275277
it('does not remint named provenance into a copied file with a different owner scope', async () => {
276278
const targetContentUpdatedAt = new Date('2026-08-04T00:00:02.000Z')
277-
queueTableRows(workspaceFiles, [
278-
{
279-
key: 'source-key',
280-
userId: 'source-user',
281-
workspaceId: 'source-workspace',
282-
fileContentUpdatedAt: CONTENT_UPDATED_AT,
283-
provenanceContentUpdatedAt: CONTENT_UPDATED_AT,
284-
status: 'exact',
285-
entries: [{ name: 'API_KEY', encryptedValue: 'encrypted' }],
286-
},
287-
])
288-
queueTableRows(workspaceFiles, [
289-
{
290-
userId: 'target-user',
291-
workspaceId: 'target-workspace',
292-
contentUpdatedAt: targetContentUpdatedAt,
293-
},
294-
])
279+
dbChainMockFns.limit
280+
.mockResolvedValueOnce([
281+
{
282+
userId: 'target-user',
283+
workspaceId: 'target-workspace',
284+
contentUpdatedAt: targetContentUpdatedAt,
285+
},
286+
])
287+
.mockResolvedValueOnce([
288+
{
289+
key: 'source-key',
290+
userId: 'source-user',
291+
workspaceId: 'source-workspace',
292+
fileContentUpdatedAt: CONTENT_UPDATED_AT,
293+
provenanceContentUpdatedAt: CONTENT_UPDATED_AT,
294+
status: 'exact',
295+
entries: [{ name: 'API_KEY', encryptedValue: 'encrypted' }],
296+
},
297+
])
295298

296299
await copyWorkspaceFileSecretProvenanceInTx(
297300
dbChainMock.db as unknown as DbOrTx,
@@ -316,24 +319,25 @@ describe('workspace file secret provenance', () => {
316319
it('marks the copy unknown when the source changed after planning', async () => {
317320
const nextSourceContentUpdatedAt = new Date('2026-08-04T00:00:01.000Z')
318321
const targetContentUpdatedAt = new Date('2026-08-04T00:00:02.000Z')
319-
queueTableRows(workspaceFiles, [
320-
{
321-
key: 'new-source-key',
322-
userId: 'user-1',
323-
workspaceId: 'workspace-1',
324-
fileContentUpdatedAt: nextSourceContentUpdatedAt,
325-
provenanceContentUpdatedAt: nextSourceContentUpdatedAt,
326-
status: 'exact',
327-
entries: [{ name: 'API_KEY', encryptedValue: 'new-encrypted-value' }],
328-
},
329-
])
330-
queueTableRows(workspaceFiles, [
331-
{
332-
userId: 'user-1',
333-
workspaceId: 'workspace-1',
334-
contentUpdatedAt: targetContentUpdatedAt,
335-
},
336-
])
322+
dbChainMockFns.limit
323+
.mockResolvedValueOnce([
324+
{
325+
userId: 'user-1',
326+
workspaceId: 'workspace-1',
327+
contentUpdatedAt: targetContentUpdatedAt,
328+
},
329+
])
330+
.mockResolvedValueOnce([
331+
{
332+
key: 'new-source-key',
333+
userId: 'user-1',
334+
workspaceId: 'workspace-1',
335+
fileContentUpdatedAt: nextSourceContentUpdatedAt,
336+
provenanceContentUpdatedAt: nextSourceContentUpdatedAt,
337+
status: 'exact',
338+
entries: [{ name: 'API_KEY', encryptedValue: 'new-encrypted-value' }],
339+
},
340+
])
337341

338342
await copyWorkspaceFileSecretProvenanceInTx(
339343
dbChainMock.db as unknown as DbOrTx,

0 commit comments

Comments
 (0)