Repository navigation
Conversation
…o early
Sub-expressions (backtick or $(..)) inside an xargs stage were evaluated
depth-first while preparing the stage, before the piped collection existed,
so every iteration shared a single early result and commands like
`render {{score}}` saw the whole upstream collection instead of the
current item.
The interpreter now recognizes an xargs stage containing sub-expressions
and dispatches it unparsed; xargs late-evaluates each $(..) group per
item, inside the *contextual-data* binding that already rebinds to each
item's data. Args with no sub-expressions are dispatched exactly as
before.
See yetibot/yetibot#995
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.
Problem
Closes the evaluation-order half of yetibot/yetibot#995 — Sub expressions in xargs are expanded too early (the interpreter/xargs code lives in this repo; the app repo only carries the issue).
Because the evaluator walks the parse tree depth-first, a sub-expression inside an
xargsstage — e.g.`random`or`render {{score}}`— was evaluated once, before the piped collection reachedxargs:The old
xargscode even documented the dead-end: the item-loopbindingof*contextual-data*"achieves nothing" because the sub-commands "would have been evaluated too early… see #995". This PR makes that binding achieve exactly what it was planted for.Approach
src/yetibot/core/interpreter.clj): when a pipeline stage is structurally anxargscommand whose AST contains at least one:sub-exprnode, skip the depth-first evaluation of that stage and dispatch it with its unparsed text (sub-expressions normalized to$(…)form via the existingunparse-transformer). Detection is structural, so quotes/fences/literals can't fool it.src/yetibot/core/commands/collections.clj): newlate-eval-sub-exprshelper scans the args for$(…)groups (quote-aware, nesting-aware) and evaluates each group, once per item, viaparser/parse-and-eval— inside the*contextual-data*binding that already rebinds to the current item's data. The surrounding command text is untouched, so per-item dispatch works as before.Semantics chosen (per the issue's own framing and
xargs(1)analogy): evaluate once per item. "Evaluate once total" remains expressible by hoisting the sub-expression ahead of the pipe (`random` | xargs …).Stages without sub-expressions — the overwhelmingly common
xargsusage — are dispatched exactly as before, byte for byte.Verification
repeat 3 hello | xargs echotick2` + backtick → counter command fired 3× (once per item; pre-fix: exactly 1×)repeat 3 hello | xargs echorandom+ backtick → three **distinct** values (distinct?` → true)repeat 2 hello | xargs echotick2tick2+ backtick →("2 3 …" "1 4 …")` — two fresh evaluations per item$(…)syntax handled identically;echo a b c | words | xargs echo itemregression unchanged:("item a" "item b" "item c");echo there | echoecho hi+ backtick →"hi there"` (early evaluation preserved outside xargs stages)late-eval-sub-exprs (issue #995)): pass-through (no sub-exprs / blank / nil), quoted$(…)literals untouched, single/multiple/nested group substitution with call-count assertions, error-text substitution, exception fallback.lein with-profile +test midje :all+ Postgres 16): 2730 succeeded (baseline 2717 → +13 = the new checks), and the same 31 pre-existing environment-dependent failures (history/veo specs) as the unmodifiedmasterbaseline run — no regressions introduced.Notes
unparse-transformer,parse-and-eval, and the existing contextual-data binding.Bump yetibot/corePR (e.g. #1339-style) after a core release.