All files / scripts/roll-forward-pirs confidence.ts

100% Statements 6/6
100% Branches 4/4
100% Functions 1/1
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                                  35x 35x 1x   34x 32x    
/**
 * @module roll-forward-pirs/confidence
 * @description Confidence-label degradation helper used when rolling open
 * PIRs forward into a new cycle.
 *
 * @author Hack23 AB
 * @license Apache-2.0
 */
 
import { CONFIDENCE_ORDER } from './constants.js';
import type { Confidence } from './types.js';
 
/**
 * Degrade a confidence label one step toward `VERY LOW`.
 * Throws on unknown values rather than silently returning `VERY HIGH`.
 */
export function degrade(c: Confidence): Confidence {
  const idx = CONFIDENCE_ORDER.indexOf(c);
  if (idx === -1) {
    throw new Error(`Unknown confidence value: '${String(c)}'`);
  }
  if (idx >= CONFIDENCE_ORDER.length - 1) return 'VERY LOW';
  return CONFIDENCE_ORDER[idx + 1] as Confidence;
}