@@ -13,6 +13,7 @@ import {
1313} from "./helpers/normalize" ;
1414import { runInTempDir } from "./helpers/run-in-tmp" ;
1515import { runWrangler } from "./helpers/run-wrangler" ;
16+ import { writeWorkerSource } from "./helpers/write-worker-source" ;
1617import { writeWranglerConfig } from "./helpers/write-wrangler-config" ;
1718import type { Instance , Workflow } from "../workflows/types" ;
1819
@@ -667,4 +668,117 @@ describe("wrangler workflows", () => {
667668 ) ;
668669 } ) ;
669670 } ) ;
671+
672+ describe ( "workflow binding validation" , ( ) => {
673+ it ( "should validate workflow binding with valid name" , async ( ) => {
674+ writeWorkerSource ( { format : "ts" } ) ;
675+ writeWranglerConfig ( {
676+ main : "index.ts" ,
677+ workflows : [
678+ {
679+ binding : "MY_WORKFLOW" ,
680+ name : "valid-workflow-name" ,
681+ class_name : "MyWorkflow" ,
682+ script_name : "external-script" ,
683+ } ,
684+ ] ,
685+ } ) ;
686+
687+ await runWrangler ( "deploy --dry-run" ) ;
688+ expect ( std . err ) . toBe ( "" ) ;
689+ } ) ;
690+
691+ it ( "should reject workflow binding with name exceeding 64 characters" , async ( ) => {
692+ const longName = "a" . repeat ( 65 ) ; // 65 characters
693+ writeWranglerConfig ( {
694+ workflows : [
695+ {
696+ binding : "MY_WORKFLOW" ,
697+ name : longName ,
698+ class_name : "MyWorkflow" ,
699+ } ,
700+ ] ,
701+ } ) ;
702+
703+ await expect ( runWrangler ( "deploy --dry-run" ) ) . rejects . toThrow ( ) ;
704+ expect ( std . err ) . toContain ( "must be 64 characters or less" ) ;
705+ expect ( std . err ) . toContain ( "but got 65 characters" ) ;
706+ } ) ;
707+
708+ it ( "should accept workflow binding with name exactly 64 characters" , async ( ) => {
709+ const maxLengthName = "a" . repeat ( 64 ) ; // exactly 64 characters
710+ writeWorkerSource ( { format : "ts" } ) ;
711+ writeWranglerConfig ( {
712+ main : "index.ts" ,
713+ workflows : [
714+ {
715+ binding : "MY_WORKFLOW" ,
716+ name : maxLengthName ,
717+ class_name : "MyWorkflow" ,
718+ script_name : "external-script" ,
719+ } ,
720+ ] ,
721+ } ) ;
722+
723+ await runWrangler ( "deploy --dry-run" ) ;
724+ expect ( std . err ) . toBe ( "" ) ;
725+ } ) ;
726+
727+ it ( "should validate required fields for workflow binding" , async ( ) => {
728+ writeWranglerConfig ( {
729+ workflows : [
730+ {
731+ binding : "MY_WORKFLOW" ,
732+ } as any , // eslint-disable-line @typescript-eslint/no-explicit-any
733+ ] ,
734+ } ) ;
735+
736+ await expect ( runWrangler ( "deploy --dry-run" ) ) . rejects . toThrow ( ) ;
737+ expect ( std . err ) . toContain ( 'should have a string "name" field' ) ;
738+ expect ( std . err ) . toContain ( 'should have a string "class_name" field' ) ;
739+ } ) ;
740+
741+ it ( "should validate optional fields for workflow binding" , async ( ) => {
742+ writeWorkerSource ( { format : "ts" } ) ;
743+ writeWranglerConfig ( {
744+ main : "index.ts" ,
745+ workflows : [
746+ {
747+ binding : "MY_WORKFLOW" ,
748+ name : "my-workflow" ,
749+ class_name : "MyWorkflow" ,
750+ script_name : "external-script" ,
751+ experimental_remote : true ,
752+ } ,
753+ ] ,
754+ } ) ;
755+
756+ await runWrangler ( "deploy --dry-run" ) ;
757+ expect ( std . err ) . toBe ( "" ) ;
758+ } ) ;
759+
760+ it ( "should reject workflow binding with invalid field types" , async ( ) => {
761+ writeWranglerConfig ( {
762+ workflows : [
763+ {
764+ binding : 123 , // should be string
765+ name : "my-workflow" ,
766+ class_name : "MyWorkflow" ,
767+ } as any , // eslint-disable-line @typescript-eslint/no-explicit-any
768+ ] ,
769+ } ) ;
770+
771+ await expect ( runWrangler ( "deploy --dry-run" ) ) . rejects . toThrow ( ) ;
772+ expect ( std . err ) . toContain ( 'should have a string "binding" field' ) ;
773+ } ) ;
774+
775+ it ( "should reject workflow binding that is not an object" , async ( ) => {
776+ writeWranglerConfig ( {
777+ workflows : [ "invalid-workflow-config" ] as any , // eslint-disable-line @typescript-eslint/no-explicit-any
778+ } ) ;
779+
780+ await expect ( runWrangler ( "deploy --dry-run" ) ) . rejects . toThrow ( ) ;
781+ expect ( std . err ) . toContain ( '"workflows" bindings should be objects' ) ;
782+ } ) ;
783+ } ) ;
670784} ) ;
0 commit comments