import test from 'node:test';
import assert from 'node:assert';
import { safeImport } from '../_helpers/path.js';
import { FakeLLMClient } from '../_helpers/fakeLLMClient.js';
import { AutoReporter } from '../reporters/AutoReporter.js';

function skip(msg){ console.warn('[SKIP]', msg); }


// Auto-Reporter Configuration
const autoReporter = new AutoReporter();

test('LLMManager: returns usage and computes cost if table provided', async () => {
  const res = await safeImport('LLMManager');
  if (!res.ok) { skip(res.reason); return; }
  const L = res.mod;

  if (typeof L.__setClient !== 'function' || typeof L.__setCosts !== 'function') {
    skip('Missing __setClient/__setCosts hooks');
    return;
  }

  const fake = new FakeLLMClient();
  L.__setClient('mock', fake);
  L.__setCosts({ 'mock:fake-1': { in: 0.001, out: 0.003 } }); // $/1k tokens

  const out = await L.callModel({ provider:'mock', model:'fake-1', input:'price me' });
  const usage = out.usage || out.meta?.usage;
  assert.ok(usage, 'usage expected');
  const cost = out.__meta?.cost ?? out.cost;
  assert.ok(typeof cost === 'number', 'cost numeric expected');
  // 100 in, 150 out => 0.1k*0.001 + 0.15k*0.003 = 0.0001 + 0.00045 = 0.00055
  assert.ok(cost > 0 && cost < 0.001, `cost looks off: ${cost}`);
});
