Skip to content

Commit 5cd6afe

Browse files
authored
Merge pull request #1 from OriginTrail/test
update ragas dashbaords and add reports for jenkins failed builds
2 parents cfb2dd7 + 6a722b9 commit 5cd6afe

File tree

5 files changed

+105
-20
lines changed

5 files changed

+105
-20
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
const { publish, defineConfig } = require("test-results-reporter");
2+
const dotenv = require("dotenv");
3+
const path = require("path");
4+
const fs = require("fs");
5+
6+
// Load .env from agent directory
7+
// __dirname is apps/agent/tests/e2e/utils, go up 3 levels to apps/agent
8+
dotenv.config({ path: path.resolve(__dirname, "../../../.env") });
9+
10+
const teamsHookBaseURL = process.env.DKG_Node_Teams_Hook;
11+
const jenkinsUrl = process.env.JENKINS_URL;
12+
13+
// Check if required environment variables are set
14+
if (!teamsHookBaseURL) {
15+
console.error("Error: DKG_Node_Teams_Hook environment variable is not set");
16+
console.error("Please add DKG_Node_Teams_Hook to your .env file in apps/agent/");
17+
process.exit(1);
18+
}
19+
20+
// Check if XML test results file exists
21+
// __dirname is apps/agent/tests/e2e/utils, go up 3 levels to apps/agent
22+
const xmlFilePath = path.resolve(__dirname, "../../../DKG_Node_UI_Tests.xml");
23+
if (!fs.existsSync(xmlFilePath)) {
24+
console.error(`Error: Test results file not found at: ${xmlFilePath}`);
25+
console.error("Please run the UI tests first using: npm run test:e2e");
26+
process.exit(1);
27+
}
28+
29+
// Build extensions array conditionally
30+
const extensions = [
31+
{
32+
name: "quick-chart-test-summary",
33+
},
34+
];
35+
36+
// Only add hyperlinks extension if JENKINS_URL is set
37+
if (jenkinsUrl) {
38+
extensions.push({
39+
name: "hyperlinks",
40+
inputs: {
41+
links: [
42+
{
43+
text: "UI Tests HTML Report",
44+
url: `${jenkinsUrl}/job/DKG-Node-Tests/DKG_20Node_20UI_20Report/*zip*/DKG_20Node_20UI_20Report.zip`,
45+
},
46+
],
47+
},
48+
});
49+
}
50+
51+
const config = defineConfig({
52+
reports: [
53+
{
54+
targets: [
55+
{
56+
name: "teams",
57+
condition: "fail",
58+
inputs: {
59+
url: teamsHookBaseURL,
60+
only_failures: true,
61+
publish: "test-summary-slim",
62+
title: "DKG Node UI Tests Report",
63+
width: "Full",
64+
},
65+
extensions: extensions,
66+
},
67+
],
68+
results: [
69+
{
70+
type: "junit",
71+
files: [xmlFilePath],
72+
},
73+
],
74+
},
75+
],
76+
});
77+
78+
publish({ config });

apps/agent/tests/ragas/dashboard.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ interface EvaluationReport {
3838
}
3939

4040
function getReportsDirectory(): string {
41-
// Use absolute path to project root tests directory
42-
const projectRoot = path.resolve(__dirname, "../../../../"); // Go to project root
43-
return path.join(projectRoot, "tests/ragas/reports");
41+
// Reports are in the same directory structure as dashboard
42+
return path.join(__dirname, "reports");
4443
}
4544

4645
function getAllReports(): any[] {

apps/agent/tests/ragas/evaluate.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -384,15 +384,21 @@ class DkgNodeRagasEvaluator {
384384
const scores = results.scores;
385385
const summary = this.generateSummary(scores);
386386
const recommendations = this.generateRecommendations(scores);
387-
const failures = this.analyzeFailures(results.dataset, scores);
387+
const detailedResults = results.detailedResults;
388+
389+
const timestamp = new Date().toISOString();
390+
const timestampFormatted = timestamp.replace(/[:.]/g, "-");
388391

389392
const report = {
393+
timestamp: timestamp,
390394
scores,
391395
summary,
392396
recommendations,
393-
failures,
394-
thresholds: this.config.thresholds,
395-
timestamp: new Date().toISOString(),
397+
detailedResults: detailedResults,
398+
config: {
399+
thresholds: this.config.thresholds,
400+
metrics: this.config.metrics,
401+
},
396402
};
397403

398404
// Generate different report formats
@@ -401,24 +407,29 @@ class DkgNodeRagasEvaluator {
401407
const dbJson = this.generateDatabaseJSON(scores);
402408

403409
// Save reports to files
404-
const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
405410
const reportsDir = path.join(__dirname, "reports");
411+
const evaluationDir = path.join(reportsDir, `evaluation-${timestampFormatted}`);
406412

407-
// Create reports directory if it doesn't exist
408-
if (!fs.existsSync(reportsDir)) {
409-
fs.mkdirSync(reportsDir, { recursive: true });
413+
// Create evaluation directory
414+
if (!fs.existsSync(evaluationDir)) {
415+
fs.mkdirSync(evaluationDir, { recursive: true });
410416
}
411417

412-
// Save reports
413-
const csvPath = path.join(reportsDir, `ragas-report-${timestamp}.csv`);
418+
// Save main JSON report for dashboard
419+
const jsonReportPath = path.join(evaluationDir, "evaluation-report.json");
420+
fs.writeFileSync(jsonReportPath, JSON.stringify(report, null, 2));
421+
422+
// Save additional formats
423+
const csvPath = path.join(evaluationDir, `ragas-report-${timestampFormatted}.csv`);
414424
fs.writeFileSync(csvPath, csvReport);
415425

416-
const htmlPath = path.join(reportsDir, `ragas-report-${timestamp}.html`);
426+
const htmlPath = path.join(evaluationDir, `ragas-report-${timestampFormatted}.html`);
417427
fs.writeFileSync(htmlPath, htmlReport);
418428

419429
const dbJsonPath = path.join(__dirname, "ragas-results.json");
420430
fs.writeFileSync(dbJsonPath, JSON.stringify(dbJson, null, 2));
421431

432+
console.log(`\n📁 Reports saved to: ${evaluationDir}`);
422433
console.log(`\n🎯 RAGAS Evaluation Summary:`);
423434
console.log(
424435
`Overall Score: ${(summary.overall.averageScore * 100).toFixed(1)}%`,

apps/agent/tests/ragas/show-results.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ interface EvaluationReport {
3434
}
3535

3636
function findLatestReport(): string | null {
37-
// Use absolute path to project root tests directory
38-
const projectRoot = path.resolve(__dirname, "../../../../"); // Go to project root
39-
const reportsDir = path.join(projectRoot, "tests/ragas/reports");
37+
// Reports are in the same directory structure
38+
const reportsDir = path.join(__dirname, "reports");
4039

4140
if (!fs.existsSync(reportsDir)) {
4241
console.log("📁 No reports directory found");

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
"test:e2e": "turbo run test:e2e --filter=@dkg/agent --force",
1616
"test:api": "turbo run test --filter='@dkg/plugin-*' --force",
1717
"test:integration": "cd apps/agent && npm run test:integration",
18-
"test:ui:report": "node report-UI-Tests-config.js",
19-
"test:api:report": "node report-API-Tests-config.js",
20-
"test:integration:report": "node report-Integration-Tests-config.js",
18+
"test:ui:report": "node apps/agent/tests/e2e/utils/report-UI-Tests-config.js",
2119
"ragas:insert:guardian": "RAGAS_SOURCE=guardian node apps/agent/tests/ragas/scripts/insert_ragas_to_db.js",
2220
"ragas:insert:dkg_node": "RAGAS_SOURCE=dkg_node node apps/agent/tests/ragas/scripts/insert_ragas_to_db.js",
2321
"ragas": "cd apps/agent && npm run ragas"

0 commit comments

Comments
 (0)