11import { WorkflowRuntimeError , WorkflowWorldError } from '@workflow/errors' ;
2- import { SPEC_VERSION_CURRENT , SPEC_VERSION_LEGACY } from '@workflow/world' ;
2+ import {
3+ SPEC_VERSION_CURRENT ,
4+ SPEC_VERSION_LEGACY ,
5+ SPEC_VERSION_SUPPORTS_CBOR_QUEUE_TRANSPORT ,
6+ SPEC_VERSION_SUPPORTS_EVENT_SOURCING ,
7+ } from '@workflow/world' ;
38import {
49 afterEach ,
510 beforeEach ,
@@ -10,8 +15,8 @@ import {
1015 vi ,
1116} from 'vitest' ;
1217import type { Run } from './run.js' ;
13- import { start } from './start.js' ;
1418import type { WorkflowFunction } from './start.js' ;
19+ import { start } from './start.js' ;
1520import { getWorld } from './world.js' ;
1621
1722// Mock @vercel /functions
@@ -109,11 +114,35 @@ describe('start', () => {
109114 vi . clearAllMocks ( ) ;
110115 } ) ;
111116
112- it ( 'should use SPEC_VERSION_CURRENT when specVersion is not provided ' , async ( ) => {
117+ it ( 'should use world.specVersion when available, falling back to SPEC_VERSION_SUPPORTS_EVENT_SOURCING ' , async ( ) => {
113118 const validWorkflow = Object . assign ( ( ) => Promise . resolve ( 'result' ) , {
114119 workflowId : 'test-workflow' ,
115120 } ) ;
116121
122+ // Mock world without specVersion → falls back to safe baseline (v2)
123+ await start ( validWorkflow , [ ] ) ;
124+
125+ expect ( mockEventsCreate ) . toHaveBeenCalledWith (
126+ expect . stringMatching ( / ^ w r u n _ / ) ,
127+ expect . objectContaining ( {
128+ eventType : 'run_created' ,
129+ specVersion : SPEC_VERSION_SUPPORTS_EVENT_SOURCING ,
130+ } ) ,
131+ expect . objectContaining ( {
132+ v1Compat : false ,
133+ } )
134+ ) ;
135+
136+ vi . clearAllMocks ( ) ;
137+
138+ // Mock world with specVersion 3 → uses it
139+ vi . mocked ( getWorld ) . mockReturnValue ( {
140+ specVersion : SPEC_VERSION_CURRENT ,
141+ getDeploymentId : vi . fn ( ) . mockResolvedValue ( 'deploy_123' ) ,
142+ events : { create : mockEventsCreate } ,
143+ queue : mockQueue ,
144+ } as any ) ;
145+
117146 await start ( validWorkflow , [ ] ) ;
118147
119148 expect ( mockEventsCreate ) . toHaveBeenCalledWith (
@@ -408,6 +437,8 @@ describe('start', () => {
408437 const mockEventsCreate = vi . fn ( ) . mockRejectedValue ( serverError ) ;
409438
410439 vi . mocked ( getWorld ) . mockReturnValue ( {
440+ // World declares specVersion 3 to enable CBOR queue transport + runInput
441+ specVersion : SPEC_VERSION_SUPPORTS_CBOR_QUEUE_TRANSPORT ,
411442 getDeploymentId : vi . fn ( ) . mockResolvedValue ( 'deploy_123' ) ,
412443 events : { create : mockEventsCreate } ,
413444 queue : mockQueue ,
@@ -423,7 +454,9 @@ describe('start', () => {
423454 expect ( queuePayload . runInput ) . toBeDefined ( ) ;
424455 expect ( queuePayload . runInput . deploymentId ) . toBe ( 'deploy_123' ) ;
425456 expect ( queuePayload . runInput . workflowName ) . toBe ( 'test-workflow' ) ;
426- expect ( queuePayload . runInput . specVersion ) . toBe ( SPEC_VERSION_CURRENT ) ;
457+ expect ( queuePayload . runInput . specVersion ) . toBe (
458+ SPEC_VERSION_SUPPORTS_CBOR_QUEUE_TRANSPORT
459+ ) ;
427460 } ) ;
428461
429462 it ( 'should throw when queue fails even if events.create succeeds' , async ( ) => {
0 commit comments