mirror of
https://github.com/koala73/worldmonitor.git
synced 2026-04-25 17:14:57 +02:00
* feat(resilience): recovery capacity pillar — 6 new dimensions + 5 seeders (Phase 2 T2.2b) Add the recovery-capacity pillar with 6 new dimensions: - fiscalSpace: IMF GGR_G01_GDP_PT + GGXCNL_G01_GDP_PT + GGXWDG_NGDP_PT - reserveAdequacy: World Bank FI.RES.TOTL.MO - externalDebtCoverage: WB DT.DOD.DSTC.CD / FI.RES.TOTL.CD ratio - importConcentration: UN Comtrade HHI (stub seeder) - stateContinuity: derived from WGI + UCDP + displacement (no new fetch) - fuelStockDays: IEA/EIA (stub seeder, Enrichment tier) Each dimension has a scorer in _dimension-scorers.ts, registry entries in _indicator-registry.ts, methodology doc subsections, and fixture data. Seeders: fiscal-space (real, IMF WEO), reserve-adequacy (real, WB API), external-debt (real, WB API), import-hhi (stub), fuel-stocks (stub). Recovery domain weight is 0 until PR 4 (T2.3) ships the penalized weighted mean across pillars. The domain appears in responses structurally but does not affect the overall score. Bootstrap: STANDALONE_KEYS + SEED_META + EMPTY_DATA_OK_KEYS + ON_DEMAND_KEYS all updated in api/health.js. Source-failure mapping updated for stateContinuity (WGI adapter). Widget labels and LOCKED_PREVIEW updated. All 282 resilience tests pass, typecheck clean, methodology lint clean. * fix(resilience): ISO3→ISO2 normalization in WB recovery seeders (#2987 P1) Both seed-recovery-reserve-adequacy.mjs and seed-recovery-external-debt.mjs used countryiso3code from the World Bank API response then immediately rejected codes where length !== 2. WB returns ISO3 codes (USA, DEU, etc.), so all real rows were silently dropped and the feed was always empty. Fix: import scripts/shared/iso3-to-iso2.json and normalize before the length check. Also removed from EMPTY_DATA_OK_KEYS in health.js since empty results now indicate a real failure, not a structural absence. * fix(resilience): remove unused import + no-op overrides (#2987 review) * fix(test): update release-gate to expect 6 domains after recovery pillar
71 lines
3.3 KiB
TypeScript
71 lines
3.3 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import { describe, it } from 'node:test';
|
|
|
|
import { RESILIENCE_DIMENSION_ORDER } from '../server/worldmonitor/resilience/v1/_dimension-scorers.ts';
|
|
import { INDICATOR_REGISTRY } from '../server/worldmonitor/resilience/v1/_indicator-registry.ts';
|
|
import type { IndicatorSpec } from '../server/worldmonitor/resilience/v1/_indicator-registry.ts';
|
|
|
|
describe('indicator registry', () => {
|
|
it('covers all 19 dimensions', () => {
|
|
const coveredDimensions = new Set(INDICATOR_REGISTRY.map((i) => i.dimension));
|
|
for (const dimId of RESILIENCE_DIMENSION_ORDER) {
|
|
assert.ok(coveredDimensions.has(dimId), `${dimId} has no indicators in registry`);
|
|
}
|
|
assert.equal(coveredDimensions.size, 19);
|
|
});
|
|
|
|
it('has no duplicate indicator ids', () => {
|
|
const ids = INDICATOR_REGISTRY.map((i) => i.id);
|
|
const unique = new Set(ids);
|
|
assert.equal(ids.length, unique.size, `duplicate ids: ${ids.filter((id, idx) => ids.indexOf(id) !== idx).join(', ')}`);
|
|
});
|
|
|
|
it('every indicator has valid direction and positive weight', () => {
|
|
for (const spec of INDICATOR_REGISTRY) {
|
|
assert.ok(['higherBetter', 'lowerBetter'].includes(spec.direction), `${spec.id} has invalid direction: ${spec.direction}`);
|
|
assert.ok(spec.weight > 0, `${spec.id} has non-positive weight: ${spec.weight}`);
|
|
}
|
|
});
|
|
|
|
it('every indicator has valid cadence and scope', () => {
|
|
const validCadences = new Set(['realtime', 'daily', 'weekly', 'monthly', 'annual']);
|
|
const validScopes = new Set(['global', 'curated']);
|
|
for (const spec of INDICATOR_REGISTRY) {
|
|
assert.ok(validCadences.has(spec.cadence), `${spec.id} has invalid cadence: ${spec.cadence}`);
|
|
assert.ok(validScopes.has(spec.scope), `${spec.id} has invalid scope: ${spec.scope}`);
|
|
}
|
|
});
|
|
|
|
it('goalposts worst != best for every indicator', () => {
|
|
for (const spec of INDICATOR_REGISTRY) {
|
|
assert.notEqual(spec.goalposts.worst, spec.goalposts.best, `${spec.id} has worst === best (${spec.goalposts.worst})`);
|
|
}
|
|
});
|
|
|
|
it('imputation entries have valid type, score in [0,100], certainty in (0,1]', () => {
|
|
const withImputation = INDICATOR_REGISTRY.filter((i): i is IndicatorSpec & { imputation: NonNullable<IndicatorSpec['imputation']> } => i.imputation != null);
|
|
assert.ok(withImputation.length > 0, 'expected at least one indicator with imputation');
|
|
for (const spec of withImputation) {
|
|
assert.ok(['absenceSignal', 'conservative'].includes(spec.imputation.type), `${spec.id} has invalid imputation type`);
|
|
assert.ok(spec.imputation.score >= 0 && spec.imputation.score <= 100, `${spec.id} imputation score out of range`);
|
|
assert.ok(spec.imputation.certainty > 0 && spec.imputation.certainty <= 1, `${spec.id} imputation certainty out of range`);
|
|
}
|
|
});
|
|
|
|
it('every dimension has weights that sum to a consistent total', () => {
|
|
const byDimension = new Map<string, IndicatorSpec[]>();
|
|
for (const spec of INDICATOR_REGISTRY) {
|
|
const list = byDimension.get(spec.dimension) ?? [];
|
|
list.push(spec);
|
|
byDimension.set(spec.dimension, list);
|
|
}
|
|
for (const [dimId, specs] of byDimension) {
|
|
const totalWeight = specs.reduce((sum, s) => sum + s.weight, 0);
|
|
assert.ok(
|
|
Math.abs(totalWeight - 1) < 0.01,
|
|
`${dimId} weights sum to ${totalWeight.toFixed(4)}, expected ~1.0`,
|
|
);
|
|
}
|
|
});
|
|
});
|