-
Notifications
You must be signed in to change notification settings - Fork 3.5k
fix(resolver): turn off resolver for opaque schema nodes, unrun paths #4208
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
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| /** | ||
| * @vitest-environment node | ||
| */ | ||
| import { describe, expect, it, vi } from 'vitest' | ||
| import type { ExecutionContext } from '@/executor/types' | ||
| import type { VariableResolver } from '@/executor/variables/resolver' | ||
| import { resolveArrayInput } from './subflow-utils' | ||
|
icecrasher321 marked this conversation as resolved.
|
||
|
|
||
| describe('resolveArrayInput', () => { | ||
| const fakeCtx = {} as unknown as ExecutionContext | ||
|
|
||
| it('returns arrays as-is', () => { | ||
| expect(resolveArrayInput(fakeCtx, [1, 2, 3], null)).toEqual([1, 2, 3]) | ||
| }) | ||
|
|
||
| it('converts plain objects to entries', () => { | ||
| expect(resolveArrayInput(fakeCtx, { a: 1, b: 2 }, null)).toEqual([ | ||
| ['a', 1], | ||
| ['b', 2], | ||
| ]) | ||
| }) | ||
|
|
||
| it('returns empty array when a pure reference resolves to null (skipped block)', () => { | ||
| // `resolveSingleReference` returns `null` for a reference that points at a | ||
| // block that exists in the workflow but did not execute on this path. | ||
| // A loop/parallel over such a reference should run zero iterations rather | ||
| // than fail the workflow. | ||
| const resolver = { | ||
| resolveSingleReference: vi.fn().mockReturnValue(null), | ||
| } as unknown as VariableResolver | ||
|
|
||
| const result = resolveArrayInput(fakeCtx, '<SkippedBlock.result.items>', resolver) | ||
|
|
||
| expect(result).toEqual([]) | ||
| expect(resolver.resolveSingleReference).toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('returns the array from a pure reference that resolved to an array', () => { | ||
| const resolver = { | ||
| resolveSingleReference: vi.fn().mockReturnValue([1, 2, 3]), | ||
| } as unknown as VariableResolver | ||
|
|
||
| expect(resolveArrayInput(fakeCtx, '<Block.items>', resolver)).toEqual([1, 2, 3]) | ||
| }) | ||
|
|
||
| it('converts resolved objects to entries', () => { | ||
| const resolver = { | ||
| resolveSingleReference: vi.fn().mockReturnValue({ x: 1, y: 2 }), | ||
| } as unknown as VariableResolver | ||
|
|
||
| expect(resolveArrayInput(fakeCtx, '<Block.obj>', resolver)).toEqual([ | ||
| ['x', 1], | ||
| ['y', 2], | ||
| ]) | ||
| }) | ||
|
|
||
| it('throws when a pure reference resolves to a non-array, non-object, non-null value', () => { | ||
| const resolver = { | ||
| resolveSingleReference: vi.fn().mockReturnValue(42), | ||
| } as unknown as VariableResolver | ||
|
|
||
| expect(() => resolveArrayInput(fakeCtx, '<Block.count>', resolver)).toThrow( | ||
| /did not resolve to an array or object/ | ||
| ) | ||
| }) | ||
|
|
||
| it('throws when a pure reference resolves to undefined (unknown block)', () => { | ||
| // `undefined` means the reference could not be matched to any block at | ||
| // all (typo / deleted block). This must still fail loudly. | ||
| const resolver = { | ||
| resolveSingleReference: vi.fn().mockReturnValue(undefined), | ||
| } as unknown as VariableResolver | ||
|
|
||
| expect(() => resolveArrayInput(fakeCtx, '<Missing.items>', resolver)).toThrow( | ||
| /did not resolve to an array or object/ | ||
| ) | ||
| }) | ||
|
|
||
| it('parses a JSON array string', () => { | ||
| expect(resolveArrayInput(fakeCtx, '[1, 2, 3]', null)).toEqual([1, 2, 3]) | ||
| }) | ||
|
|
||
| it('throws on a string that is neither a reference nor valid JSON array/object', () => { | ||
| expect(() => resolveArrayInput(fakeCtx, 'not json', null)).toThrow() | ||
| }) | ||
| }) | ||
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
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.