tests: add lazy-state integration tests - #1506
Open
AchrafReyani wants to merge 1 commit into
Open
Conversation
Adds a methodical set of lazy-state ($) tests to the execute integration suite: basic reads, expressions, object mapping / each / group, scoping rules, and the illegal usages documented on the docs site. Fixes OpenFn#840
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.
Short Description
Adds 21 lazy-state (
$) tests tointegration-tests/execute/test/lazy-state.test.ts, building up from simple reads to expressions, mapping/iteration, scoping rules and illegal usage.Fixes #840
Implementation Details
The new tests are grouped and ordered methodically, following the examples on the Lazy State Operator docs page:
fn($.data)returning a value from state as the next state.&&/||/!, ternary, and$as a dynamic property key (codes[$.location.country]).create('agent', { name: $.patient.name })shape, via a tiny in-jobupserthelper that resolves its argument the wayexpandReferencesdoes),each($.data.items, …), reading the current item with$.datainsideeach(), andgroup($.data.rows, $.keyPath).$declared as a parameter or a localconstis left alone;$inside a string literal is not converted.LazyStateErrormessage: assigning$to a variable, using it inside a nullary arrow, inside an arrow whose parameter isn't namedstate, and writing to$at the top level or inside an operation.No source changes; only the test file is touched. No changeset added since
@openfn/integration-tests-executeis private (same as previous test-only changes here).One thing I noticed while writing these and deliberately left out: a method call on a nested state value, e.g.
fnIf($.name.toUpperCase() === 'JOHN', …), currently compiles to(state => state.name.toUpperCase)() === 'JOHN'– the arrow wraps the callee rather than the call (the special case inensureParentArrowonly handles$.method()directly on state). Happy to open a separate issue for that if useful.QA Notes
Ran in a clean
node:22Linux container (freshpnpm install --frozen-lockfile+pnpm -r --filter=./packages/* run build):Also
tsc --noEmit -p integration-tests/execute/tsconfig.jsonandprettier --checkon the file pass.(Side note, not addressed here: on Windows the whole
executeintegration suite fails before any test runs because the runtime linker buildsfile://C:\…instead of afile:///C:/…URL; CI on Linux is unaffected.)AI Usage