#!/usr/bin/env node
/**
 * CI gate — every featureGate('code') in app.js must exist in featureGateRegistry.js
 */
'use strict';

const fs = require('fs');
const path = require('path');

const appPath = path.join(__dirname, '../src/api/app.js');
const registryPath = path.join(__dirname, '../src/api/lib/featureGateRegistry.js');
const appSrc = fs.readFileSync(appPath, 'utf8');
const { FEATURE_REGISTRY } = require(registryPath);

const used = new Set();
const re = /featureGate\(\s*['"]([^'"]+)['"]/g;
let m;
while ((m = re.exec(appSrc)) !== null) used.add(m[1]);

const unknown = [...used].filter(c => !FEATURE_REGISTRY[c]);
if (unknown.length) {
  console.error('[verify:feature-gates] FAIL — unknown feature gate codes in app.js:');
  unknown.forEach(c => console.error('  ', c));
  process.exit(1);
}

console.log(`[verify:feature-gates] OK — ${used.size} gate codes validated against registry`);
