@@ -169,9 +169,29 @@ export async function preserveWorkspaceFileSecretProvenanceInTx(
169169/** Copies exact provenance for a byte-identical, same-owner-scope file copy; otherwise unknown. */
170170export async function copyWorkspaceFileSecretProvenanceInTx (
171171 tx : DbOrTx ,
172- expectedSource : WorkspaceFileSecretProvenanceCopySource ,
172+ expectedSource : WorkspaceFileSecretProvenanceCopySource | undefined ,
173173 targetFileId : string
174174) : Promise < void > {
175+ const [ target ] = await tx
176+ . select ( {
177+ userId : workspaceFiles . userId ,
178+ workspaceId : workspaceFiles . workspaceId ,
179+ contentUpdatedAt : workspaceFiles . contentUpdatedAt ,
180+ } )
181+ . from ( workspaceFiles )
182+ . where ( eq ( workspaceFiles . id , targetFileId ) )
183+ . limit ( 1 )
184+
185+ if ( ! target ) {
186+ throw new Error ( 'Workspace file provenance copy could not bind the target file version' )
187+ }
188+ if ( ! expectedSource ) {
189+ await replaceWorkspaceFileSecretProvenanceInTx ( tx , targetFileId , target . contentUpdatedAt , {
190+ status : 'unknown' ,
191+ } )
192+ return
193+ }
194+
175195 const [ source ] = await tx
176196 . select ( {
177197 key : workspaceFiles . key ,
@@ -189,19 +209,6 @@ export async function copyWorkspaceFileSecretProvenanceInTx(
189209 )
190210 . where ( eq ( workspaceFiles . id , expectedSource . fileId ) )
191211 . limit ( 1 )
192- const [ target ] = await tx
193- . select ( {
194- userId : workspaceFiles . userId ,
195- workspaceId : workspaceFiles . workspaceId ,
196- contentUpdatedAt : workspaceFiles . contentUpdatedAt ,
197- } )
198- . from ( workspaceFiles )
199- . where ( eq ( workspaceFiles . id , targetFileId ) )
200- . limit ( 1 )
201-
202- if ( ! target ) {
203- throw new Error ( 'Workspace file provenance copy could not bind the target file version' )
204- }
205212 if (
206213 ! source ||
207214 source . key !== expectedSource . key ||
0 commit comments