From bd0cd3c2efe3fb2f8958971a7ef3f673ca884423 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Thu, 8 Oct 2026 22:13:12 +1100 Subject: [PATCH] refactor(workflow): keep the call key change inside the lint gate golangci-lint failed on the change and had not before: gofumpt wants StartCall's same-typed parameters grouped, and runWorkflowCall reached a cyclomatic complexity of 16. The unwaited call's early close moves into closeUnwaitedCall on *TaskContext -- it needs only the call step, the callee and the settings -- which leaves runWorkflowCall below the limit with its behaviour unchanged. The walk's id-less call case is deleted: ParseDefinition now refuses that definition before validateWorkflowCalls runs, so it passed for the wrong reason. The refusal is pinned where it happens instead, by the compile case in TestWorkflowCallKeyIsTheDeclaredPath, now asserting the whole message so it still names the step it refused. --- internal/domain/workflow/workflow_call.go | 18 ++++++++++------- .../domain/workflow/workflow_call_test.go | 20 +++---------------- internal/infrastructure/postgres/store.go | 2 +- 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/internal/domain/workflow/workflow_call.go b/internal/domain/workflow/workflow_call.go index f2297a138..bc68ec9ea 100644 --- a/internal/domain/workflow/workflow_call.go +++ b/internal/domain/workflow/workflow_call.go @@ -139,13 +139,7 @@ func runWorkflowCall(ctx context.Context, s workflowCallSettings, tc *TaskContex return fmt.Errorf("%s: could not be recorded: %w", WorkflowCallStepName, err) } if !s.Wait { - // The call step closes at once: the callee runs on, and nothing the - // caller waits on remains open. - if err := tc.finishChildStep(ctx, callStep, taskstate.StepSucceeded, - fmt.Sprintf("started %q (task %d); no wait", s.Workflow, callee.ID), 0); err != nil { - return fmt.Errorf("%s: could not be closed: %w", WorkflowCallStepName, err) - } - return nil + return tc.closeUnwaitedCall(ctx, s, callStep, callee.ID) } // Close the call step with the callee's outcome, unless the caller itself was // cancelled. @@ -176,6 +170,16 @@ func runWorkflowCall(ctx context.Context, s workflowCallSettings, tc *TaskContex return nil } +// closeUnwaitedCall closes the call step of a wait:false call at once: the +// callee runs on, and nothing the caller waits on remains open. +func (tc *TaskContext) closeUnwaitedCall(ctx context.Context, s workflowCallSettings, callStep, calleeTaskID int64) error { + if err := tc.finishChildStep(ctx, callStep, taskstate.StepSucceeded, + fmt.Sprintf("started %q (task %d); no wait", s.Workflow, calleeTaskID), 0); err != nil { + return fmt.Errorf("%s: could not be closed: %w", WorkflowCallStepName, err) + } + return nil +} + // workflowCallPath is the running call site's declared path within the run, // which names the step and identifies the call. Every registry stage is // wrapped, so a run reaching here without a path has no identity to key its diff --git a/internal/domain/workflow/workflow_call_test.go b/internal/domain/workflow/workflow_call_test.go index 2438e680d..8e063c892 100644 --- a/internal/domain/workflow/workflow_call_test.go +++ b/internal/domain/workflow/workflow_call_test.go @@ -120,7 +120,9 @@ steps: - type: workflow.call settings: {workflow: callee} `, - wantErr: "needs an id", + // The whole message, so the refusal still names the step it + // refused: this is where a pinned definition is compiled. + wantErr: `workflow "caller" step 1: "workflow.call" needs an id`, }, } for _, tt := range tests { @@ -260,22 +262,6 @@ steps: }, wantErr: `workflow "caller" step 1 branch "a" step 1 calls "missing", which is not defined`, }, - { - name: "a call step with no id is refused naming the step", - defs: map[string]string{ - "caller": `id: caller -repository: none -steps: - - {type: workflow.call, settings: {workflow: callee}} -`, - "callee": `id: callee -repository: none -steps: - - type: workflow.finish -`, - }, - wantErr: `workflow "caller" step 1: "workflow.call" needs an id`, - }, { name: "a cycle through branch calls is refused", defs: map[string]string{ diff --git a/internal/infrastructure/postgres/store.go b/internal/infrastructure/postgres/store.go index aa287d868..c7a4f4596 100644 --- a/internal/infrastructure/postgres/store.go +++ b/internal/infrastructure/postgres/store.go @@ -786,7 +786,7 @@ func (s *Store) TaskByID(ctx context.Context, taskID int64) (*workflow.Task, err // callerTaskID and callKey when there is one. A child that ended dead or // declined freed its key, so such a call starts a fresh child. The caller must // be running and within workflow.MaxCallDepth. -func (s *Store) StartCall(ctx context.Context, callerTaskID int64, callKey string, wf string, inputs map[string]any) (*workflow.Task, error) { +func (s *Store) StartCall(ctx context.Context, callerTaskID int64, callKey, wf string, inputs map[string]any) (*workflow.Task, error) { encoded, err := task.EncodeInputs(inputs) if err != nil { return nil, err