-
Notifications
You must be signed in to change notification settings - Fork 3.6k
improvement(resolver): use context variables for block outputs in function block code #4223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
icecrasher321
merged 37 commits into
simstudioai:staging
from
octo-patch:fix/issue-4195-function-block-context-vars
May 6, 2026
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
0b9019d
v0.6.23: MCP fixes, remove local state in favor of server state, moth…
waleedlatif1 a54dcbe
v0.6.24: copilot feedback wiring, captcha fixes
waleedlatif1 28af223
v0.6.25: cloudwatch, cloudformation, live kb sync, linear fixes, post…
waleedlatif1 d889f32
v0.6.26: ui improvements, multiple response blocks, docx previews, ol…
waleedlatif1 316bc8c
v0.6.27: new triggers, mothership improvements, files archive, queuei…
waleedlatif1 3f508e4
v0.6.28: new docs, delete confirmation standardization, dagster integ…
waleedlatif1 d6ec115
v0.6.29: login improvements, posthog telemetry (#4026)
TheodoreSpeaks d7da35b
v0.6.30: slack trigger enhancements, connectors performance improveme…
waleedlatif1 cf233bb
v0.6.31: elevenlabs voice, trigger.dev fixes, cloud whitelabeling for…
waleedlatif1 f8f3758
v0.6.32: BYOK fixes, ui improvements, cloudwatch tools, jsm tools ext…
waleedlatif1 3c8bb40
v0.6.33: polling improvements, jsm forms tools, credentials reactquer…
waleedlatif1 d33acf4
v0.6.34: trigger.dev fixes, CI speedup, atlassian error extractor
waleedlatif1 4f40c4c
v0.6.35: additional jira fields, HITL docs, logs cleanup efficiency
waleedlatif1 cbfab1c
v0.6.36: new chunkers, sockets state machine, google sheets/drive/cal…
waleedlatif1 4309d06
v0.6.37: audit logs page, isolated-vm worker rotation, permission gro…
waleedlatif1 8b57476
v0.6.38: models page
waleedlatif1 e3d0e74
v0.6.39: billing fixes, tools audit, landing fix
waleedlatif1 0ac0539
v0.6.40: mothership tool loop, new skills, agiloft, STS, IAM integrat…
waleedlatif1 3838b6e
v0.6.41: webhooks fix, workers removal
waleedlatif1 fc07922
v0.6.42: mothership nested file reads, search modal improvements
waleedlatif1 3a1b1a8
v0.6.43: mothership billing idempotency, env var resolution fixes
waleedlatif1 46ffc49
v0.6.44: streamdown, mothership intelligence, excel extension
waleedlatif1 010435c
v0.6.45: superagent, csp, brightdata integration, gemini response for…
Sg312 c0bc62c
Merge pull request #4190 from simstudioai/staging
icecrasher321 387cc97
v0.6.46: mothership queueing, web vitals
waleedlatif1 2dbc7fd
v0.6.47: files focusing, documentation, opus 4.7
waleedlatif1 8a50f18
v0.6.48: import csv into tables, subflow fixes, CSP updates
waleedlatif1 dcf3302
v0.6.49: deploy sockets event, resolver, logs improvements, monday.co…
waleedlatif1 6734052
fix: use context variables for block outputs in function block code
2783606
fix: address Cursor and Greptile bot review comments
19787e1
fix: shell block references and complex env value serialization
7d972ae
fix lint
icecrasher321 4d695cf
review pass
icecrasher321 3208e07
ignore shell comments
icecrasher321 665bb91
Merge branch 'staging' into fix/issue-4195-function-block-context-vars
icecrasher321 a6be984
update contract
icecrasher321 5def77c
fix tests
icecrasher321 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| /** | ||
| * @vitest-environment node | ||
| */ | ||
| import { describe, expect, it } from 'vitest' | ||
| import { BlockType } from '@/executor/constants' | ||
| import { ExecutionState } from '@/executor/execution/state' | ||
| import type { ExecutionContext } from '@/executor/types' | ||
| import { VariableResolver } from '@/executor/variables/resolver' | ||
| import type { SerializedBlock, SerializedWorkflow } from '@/serializer/types' | ||
|
|
||
| function createBlock(id: string, name: string, type: string, params = {}): SerializedBlock { | ||
| return { | ||
| id, | ||
| metadata: { id: type, name }, | ||
| position: { x: 0, y: 0 }, | ||
| config: { tool: type, params }, | ||
| inputs: {}, | ||
| outputs: { | ||
| result: 'string', | ||
| items: 'json', | ||
| }, | ||
| enabled: true, | ||
| } | ||
| } | ||
|
|
||
| function createResolver(language = 'javascript') { | ||
| const producer = createBlock('producer', 'Producer', BlockType.API) | ||
| const functionBlock = createBlock('function', 'Function', BlockType.FUNCTION, { | ||
| language, | ||
| }) | ||
| const workflow: SerializedWorkflow = { | ||
| version: '1', | ||
| blocks: [producer, functionBlock], | ||
| connections: [], | ||
| loops: {}, | ||
| parallels: {}, | ||
| } | ||
| const state = new ExecutionState() | ||
| state.setBlockOutput('producer', { | ||
| result: 'hello world', | ||
| items: ['a', 'b'], | ||
| }) | ||
| const ctx = { | ||
| blockStates: state.getBlockStates(), | ||
| blockLogs: [], | ||
| environmentVariables: {}, | ||
| workflowVariables: {}, | ||
| decisions: { router: new Map(), condition: new Map() }, | ||
| loopExecutions: new Map(), | ||
| executedBlocks: new Set(), | ||
| activeExecutionPath: new Set(), | ||
| completedLoops: new Set(), | ||
| metadata: {}, | ||
| } as ExecutionContext | ||
|
|
||
| return { | ||
| block: functionBlock, | ||
| ctx, | ||
| resolver: new VariableResolver(workflow, {}, state), | ||
| } | ||
| } | ||
|
|
||
| describe('VariableResolver function block inputs', () => { | ||
| it('returns empty inputs when params are missing', () => { | ||
| const { block, ctx, resolver } = createResolver() | ||
|
|
||
| const result = resolver.resolveInputsForFunctionBlock(ctx, 'function', undefined, block) | ||
|
|
||
| expect(result).toEqual({ resolvedInputs: {}, contextVariables: {} }) | ||
| }) | ||
|
|
||
| it('resolves JavaScript block references through globalThis context variables', () => { | ||
| const { block, ctx, resolver } = createResolver('javascript') | ||
|
|
||
| const result = resolver.resolveInputsForFunctionBlock( | ||
| ctx, | ||
| 'function', | ||
| { code: 'return <Producer.result>' }, | ||
| block | ||
| ) | ||
|
|
||
| expect(result.resolvedInputs.code).toBe('return globalThis["__blockRef_0"]') | ||
| expect(result.contextVariables).toEqual({ __blockRef_0: 'hello world' }) | ||
| }) | ||
|
|
||
| it('resolves Python block references through globals lookup', () => { | ||
| const { block, ctx, resolver } = createResolver('python') | ||
|
|
||
| const result = resolver.resolveInputsForFunctionBlock( | ||
| ctx, | ||
| 'function', | ||
| { code: 'return <Producer.result>' }, | ||
| block | ||
| ) | ||
|
|
||
| expect(result.resolvedInputs.code).toBe('return globals()["__blockRef_0"]') | ||
| expect(result.contextVariables).toEqual({ __blockRef_0: 'hello world' }) | ||
| }) | ||
|
|
||
| it('uses separate Python context variables for repeated mutable references', () => { | ||
| const { block, ctx, resolver } = createResolver('python') | ||
|
|
||
| const result = resolver.resolveInputsForFunctionBlock( | ||
| ctx, | ||
| 'function', | ||
| { code: 'a = <Producer.items>\nb = <Producer.items>\nreturn b' }, | ||
| block | ||
| ) | ||
|
|
||
| expect(result.resolvedInputs.code).toBe( | ||
| 'a = globals()["__blockRef_0"]\nb = globals()["__blockRef_1"]\nreturn b' | ||
| ) | ||
| expect(result.contextVariables).toEqual({ | ||
| __blockRef_0: ['a', 'b'], | ||
| __blockRef_1: ['a', 'b'], | ||
| }) | ||
| }) | ||
|
|
||
| it('uses shell-safe expansions for block references', () => { | ||
| const { block, ctx, resolver } = createResolver('shell') | ||
|
|
||
| const result = resolver.resolveInputsForFunctionBlock( | ||
| ctx, | ||
| 'function', | ||
| { code: 'echo <Producer.result>suffix && echo "<Producer.result>"' }, | ||
| block | ||
| ) | ||
|
|
||
| expect(result.resolvedInputs.code).toBe( | ||
| `echo "\${__blockRef_0}"suffix && echo "\${__blockRef_1}"` | ||
| ) | ||
| expect(result.contextVariables).toEqual({ | ||
| __blockRef_0: 'hello world', | ||
| __blockRef_1: 'hello world', | ||
| }) | ||
| }) | ||
|
|
||
| it('ignores shell comment quotes when formatting later block references', () => { | ||
| const { block, ctx, resolver } = createResolver('shell') | ||
|
|
||
| const result = resolver.resolveInputsForFunctionBlock( | ||
| ctx, | ||
| 'function', | ||
| { code: "# don't confuse quote tracking\necho <Producer.result>" }, | ||
| block | ||
| ) | ||
|
|
||
| expect(result.resolvedInputs.code).toBe( | ||
| `# don't confuse quote tracking\necho "\${__blockRef_0}"` | ||
| ) | ||
| expect(result.contextVariables).toEqual({ __blockRef_0: 'hello world' }) | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.