@@ -77,6 +77,47 @@ func TestPlanDispatches_RoutesEachResourceToItsServer(t *testing.T) {
7777 }
7878}
7979
80+ func TestPlanDispatches_RoutesOnMergedPerJobConfig (t * testing.T ) {
81+ // One shared agent with no serverUrl of its own; each job entry supplies
82+ // its serverUrl via per-job config. Routing must see the merged config.
83+ ref := uuid .New ()
84+ runner := db.JobAgent {ID : ref , Config : oapi.JobAgentConfig {}}
85+ runners := map [string ]db.JobAgent {ref .String (): runner }
86+
87+ entry := func (name , serverURL string ) oapi.WorkflowJobAgent {
88+ return oapi.WorkflowJobAgent {
89+ Ref : ref .String (),
90+ Name : name ,
91+ Config : map [string ]any {"serverUrl" : serverURL },
92+ Selector : argoRoutingSelector ,
93+ }
94+ }
95+
96+ resources := []* oapi.Resource {
97+ resourceOnServer ("r1" , "https://argocd.prod.example.com" ),
98+ resourceOnServer ("r2" , "https://argocd.staging.example.com" ),
99+ }
100+ base := & oapi.DispatchContext {Workflow : & oapi.Workflow {Id : uuid .New ().String ()}}
101+
102+ dispatches , err := planDispatches (
103+ context .Background (), base , resources ,
104+ []oapi.WorkflowJobAgent {
105+ entry ("prod" , "argocd.prod.example.com" ),
106+ entry ("staging" , "argocd.staging.example.com" ),
107+ },
108+ runners ,
109+ )
110+
111+ require .NoError (t , err )
112+ require .Len (t , dispatches , 2 ) // r1 → prod entry, r2 → staging entry
113+
114+ for _ , d := range dispatches {
115+ server := d .dispatchCtx .Resource .Config ["argo" ].(map [string ]any )["server" ].(string )
116+ serverURL := d .mergedConfig ["serverUrl" ].(string )
117+ assert .Contains (t , server , serverURL , "resource routed to the wrong per-job entry" )
118+ }
119+ }
120+
80121func TestPlanDispatches_NoMatchingServerYieldsNoDispatches (t * testing.T ) {
81122 prodAgent , prodRunner := argoAgent ("argocd.prod.example.com" )
82123
0 commit comments