import { swingFeatures } from './features.js';

function runTest() {
  console.log("Running no-lookahead guardrail test...");
  
  // Create mock candles where index = day
  const candles = [];
  for (let i = 0; i < 250; i++) {
    candles.push({
      date: `2024-01-${i}`,
      open: 100 + i,
      high: 105 + i,
      low: 95 + i,
      close: 102 + i,
      volume: 1000000
    });
  }

  const spyCandles = [...candles]; // clone
  const vix = 15;

  // We are at day index 210. 
  const currentDayIdx = 210;
  
  // Guardrail: Pass ONLY the slice up to current day
  const slicedCandles = candles.slice(0, currentDayIdx + 1);
  const slicedSpy = spyCandles.slice(0, currentDayIdx + 1);

  // Compute features
  const feats = swingFeatures(slicedCandles, slicedSpy, vix);

  if (!feats) {
    throw new Error("Features returned null unexpectedly.");
  }

  // The slice literally does not contain any future data in memory.
  // We can verify the length of the array inside the feature to be absolutely sure.
  if (slicedCandles.length > currentDayIdx + 1) {
    throw new Error("Lookahead leak: slicedCandles contains future data!");
  }

  console.log("PASS: Features successfully computed without lookahead bias.");
  console.log("Computed Features:", feats);
}

runTest();
