Files
worldmonitor/tests/climate-ocean-ice-client.test.mts
Fayez Bast 02f55dc584 feat(climate): add ocean ice indicators seed and RPC (#2652)
* feat(climate): add ocean ice indicators seed and RPC

* fix(review): restore MCP maxStaleMin, widen health threshold, harden sea level parser, type globe.gl shim

- Restore get_climate_data _maxStaleMin to 2880 (was accidentally lowered to 1440)
- Bump oceanIce SEED_META maxStaleMin from 1440 to 2880 (2× daily interval, tolerates one missed run)
- Add fallback regex patterns for NASA sea level overlay HTML parsing
- Replace globe.gl GlobeInstance `any` with typed interface (index sig stays `any` for Three.js compat)

* fix(review): merge prior cache on partial failures, fix fallback regex, omit trend without baseline

- P1: fetchOceanIceData() now reads prior cache and merges last-known-good
  indicators when any upstream source fails, preventing partial overwrites
  from erasing previously healthy data
- P1: sea level fallback regex now requires "current" context to avoid
  matching the historical 1993 baseline rate instead of the current rate
- P2: classifyArcticTrend() returns null (omitted from payload) when no
  climatology baseline exists, instead of misleadingly labeling as "average"
- Added tests for all three fixes

* fix(review): merge prior cache by source field group, not whole object

Prior-cache merge was too coarse: Object.assign(payload, priorCache)
reintroduced stale arctic_extent_anomaly_mkm2 and arctic_trend from
prior cache when sea-ice succeeded but intentionally omitted those
fields (no climatology baseline), and an unrelated source like OHC
or sea level failed in the same run.

Fix: define per-source field groups (seaIce, seaLevel, ohc, sst).
Only fall back to prior cache fields for groups whose source failed
entirely. When a source succeeds, only its returned fields appear
in the payload, even if it omits fields it previously provided.

Added test covering the exact combined case: sea-ice climatology
unavailable + unrelated source failure + prior-cache merge enabled.

---------

Co-authored-by: Elie Habib <elie.habib@gmail.com>
2026-04-04 08:11:49 +04:00

37 lines
971 B
TypeScript

import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { normalizeHydratedOceanIce } from '../src/services/climate/ocean-ice.ts';
describe('normalizeHydratedOceanIce', () => {
it('returns null for hydrated proto payloads that only contain an empty trend array', () => {
const data = normalizeHydratedOceanIce({
data: {
iceTrend12m: [],
},
});
assert.equal(data, null);
});
it('returns null for snake-case seed payloads that only contain an empty trend array', () => {
const data = normalizeHydratedOceanIce({
ice_trend_12m: [],
});
assert.equal(data, null);
});
it('keeps hydrated proto payloads when at least one real field is present', () => {
const data = normalizeHydratedOceanIce({
data: {
arcticTrend: 'below_average',
iceTrend12m: [],
},
});
assert.ok(data);
assert.equal(data.arcticTrend, 'below_average');
});
});