@@ -14,7 +14,9 @@ import path from "node:path";
1414import { pathToFileURL } from "node:url" ;
1515import {
1616 extractChangelogReleaseSections ,
17+ formatContributionRecordProvenance ,
1718 formatShippedBaselineExclusions ,
19+ parseContributionRecordProvenance ,
1820 parseShippedBaselineExclusions ,
1921 releaseNotesVersionForTag ,
2022 verifyGithubReleaseNotes ,
@@ -671,10 +673,8 @@ export function contributionRecordTarget(section) {
671673 if ( recordStart < 0 ) {
672674 return undefined ;
673675 }
674- return section . source
675- . slice ( recordStart )
676- . match ( / ^ T h i s a u d i t e d r e c o r d c o v e r s t h e c o m p l e t e \S + \. \. (?< target > [ 0 - 9 a - f ] { 40 } ) h i s t o r y : / mu)
677- ?. groups ?. target ;
676+ const target = parseContributionRecordProvenance ( section . source . slice ( recordStart ) ) ?. target ;
677+ return target && / ^ [ 0 - 9 a - f ] { 40 } $ / u. test ( target ) ? target : undefined ;
678678}
679679
680680export function pullRequestTitleFromCommitSubject ( subject , number ) {
@@ -688,19 +688,12 @@ function completeContributionRecord(section, label) {
688688 fail ( `${ label } is missing ### Complete contribution record` ) ;
689689 }
690690 const recordSource = section . source . slice ( recordStart ) ;
691- const provenance = recordSource . match (
692- / ^ T h i s a u d i t e d r e c o r d c o v e r s t h e c o m p l e t e \S + \. \. [ 0 - 9 a - f ] { 40 } h i s t o r y : (?< count > [ 0 - 9 ] + ) m e r g e d P R s ? \. / mu,
693- ) ;
694- if ( ! provenance ?. groups ?. count ) {
691+ const provenance = parseContributionRecordProvenance ( recordSource ) ;
692+ if ( ! provenance || ! / ^ [ 0 - 9 a - f ] { 40 } $ / u. test ( provenance . target ) ) {
695693 fail ( `${ label } is missing exact complete contribution record provenance` ) ;
696694 }
697695 const record = contributionRecordFor ( section ) ;
698- const declaredCount = Number ( provenance . groups . count ) ;
699- if ( record . pullRequests . size !== declaredCount ) {
700- fail (
701- `${ label } contribution record declares ${ declaredCount } PRs but contains ${ record . pullRequests . size } ` ,
702- ) ;
703- }
696+ const declaredCount = provenance . uniquePullRequests ;
704697 return { record, declaredCount } ;
705698}
706699
@@ -2069,6 +2062,10 @@ export function ledgerFor(
20692062 ! revertedReferences . has ( entry . number ) ,
20702063 ) ;
20712064 const issues = entries . filter ( ( entry ) => entry . type === "Issue" ) ;
2065+ const inRangePullRequestNumbers = new Set ( [
2066+ ...sourcePullRequests ,
2067+ ...[ ...sourceReferences ] . filter ( ( number ) => nodes . get ( number ) ?. __typename === "PullRequest" ) ,
2068+ ] ) ;
20722069 const legacyIssues = legacyIssuesByPullRequest ( priorRecord , nodes ) ;
20732070 const records = pullRequests . map ( ( entry ) => {
20742071 const priorEntry = priorRecord . pullRequests . get ( entry . number ) ;
@@ -2097,11 +2094,20 @@ export function ledgerFor(
20972094 thanks,
20982095 } ) ;
20992096 } ) ;
2097+ const inRangePullRequests = records . filter ( ( entry ) =>
2098+ inRangePullRequestNumbers . has ( entry . number ) ,
2099+ ) . length ;
2100+ const retainedSeedOnlyPullRequests = records . length - inRangePullRequests ;
2101+ const provenance = {
2102+ inRangePullRequests,
2103+ retainedSeedOnlyPullRequests,
2104+ uniquePullRequests : records . length ,
2105+ } ;
21002106 const shippedBaselineLine = formatShippedBaselineExclusions ( shippedBaselines ) ;
21012107 const ledger = [
21022108 "### Complete contribution record" ,
21032109 "" ,
2104- `This audited record covers the complete ${ base } .. ${ target } history: ${ records . length } merged PRs. The generation manifest also supplies direct commits as editorial input; the grouped notes above prioritize user impact.` ,
2110+ `${ formatContributionRecordProvenance ( { base , target , ... provenance } ) } The generation manifest also supplies direct commits as editorial input; the grouped notes above prioritize user impact.` ,
21052111 ...( shippedBaselineLine ? [ "" , shippedBaselineLine ] : [ ] ) ,
21062112 "" ,
21072113 "#### Pull requests" ,
@@ -2113,6 +2119,7 @@ export function ledgerFor(
21132119 issues,
21142120 ledger,
21152121 pullRequests : records ,
2122+ provenance,
21162123 titleReferences : titleReferences ( records ) ,
21172124 } ;
21182125}
@@ -2176,6 +2183,22 @@ export function ledgerChecks(section, pullRequests, nodes, directCommits, shippe
21762183 return errors ;
21772184 }
21782185 const ledger = section . source . slice ( ledgerStart ) ;
2186+ try {
2187+ const provenance = parseContributionRecordProvenance ( ledger ) ;
2188+ if ( ! provenance ) {
2189+ errors . push ( "missing exact complete contribution record provenance" ) ;
2190+ } else if (
2191+ section . expectedProvenance &&
2192+ provenance . inRangePullRequests !== undefined &&
2193+ ( provenance . inRangePullRequests !== section . expectedProvenance . inRangePullRequests ||
2194+ provenance . retainedSeedOnlyPullRequests !==
2195+ section . expectedProvenance . retainedSeedOnlyPullRequests )
2196+ ) {
2197+ errors . push ( "contribution record provenance partition does not match generated inventory" ) ;
2198+ }
2199+ } catch ( error ) {
2200+ errors . push ( error instanceof Error ? error . message : String ( error ) ) ;
2201+ }
21792202 const expectedShippedBaselineLine = formatShippedBaselineExclusions ( shippedBaselines ) ;
21802203 try {
21812204 const sectionShippedBaselineLine = formatShippedBaselineExclusions (
@@ -2312,15 +2335,15 @@ function manifestFor(options, source, ledger, directCommitRecords) {
23122335 } ) ) ;
23132336 const unlinkedCommits = directCommits . filter ( ( commit ) => commit . references . length === 0 ) ;
23142337 return {
2315- schemaVersion : 2 ,
2338+ schemaVersion : 3 ,
23162339 base : options . base ,
23172340 target : options . target ,
23182341 mergeBase : source . mergeBase ,
23192342 version : options . version ,
23202343 shippedBaselines : source . shippedBaselines ,
23212344 source : {
23222345 references : ledger . entries . length ,
2323- pullRequests : ledger . pullRequests . length ,
2346+ ... ledger . provenance ,
23242347 issues : ledger . issues . length ,
23252348 directCommits : directCommits . length ,
23262349 unlinkedCommits : unlinkedCommits . length ,
@@ -2589,7 +2612,7 @@ function main() {
25892612 }
25902613
25912614 const errors = ledgerChecks (
2592- candidateSection ,
2615+ { ... candidateSection , expectedProvenance : ledger . provenance } ,
25932616 ledger . pullRequests ,
25942617 nodes ,
25952618 relationships . directCommits ,
@@ -2619,7 +2642,7 @@ function main() {
26192642 shippedBaselines : source . shippedBaselines ,
26202643 source : {
26212644 references : references . length ,
2622- pullRequests : ledger . pullRequests . length ,
2645+ ... ledger . provenance ,
26232646 issues : ledger . issues . length ,
26242647 directCommits : manifest . directCommits . length ,
26252648 unlinkedCommits : manifest . unlinkedCommits . length ,
@@ -2642,7 +2665,7 @@ function main() {
26422665 ? `, GitHub snapshot ${ githubSnapshotState . hits } hits/${ githubSnapshotState . misses } misses`
26432666 : "" ;
26442667 process . stdout . write (
2645- `${ options . version } : ${ ledger . pullRequests . length } PRs, ${ ledger . issues . length } issues, ${ errors . length === 0 ? "verified" : `${ errors . length } errors` } ${ snapshotSummary } \n` ,
2668+ `${ options . version } : ${ ledger . provenance . uniquePullRequests } unique PRs ( ${ ledger . provenance . inRangePullRequests } in-range + ${ ledger . provenance . retainedSeedOnlyPullRequests } retained seed-only) , ${ ledger . issues . length } issues, ${ errors . length === 0 ? "verified" : `${ errors . length } errors` } ${ snapshotSummary } \n` ,
26462669 ) ;
26472670 }
26482671 if ( errors . length > 0 ) {
0 commit comments