@@ -327,6 +327,14 @@ function isStringArray(value) {
327327 return true ;
328328}
329329
330+ function isContextDiagnostic ( record ) {
331+ return record . type === 'bench:diagnostic' &&
332+ ( record . data . benchId !== undefined ||
333+ record . data . phase !== undefined ||
334+ record . data . index !== undefined ||
335+ record . data . detail !== undefined ) ;
336+ }
337+
330338function validateRecord ( record ) {
331339 if ( record === null || typeof record !== 'object' ||
332340 ! kEventTypes . has ( record . type ) || record . data === null ||
@@ -339,8 +347,10 @@ function validateRecord(record) {
339347 throw new ERR_INVALID_ARG_VALUE (
340348 'benchmark child message' , record , 'is not a valid benchmark record' ) ;
341349 }
350+ const contextDiagnostic = isContextDiagnostic ( record ) ;
342351 if ( ( record . type === 'bench:plan' || record . type === 'bench:start' ||
343- record . type === 'bench:sample' || record . type === 'bench:complete' ) &&
352+ record . type === 'bench:sample' || record . type === 'bench:complete' ||
353+ contextDiagnostic ) &&
344354 ( typeof record . data . fileRunId !== 'string' ||
345355 typeof record . data . benchId !== 'string' ||
346356 ( record . data . parentId !== null &&
@@ -385,6 +395,21 @@ function validateRecord(record) {
385395 'is not a valid benchmark plan' ) ;
386396 }
387397 }
398+ if ( contextDiagnostic &&
399+ ( ( record . data . phase !== 'warmup' &&
400+ record . data . phase !== 'measurement' ) ||
401+ ! NumberIsSafeInteger ( record . data . index ) || record . data . index < 0 ||
402+ record . data . index > 0xFFFFFFFF ||
403+ typeof record . data . message !== 'string' ||
404+ ( record . data . level !== 'info' && record . data . level !== 'warning' ) ||
405+ typeof record . data . file !== 'string' ||
406+ ! NumberIsSafeInteger ( record . data . line ) || record . data . line < 0 ||
407+ ! NumberIsSafeInteger ( record . data . column ) || record . data . column < 0 ||
408+ record . data . error !== undefined ) ) {
409+ throw new ERR_INVALID_ARG_VALUE (
410+ 'benchmark child diagnostic' , record . data ,
411+ 'is not a valid benchmark diagnostic' ) ;
412+ }
388413 if ( record . type === 'bench:summary' ) {
389414 const { counts, duration_ns, success } = record . data ;
390415 if ( typeof success !== 'boolean' || typeof duration_ns !== 'bigint' ||
@@ -602,6 +627,7 @@ async function runChild(path, options, scope, onRecord) {
602627 stdio : [ 'inherit' , 'pipe' , 'pipe' , 'ipc' ] ,
603628 } ) ;
604629 let protocolError ;
630+ let activeBenchId ;
605631 let plansComplete = false ;
606632 let recordPending = false ;
607633 let summaryReceived = false ;
@@ -662,7 +688,14 @@ async function runChild(path, options, scope, onRecord) {
662688 }
663689 recordPending = true ;
664690 const record = deserializeRecord ( validateRecord ( message . record ) ) ;
665- if ( summaryReceived || ( record . type === 'bench:plan' && plansComplete ) ) {
691+ const contextDiagnostic = isContextDiagnostic ( record ) ;
692+ if ( summaryReceived || ( record . type === 'bench:plan' && plansComplete ) ||
693+ ( record . type === 'bench:start' && activeBenchId !== undefined ) ||
694+ ( ( record . type === 'bench:sample' || contextDiagnostic ) &&
695+ activeBenchId !== record . data . benchId ) ||
696+ ( record . type === 'bench:complete' && activeBenchId !== undefined &&
697+ activeBenchId !== record . data . benchId ) ||
698+ ( record . type === 'bench:summary' && activeBenchId !== undefined ) ) {
666699 throw new ERR_INVALID_ARG_VALUE (
667700 'benchmark child message' , message ,
668701 'does not have a valid lifecycle sequence' ) ;
@@ -671,6 +704,12 @@ async function runChild(path, options, scope, onRecord) {
671704 record . type !== 'bench:diagnostic' ) {
672705 plansComplete = true ;
673706 }
707+ if ( record . type === 'bench:start' ) {
708+ activeBenchId = record . data . benchId ;
709+ } else if ( record . type === 'bench:complete' &&
710+ activeBenchId === record . data . benchId ) {
711+ activeBenchId = undefined ;
712+ }
674713 if ( record . type === 'bench:summary' ) summaryReceived = true ;
675714 record . data . runId = options . runId ;
676715 record . data . fileRunId = scope . fileRunId ;
0 commit comments