68 lines
3.6 KiB
JavaScript
68 lines
3.6 KiB
JavaScript
const { test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { load, validateCatalogue, validateFrontend, validateCensus, validateResearch } = require('./validate-research.cjs');
|
|
|
|
test('existing catalogue and immutable frontend/backend inventories reconcile', () => {
|
|
const report = validateResearch();
|
|
assert.equal(report.catalogue.candidates, 60);
|
|
assert.equal(report.catalogue.euLanguageGroups, 24);
|
|
assert.equal(report.frontend.messages, 3119);
|
|
assert.equal(report.frontend.staticCallSites, 3164);
|
|
assert.deepEqual(report.backend.map(batch => batch.fileRecordTraceBindings), [117, 102]);
|
|
});
|
|
|
|
test('all 60 candidate and 360 surface status promotions are rejected', () => {
|
|
const catalogue = load('LOCALE_CATALOG.json');
|
|
for (const locale of catalogue.locales) {
|
|
locale.status = 'released';
|
|
assert.throws(() => validateCatalogue(catalogue));
|
|
locale.status = 'planned';
|
|
for (const surface of Object.keys(locale.surfaces)) {
|
|
locale.surfaces[surface] = 'released';
|
|
assert.throws(() => validateCatalogue(catalogue));
|
|
locale.surfaces[surface] = 'planned';
|
|
}
|
|
}
|
|
});
|
|
|
|
for (const [name, mutate] of [
|
|
['missing EU language', catalogue => { catalogue.locales = catalogue.locales.filter(locale => locale.tag !== 'mt-MT'); }],
|
|
['same-count substituted candidate', catalogue => { catalogue.locales[8].tag = 'zz-ZZ'; }],
|
|
['duplicate candidate', catalogue => { catalogue.locales[8].tag = catalogue.locales[9].tag; }],
|
|
['canonicalisation replacing Montenegrin identity', catalogue => { catalogue.locales.find(locale => locale.tag === 'cnr-ME').tag = 'sr-ME'; }],
|
|
['forged reviewer', catalogue => { catalogue.locales[0].reviewer = 'approved'; }],
|
|
['unknown surface', catalogue => { catalogue.locales[0].surfaces.extra = 'planned'; }],
|
|
]) test(`rejects ${name}`, () => {
|
|
const catalogue = load('LOCALE_CATALOG.json');
|
|
mutate(catalogue);
|
|
assert.throws(() => validateCatalogue(catalogue));
|
|
});
|
|
|
|
for (const [name, mutate] of [
|
|
['omitted English source entry', inventory => { inventory.messages.pop(); }],
|
|
['changed English text', inventory => { inventory.messages[0].english = 'forged'; }],
|
|
['duplicate English key', inventory => { inventory.messages[1].id = inventory.messages[0].id; }],
|
|
['changed frontend source hash', inventory => { inventory.messages[0].sourceSha256 = '0'.repeat(64); }],
|
|
['changed placeholder inventory', inventory => { inventory.messages[0].placeholders = ['forged']; }],
|
|
['missing static caller', inventory => { inventory.messages[0].callers.pop(); }],
|
|
]) test(`rejects ${name}`, () => {
|
|
const inventory = load('MESSAGE_INVENTORY.json');
|
|
mutate(inventory);
|
|
assert.throws(() => validateFrontend(inventory));
|
|
});
|
|
|
|
for (const [name, mutate] of [
|
|
['changed source hash', census => { census.sourceBindings[0].sha256 = '0'.repeat(64); }],
|
|
['changed source expression', census => { census.records[0].sourceExpression = 'forged'; }],
|
|
['duplicate source locus', census => { census.records.push(census.records[0]); }],
|
|
['lost segment', census => { census.records[0].translationCandidateSegments = []; }],
|
|
['forged native approval', census => { census.records[0].nativeReview = 'approved'; }],
|
|
['wrong category accounting', census => { census.counts.byCategory['controlled-message']++; }],
|
|
['broken trace reference', census => { census.records[0].traceIds = ['missing']; }],
|
|
['changed trace evidence', census => { census.traces[0].evidence[0].sourceExpression = 'forged'; }],
|
|
]) test(`rejects ${name}`, () => {
|
|
const census = load('BACKEND_MESSAGE_CENSUS_B02.json');
|
|
mutate(census);
|
|
assert.throws(() => validateCensus(census));
|
|
});
|