@@ -474,6 +474,92 @@ export function summarizeRttSamples(samples) {
474474 } ;
475475}
476476
477+ function isRecord ( value ) {
478+ return value !== null && typeof value === "object" && ! Array . isArray ( value ) ;
479+ }
480+
481+ function assertPayloadObject ( method , payload ) {
482+ if ( ! isRecord ( payload ) ) {
483+ throw new Error ( `${ method } returned invalid payload: expected object.` ) ;
484+ }
485+ return payload ;
486+ }
487+
488+ function assertHealthSmokePayload ( payload ) {
489+ const summary = assertPayloadObject ( "health" , payload ) ;
490+ if ( summary . ok !== true ) {
491+ throw new Error ( "health returned invalid payload: expected ok=true." ) ;
492+ }
493+ if ( ! Number . isFinite ( summary . ts ) ) {
494+ throw new Error ( "health returned invalid payload: expected numeric ts." ) ;
495+ }
496+ if ( ! Number . isFinite ( summary . durationMs ) ) {
497+ throw new Error ( "health returned invalid payload: expected numeric durationMs." ) ;
498+ }
499+ if ( typeof summary . defaultAgentId !== "string" || summary . defaultAgentId . trim ( ) === "" ) {
500+ throw new Error ( "health returned invalid payload: expected defaultAgentId." ) ;
501+ }
502+ if ( ! Array . isArray ( summary . agents ) ) {
503+ throw new Error ( "health returned invalid payload: expected agents array." ) ;
504+ }
505+ if ( ! isRecord ( summary . channels ) ) {
506+ throw new Error ( "health returned invalid payload: expected channels object." ) ;
507+ }
508+ if ( ! Array . isArray ( summary . channelOrder ) ) {
509+ throw new Error ( "health returned invalid payload: expected channelOrder array." ) ;
510+ }
511+ if ( ! isRecord ( summary . sessions ) ) {
512+ throw new Error ( "health returned invalid payload: expected sessions object." ) ;
513+ }
514+ }
515+
516+ function assertConfigGetSmokePayload ( payload ) {
517+ const snapshot = assertPayloadObject ( "config.get" , payload ) ;
518+ if ( typeof snapshot . path !== "string" || snapshot . path . trim ( ) === "" ) {
519+ throw new Error ( "config.get returned invalid payload: expected config path." ) ;
520+ }
521+ if ( typeof snapshot . exists !== "boolean" ) {
522+ throw new Error ( "config.get returned invalid payload: expected exists boolean." ) ;
523+ }
524+ if ( typeof snapshot . valid !== "boolean" ) {
525+ throw new Error ( "config.get returned invalid payload: expected valid boolean." ) ;
526+ }
527+ if ( ! isRecord ( snapshot . sourceConfig ) ) {
528+ throw new Error ( "config.get returned invalid payload: expected sourceConfig object." ) ;
529+ }
530+ if ( ! isRecord ( snapshot . resolved ) ) {
531+ throw new Error ( "config.get returned invalid payload: expected resolved object." ) ;
532+ }
533+ if ( ! isRecord ( snapshot . runtimeConfig ) ) {
534+ throw new Error ( "config.get returned invalid payload: expected runtimeConfig object." ) ;
535+ }
536+ if ( ! isRecord ( snapshot . config ) ) {
537+ throw new Error ( "config.get returned invalid payload: expected config object." ) ;
538+ }
539+ if ( ! Array . isArray ( snapshot . issues ) ) {
540+ throw new Error ( "config.get returned invalid payload: expected issues array." ) ;
541+ }
542+ if ( ! Array . isArray ( snapshot . warnings ) ) {
543+ throw new Error ( "config.get returned invalid payload: expected warnings array." ) ;
544+ }
545+ if ( ! Array . isArray ( snapshot . legacyIssues ) ) {
546+ throw new Error ( "config.get returned invalid payload: expected legacyIssues array." ) ;
547+ }
548+ }
549+
550+ export function assertRpcSmokeResponse ( method , response ) {
551+ if ( ! response ?. ok ) {
552+ throw new Error ( `${ method } failed: ${ JSON . stringify ( response ?. error ) } ` ) ;
553+ }
554+ if ( method === "health" ) {
555+ assertHealthSmokePayload ( response . payload ) ;
556+ return ;
557+ }
558+ if ( method === "config.get" ) {
559+ assertConfigGetSmokePayload ( response . payload ) ;
560+ }
561+ }
562+
477563function toText ( data ) {
478564 if ( typeof data === "string" ) {
479565 return data ;
@@ -720,9 +806,7 @@ async function main() {
720806 const response = await client . request ( method , { } , 10_000 ) ;
721807 const durationMs = performance . now ( ) - requestStartedAtMs ;
722808 const roundedDurationMs = roundMeasuredMs ( durationMs , `${ method } durationMs` ) ;
723- if ( ! response . ok ) {
724- throw new Error ( `${ method } failed: ${ JSON . stringify ( response . error ) } ` ) ;
725- }
809+ assertRpcSmokeResponse ( method , response ) ;
726810 samples . push ( { method, durationMs } ) ;
727811 events . push ( {
728812 event : "gateway-rpc" ,
0 commit comments