Self-hosted workflows for coding-agent delivery. Orchestrate CodeBuddy, Codex and Claude Code with scripts and human approval gates. Includes Local workflows for coding assistants.
JavaScript agent-orchestrationagentic-workflowai-agentsai-codingclaude-codecode-reviewcodebuddycodexcoding-agentscursordeveloper-toolshuman-on-the-loopllmmcpmulti-agentsdlcself-hostedsopworkflow-automationworkflow-engine
【架构优化】合并 buildRequirementLanes 中重复的 workflow 解析与 lane 命名回退 (#648) (#650)
fx-kurumi0534934cc534
diff --git a/internal/repo/requirement.go b/internal/repo/requirement.goindex d7f8ae94..36f33928 100644--- a/internal/repo/requirement.go+++ b/internal/repo/requirement.go@@ -148,14 +148,9 @@ func buildRequirementLanes(issue domain.Issue, project domain.Project, runs []do}acc := byWF[workflowID]if acc == nil {- if workflow.ID == "" {- workflow = workflows[workflowID]- }+ workflow = resolvedRequirementWorkflow(workflows, workflowID, workflow)lane := domain.InferSOPLane(workflow)- name := workflow.Name- if name == "" {- name = workflowID- }+ name := requirementLaneName(workflow, workflowID)acc = &wfAcc{lane: domain.RequirementLane{Lane: lane, Label: name, WorkflowID: workflowID, WorkflowName: name,}}@@ -164,10 +159,7 @@ func buildRequirementLanes(issue domain.Issue, project domain.Project, runs []doreturn acc}for _, run := range runs {- workflow := run.WorkflowSnapshot- if workflow.ID == "" {- workflow = workflows[run.WorkflowID]- }+ workflow := resolvedRequirementWorkflow(workflows, run.WorkflowID, run.WorkflowSnapshot)acc := accumulate(run.WorkflowID, workflow)if acc == nil {continue@@ -239,10 +231,7 @@ func buildRequirementLanes(issue domain.Issue, project domain.Project, runs []doif workflow.ID == "" {lane.Lane = domain.InferSOPLane(domain.WorkflowDefinition{ID: binding.WorkflowID})}- lane.WorkflowName = workflow.Name- if lane.WorkflowName == "" {- lane.WorkflowName = binding.WorkflowID- }+ lane.WorkflowName = requirementLaneName(workflow, binding.WorkflowID)lane.Label = lane.WorkflowNameif acc := byWF[binding.WorkflowID]; acc != nil {copied := withSOPBinding(acc.lane, binding)@@ -296,6 +285,25 @@ func buildRequirementLanes(issue domain.Issue, project domain.Project, runs []doreturn out}+// resolvedRequirementWorkflow prefers the workflow definition frozen into a run+// snapshot and falls back to the catalog entry when the snapshot is missing, so+// a lane still gets a name and lane after its workflow leaves the catalog.+func resolvedRequirementWorkflow(workflows map[string]domain.WorkflowDefinition, workflowID string, snapshot domain.WorkflowDefinition) domain.WorkflowDefinition {+ if snapshot.ID != "" {+ return snapshot+ }+ return workflows[workflowID]+}++// requirementLaneName is the lane display name: the workflow name, or the bare+// id when the catalog entry is unknown.+func requirementLaneName(workflow domain.WorkflowDefinition, workflowID string) string {+ if workflow.Name != "" {+ return workflow.Name+ }+ return workflowID+}+func laneStatusFromRun(run domain.Run) string {if run.ID == "" {return "not_started"diff --git a/internal/repo/requirement_lane_test.go b/internal/repo/requirement_lane_test.gonew file mode 100644index 00000000..fa1903b0--- /dev/null+++ b/internal/repo/requirement_lane_test.go@@ -0,0 +1,81 @@+package repo++import (+ "testing"+ "time"++ "agentflow/internal/domain"+)++func TestResolvedRequirementWorkflowPrefersSnapshot(t *testing.T) {+ catalog := domain.WorkflowDefinition{ID: "wf-a", Name: "目录 A"}+ snapshot := domain.WorkflowDefinition{ID: "wf-a", Name: "快照 A"}+ if got := resolvedRequirementWorkflow(map[string]domain.WorkflowDefinition{"wf-a": catalog}, "wf-a", snapshot); got.Name != "快照 A" {+ t.Fatalf("snapshot should win, got %#v", got)+ }+}++func TestResolvedRequirementWorkflowFallsBackToCatalog(t *testing.T) {+ catalog := domain.WorkflowDefinition{ID: "wf-a", Name: "目录 A"}+ if got := resolvedRequirementWorkflow(map[string]domain.WorkflowDefinition{"wf-a": catalog}, "wf-a", domain.WorkflowDefinition{}); got.Name != "目录 A" {+ t.Fatalf("catalog fallback failed, got %#v", got)+ }+}++func TestResolvedRequirementWorkflowUnknownReturnsZero(t *testing.T) {+ got := resolvedRequirementWorkflow(map[string]domain.WorkflowDefinition{}, "wf-missing", domain.WorkflowDefinition{})+ if got.ID != "" || got.Name != "" {+ t.Fatalf("unknown workflow should resolve to zero value, got %#v", got)+ }+}++func TestRequirementLaneNameFallsBackToID(t *testing.T) {+ if got := requirementLaneName(domain.WorkflowDefinition{ID: "wf-a", Name: "名字 A"}, "wf-a"); got != "名字 A" {+ t.Fatalf("want workflow name, got %q", got)+ }+ if got := requirementLaneName(domain.WorkflowDefinition{ID: "wf-a"}, "wf-a"); got != "wf-a" {+ t.Fatalf("want id fallback, got %q", got)+ }+ if got := requirementLaneName(domain.WorkflowDefinition{}, "wf-unknown"); got != "wf-unknown" {+ t.Fatalf("want id for unknown workflow, got %q", got)+ }+}++// The two helpers must reproduce the lane naming and lane classification the+// bindings path produced inline before the extraction.+func TestBuildRequirementLanesNamesUnknownBindingByID(t *testing.T) {+ now := time.Now().UTC()+ issue := domain.Issue{+ ID: "iss-unknown-wf", Kind: "requirement",+ SOPBindings: []domain.IssueSOPBinding{{ID: "b-1", WorkflowID: "wf-gone", Order: 1}},+ }+ lanes := buildRequirementLanes(issue, domain.Project{}, nil, nil, nil, map[string]domain.WorkflowDefinition{}, now)+ if len(lanes) != 1 {+ t.Fatalf("lanes=%#v", lanes)+ }+ got := lanes[0]+ if got.WorkflowName != "wf-gone" || got.Label != "wf-gone" {+ t.Fatalf("unknown binding lane should fall back to its id: %#v", got)+ }+ if got.Lane != domain.InferSOPLane(domain.WorkflowDefinition{ID: "wf-gone"}) {+ t.Fatalf("lane classification=%q", got.Lane)+ }+}++// A run whose workflow has left the catalog still gets a lane named after the+// frozen snapshot rather than being dropped.+func TestBuildRequirementLanesKeepsRunSnapshotName(t *testing.T) {+ now := time.Now().UTC()+ frozen := domain.WorkflowDefinition{ID: "wf-frozen", Name: "冻结 SOP", Nodes: []domain.WorkflowNode{{ID: "code", Name: "实现"}}}+ runs := []domain.Run{{+ ID: "run-frozen", WorkflowID: frozen.ID, WorkflowSnapshot: frozen, Status: "succeeded",+ CreatedAt: now, UpdatedAt: now,+ }}+ lanes := buildRequirementLanes(domain.Issue{ID: "iss-frozen"}, domain.Project{}, runs, nil, nil, map[string]domain.WorkflowDefinition{}, now.Add(time.Minute))+ if len(lanes) != 1 {+ t.Fatalf("lanes=%#v", lanes)+ }+ if got := lanes[0]; got.WorkflowName != "冻结 SOP" || got.Label != "冻结 SOP" || !got.Started {+ t.Fatalf("lane=%#v", got)+ }+}