eda: reduce complexity in bootstrap.go loadWorkflows and routing.go LoadPlaybookDirs #439

Closed
opened 2026-10-27 13:36:20 +00:00 by sam · 0 comments
Owner

task check now runs golangci-lint (Sam's explicit requirement, 2026-09-03 -- catch lint regressions as part of the definitive gate, not just fmt/vet/build/test). First run surfaced two real findings, both accumulated debt from this session's own EDA slices, not pre-existing:

  1. internal/app/archied/bootstrap.go:647 loadWorkflows -- cyclomatic complexity 17, max 15 (cyclop). Grew incrementally across t2db.9 (kindWorkflows), t2db.10 (labelWorkflows), t2db.11 (PlaybookDirs merge), t2db.15 (EDAPlaybookDir) -- each addition was small, the function as a whole crossed the threshold.
  2. internal/domain/workflow/routing.go:103 LoadPlaybookDirs -- cognitive complexity 52, max 30 (gocognit), from t2db.11's directory-merge loader (kind-vs-label detection, per-file and cross-file collision checks all inline).

Root-cause fix required, not suppression: no //nolint. Extract cohesive sub-steps into named helper functions -- this is exactly the kind of case AGENTS.md's Architectural Simplicity rule describes (prefer a clean extraction over papering past a threshold).

Design

For loadWorkflows: extract the four independent load-and-set steps (kind-file load, label-file load, playbook-dirs load+merge, EDAPlaybookDir load) into named helpers the top-level function calls in sequence, each returning its own error for the existing log-and-abort pattern. Do not change the log-and-abort error-handling shape or field names.

For LoadPlaybookDirs: split the per-file parsing loop's kind-detection-vs-label-detection-vs-collision-check logic into a couple of named helpers (e.g. classifyBinding, checkCollision) called from the main loop, keeping the existing collision error messages and behavior byte-identical -- this is a pure refactor, not a behavior change.

Acceptance criteria

golangci-lint run ./... reports zero cyclop/gocognit findings on these two functions. All existing tests for workflow.LoadPlaybookDirs, kindWorkflows, labelWorkflows, and bootstrap's loadWorkflows-adjacent behavior pass unchanged (byte-identical collision error messages -- diff the exact strings, do not just check err != nil). task check (now including lint) passes fully.

Close reason

Verified landed: boot.loadWorkflowRouting extracted; LoadPlaybookDirs decomposed into sortedPlaybookFilenames/loadPlaybookFile.


Imported from beads archie-core-t2db.16 · GitHub #738 · type task · priority P2 · created 2026-09-02 · closed 2026-09-11

task check now runs golangci-lint (Sam's explicit requirement, 2026-09-03 -- catch lint regressions as part of the definitive gate, not just fmt/vet/build/test). First run surfaced two real findings, both accumulated debt from this session's own EDA slices, not pre-existing: 1. internal/app/archied/bootstrap.go:647 loadWorkflows -- cyclomatic complexity 17, max 15 (cyclop). Grew incrementally across t2db.9 (kindWorkflows), t2db.10 (labelWorkflows), t2db.11 (PlaybookDirs merge), t2db.15 (EDAPlaybookDir) -- each addition was small, the function as a whole crossed the threshold. 2. internal/domain/workflow/routing.go:103 LoadPlaybookDirs -- cognitive complexity 52, max 30 (gocognit), from t2db.11's directory-merge loader (kind-vs-label detection, per-file and cross-file collision checks all inline). Root-cause fix required, not suppression: no //nolint. Extract cohesive sub-steps into named helper functions -- this is exactly the kind of case AGENTS.md's Architectural Simplicity rule describes (prefer a clean extraction over papering past a threshold). ### Design For loadWorkflows: extract the four independent load-and-set steps (kind-file load, label-file load, playbook-dirs load+merge, EDAPlaybookDir load) into named helpers the top-level function calls in sequence, each returning its own error for the existing log-and-abort pattern. Do not change the log-and-abort error-handling shape or field names. For LoadPlaybookDirs: split the per-file parsing loop's kind-detection-vs-label-detection-vs-collision-check logic into a couple of named helpers (e.g. classifyBinding, checkCollision) called from the main loop, keeping the existing collision error messages and behavior byte-identical -- this is a pure refactor, not a behavior change. ### Acceptance criteria golangci-lint run ./... reports zero cyclop/gocognit findings on these two functions. All existing tests for workflow.LoadPlaybookDirs, kindWorkflows, labelWorkflows, and bootstrap's loadWorkflows-adjacent behavior pass unchanged (byte-identical collision error messages -- diff the exact strings, do not just check err != nil). task check (now including lint) passes fully. ### Close reason Verified landed: boot.loadWorkflowRouting extracted; LoadPlaybookDirs decomposed into sortedPlaybookFilenames/loadPlaybookFile. --- _Imported from beads `archie-core-t2db.16` · GitHub #738 · type task · priority P2 · created 2026-09-02 · closed 2026-09-11_
sam added the mediumtask labels 2026-10-27 13:36:20 +00:00
sam self-assigned this 2026-10-27 13:36:20 +00:00
sam closed this issue 2026-10-27 13:36:20 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sam/archie#439