Skip to content

Commit

Permalink
chore: use failure analysis endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ASaiAnudeep committed Oct 19, 2024
1 parent e7e7b35 commit b2881f0
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 23 deletions.
14 changes: 14 additions & 0 deletions src/beats/beats.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ class BeatsApi {
}
});
}

/**
*
* @param {string} run_id
* @returns {import('./beats.types').IFailureAnalysisMetric[]}
*/
getFailureAnalysis(run_id) {
return request.get({
url: `${this.getBaseUrl()}/api/core/v1/test-runs/${run_id}/failure-analysis`,
headers: {
'x-api-key': this.config.api_key
}
});
}
}

module.exports = { BeatsApi }
3 changes: 2 additions & 1 deletion src/beats/beats.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,12 @@ class Beats {
try {
logger.info('🪄 Fetching Failure Analysis...');
await this.#setTestRun('Failure Analysis Status', 'failure_analysis_status');
const metrics = await this.api.getFailureAnalysis(this.test_run_id);
this.config.extensions.push({
name: 'failure-analysis',
hook: HOOK.AFTER_SUMMARY,
inputs: {
data: this.test_run
data: metrics
}
});
} catch (error) {
Expand Down
12 changes: 6 additions & 6 deletions src/beats/beats.types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ export type IBeatExecutionMetric = {
added: number
removed: number
flaky: number
product_bugs: number
environment_issues: number
automation_bugs: number
not_a_defects: number
to_investigate: number
auto_analysed: number
failure_summary: any
failure_summary_provider: any
failure_summary_model: any
Expand All @@ -38,3 +32,9 @@ export type IErrorCluster = {
failure: string
count: number
}

export type IFailureAnalysisMetric = {
id: string
name: string
count: number
}
29 changes: 15 additions & 14 deletions src/extensions/failure-analysis.extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,29 @@ class FailureAnalysisExtension extends BaseExtension {
}

#setText() {
const data = this.extension.inputs.data;
if (!data) {
return;
}

/**
* @type {import('../beats/beats.types').IBeatExecutionMetric}
* @type {import('../beats/beats.types').IFailureAnalysisMetric[]}
*/
const execution_metrics = data.execution_metrics[0];

if (!execution_metrics) {
logger.warn('⚠️ No execution metrics found. Skipping.');
const metrics = this.extension.inputs.data;
if (!metrics || metrics.length === 0) {
logger.warn('⚠️ No failure analysis metrics found. Skipping.');
return;
}

const to_investigate = metrics.find(metric => metric.name === 'To Investigate');
const auto_analysed = metrics.find(metric => metric.name === 'Auto Analysed');

const failure_analysis = [];

if (execution_metrics.to_investigate) {
failure_analysis.push(`🔎 To Investigate: ${execution_metrics.to_investigate}`);
if (to_investigate && to_investigate.count > 0) {
failure_analysis.push(`🔎 To Investigate: ${to_investigate.count}`);
}
if (auto_analysed && auto_analysed.count > 0) {
failure_analysis.push(`🪄 Auto Analysed: ${auto_analysed.count}`);
}
if (execution_metrics.auto_analysed) {
failure_analysis.push(`🪄 Auto Analysed: ${execution_metrics.auto_analysed}`);

if (failure_analysis.length === 0) {
return;
}

this.text = failure_analysis.join('    ');
Expand Down
4 changes: 3 additions & 1 deletion test/beats.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ describe('TestBeats', () => {
const id1 = mock.addInteraction('post test results to beats');
const id2 = mock.addInteraction('get test results with failure analysis from beats');
const id3 = mock.addInteraction('get empty error clusters from beats');
const id4 = mock.addInteraction('post test-summary with beats to teams with ai failure summary and smart analysis and failure analysis');
const id4 = mock.addInteraction('get failure analysis from beats');
const id5 = mock.addInteraction('post test-summary with beats to teams with ai failure summary and smart analysis and failure analysis');
await publish({
config: {
api_key: 'api-key',
Expand Down Expand Up @@ -262,6 +263,7 @@ describe('TestBeats', () => {
assert.equal(mock.getInteraction(id2).exercised, true);
assert.equal(mock.getInteraction(id3).exercised, true);
assert.equal(mock.getInteraction(id4).exercised, true);
assert.equal(mock.getInteraction(id5).exercised, true);
});

});
24 changes: 23 additions & 1 deletion test/mocks/beats.mock.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { addInteractionHandler } = require('pactum').handler;
const { like, includes } = require('pactum-matchers');

addInteractionHandler('post test results to beats', () => {
return {
Expand Down Expand Up @@ -155,6 +154,29 @@ addInteractionHandler('get empty error clusters from beats', () => {
}
});

addInteractionHandler('get failure analysis from beats', () => {
return {
strict: false,
request: {
method: 'GET',
path: '/api/core/v1/test-runs/test-run-id/failure-analysis'
},
response: {
status: 200,
body: [
{
name: 'To Investigate',
count: 1
},
{
name: 'Auto Analysed',
count: 1
}
]
}
}
});

addInteractionHandler('upload attachments', () => {
return {
strict: false,
Expand Down

0 comments on commit b2881f0

Please sign in to comment.