@@ -193,6 +193,7 @@ describe('workspace file secret provenance', () => {
193193 const targetContentUpdatedAt = new Date ( '2026-08-04T00:00:01.000Z' )
194194 queueTableRows ( workspaceFiles , [
195195 {
196+ key : 'source-key' ,
196197 userId : 'user-1' ,
197198 workspaceId : 'workspace-1' ,
198199 fileContentUpdatedAt : CONTENT_UPDATED_AT ,
@@ -211,7 +212,11 @@ describe('workspace file secret provenance', () => {
211212
212213 await copyWorkspaceFileSecretProvenanceInTx (
213214 dbChainMock . db as unknown as DbOrTx ,
214- 'source-file' ,
215+ {
216+ fileId : 'source-file' ,
217+ key : 'source-key' ,
218+ contentUpdatedAtMs : CONTENT_UPDATED_AT . getTime ( ) ,
219+ } ,
215220 'target-file'
216221 )
217222
@@ -226,12 +231,14 @@ describe('workspace file secret provenance', () => {
226231 } )
227232
228233 it ( 'marks a copied file unknown when source provenance is stale' , async ( ) => {
234+ const sourceContentUpdatedAt = new Date ( '2026-08-04T00:00:01.000Z' )
229235 const targetContentUpdatedAt = new Date ( '2026-08-04T00:00:02.000Z' )
230236 queueTableRows ( workspaceFiles , [
231237 {
238+ key : 'source-key' ,
232239 userId : 'user-1' ,
233240 workspaceId : 'workspace-1' ,
234- fileContentUpdatedAt : new Date ( '2026-08-04T00:00:01.000Z' ) ,
241+ fileContentUpdatedAt : sourceContentUpdatedAt ,
235242 provenanceContentUpdatedAt : CONTENT_UPDATED_AT ,
236243 status : 'exact' ,
237244 entries : [ { name : 'API_KEY' , encryptedValue : 'encrypted' } ] ,
@@ -247,7 +254,11 @@ describe('workspace file secret provenance', () => {
247254
248255 await copyWorkspaceFileSecretProvenanceInTx (
249256 dbChainMock . db as unknown as DbOrTx ,
250- 'source-file' ,
257+ {
258+ fileId : 'source-file' ,
259+ key : 'source-key' ,
260+ contentUpdatedAtMs : sourceContentUpdatedAt . getTime ( ) ,
261+ } ,
251262 'target-file'
252263 )
253264
@@ -265,6 +276,7 @@ describe('workspace file secret provenance', () => {
265276 const targetContentUpdatedAt = new Date ( '2026-08-04T00:00:02.000Z' )
266277 queueTableRows ( workspaceFiles , [
267278 {
279+ key : 'source-key' ,
268280 userId : 'source-user' ,
269281 workspaceId : 'source-workspace' ,
270282 fileContentUpdatedAt : CONTENT_UPDATED_AT ,
@@ -283,7 +295,53 @@ describe('workspace file secret provenance', () => {
283295
284296 await copyWorkspaceFileSecretProvenanceInTx (
285297 dbChainMock . db as unknown as DbOrTx ,
286- 'source-file' ,
298+ {
299+ fileId : 'source-file' ,
300+ key : 'source-key' ,
301+ contentUpdatedAtMs : CONTENT_UPDATED_AT . getTime ( ) ,
302+ } ,
303+ 'target-file'
304+ )
305+
306+ expect ( dbChainMockFns . values ) . toHaveBeenCalledWith (
307+ expect . objectContaining ( {
308+ fileId : 'target-file' ,
309+ contentUpdatedAt : targetContentUpdatedAt ,
310+ status : 'unknown' ,
311+ entries : [ ] ,
312+ } )
313+ )
314+ } )
315+
316+ it ( 'marks the copy unknown when the source changed after planning' , async ( ) => {
317+ const nextSourceContentUpdatedAt = new Date ( '2026-08-04T00:00:01.000Z' )
318+ 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+ ] )
337+
338+ await copyWorkspaceFileSecretProvenanceInTx (
339+ dbChainMock . db as unknown as DbOrTx ,
340+ {
341+ fileId : 'source-file' ,
342+ key : 'old-source-key' ,
343+ contentUpdatedAtMs : CONTENT_UPDATED_AT . getTime ( ) ,
344+ } ,
287345 'target-file'
288346 )
289347
0 commit comments