Skip to content

feat(stepfunctions): real UpdateExpression eval for dynamodb:updateItem#762

Merged
vieiralucas merged 3 commits intomainfrom
worktree-batch6-stepfn-updateitem
Apr 25, 2026
Merged

feat(stepfunctions): real UpdateExpression eval for dynamodb:updateItem#762
vieiralucas merged 3 commits intomainfrom
worktree-batch6-stepfn-updateitem

Conversation

@vieiralucas
Copy link
Copy Markdown
Member

@vieiralucas vieiralucas commented Apr 25, 2026

Summary

  • Replaces the simplified Key + ExpressionAttributeValues merge with a real UpdateExpression evaluator that parses up to four clauses in any order (SET, REMOVE, ADD, DELETE)
  • SET supports path = :v, path = path + :inc, path = path - :dec, and path = if_not_exists(path, :default)
  • ADD is numeric increment with implicit initialization when the attribute is absent
  • DELETE subtracts set elements from SS / NS / BS and drops the attribute when the resulting set is empty
  • DynamoDB number wire format ({"N":"<str>"}) preserved on arithmetic; comma splitting respects parentheses so if_not_exists(a, :b) doesn't fragment assignments

Test plan

  • 7 new unit tests: SET arithmetic increment + decrement, REMOVE, ADD existing + absent, DELETE set elements, if_not_exists both branches, multi-clause SET ... ADD ... REMOVE
  • All 137 existing fakecloud-stepfunctions tests still green (legacy set keyword + alias attribute names included)
  • cargo clippy --workspace --all-targets -- -D warnings clean
  • cargo fmt --check clean

Summary by cubic

Adds a real DynamoDB UpdateExpression evaluator for dynamodb:updateItem, supporting SET, REMOVE, ADD, and DELETE. Fixes incorrect merges so increments, conditional sets, attribute removal, and set deletes follow DynamoDB semantics.

  • New Features

    • Parses clauses in any order and splits on top-level commas (parentheses respected).
    • SET: assign value, arithmetic +/-, and if_not_exists.
    • ADD: numeric increment; initializes when absent.
    • DELETE: removes elements from SS/NS/BS; drops the attribute when empty.
    • Preserves DynamoDB number wire format and upserts from Key when no item exists.
  • Bug Fixes

    • Number formatting: range-checks f64 before i64 cast and uses an exclusive i64::MAX bound to avoid truncation or saturation on large whole numbers.

Written for commit 29b99c0. Summary will update on new commits.

Step Functions Task -> dynamodb:updateItem previously merged Key + the
ExpressionAttributeValues map directly into the existing item, ignoring
the UpdateExpression's clause structure. Counter increments, conditional
set operations, attribute removal, and set deletes all silently failed
or wrote the wrong shape.

The new evaluator parses up to four clauses (SET, REMOVE, ADD, DELETE)
in any order, splitting the body of each on top-level commas (so commas
inside `if_not_exists(a, :b)` don't fragment assignments), and supports:

- SET path = :v, SET path = path + :inc, SET path = path - :dec
- SET path = if_not_exists(path, :default)
- REMOVE path1, path2
- ADD path :n (numeric increment, initializes when absent)
- DELETE path :elements (subtract elements from SS/NS/BS sets, drop the
  attribute if the resulting set is empty)

DynamoDB number wire format ({"N":"<str>"}) is preserved on arithmetic.

Nine unit tests cover each clause, mixed-clause expressions, increment,
decrement, if_not_exists in both branches, and set element removal.
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="crates/fakecloud-stepfunctions/src/interpreter.rs">

<violation number="1" location="crates/fakecloud-stepfunctions/src/interpreter.rs:1619">
P2: `n as i64` saturates for whole-number f64 values outside the i64 range, silently corrupting the formatted number. Add a range check before the cast.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread crates/fakecloud-stepfunctions/src/interpreter.rs
Cubic flagged saturating cast in format_number — large whole-number f64
values outside i64 range silently truncated. Add MIN/MAX bounds check;
fall through to default f64 formatting when out of range.
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="crates/fakecloud-stepfunctions/src/interpreter.rs">

<violation number="1" location="crates/fakecloud-stepfunctions/src/interpreter.rs:1618">
P2: The inclusive `f64` bound check still allows `2^63`, which then saturates on `as i64` and formats to an incorrect value.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread crates/fakecloud-stepfunctions/src/interpreter.rs Outdated
Cubic flagged inclusive bound: `i64::MAX as f64` rounds up to 2^63
(i64::MAX is 2^63-1, not exactly representable). Casting 2^63 back to
i64 saturates. Use `n < i64::MAX as f64` so saturating values fall
through to default f64 formatting.
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 25, 2026

Codecov Report

❌ Patch coverage is 92.23602% with 25 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/fakecloud-stepfunctions/src/interpreter.rs 92.23% 25 Missing ⚠️

📢 Thoughts on this report? Let us know!

@vieiralucas vieiralucas merged commit 1fc0413 into main Apr 25, 2026
22 checks passed
@vieiralucas vieiralucas deleted the worktree-batch6-stepfn-updateitem branch April 25, 2026 20:52
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.

1 participant