Skip to content

refactor: extract microflow anchor selection helpers#325

Open
hjotha wants to merge 1 commit intomendixlabs:mainfrom
hjotha:refactor/builder-extract-anchor-helpers
Open

refactor: extract microflow anchor selection helpers#325
hjotha wants to merge 1 commit intomendixlabs:mainfrom
hjotha:refactor/builder-extract-anchor-helpers

Conversation

@hjotha
Copy link
Copy Markdown
Contributor

@hjotha hjotha commented Apr 26, 2026

Part of #332.

Closes #324.

Summary

Extracts duplicated microflow builder anchor selection logic into two helpers. This is a no-behavior-change refactor intended to make follow-up anchor/handler fixes smaller and easier to review.

Root cause

Several builder paths repeated the same precedence checks inline for pending anchors, branch anchors, and statement anchors.

Refactor

  • Add branchDestinationAnchor.
  • Add pendingFlowAnchors.
  • Route existing IF and graph construction call sites through the helpers.

Behavior

No behavior change intended. Behavior-changing fixes remain in separate branches.

Tests

No new behavior tests added because this only extracts existing logic. Existing tests cover the affected paths.

Validation

  • make build
  • make test
  • make lint-go
  • make test-integration

Agentic Code Testing

  • No user-facing syntax or behavior change.
  • Existing test suite covers the refactored builder paths.

Test plan

  • Full test suite remains green after refactor.

Symptom: microflow builder code duplicated the same pending-anchor and branch-destination selection logic in multiple flow construction paths.

Root cause: each call site expanded the precedence checks inline, making follow-up handler and branch fixes harder to review independently.

Fix: add branchDestinationAnchor and pendingFlowAnchors helpers, then route the existing graph and IF first-branch call sites through them while preserving the current origin/main anchor precedence.

Tests: make build and make test both pass. This is a no-behaviour-change refactor; behaviour-changing branch-anchor precedence fixes stay in downstream audit branches.
@github-actions
Copy link
Copy Markdown

AI Code Review

Critical Issues

None found.

Moderate Issues

None found.

Minor Issues

None found.

What Looks Good

  • Refactor quality: The duplicated anchor selection logic has been cleanly extracted into two well-named helper functions (branchDestinationAnchor and pendingFlowAnchors). The refactor is applied consistently across all identified call sites in the microflow builder.
  • Scope adherence: This is a pure refactor with no behavior changes, as stated and validated. The PR description clearly limits the scope to extracting duplicated logic.
  • Test coverage: Existing tests cover the refactored paths (confirmed by validation checklist: make test, make test-integration pass). No new behavior tests were needed per the refactor nature.
  • Code placement: Helpers are added to cmd_microflows_builder_flows.go alongside the existing applyUserAnchors function, which is logical and maintains cohesion.
  • Validation: Author verified build, test, lint, and integration tests pass. Agentic checks confirm no user-facing syntax/behavior change and existing test coverage.
  • Pattern consistency: All instances of the original inline anchor precedence checks have been replaced with the helpers, eliminating duplication without altering control flow.

Recommendation

Approve. The refactor improves code maintainability with zero behavior risk, follows the project's atomic commit principles, and has been thoroughly validated. No changes are needed.


Automated review via OpenRouter (Nemotron Super 120B) — workflow source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Microflow builder anchor precedence is duplicated across flow construction paths

2 participants