All files / lib/reflection flags.ts

0% Statements 0/27
100% Branches 1/1
100% Functions 1/1
0% Lines 0/27

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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49                                                                                                 
// lib/reflection/flags.ts
 
const isTest = process.env.NODE_ENV === 'test';
const isProd = process.env.NODE_ENV === 'production';
 
/**
 * Checks if the entire self-reflection layer is enabled.
 */
export function isReflectionEnabled(): boolean {
  // If an explicit REFLECTION_ENABLED env var is provided, trust it across envs
  if (typeof process.env.REFLECTION_ENABLED !== 'undefined') {
    return process.env.REFLECTION_ENABLED === 'true';
  }
 
  if (isTest) {
    return process.env.TEST_REFLECTION === 'true';
  }
 
  if (isProd) {
    return false; // default off in production unless explicitly enabled
  }
 
  return true; // Default to true in development
}
 
/**
 * Checks if the reflection system is in DRY_RUN mode.
 */
export function isDryRun(): boolean {
  // In test, default to false unless specified, to allow policy application to be tested.
  if (isTest) {
    return process.env.REFLECTION_DRY_RUN === 'true';
  }
  // In prod/dev, default to true for safety.
  return process.env.REFLECTION_DRY_RUN !== 'false';
}
 
/**
 * Checks if verbose logging for the reflection layer is enabled.
 */
export function isVerbose(): boolean {
  if (!isReflectionEnabled()) return false;
  return (
    process.env.REFLECTION_VERBOSE === 'true' ||
    process.env.TEST_REFLECTION_VERBOSE === 'true' ||
    false
  );
}