@@ -973,7 +973,10 @@ function startActionEventCrabFleetPost(
973973export function importActionEventShards (
974974 sourceRoot : string ,
975975 destinationRoot : string ,
976- options : { expectedProducer ?: ExpectedActionEventProducer | undefined } = { } ,
976+ options : {
977+ expectedProducer ?: ExpectedActionEventProducer | undefined ;
978+ expectedEventPaths ?: readonly string [ ] | undefined ;
979+ } = { } ,
977980) : ActionEventShardImportResult {
978981 const emptyResult = ( ) : ActionEventShardImportResult => ( {
979982 created : 0 ,
@@ -983,21 +986,33 @@ export function importActionEventShards(
983986 completionPaths : [ ] ,
984987 paths : [ ] ,
985988 } ) ;
989+ const expectedEventPaths = options . expectedEventPaths
990+ ? validateExpectedActionEventPaths ( options . expectedEventPaths )
991+ : null ;
986992 let safeSource : SafeReadRoot ;
987993 try {
988994 safeSource = prepareSafeReadRoot ( sourceRoot , "action event shard import source" ) ;
989995 } catch ( error ) {
990- if ( isNotFoundError ( error ) ) return emptyResult ( ) ;
996+ if ( isNotFoundError ( error ) && expectedEventPaths === null ) return emptyResult ( ) ;
997+ if ( isNotFoundError ( error ) ) {
998+ throw new Error ( "action event shard manifest source root is missing" ) ;
999+ }
9911000 throw error ;
9921001 }
9931002 let relativePaths : string [ ] ;
994- try {
995- relativePaths = collectActionEventShardFiles ( safeSource ) ;
996- } catch ( error ) {
997- if ( isNotFoundError ( error ) ) return emptyResult ( ) ;
998- throw error ;
1003+ if ( expectedEventPaths ) {
1004+ relativePaths = expectedEventPaths ;
1005+ } else {
1006+ try {
1007+ relativePaths = collectActionEventShardFiles ( safeSource ) ;
1008+ } catch ( error ) {
1009+ if ( isNotFoundError ( error ) ) return emptyResult ( ) ;
1010+ throw error ;
1011+ }
9991012 }
1000- const shards = readImportedActionEventShards ( safeSource , relativePaths ) ;
1013+ const shards = readImportedActionEventShards ( safeSource , relativePaths , {
1014+ requireManifestPaths : expectedEventPaths !== null ,
1015+ } ) ;
10011016 if ( options . expectedProducer ) {
10021017 validateImportedActionEventProducer ( shards , options . expectedProducer ) ;
10031018 }
@@ -1359,14 +1374,23 @@ function readImportedActionEventIdentityBinding(
13591374function readImportedActionEventShards (
13601375 source : SafeReadRoot ,
13611376 relativePaths : readonly string [ ] ,
1377+ options : { requireManifestPaths ?: boolean } = { } ,
13621378) : ImportedActionEventShard [ ] {
13631379 let totalBytes = 0 ;
13641380 const contents = relativePaths . map ( ( relativePath ) => {
13651381 if ( ! ACTION_EVENT_SHARD_PATH_PATTERN . test ( relativePath ) ) {
13661382 throw new Error ( `invalid action event shard path: ${ relativePath } ` ) ;
13671383 }
13681384 const target = prepareSafeReadTarget ( source , relativePath , "action event shard import source" ) ;
1369- const content = readUtf8FileNoFollow ( target , ACTION_EVENT_SHARD_IMPORT_LIMITS . maxFileBytes ) ;
1385+ let content : string ;
1386+ try {
1387+ content = readUtf8FileNoFollow ( target , ACTION_EVENT_SHARD_IMPORT_LIMITS . maxFileBytes ) ;
1388+ } catch ( error ) {
1389+ if ( options . requireManifestPaths && isNotFoundError ( error ) ) {
1390+ throw new Error ( `action event shard manifest path is missing: ${ relativePath } ` ) ;
1391+ }
1392+ throw error ;
1393+ }
13701394 const bytes = Buffer . byteLength ( content , "utf8" ) ;
13711395 totalBytes += bytes ;
13721396 if ( totalBytes > ACTION_EVENT_SHARD_IMPORT_LIMITS . maxTotalBytes ) {
@@ -1401,6 +1425,30 @@ function readImportedActionEventShards(
14011425 return validated ;
14021426}
14031427
1428+ function validateExpectedActionEventPaths ( paths : readonly string [ ] ) : string [ ] {
1429+ if ( paths . length === 0 ) {
1430+ throw new Error ( "action event shard manifest is empty" ) ;
1431+ }
1432+ if ( paths . length > ACTION_EVENT_SHARD_IMPORT_LIMITS . maxFiles ) {
1433+ throw new Error (
1434+ `action event shard manifest exceeds ${ ACTION_EVENT_SHARD_IMPORT_LIMITS . maxFiles } event paths` ,
1435+ ) ;
1436+ }
1437+ const canonical = [ ...new Set ( paths ) ] . sort ( ) ;
1438+ if (
1439+ canonical . length !== paths . length ||
1440+ canonical . some ( ( value , index ) => value !== paths [ index ] )
1441+ ) {
1442+ throw new Error ( "action event shard manifest paths must be sorted and unique" ) ;
1443+ }
1444+ for ( const relativePath of canonical ) {
1445+ if ( ! ACTION_EVENT_SHARD_PATH_PATTERN . test ( relativePath ) ) {
1446+ throw new Error ( `invalid action event shard manifest path: ${ relativePath } ` ) ;
1447+ }
1448+ }
1449+ return canonical ;
1450+ }
1451+
14041452function importedShardReplayEquivalent (
14051453 content : string ,
14061454 candidate : ImportedActionEventShard ,
0 commit comments