Skip to content

Commit 1b6e0d9

Browse files
chore: merge workflow agent config for resource selection (#1163)
1 parent 81ac42e commit 1b6e0d9

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

‎apps/workspace-engine/svc/http/server/openapi/workflows/dispatch.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ func planDispatches(
4343
runner := runners[jobAgent.Ref]
4444
mergedConfig := mergeWorkflowJobAgentConfig(runner.Config, jobAgent.Config)
4545
dispatchCtx := buildJobDispatchContext(&resourceCtx, runner, mergedConfig)
46+
matchAgent := dispatchCtx.JobAgent
47+
matchAgent.Config = mergedConfig
4648

4749
matched, err := selector.MatchJobAgentsWithResource(
4850
ctx,
4951
jobAgent.Selector,
50-
[]oapi.JobAgent{dispatchCtx.JobAgent},
52+
[]oapi.JobAgent{matchAgent},
5153
matchResource,
5254
)
5355
if err != nil {

‎apps/workspace-engine/svc/http/server/openapi/workflows/workflows_test.go‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
80121
func TestPlanDispatches_NoMatchingServerYieldsNoDispatches(t *testing.T) {
81122
prodAgent, prodRunner := argoAgent("argocd.prod.example.com")
82123

0 commit comments

Comments
 (0)