File size: 2,900 Bytes
50b456f 8bfdee7 50b456f 8bfdee7 50b456f | 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 78 79 80 81 82 83 84 85 86 87 | #!/usr/bin/env node
'use strict';
/**
* PLT Dataset — Validator
* Validates JSONL files against SCHEMA.md trajectory structure.
*/
const fs = require('fs');
const path = require('path');
const DATA = path.join(__dirname, '..', 'data');
const REQUIRED_TOP = ['id', 'type', 'payload', 'plb', 'meta'];
const VALID_TYPES = ['cheat_code','law','archetype','mistake','soul_code','chamber','council_member','council_trace','decision','reflection','doctrine_snippet','frequency_marker','daily_log','exit_calculation','frequency_band','dimension','multiversal_principle','quantum_decision','fractal_code','paradox'];
const VALID_HORIZONS = ['90d', '1yr', '5yr', 'multiple', 'real-time', 'generational', 'infinity'];
let errors = 0, warnings = 0, total = 0;
const files = fs.readdirSync(DATA).filter(f => f.endsWith('.jsonl')).sort();
console.log('=== PLT Dataset Validation ===\n');
for (const file of files) {
const rows = fs.readFileSync(path.join(DATA, file), 'utf8')
.split('\n').filter(Boolean);
let fileErrors = 0;
console.log(`\n${file} (${rows.length} rows)`);
rows.forEach((line, i) => {
total++;
let row;
try { row = JSON.parse(line); } catch {
errors++; fileErrors++;
console.log(` ✗ Row ${i+1}: invalid JSON`);
return;
}
// Required top-level
for (const k of REQUIRED_TOP) {
if (!(k in row)) {
errors++; fileErrors++;
console.log(` ✗ Row ${i+1} (${row.id || '?'}): missing field "${k}"`);
}
}
// Type validation
if (!VALID_TYPES.includes(row.type)) {
warnings++;
console.log(` ⚠ Row ${i+1}: unknown type "${row.type}"`);
}
// plb validation
const plb = row.plb || {};
for (const k of ['profit', 'love', 'tax']) {
if (typeof plb[k] !== 'number' || plb[k] < -1 || plb[k] > 1) {
warnings++;
console.log(` ⚠ Row ${i+1}: plb.${k} out of range: ${plb[k]}`);
}
}
if (!VALID_HORIZONS.includes(plb.time_horizon)) {
warnings++;
console.log(` ⚠ Row ${i+1}: invalid time_horizon "${plb.time_horizon}"`);
}
// Type-specific payload checks
if (row.type === 'cheat_code' && !row.payload?.rcc_number) {
console.log(` ⚠ Row ${i+1}: cheat_code missing rcc_number`);
}
if (row.type === 'archetype' && !row.payload?.number) {
console.log(` ⚠ Row ${i+1}: archetype missing number`);
}
// Meta checks
if (!row.meta?.source_book) {
warnings++;
console.log(` ⚠ Row ${i+1}: meta.source_book missing`);
}
});
console.log(` ${fileErrors} errors, ${rows.length - fileErrors} OK`);
}
console.log(`\n=== Summary ===`);
console.log(`Total rows: ${total}`);
console.log(`Errors: ${errors}`);
console.log(`Warnings: ${warnings}`);
console.log(errors === 0 ? '\n✓ All files valid.' : `\n✗ ${errors} errors found.`);
process.exit(errors > 0 ? 1 : 0);
|