1919
2020import { describe , expect , test } from "bun:test" ;
2121import { formatOperatorResult } from "./result-formatting" ;
22- import type { OperatorExecutionSummary , OperatorState , SampleRow } from "../../types/execution" ;
22+ import {
23+ ConsoleMessageType ,
24+ OperatorState ,
25+ OperatorResultMode ,
26+ WorkflowFatalErrorType ,
27+ type OperatorExecutionSummary ,
28+ type WorkflowFatalError ,
29+ type SampleRow ,
30+ } from "../../types/execution" ;
2331
2432// Convert flat test rows (with an optional embedded __row_index__) into the
2533// structured SampleRow[] the summary now carries.
@@ -36,29 +44,40 @@ interface OpInfoOverrides {
3644 state ?: OperatorState ;
3745 error ?: string ;
3846 outputTuples ?: number ;
39- totalRowCount ?: number ;
47+ tuplesCount ?: number ;
4048 warnings ?: string [ ] ;
4149 result ?: Record < string , any > [ ] ;
4250}
4351
52+ function makeExecutionFailure ( message : string ) : WorkflowFatalError {
53+ return {
54+ type : { name : WorkflowFatalErrorType . EXECUTION_FAILURE } ,
55+ timestamp : { seconds : 0 , nanos : 0 } ,
56+ message,
57+ details : "" ,
58+ operatorId : "" ,
59+ workerId : "" ,
60+ } ;
61+ }
62+
4463function makeOpInfo ( overrides : OpInfoOverrides = { } ) : OperatorExecutionSummary {
4564 const summary : OperatorExecutionSummary = {
46- state : overrides . state ?? "Completed" ,
47- errorMessages : overrides . error ? [ { type : "EXECUTION_FAILURE" , message : overrides . error } ] : [ ] ,
65+ state : overrides . state ?? OperatorState . COMPLETED ,
66+ errorMessages : overrides . error ? [ makeExecutionFailure ( overrides . error ) ] : [ ] ,
4867 } ;
4968 // The result summary is present only when the operator produced a result.
5069 if ( overrides . result !== undefined ) {
5170 summary . resultSummary = {
52- resultMode : "table" ,
71+ resultMode : OperatorResultMode . TABLE ,
5372 // Non-arrays are passed through to exercise the "(no result data)" guard.
5473 sampleTuples : Array . isArray ( overrides . result ) ? toSampleRows ( overrides . result ) : ( overrides . result as any ) ,
55- totalRowCount : overrides . totalRowCount ?? overrides . outputTuples ?? 0 ,
74+ tuplesCount : overrides . tuplesCount ?? overrides . outputTuples ?? 0 ,
5675 } ;
5776 }
5877 if ( overrides . warnings ) {
5978 // Warnings are derived from console messages whose title is "WARNING: ...".
6079 summary . consoleLogsSummary = {
61- messages : overrides . warnings . map ( w => ( { msgType : " PRINT" , title : w , message : "" } ) ) ,
80+ messages : overrides . warnings . map ( w => ( { msgType : ConsoleMessageType . PRINT , title : w , message : "" } ) ) ,
6281 } ;
6382 }
6483 return summary ;
@@ -93,15 +112,15 @@ describe("formatOperatorResult - early returns", () => {
93112} ) ;
94113
95114describe ( "formatOperatorResult - table shape and metadata" , ( ) => {
96- test ( "uses outputTuples for row count when totalRowCount missing" , ( ) => {
115+ test ( "uses outputTuples for row count when tuplesCount missing" , ( ) => {
97116 const out = formatOperatorResult ( "op1" , makeOpInfo ( { outputTuples : 7 , result : [ { a : 1 , b : 2 } ] } ) ) ;
98117 expect ( out ) . toContain ( "Output table shape: (7, 2)" ) ;
99118 } ) ;
100119
101- test ( "totalRowCount overrides outputTuples in output shape" , ( ) => {
120+ test ( "tuplesCount overrides outputTuples in output shape" , ( ) => {
102121 const out = formatOperatorResult (
103122 "op1" ,
104- makeOpInfo ( { outputTuples : 7 , totalRowCount : 999 , result : [ { a : 1 , b : 2 } ] } )
123+ makeOpInfo ( { outputTuples : 7 , tuplesCount : 999 , result : [ { a : 1 , b : 2 } ] } )
105124 ) ;
106125 expect ( out ) . toContain ( "Output table shape: (999, 2)" ) ;
107126 } ) ;
0 commit comments