feat(core): Add support for partial-match execution filters (#15797)

This commit is contained in:
Daria
2025-06-04 09:37:35 +03:00
committed by GitHub
parent 7639cfbaa7
commit 1335af05d5
8 changed files with 99 additions and 21 deletions

View File

@@ -80,6 +80,10 @@ export const schemaGetExecutionsQueryFilter = {
type: 'string',
},
value: { type: 'string' },
exactMatch: {
type: 'boolean',
default: true,
},
},
},
},
@@ -244,7 +248,7 @@ export class ExecutionService {
async delete(req: ExecutionRequest.Delete, sharedWorkflowIds: string[]) {
const { deleteBefore, ids, filters: requestFiltersRaw } = req.body;
let requestFilters;
let requestFilters: IGetExecutionsQueryFilter | undefined;
if (requestFiltersRaw) {
try {
Object.keys(requestFiltersRaw).map((key) => {

View File

@@ -270,21 +270,22 @@ describe('ExecutionService', () => {
]);
});
test('should filter executions by `metadata`', async () => {
test('should filter executions by `metadata` with an exact match by default', async () => {
const workflow = await createWorkflow();
const metadata = [{ key: 'myKey', value: 'myValue' }];
const key = 'myKey';
const value = 'myValue';
await Promise.all([
createExecution({ status: 'success', metadata }, workflow),
createExecution({ status: 'error' }, workflow),
createExecution({ status: 'success', metadata: [{ key, value }] }, workflow),
createExecution({ status: 'error', metadata: [{ key, value: `${value}2` }] }, workflow),
]);
const query: ExecutionSummaries.RangeQuery = {
kind: 'range',
range: { limit: 20 },
accessibleWorkflowIds: [workflow.id],
metadata,
metadata: [{ key, value, exactMatch: true }],
};
const output = await executionService.findRangeWithCount(query);
@@ -296,6 +297,36 @@ describe('ExecutionService', () => {
});
});
test('should filter executions by `metadata` with a partial match', async () => {
const workflow = await createWorkflow();
const key = 'myKey';
await Promise.all([
createExecution({ status: 'success', metadata: [{ key, value: 'myValue' }] }, workflow),
createExecution({ status: 'error', metadata: [{ key, value: 'var' }] }, workflow),
createExecution({ status: 'success', metadata: [{ key, value: 'evaluation' }] }, workflow),
]);
const query: ExecutionSummaries.RangeQuery = {
kind: 'range',
range: { limit: 20 },
accessibleWorkflowIds: [workflow.id],
metadata: [{ key, value: 'val', exactMatch: false }],
};
const output = await executionService.findRangeWithCount(query);
expect(output).toEqual({
count: 2,
estimated: false,
results: [
expect.objectContaining({ status: 'success' }),
expect.objectContaining({ status: 'success' }),
],
});
});
test('should filter executions by `projectId`', async () => {
const firstProject = await createTeamProject();
const secondProject = await createTeamProject();