// Karma configuration for `ng test` (@angular/build:karma builder).
// A headless, sandbox-free Chrome launcher so the suite runs in CI and in
// restricted/dev environments where Chrome isn't on PATH. CHROME_BIN falls
// back to the default Windows install path when the env var isn't set.
process.env.CHROME_BIN =
  process.env.CHROME_BIN || 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe';

module.exports = function (config) {
  config.set({
    frameworks: ['jasmine'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage'),
    ],
    browsers: ['ChromeHeadlessNoSandbox'],
    customLaunchers: {
      ChromeHeadlessNoSandbox: {
        base: 'ChromeHeadless',
        flags: ['--no-sandbox', '--disable-gpu', '--disable-dev-shm-usage'],
      },
    },
    reporters: ['progress', 'coverage'],
    coverageReporter: {
      dir: require('path').join(__dirname, 'coverage'),
      subdir: '.',
      reporters: [{ type: 'text-summary' }, { type: 'html' }, { type: 'lcovonly' }],
      // Floor set 2026-08-18, ~5 points below the measured level right
      // after this session's facade-test pass (43.3%/29.0%/34.1%/43.7%
      // statements/branches/functions/lines) - a deliberate floor per the
      // delivery plan's Q9 ("deliberately unset today"), not an aspiration.
      // Ratchet this UP as coverage grows; a PR that drops below it should
      // fail CI, not get merged with a lower number quietly re-baselined in.
      check: {
        global: {
          statements: 40,
          branches: 25,
          functions: 30,
          lines: 40,
        },
      },
    },
    restartOnFileChange: true,
  });
};
