Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | 12x 12x 2x 10x 2x 8x 2x 6x 6x 6x 6x 12x 12x 2x 4x 12x 12x 12x 4x 4x 1x 3x 3x | /**
* @module Infrastructure/Rss/Validator
* @category Intelligence Operations / Supporting Infrastructure
* @name rss.xml structural validator
*
* @description
* Cheap structural checks on the generated XML: declaration, RSS 2.0
* version, `<channel>`, mandatory channel children, item count, and
* per-item presence of `<title>`, `<link>`, `<guid>`. Throws a
* descriptive error on the first failed check so the CLI exits with
* status 1 in CI.
*
* Round-6 split: extracted from `scripts/generate-rss.ts`.
*
* @author Hack23 AB (Infrastructure Team)
* @license Apache-2.0
*/
/**
* Validate the structural integrity of an RSS XML string. Returns
* `true` on success and throws on the first failed check.
*/
export function validateRss(xml: string): boolean {
console.log('✅ Validating RSS feed...');
if (!xml.includes('<?xml version="1.0"')) {
throw new Error('Invalid XML declaration');
}
if (!xml.includes('<rss version="2.0"')) {
throw new Error('Missing RSS 2.0 version');
}
if (!xml.includes('<channel>')) {
throw new Error('Missing <channel> element');
}
Iif (!xml.includes('<title>')) {
throw new Error('Missing <title> element');
}
Iif (!xml.includes('<link>')) {
throw new Error('Missing <link> element');
}
Iif (!xml.includes('<description>')) {
throw new Error('Missing <description> element');
}
const itemCount = (xml.match(/<item>/g) || []).length;
console.log(` Found ${itemCount} items in RSS feed`);
if (itemCount === 0) {
throw new Error('No items in RSS feed');
}
// Validate all items have required elements
const titleCount = (xml.match(/<item>[\s\S]*?<title>/g) || []).length;
const linkCount = (xml.match(/<item>[\s\S]*?<link>/g) || []).length;
const guidCount = (xml.match(/<guid/g) || []).length;
Iif (titleCount !== itemCount) {
throw new Error(`Not all items have <title> tags (${titleCount}/${itemCount})`);
}
Iif (linkCount !== itemCount) {
throw new Error(`Not all items have <link> tags (${linkCount}/${itemCount})`);
}
if (guidCount !== itemCount) {
throw new Error(`Not all items have <guid> tags (${guidCount}/${itemCount})`);
}
console.log(' ✅ RSS feed validation passed');
return true;
}
|