Make task_cost_check test resilient to changes in order (#204045)

## Summary

Addresses failures such as
https://buildkite.com/elastic/kibana-pull-request/builds/259739#0193bb07-c759-4749-965e-10e63ac0810a.

We believe the order in which task types are registered might have been
affected by the relocation of the
`@kbn/observability-ai-assistant-app-plugin` in the scope of
_Sustainable Kibana Architecture_.
This commit is contained in:
Gerard Soldevila 2024-12-12 17:50:03 +01:00 committed by GitHub
parent 2ab38a3664
commit a4e4a6061b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 74 additions and 70 deletions

View file

@ -2,26 +2,82 @@
exports[`Task cost checks detects tasks with cost definitions 1`] = `
Array [
Object {
"cost": 1,
"taskType": "actions:.bedrock",
},
Object {
"cost": 1,
"taskType": "actions:.cases",
},
Object {
"cost": 1,
"taskType": "actions:.cases-webhook",
},
Object {
"cost": 1,
"taskType": "actions:.crowdstrike",
},
Object {
"cost": 1,
"taskType": "actions:.d3security",
},
Object {
"cost": 1,
"taskType": "actions:.email",
},
Object {
"cost": 1,
"taskType": "actions:.gemini",
},
Object {
"cost": 1,
"taskType": "actions:.gen-ai",
},
Object {
"cost": 1,
"taskType": "actions:.index",
},
Object {
"cost": 1,
"taskType": "actions:.jira",
},
Object {
"cost": 1,
"taskType": "actions:.observability-ai-assistant",
},
Object {
"cost": 1,
"taskType": "actions:.opsgenie",
},
Object {
"cost": 1,
"taskType": "actions:.pagerduty",
},
Object {
"cost": 1,
"taskType": "actions:.swimlane",
"taskType": "actions:.resilient",
},
Object {
"cost": 1,
"taskType": "actions:.sentinelone",
},
Object {
"cost": 1,
"taskType": "actions:.server-log",
},
Object {
"cost": 1,
"taskType": "actions:.servicenow",
},
Object {
"cost": 1,
"taskType": "actions:.servicenow-itom",
},
Object {
"cost": 1,
"taskType": "actions:.servicenow-sir",
},
Object {
"cost": 1,
"taskType": "actions:.slack",
@ -32,31 +88,7 @@ Array [
},
Object {
"cost": 1,
"taskType": "actions:.webhook",
},
Object {
"cost": 1,
"taskType": "actions:.cases-webhook",
},
Object {
"cost": 1,
"taskType": "actions:.xmatters",
},
Object {
"cost": 1,
"taskType": "actions:.servicenow",
},
Object {
"cost": 1,
"taskType": "actions:.servicenow-sir",
},
Object {
"cost": 1,
"taskType": "actions:.servicenow-itom",
},
Object {
"cost": 1,
"taskType": "actions:.jira",
"taskType": "actions:.swimlane",
},
Object {
"cost": 1,
@ -64,11 +96,7 @@ Array [
},
Object {
"cost": 1,
"taskType": "actions:.torq",
},
Object {
"cost": 1,
"taskType": "actions:.opsgenie",
"taskType": "actions:.thehive",
},
Object {
"cost": 1,
@ -76,43 +104,15 @@ Array [
},
Object {
"cost": 1,
"taskType": "actions:.gen-ai",
"taskType": "actions:.torq",
},
Object {
"cost": 1,
"taskType": "actions:.bedrock",
"taskType": "actions:.webhook",
},
Object {
"cost": 1,
"taskType": "actions:.gemini",
},
Object {
"cost": 1,
"taskType": "actions:.d3security",
},
Object {
"cost": 1,
"taskType": "actions:.resilient",
},
Object {
"cost": 1,
"taskType": "actions:.thehive",
},
Object {
"cost": 1,
"taskType": "actions:.sentinelone",
},
Object {
"cost": 1,
"taskType": "actions:.crowdstrike",
},
Object {
"cost": 1,
"taskType": "actions:.cases",
},
Object {
"cost": 1,
"taskType": "actions:.observability-ai-assistant",
"taskType": "actions:.xmatters",
},
Object {
"cost": 10,

View file

@ -12,6 +12,7 @@ import {
import { TaskCost, TaskDefinition } from '../task';
import { setupTestServers } from './lib';
import { TaskTypeDictionary } from '../task_type_dictionary';
import { sortBy } from 'lodash';
jest.mock('../task_type_dictionary', () => {
const actual = jest.requireActual('../task_type_dictionary');
@ -50,14 +51,17 @@ describe('Task cost checks', () => {
it('detects tasks with cost definitions', async () => {
const taskTypes = taskTypeDictionary.getAllDefinitions();
const taskTypesWithCost = taskTypes
.map((taskType: TaskDefinition) =>
!!taskType.cost ? { taskType: taskType.type, cost: taskType.cost } : null
)
.filter(
(tt: { taskType: string; cost: TaskCost } | null) =>
null != tt && tt.cost !== TaskCost.Normal
);
const taskTypesWithCost = sortBy(
taskTypes
.map((taskType: TaskDefinition) =>
!!taskType.cost ? { taskType: taskType.type, cost: taskType.cost } : null
)
.filter(
(tt: { taskType: string; cost: TaskCost } | null) =>
null != tt && tt.cost !== TaskCost.Normal
),
'taskType'
);
expect(taskTypesWithCost).toMatchSnapshot();
});
});