Skip to content

feat(cel): add fold support#156

Merged
yashmehrotra merged 5 commits intomainfrom
fold-support
May 4, 2026
Merged

feat(cel): add fold support#156
yashmehrotra merged 5 commits intomainfrom
fold-support

Conversation

@yashmehrotra
Copy link
Copy Markdown
Member

@yashmehrotra yashmehrotra commented May 4, 2026

Summary by CodeRabbit

Release Notes

  • New Features

    • Added fold functionality to CEL for processing lists and maps with accumulator patterns.
  • Documentation

    • Updated CEL documentation with examples demonstrating fold operations on collections.
  • Tests

    • Added test coverage for fold functionality on lists and maps.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 4, 2026

Warning

Rate limit exceeded

@yashmehrotra has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 54 minutes and 17 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9e41f878-a1e7-49ba-8366-a5264d5dbf51

📥 Commits

Reviewing files that changed from the base of the PR and between b646c24 and 4612f24.

📒 Files selected for processing (1)
  • cel_fold.go

Walkthrough

This PR introduces CEL fold functionality with two independent changes: a new fold library for CEL expressions supporting list and map aggregation patterns, plus documentation examples; and removal of the disabled goconst linter configuration.

Changes

CEL Fold Feature

Layer / File(s) Summary
API Documentation
CEL.md
Added fold examples demonstrating list summation and map value concatenation, with a note that any-typed variables must be wrapped with dyn(...) for CEL comprehension ranges.
Core Fold Implementation
cel_fold.go
New file implementing gomplate.fold CEL library with list and map fold macros that rewrite into comprehensions, plus runtime helpers: foldInitialValue (seeding accumulators), sortedMapEntries (stable key ordering), mergeMaps (right-hand overwrite), and zeroValueForFold (type-appropriate neutral values).
Environment Integration
cel.go
Appended getFoldCelLibrary() to the CEL environment options in GetCelEnv to activate fold macros and functions.
Tests
tests/cel_test.go
Added TestCelFold validating fold over a numeric list, a key/value map, and dynamic objects with JSON output verification.

Linter Configuration Cleanup

Layer / File(s) Summary
Linter Config
.golangci.yml
Removed goconst from the enabled linters list and deleted its dedicated configuration block.

Sequence Diagram

sequenceDiagram
    participant User as User Code
    participant Parser as CEL Parser
    participant Macro as Fold Macro
    participant Comp as CEL Comprehension
    participant Helpers as Runtime Helpers
    participant Result as Result

    User->>Parser: fold(items, acc, expr)
    Parser->>Macro: Invoke fold macro
    Macro->>Macro: Extract identifiers & validate
    Macro->>Helpers: foldInitialValue(items)
    Helpers->>Result: Return seed value
    Macro->>Comp: Generate comprehension<br/>with step expression
    Comp->>Helpers: Call merge() or<br/>accumulator update
    Helpers->>Comp: Return new accumulator
    Comp->>Comp: Iterate over items
    Comp->>Result: Final accumulator value
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'feat(cel): add fold support' accurately summarizes the main objective of the changeset, which introduces fold support to the CEL environment.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fold-support
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fold-support

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 54 minutes and 17 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@yashmehrotra yashmehrotra requested a review from moshloop May 4, 2026 05:45
Comment thread tests/cel_test.go Outdated

out, err := gomplate.RunExpression(map[string]any{
"tags": []map[string]any{
{"key": "application", "value": "IIAB"},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{"key": "application", "value": "IIAB"},
{"key": "application", "value": "ACME"},

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cel_fold.go`:
- Around line 109-112: The temporary fold entry name generation (entryVar) in
cel_fold.go currently only tries a single fallback "__fold_entry2__" and can
still collide with user vars; change the logic that sets entryVar so it
iteratively picks a name that does not conflict with keyVar, valVar, or accuVar
(e.g., "__fold_entry__", "__fold_entry2__", "__fold_entry3__", ...) by
looping/incrementing a suffix until an unused name is found; update any code
that references entryVar to use the chosen unique name.
- Around line 152-157: The code currently picks the fold seed by using
m.Iterator() and taking the first iteration result (it.HasNext()/it.Next()),
which is nondeterministic for Go maps; change foldInitialValue logic to select
the seed deterministically by enumerating map keys (use m.Keys() or collect
entries), convert keys to a stable sortable representation (e.g., string form),
sort them, pick the first sorted key, and then call m.Get(firstKey) to set
first; keep the same conversion to types.DefaultTypeAdapter.NativeToValue(nil)
where needed and update any references to first and foldInitialValue
accordingly.
- Around line 180-182: The comparator used in sort.SliceStable(keys, ...) is not
a total order because it only compares fmt.Sprint(keys[i].Value()) —
different-typed values like int(1) and string("1") stringify the same and can
leave the order undefined; update the comparator for the keys slice (the
sort.SliceStable call) to produce a total ordering by incorporating the value
type before the stringified value (for example using the value's concrete type
name or a type-tag plus the printed value via reflect.TypeOf or
fmt.Sprintf("%T:%v")) so that items with equal printed forms but different types
are ordered deterministically.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cdc9cc48-a9d3-40e9-87e5-07bce712f179

📥 Commits

Reviewing files that changed from the base of the PR and between cac6eb1 and b646c24.

📒 Files selected for processing (5)
  • .golangci.yml
  • CEL.md
  • cel.go
  • cel_fold.go
  • tests/cel_test.go
💤 Files with no reviewable changes (1)
  • .golangci.yml

Comment thread cel_fold.go
Comment thread cel_fold.go Outdated
Comment thread cel_fold.go
@yashmehrotra yashmehrotra merged commit c8f67a2 into main May 4, 2026
7 checks passed
@yashmehrotra yashmehrotra deleted the fold-support branch May 4, 2026 10:36
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.

2 participants