-
Notifications
You must be signed in to change notification settings - Fork 3.8k
improvement(logs-block): filter runs by trigger type #6824
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
Show all changes
5 commits
Select commit
Hold shift + click to select a range
92264bf
improvement(logs-block): filter runs by trigger type
waleedlatif1 9f2469d
fix(logs-block): declare the triggers input as the string it becomes
waleedlatif1 fd50a97
fix(logs-block): trim each entry when joining filter ids
waleedlatif1 e1b61f5
test(logs-block): lock the shared joinIds output for existing filters
waleedlatif1 70e6841
test(logs-block): exercise the trigger options against the real registry
waleedlatif1 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| /** | ||
| * @vitest-environment node | ||
| */ | ||
| import { describe, expect, it, vi } from 'vitest' | ||
|
|
||
| vi.mock('@/lib/workflows/subblocks/options', () => ({ | ||
| fetchTriggerTypeOptions: vi.fn(), | ||
| fetchWorkspaceWorkflowOptions: vi.fn(), | ||
| })) | ||
|
|
||
| import { LogsV2Block } from '@/blocks/blocks/logs' | ||
|
|
||
| function buildQueryParams(params: Record<string, unknown>) { | ||
| return LogsV2Block.tools.config!.params!({ operation: 'query', ...params }) | ||
| } | ||
|
|
||
| describe('LogsV2Block trigger filter', () => { | ||
| it('omits triggers when the filter is untouched, leaving pre-existing queries unfiltered', () => { | ||
| expect(buildQueryParams({}).triggers).toBeUndefined() | ||
| expect(buildQueryParams({ triggers: [] }).triggers).toBeUndefined() | ||
| expect(buildQueryParams({ triggers: '' }).triggers).toBeUndefined() | ||
| }) | ||
|
|
||
| it('joins a multi-select selection into the comma-separated list the API expects', () => { | ||
| expect(buildQueryParams({ triggers: ['api', 'schedule'] }).triggers).toBe('api,schedule') | ||
| }) | ||
|
|
||
| it('flattens a merged option id so one label can select several trigger values', () => { | ||
| expect(buildQueryParams({ triggers: ['api', 'copilot,mothership'] }).triggers).toBe( | ||
| 'api,copilot,mothership' | ||
| ) | ||
| }) | ||
|
|
||
| it('accepts an advanced-mode string of provider ids', () => { | ||
| expect(buildQueryParams({ triggers: ' slack,gmail ' }).triggers).toBe('slack,gmail') | ||
| }) | ||
|
|
||
| it('trims each hand-typed entry, not just the ends of the string', () => { | ||
| // The filters split on commas without trimming, so a surviving space would | ||
| // match no stored trigger and silently narrow the result set to nothing. | ||
| expect(buildQueryParams({ triggers: 'api, schedule, slack' }).triggers).toBe( | ||
| 'api,schedule,slack' | ||
| ) | ||
| expect(buildQueryParams({ triggers: 'api,,schedule,' }).triggers).toBe('api,schedule') | ||
| expect(buildQueryParams({ triggers: ' , ' }).triggers).toBeUndefined() | ||
| }) | ||
|
|
||
| it('trims entries inside a multi-select selection too', () => { | ||
| expect(buildQueryParams({ triggers: ['api ', ' copilot, mothership'] }).triggers).toBe( | ||
| 'api,copilot,mothership' | ||
| ) | ||
| }) | ||
|
|
||
| it('never sends triggers on the run-details operation', () => { | ||
| expect( | ||
| LogsV2Block.tools.config!.params!({ | ||
| operation: 'get_run_details', | ||
| runId: 'run-1', | ||
| triggers: ['api'], | ||
| }) | ||
| ).toEqual({ runId: 'run-1' }) | ||
| }) | ||
| }) | ||
|
|
||
| describe('LogsV2Block backwards compatibility', () => { | ||
| // `joinIds` is shared with the pre-existing workflow and status filters, so the | ||
| // per-entry trimming added for hand-typed triggers must not move their output. | ||
| // Every value a stored multi-select or advanced field can hold is listed here: | ||
| // option ids and workflow ids contain neither spaces nor commas. | ||
| const UUID = '3f2504e0-4f89-11d3-9a0c-0305e82c3301' | ||
|
|
||
| it.each([ | ||
| ['unset', undefined, undefined], | ||
| ['empty selection', [], undefined], | ||
| ['one workflow', [UUID], UUID], | ||
| [ | ||
| 'two workflows', | ||
| [UUID, 'b7a1c2d3-0000-4000-8000-000000000001'], | ||
| `${UUID},b7a1c2d3-0000-4000-8000-000000000001`, | ||
| ], | ||
| ['advanced string', 'id-one,id-two', 'id-one,id-two'], | ||
| ['empty string', '', undefined], | ||
| ])('leaves workflowIds untouched for %s', (_name, value, expected) => { | ||
| expect(buildQueryParams({ workflowIds: value }).workflowIds).toBe(expected) | ||
| }) | ||
|
|
||
| it.each([ | ||
| ['unset', undefined, undefined], | ||
| ['empty selection', [], undefined], | ||
| ['one status', ['info'], 'info'], | ||
| ['several statuses', ['info', 'error', 'cancelled'], 'info,error,cancelled'], | ||
| ])('leaves level untouched for %s', (_name, value, expected) => { | ||
| expect(buildQueryParams({ level: value }).level).toBe(expected) | ||
| }) | ||
|
|
||
| it('omits triggers entirely for a block saved before the filter existed', () => { | ||
| const params = buildQueryParams({ workflowIds: [UUID], level: ['info'] }) | ||
| expect(params.triggers).toBeUndefined() | ||
| // Undefined values are dropped on serialization, so nothing reaches the query. | ||
| expect(JSON.stringify(params)).not.toContain('triggers') | ||
| }) | ||
| }) | ||
|
|
||
| describe('LogsV2Block trigger subblocks', () => { | ||
| const subBlockIds = LogsV2Block.subBlocks.map((subBlock) => subBlock.id) | ||
|
|
||
| it('declares triggers as the string it is transformed into', () => { | ||
| // The generic handler JSON.parses any post-transform input declared 'array' or | ||
| // 'json', so declaring the joined string as an array would warn on every run | ||
| // and would turn JSON-looking advanced input into an array the tool rejects. | ||
| expect(LogsV2Block.inputs.triggers.type).toBe('string') | ||
| expect(typeof buildQueryParams({ triggers: ['api', 'schedule'] }).triggers).toBe('string') | ||
| }) | ||
|
|
||
| it('exposes basic and advanced modes behind one canonical param', () => { | ||
| expect(subBlockIds).toContain('triggerSelector') | ||
| expect(subBlockIds).toContain('manualTriggers') | ||
|
|
||
| for (const id of ['triggerSelector', 'manualTriggers']) { | ||
| const subBlock = LogsV2Block.subBlocks.find((candidate) => candidate.id === id) | ||
| expect(subBlock?.canonicalParamId).toBe('triggers') | ||
| expect(subBlock?.condition).toEqual({ field: 'operation', value: 'query' }) | ||
| } | ||
| }) | ||
| }) |
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
30 changes: 30 additions & 0 deletions
30
apps/sim/lib/workflows/subblocks/trigger-options-live.test.ts
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,30 @@ | ||
| /** | ||
| * @vitest-environment node | ||
| */ | ||
| import { describe, expect, it } from 'vitest' | ||
| import { fetchTriggerTypeOptions } from '@/lib/workflows/subblocks/options' | ||
|
|
||
| /** | ||
| * Exercises the real block and trigger registries rather than a mock: the | ||
| * fetcher reaches them through a lazy import specifically to avoid an | ||
| * initialization cycle, and a mocked test cannot show that the import resolves | ||
| * or that the registry is populated by the time the dropdown asks for options. | ||
| */ | ||
| describe('fetchTriggerTypeOptions against the real registry', () => { | ||
| it('resolves the lazy import into a populated list of unique labels', async () => { | ||
| const options = await fetchTriggerTypeOptions() | ||
|
|
||
| expect(options.length).toBeGreaterThan(10) | ||
| expect(options.every((option) => option.id.length > 0 && option.label.length > 0)).toBe(true) | ||
|
|
||
| const labels = options.map((option) => option.label) | ||
| expect(new Set(labels).size).toBe(labels.length) | ||
| }) | ||
|
|
||
| it('merges the two Sim agent trigger values behind one option', async () => { | ||
| const options = await fetchTriggerTypeOptions() | ||
|
|
||
| expect(options.find((option) => option.label === 'Sim agent')?.id).toBe('copilot,mothership') | ||
| expect(options.find((option) => option.label === 'API')?.id).toBe('api') | ||
| }) | ||
| }) |
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.