@@ -977,7 +977,6 @@ async function activateCloudflareVersionWithSecretsFile(
977977 : options . trustedInheritanceVersionIds ;
978978 let inheritanceBaseline : Array < RecentCloudflareVersion > | undefined ;
979979 let trustedCandidateChain = false ;
980- let activeSecretsPinned = false ;
981980 let pinnedActiveSecrets : Array < { name : string ; type : 'secret_key' | 'secret_text' } > | undefined ;
982981 if ( options . expectedPreviousVersionId !== undefined || options . verifyInheritedSecrets === true ) {
983982 const recent = await readRecentCloudflareVersionIds ( options ) ;
@@ -1027,13 +1026,14 @@ async function activateCloudflareVersionWithSecretsFile(
10271026 return { ok : false , reason : 'inheritance-source-unavailable' } ;
10281027 }
10291028 if ( ! replacesAllRemoteSecrets ) {
1030- const activeSecrets = previous . versionId
1031- ? await readCloudflareVersionSecretBindings ( options , previous . versionId )
1029+ const activeSecrets = previousVersionId
1030+ ? await readCloudflareVersionSecretBindings ( options , previousVersionId )
10321031 : null ;
10331032 if (
1033+ ! previousVersionId ||
10341034 ! activeSecrets ||
10351035 ! options . pinActiveSecrets ||
1036- ! ( await options . pinActiveSecrets ( previous . versionId ! , activeSecrets ) )
1036+ ! ( await options . pinActiveSecrets ( previousVersionId , activeSecrets ) )
10371037 ) {
10381038 return {
10391039 ok : false ,
@@ -1042,7 +1042,6 @@ async function activateCloudflareVersionWithSecretsFile(
10421042 rollback : 'not-needed' ,
10431043 } ;
10441044 }
1045- activeSecretsPinned = true ;
10461045 pinnedActiveSecrets = activeSecrets ;
10471046 }
10481047 }
@@ -1158,10 +1157,10 @@ async function activateCloudflareVersionWithSecretsFile(
11581157 // The exact private cf placeholder has no serving preview. Publish its first
11591158 // application once through the bootstrap path, pinning its active secrets
11601159 // just as for an explicitly atomic release.
1161- if ( bootstrapVoidDraft && ! activeSecretsPinned && ! options . pinActiveSecrets ) {
1160+ if ( bootstrapVoidDraft && ! pinnedActiveSecrets && ! options . pinActiveSecrets ) {
11621161 return { ok : false , reason : 'inheritance-source-unavailable' } ;
11631162 }
1164- if ( bootstrapVoidDraft || ( ! activeSecretsPinned && options . pinActiveSecrets ) ) {
1163+ if ( bootstrapVoidDraft || ( ! pinnedActiveSecrets && options . pinActiveSecrets ) ) {
11651164 let activeSecrets : Awaited < ReturnType < typeof readCloudflareVersionSecretBindings > > ;
11661165 try {
11671166 activeSecrets = await readCloudflareVersionSecretBindings ( options , previous . versionId ) ;
@@ -1171,26 +1170,31 @@ async function activateCloudflareVersionWithSecretsFile(
11711170 if ( activeSecrets === null ) {
11721171 return { ok : false , reason : 'inheritance-source-unavailable' } ;
11731172 }
1173+ const draftSecretNames = previousVersion ?. voidDraftSecretNames ;
11741174 if (
11751175 bootstrapVoidDraft &&
1176- ( activeSecrets . length === 0 ||
1176+ ( ! draftSecretNames ||
1177+ activeSecrets . length === 0 ||
11771178 activeSecrets . some ( ( secret ) => secret . type !== 'secret_text' ) ||
11781179 ! arraysEqual (
11791180 activeSecrets . map ( ( secret ) => secret . name ) . sort ( ) ,
1180- [ ...previousVersion ! . voidDraftSecretNames ! ] . sort ( ) ,
1181+ [ ...draftSecretNames ] . sort ( ) ,
11811182 ) ||
1182- ( activeSecretsPinned &&
1183+ ( pinnedActiveSecrets &&
11831184 ! isDeepStrictEqual (
11841185 [ ...activeSecrets ] . sort ( ( a , b ) => a . name . localeCompare ( b . name ) ) ,
1185- [ ...pinnedActiveSecrets ! ] . sort ( ( a , b ) => a . name . localeCompare ( b . name ) ) ,
1186+ [ ...pinnedActiveSecrets ] . sort ( ( a , b ) => a . name . localeCompare ( b . name ) ) ,
11861187 ) ) )
11871188 ) {
11881189 return { ok : false , reason : 'inheritance-source-changed' } ;
11891190 }
1190- if ( ! activeSecretsPinned && activeSecrets . length ) {
1191+ if ( ! pinnedActiveSecrets && activeSecrets . length ) {
1192+ if ( ! options . pinActiveSecrets ) {
1193+ return { ok : false , reason : 'inheritance-source-unavailable' } ;
1194+ }
11911195 let pinned : boolean ;
11921196 try {
1193- pinned = await options . pinActiveSecrets ! ( previous . versionId , activeSecrets ) ;
1197+ pinned = await options . pinActiveSecrets ( previous . versionId , activeSecrets ) ;
11941198 } catch {
11951199 return { ok : false , reason : 'inheritance-source-unavailable' } ;
11961200 }
@@ -1213,7 +1217,7 @@ async function activateCloudflareVersionWithSecretsFile(
12131217 // explicitly supplied replacement retains its existing upload semantics.
12141218 if (
12151219 previous . versionId !== null &&
1216- ! activeSecretsPinned &&
1220+ ! pinnedActiveSecrets &&
12171221 options . pinActiveSecrets &&
12181222 options . candidateSecretsFilePath === undefined
12191223 ) {
@@ -1242,10 +1246,10 @@ async function activateCloudflareVersionWithSecretsFile(
12421246 if ( ! pinned ) {
12431247 return { ok : false , reason : 'inheritance-source-changed' } ;
12441248 }
1245- activeSecretsPinned = true ;
1249+ pinnedActiveSecrets = activeSecrets ;
12461250 }
12471251 }
1248- if ( activeSecretsPinned ) {
1252+ if ( pinnedActiveSecrets ) {
12491253 if ( ! options . verifyUploader ( ) ) {
12501254 return { ok : false , reason : 'uploader-changed' } ;
12511255 }
@@ -1255,9 +1259,10 @@ async function activateCloudflareVersionWithSecretsFile(
12551259 }
12561260 if (
12571261 owner . kind !== 'ok' ||
1262+ previousVersionId === null ||
12581263 owner . versionId !== previous . versionId ||
12591264 ! productionVersionPercentagesEqual ( owner . versions , [
1260- { versionId : previous . versionId ! , percentage : 100 } ,
1265+ { versionId : previousVersionId , percentage : 100 } ,
12611266 ] )
12621267 ) {
12631268 return {
0 commit comments