Skip to content

Commit

Permalink
feat(core): Initial TestRunner service with basic test execution (no-…
Browse files Browse the repository at this point in the history
…changelog) (#11735)
  • Loading branch information
burivuhster authored Nov 26, 2024
1 parent 6b23ad0 commit 845ba6c
Show file tree
Hide file tree
Showing 10 changed files with 661 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,13 @@ export class ExecutionRepository extends Repository<ExecutionEntity> {
if (!queryParams.relations) {
queryParams.relations = [];
}
(queryParams.relations as string[]).push('executionData', 'metadata');

if (Array.isArray(queryParams.relations)) {
queryParams.relations.push('executionData', 'metadata');
} else {
queryParams.relations.executionData = true;
queryParams.relations.metadata = true;
}
}

const executions = await this.find(queryParams);
Expand Down
22 changes: 21 additions & 1 deletion packages/cli/src/evaluation/test-definitions.controller.ee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
testDefinitionCreateRequestBodySchema,
testDefinitionPatchRequestBodySchema,
} from '@/evaluation/test-definition.schema';
import { TestRunnerService } from '@/evaluation/test-runner/test-runner.service.ee';
import { listQueryMiddleware } from '@/middlewares';
import { getSharedWorkflowIds } from '@/public-api/v1/handlers/workflows/workflows.service';

Expand All @@ -16,7 +17,10 @@ import { TestDefinitionsRequest } from './test-definitions.types.ee';

@RestController('/evaluation/test-definitions')
export class TestDefinitionsController {
constructor(private readonly testDefinitionService: TestDefinitionService) {}
constructor(
private readonly testDefinitionService: TestDefinitionService,
private readonly testRunnerService: TestRunnerService,
) {}

@Get('/', { middlewares: listQueryMiddleware })
async getMany(req: TestDefinitionsRequest.GetMany) {
Expand Down Expand Up @@ -125,4 +129,20 @@ export class TestDefinitionsController {

return testDefinition;
}

@Post('/:id/run')
async runTest(req: TestDefinitionsRequest.Run, res: express.Response) {
const { id: testDefinitionId } = req.params;

const workflowIds = await getSharedWorkflowIds(req.user, ['workflow:read']);

// Check test definition exists
const testDefinition = await this.testDefinitionService.findOne(testDefinitionId, workflowIds);
if (!testDefinition) throw new NotFoundError('Test definition not found');

// We do not await for the test run to complete
void this.testRunnerService.runTest(req.user, testDefinition);

res.status(202).json({ success: true });
}
}
2 changes: 2 additions & 0 deletions packages/cli/src/evaluation/test-definitions.types.ee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ export declare namespace TestDefinitionsRequest {
>;

type Delete = AuthenticatedRequest<RouteParams.TestId>;

type Run = AuthenticatedRequest<RouteParams.TestId>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
{
"startData": {},
"resultData": {
"runData": {
"When clicking ‘Test workflow’": [
{
"hints": [],
"startTime": 1731079118048,
"executionTime": 0,
"source": [],
"executionStatus": "success",
"data": {
"main": [
[
{
"json": {
"query": "First item"
},
"pairedItem": {
"item": 0
}
},
{
"json": {
"query": "Second item"
},
"pairedItem": {
"item": 0
}
},
{
"json": {
"query": "Third item"
},
"pairedItem": {
"item": 0
}
}
]
]
}
}
],
"Edit Fields": [
{
"hints": [],
"startTime": 1731079118049,
"executionTime": 0,
"source": [
{
"previousNode": "When clicking ‘Test workflow’"
}
],
"executionStatus": "success",
"data": {
"main": [
[
{
"json": {
"foo": "bar"
},
"pairedItem": {
"item": 0
}
},
{
"json": {
"foo": "bar"
},
"pairedItem": {
"item": 1
}
},
{
"json": {
"foo": "bar"
},
"pairedItem": {
"item": 2
}
}
]
]
}
}
],
"Code": [
{
"hints": [],
"startTime": 1731079118049,
"executionTime": 3,
"source": [
{
"previousNode": "Edit Fields"
}
],
"executionStatus": "success",
"data": {
"main": [
[
{
"json": {
"foo": "bar",
"random": 0.6315509336851373
},
"pairedItem": {
"item": 0
}
},
{
"json": {
"foo": "bar",
"random": 0.3336315687359024
},
"pairedItem": {
"item": 1
}
},
{
"json": {
"foo": "bar",
"random": 0.4241870158917733
},
"pairedItem": {
"item": 2
}
}
]
]
}
}
]
},
"pinData": {
"When clicking ‘Test workflow’": [
{
"json": {
"query": "First item"
},
"pairedItem": {
"item": 0
}
},
{
"json": {
"query": "Second item"
},
"pairedItem": {
"item": 0
}
},
{
"json": {
"query": "Third item"
},
"pairedItem": {
"item": 0
}
}
]
},
"lastNodeExecuted": "Code"
},
"executionData": {
"contextData": {},
"nodeExecutionStack": [],
"metadata": {},
"waitingExecution": {},
"waitingExecutionSource": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
"name": "Evaluation Workflow",
"nodes": [
{
"parameters": {},
"id": "285ac92b-256f-4bb2-a450-6486b01593cb",
"name": "Execute Workflow Trigger",
"type": "n8n-nodes-base.executeWorkflowTrigger",
"typeVersion": 1,
"position": [520, 340]
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict",
"version": 2
},
"conditions": [
{
"id": "9d3abc8d-3270-4bec-9a59-82622d5dbb5a",
"leftValue": "={{ $json.actual.Code[0].data.main[0].length }}",
"rightValue": 3,
"operator": {
"type": "number",
"operation": "gte"
}
},
{
"id": "894ce84b-13a4-4415-99c0-0c25182903bb",
"leftValue": "={{ $json.actual.Code[0].data.main[0][0].json.random }}",
"rightValue": 0.7,
"operator": {
"type": "number",
"operation": "lt"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "320b0355-3886-41df-b039-4666bf28e47b",
"name": "If",
"type": "n8n-nodes-base.if",
"typeVersion": 2.2,
"position": [740, 340]
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "3b65d55a-158f-40c6-9853-a1c44b7ba1e5",
"name": "success",
"value": true,
"type": "boolean"
}
]
},
"options": {}
},
"id": "0c7a1ee8-0cf0-4d7f-99a3-186bbcd8815a",
"name": "Success",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [980, 220]
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "6cc8b402-4a30-4873-b825-963a1f1b8b82",
"name": "success",
"value": false,
"type": "boolean"
}
]
},
"options": {}
},
"id": "50d3f84a-d99f-4e04-bdbd-3e8c2668e708",
"name": "Fail",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [980, 420]
}
],
"connections": {
"Execute Workflow Trigger": {
"main": [
[
{
"node": "If",
"type": "main",
"index": 0
}
]
]
},
"If": {
"main": [
[
{
"node": "Success",
"type": "main",
"index": 0
}
],
[
{
"node": "Fail",
"type": "main",
"index": 0
}
]
]
}
},
"pinData": {}
}
Loading

0 comments on commit 845ba6c

Please sign in to comment.