'use strict'; const assert = require('node:assert/strict'); const SS = require('../js/skin-score'); for (const raw of [20, 24, 28, 40, 50, 24.6, null]) { for (const realAge of [25, 30, 60, undefined]) { const result = structuredClone(SS.MOCK_RESULT); if (raw == null) delete result.skin_age; else result.skin_age = { value: raw }; const before = JSON.stringify(result); const vm = SS.buildViewModel(result, SS.MOCK_SIDE, { realAge }); assert.equal(vm.skinAgeRaw, raw); assert.equal(vm.skinAgeDisplay, raw); assert.equal(vm.ageClampNote, ''); assert.equal(SS.reportSkinAge(vm, result), raw); assert.equal(JSON.stringify(result), before); } } const legacy = { skinAgeRaw: 24, skinAgeDisplay: 57, realAge: 60 }; assert.equal(SS.reportSkinAge(legacy), 24); assert.equal(legacy.skinAgeDisplay, 57, 'historical VM is not mutated'); assert.equal(SS.reportSkinAge({ skinAgeDisplay: 57 }, { skin_age: { value: 24 } }), 24); assert.equal(SS.reportSkinAge({ skinAgeDisplay: 57 }), null, 'clamped display is never a raw-age fallback'); assert.equal(SS.reportSkinAge({ skinAgeRaw: null, skinAgeDisplay: 57 }), null); assert.equal(SS.reportSkinAge({}, { skin_age: '24.6' }), 24.6); console.log('PASS: raw age across actual-age/decimal/missing cases; old display ignored; legacy payload fallback; no mutation or invented age');