fix(loop): C063 loop options audit — 6 discrepancy fixes#270
Merged
Conversation
- `CHANGELOG.md`: Document C063 6-finding audit with per-finding descriptions - `CLAUDE.md`: Add rule on deletion-before-test ordering - `docs/reference/interpolation.md`: Fix ~13 lowercase loop vars to PascalCase - `docs/reference/loop.md`: Fix ~20 lowercase loop vars to PascalCase - `docs/user-guide/examples.md`: Fix 3 lowercase loop var references - `docs/user-guide/workflow-syntax.md`: Fix ~15 lowercase vars; expand while loop context table; fix break_when/while/max_iterations descriptions - `internal/application/loop_executor.go`: Preserve Parent chain in ExecuteForEach; add `%` to arithmetic operator detection - `internal/application/loop_executor_mocks_test.go`: Capture Parent field in stepExecutorRecorder - `internal/application/loop_executor_refactor_test.go`: Add 6 modulo operator test cases - `internal/application/loop_foreach_test.go`: Add 3 tests for buildContext equivalence and Parent chain preservation - `internal/application/loop_iterations_test.go`: Update modulo test from negative to positive assertion - `pkg/interpolation/template_resolver.go`: Add index1 and parent keys to makeLoopAccessor via loopToMap helper - `pkg/interpolation/template_resolver_test.go`: Add 7 tests for index1 and parent accessor behavior Closes #264
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
loop.item,loop.index) corrected to PascalCase (loop.Item,loop.Index) across 4 doc filesindex1andparentkeys tomakeLoopAccessorintemplate_resolver.go, enabling{{.loop.Index1}}and{{.loop.Parent.*}}to resolve correctly in templates%) expressions inmax_iterationswere not routed to the arithmetic evaluator, causing them to be parsed as literal integers and failParentchain being silently dropped:ExecuteForEachnow preserves theParentfield frombuildContextoutput or falls back tobuildLoopDataChainon the domain contextChanges
Documentation
docs/reference/interpolation.md: Replaced all lowercase loop variable references with PascalCase; updated nested parent access examplesdocs/reference/loop.md: Replaced lowercase loop variable references with PascalCase across all examples and reference tablesdocs/user-guide/workflow-syntax.md: Updated for_each and while loop context tables (addedIndex1,Last,Item,Parentrows); corrected variable casing; replaced invalid arithmeticmax_iterationsexample with single-variable form; improvedwhile/break_whenfield descriptionsdocs/user-guide/examples.md: Corrected loop variable casing in for_each and nested loop examplesCHANGELOG.md: Added C063 entry detailing all 6 findings and code changesCLAUDE.md: Added convention: apply code deletions before writing tests that validate the deletion effectImplementation
pkg/interpolation/template_resolver.go: ExtractedloopToMap()helper; addedindex1(Index+1) andparent(recursive map or nil) to loop accessor mapinternal/application/loop_executor.go: Added%tostrings.ContainsAnyoperator detection inparseMaxIterationsValue; updatedExecuteForEachto preserve theParentchain frombuildContextoutput, with fallback tobuildLoopDataChainfrom domain contextTests
pkg/interpolation/template_resolver_test.go: New file — tests forindex1(0-based, large),parentnil/value/recursive access, error on missing loop, and complex parent item serializationinternal/application/loop_executor_refactor_test.go: Added modulo test case to table-driven suite; added 5 standalone tests covering modulo detection, error handling, and complex expressionsinternal/application/loop_foreach_test.go: Added 3 tests forbuildContextequivalence verification, single-level parent nil assertion, and full iteration variable correctness after removing the redundant overrideinternal/application/loop_iterations_test.go: UpdatedTestLoopExecutor_ResolveMaxIterations_ArithmeticModulofrom negative test (expecting error) to positive test (expecting2)internal/application/loop_executor_mocks_test.go: AddedParentfield capture tostepExecutorRecorderTest plan
go test ./pkg/interpolation/... ./internal/application/...{{.loop.Index1}}and{{.loop.Parent.Item}}resolve correctly in a real nestedfor_eachworkflowmax_iterations: "{{inputs.a % inputs.b}}"evaluates correctly (e.g.,7 % 3→ 1 iteration)make testCloses #264
Generated with awf commit workflow