Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 72 additions & 20 deletions .github/scripts/aggregate-example-results.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,44 +48,88 @@ function loadResultsFromDir(resultsDir) {
return results;
}

/**
* Formats a status badge for GitHub step summary tables.
*
* @param {string} status - Raw workload execution status string.
* @returns {string} Formatted emoji badge.
*/
function formatStatusBadge(status) {
if (status === 'PASSED') {
return '✅ PASSED';
}
if (status === 'SKIPPED') {
return '⏭️ SKIPPED';
}
return '❌ FAILED';
}

/**
* Aggregates result objects into an XID mapping and markdown summary.
* Supports both trigger-only results ({id, name, status, xid}) and E2E results
* ({id, name, status, launch_status, verify_status, xid}).
*
* @param {Array<object>} results - Array of result objects { id, name, status, xid }.
* @param {Array<object>} results - Array of result objects.
* @param {object} [options]
* @param {string} [options.title] - Optional custom markdown title.
* @returns {{ xidMap: Record<string, string>, summaryMarkdown: string, allPassed: boolean }}
*/
function aggregateResults(results) {
function aggregateResults(results, { title } = {}) {
const xidMap = {};
let allPassed = true;

const isE2E = results.some(
r => r && (r.launch_status !== undefined || r.verify_status !== undefined)
);

for (const r of results) {
if (r && r.xid && r.xid !== 'skipped' && r.xid !== 'N/A') {
xidMap[r.id] = r.xid;
}
if (r && r.status === 'FAILED') {
if (r && (r.status === 'FAILED' || r.status === 'VERIFY_FAILED' || (r.status !== 'PASSED' && r.status !== 'SKIPPED'))) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The condition (r.status === 'FAILED' || r.status === 'VERIFY_FAILED' || (r.status !== 'PASSED' && r.status !== 'SKIPPED')) contains redundant checks. If r.status is not 'PASSED' and not 'SKIPPED', it already covers 'FAILED' and 'VERIFY_FAILED'. The entire expression can be simplified to just r.status !== 'PASSED' && r.status !== 'SKIPPED'.

Suggested change
if (r && (r.status === 'FAILED' || r.status === 'VERIFY_FAILED' || (r.status !== 'PASSED' && r.status !== 'SKIPPED'))) {
if (r && r.status !== 'PASSED' && r.status !== 'SKIPPED') {

allPassed = false;
}
}

const defaultTitle = isE2E
? '## 🌟 Nightly Examples E2E Test Suite Summary\n'
: '## 🌟 All Example Workloads Execution Summary\n';

const summaryLines = [
'## 🌟 All Example Workloads Execution Summary\n',
title || defaultTitle,
allPassed
? '### ✅ Overall Status: ALL PASSED\n'
: '### ⚠️ Overall Status: SOME WORKLOADS FAILED\n',
'| Example ID | Name | Status | Experiment / Identifier |',
'| --- | --- | --- | --- |'
: '### ⚠️ Overall Status: SOME WORKLOADS FAILED\n'
];

for (const r of results) {
const id = r.id || '';
const name = r.name || '';
const status = r.status || '';
const xid = r.xid || '';
const statusBadge = status === 'PASSED'
? '✅ PASSED'
: (status === 'SKIPPED' ? '⏭️ SKIPPED' : '❌ FAILED');

summaryLines.push(`| \`${id}\` | ${name} | ${statusBadge} | \`${xid}\` |`);
if (isE2E) {
summaryLines.push('| Example ID | Name | Overall Status | Launch | Verify | Experiment / Identifier |');
summaryLines.push('| --- | --- | --- | --- | --- | --- |');

for (const r of results) {
const id = r.id || '';
const name = r.name || '';
const statusBadge = formatStatusBadge(r.status);
const launchStatus = r.launch_status || '';
const verifyStatus = r.verify_status || '';
const xid = r.xid || '';

summaryLines.push(
`| \`${id}\` | ${name} | ${statusBadge} | \`${launchStatus}\` | \`${verifyStatus}\` | \`${xid}\` |`
);
}
} else {
summaryLines.push('| Example ID | Name | Status | Experiment / Identifier |');
summaryLines.push('| --- | --- | --- | --- |');

for (const r of results) {
const id = r.id || '';
const name = r.name || '';
const statusBadge = formatStatusBadge(r.status);
const xid = r.xid || '';

summaryLines.push(`| \`${id}\` | ${name} | ${statusBadge} | \`${xid}\` |`);
}
}

const summaryMarkdown = summaryLines.join('\n') + '\n';
Expand All @@ -99,22 +143,25 @@ function aggregateResults(results) {
* @param {string} [options.resultsDir='results']
* @param {string} [options.stepSummaryPath]
* @param {string} [options.githubOutputPath]
* @param {string} [options.title]
* @returns {{ results: Array<object>, xidMap: Record<string, string>, summaryMarkdown: string, allPassed: boolean }}
*/
function run({
resultsDir = 'results',
stepSummaryPath = process.env.GITHUB_STEP_SUMMARY,
githubOutputPath = process.env.GITHUB_OUTPUT
githubOutputPath = process.env.GITHUB_OUTPUT,
title
} = {}) {
const results = loadResultsFromDir(resultsDir);
const { xidMap, summaryMarkdown, allPassed } = aggregateResults(results);
const { xidMap, summaryMarkdown, allPassed } = aggregateResults(results, { title });

if (stepSummaryPath) {
fs.appendFileSync(stepSummaryPath, summaryMarkdown, 'utf8');
}

const xidsJson = JSON.stringify(xidMap);
console.log(`Aggregated launched_xids: ${xidsJson}`);
console.log(summaryMarkdown);

if (githubOutputPath) {
fs.appendFileSync(githubOutputPath, `launched_xids=${xidsJson}\n`, 'utf8');
Expand All @@ -124,11 +171,16 @@ function run({
}

if (require.main === module) {
run();
const { allPassed } = run();
if (!allPassed) {
console.error('::error::One or more example workloads failed launch or verification.');
process.exit(1);
}
}

module.exports = {
loadResultsFromDir,
formatStatusBadge,
aggregateResults,
run
};
126 changes: 124 additions & 2 deletions .github/scripts/aggregate-example-results.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,22 @@ const assert = require('node:assert');
const fs = require('node:fs');
const path = require('node:path');
const os = require('node:os');
const { spawnSync } = require('node:child_process');
const {
loadResultsFromDir,
formatStatusBadge,
aggregateResults,
run
} = require('./aggregate-example-results');

test('formatStatusBadge returns appropriate badge for each status', () => {
assert.strictEqual(formatStatusBadge('PASSED'), '✅ PASSED');
assert.strictEqual(formatStatusBadge('SKIPPED'), '⏭️ SKIPPED');
assert.strictEqual(formatStatusBadge('FAILED'), '❌ FAILED');
assert.strictEqual(formatStatusBadge('VERIFY_FAILED'), '❌ FAILED');
assert.strictEqual(formatStatusBadge('UNKNOWN'), '❌ FAILED');
});

test('loadResultsFromDir returns empty array when directory does not exist', () => {
const nonExistent = path.join(os.tmpdir(), 'xmc-non-existent-dir-' + Date.now());
const results = loadResultsFromDir(nonExistent);
Expand Down Expand Up @@ -71,7 +81,7 @@ test('loadResultsFromDir gracefully handles malformed JSON files', () => {
}
});

test('aggregateResults builds correct xidMap and passes status when all workloads pass', () => {
test('aggregateResults builds 4-column table for trigger-only results', () => {
const results = [
{ id: 'simple_job', name: 'Simple Multi-Unit Job', status: 'PASSED', xid: '6018' },
{ id: 'sidecar', name: 'Sidecar Container Job', status: 'PASSED', xid: '6019' },
Expand All @@ -85,12 +95,14 @@ test('aggregateResults builds correct xidMap and passes status when all workload
simple_job: '6018',
sidecar: '6019'
});
assert.ok(summaryMarkdown.includes('## 🌟 All Example Workloads Execution Summary'));
assert.ok(summaryMarkdown.includes('### ✅ Overall Status: ALL PASSED'));
assert.ok(summaryMarkdown.includes('| Example ID | Name | Status | Experiment / Identifier |'));
assert.ok(summaryMarkdown.includes('| `simple_job` | Simple Multi-Unit Job | ✅ PASSED | `6018` |'));
assert.ok(summaryMarkdown.includes('| `skipped_job` | Skipped Job | ⏭️ SKIPPED | `skipped` |'));
});

test('aggregateResults marks allPassed false when any workload fails', () => {
test('aggregateResults marks allPassed false when any trigger workload fails', () => {
const results = [
{ id: 'simple_job', name: 'Simple Multi-Unit Job', status: 'PASSED', xid: '6018' },
{ id: 'failed_job', name: 'Failed Job', status: 'FAILED', xid: 'N/A' }
Expand All @@ -104,6 +116,58 @@ test('aggregateResults marks allPassed false when any workload fails', () => {
assert.ok(summaryMarkdown.includes('| `failed_job` | Failed Job | ❌ FAILED | `N/A` |'));
});

test('aggregateResults builds 6-column table for E2E suite results', () => {
const results = [
{
id: 'simple_job',
name: 'Simple Job (3 Multi-Unit Batch)',
status: 'PASSED',
launch_status: 'success',
verify_status: 'success',
xid: '8001'
},
{
id: 'sidecar',
name: 'Sidecar Container Job',
status: 'VERIFY_FAILED',
launch_status: 'success',
verify_status: 'failure',
xid: '8002'
},
{
id: 'skipped_job',
name: 'Skipped Job',
status: 'SKIPPED',
launch_status: 'skipped',
verify_status: 'skipped',
xid: 'skipped'
}
];

const { xidMap, summaryMarkdown, allPassed } = aggregateResults(results);

assert.strictEqual(allPassed, false);
assert.deepStrictEqual(xidMap, {
simple_job: '8001',
sidecar: '8002'
});
assert.ok(summaryMarkdown.includes('## 🌟 Nightly Examples E2E Test Suite Summary'));
assert.ok(summaryMarkdown.includes('### ⚠️ Overall Status: SOME WORKLOADS FAILED'));
assert.ok(summaryMarkdown.includes('| Example ID | Name | Overall Status | Launch | Verify | Experiment / Identifier |'));
assert.ok(summaryMarkdown.includes('| --- | --- | --- | --- | --- | --- |'));
assert.ok(summaryMarkdown.includes('| `simple_job` | Simple Job (3 Multi-Unit Batch) | ✅ PASSED | `success` | `success` | `8001` |'));
assert.ok(summaryMarkdown.includes('| `sidecar` | Sidecar Container Job | ❌ FAILED | `success` | `failure` | `8002` |'));
assert.ok(summaryMarkdown.includes('| `skipped_job` | Skipped Job | ⏭️ SKIPPED | `skipped` | `skipped` | `skipped` |'));
});

test('aggregateResults uses custom title when provided', () => {
const results = [
{ id: 'simple_job', name: 'Simple Job', status: 'PASSED', xid: '9000' }
];
const { summaryMarkdown } = aggregateResults(results, { title: '## Custom Test Summary\n' });
assert.ok(summaryMarkdown.startsWith('## Custom Test Summary\n'));
});

test('run entrypoint writes to GITHUB_STEP_SUMMARY and GITHUB_OUTPUT files', () => {
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'xmc-run-test-'));
const resultsDir = path.join(tmpDir, 'results');
Expand Down Expand Up @@ -136,3 +200,61 @@ test('run entrypoint writes to GITHUB_STEP_SUMMARY and GITHUB_OUTPUT files', ()
fs.rmSync(tmpDir, { recursive: true, force: true });
}
});

test('CLI execution exits with code 0 on all workloads passing', () => {
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'xmc-cli-pass-test-'));
const resultsDir = path.join(tmpDir, 'results');
const scriptPath = path.join(__dirname, 'aggregate-example-results.js');

try {
fs.mkdirSync(resultsDir);
fs.writeFileSync(
path.join(resultsDir, 'job1.json'),
JSON.stringify({ id: 'job1', name: 'Job One', status: 'PASSED', xid: '1234' })
);

const proc = spawnSync(process.execPath, [scriptPath], {
cwd: tmpDir,
encoding: 'utf8'
});

assert.strictEqual(proc.status, 0);
assert.ok(proc.stdout.includes('Aggregated launched_xids: {"job1":"1234"}'));
} finally {
fs.rmSync(tmpDir, { recursive: true, force: true });
}
});

test('CLI execution exits with code 1 and error annotation when workloads fail', () => {
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'xmc-cli-fail-test-'));
const resultsDir = path.join(tmpDir, 'results');
const scriptPath = path.join(__dirname, 'aggregate-example-results.js');

try {
fs.mkdirSync(resultsDir);
fs.writeFileSync(
path.join(resultsDir, 'job1.json'),
JSON.stringify({
id: 'job1',
name: 'Job One',
status: 'VERIFY_FAILED',
launch_status: 'success',
verify_status: 'failure',
xid: '1234'
})
);

const proc = spawnSync(process.execPath, [scriptPath], {
cwd: tmpDir,
encoding: 'utf8'
});

assert.strictEqual(proc.status, 1);
assert.ok(
proc.stderr.includes('::error::One or more example workloads failed launch or verification.')
);
} finally {
fs.rmSync(tmpDir, { recursive: true, force: true });
}
});

Loading
Loading