import test from 'node:test';
import assert from 'node:assert/strict';
import { generateLLMIdeas } from '../lib/llm/ideas.mjs';

const response = JSON.stringify([{
  title: 'Test idea',
  type: 'WATCH',
  ticker: 'SPY',
  confidence: 'LOW',
  rationale: 'Test rationale',
  risk: 'Test risk',
  horizon: 'Days',
  signals: ['test'],
}]);

test('idea generation respects provider token and timeout configuration', async () => {
  let capturedOptions;
  const provider = {
    isConfigured: true,
    maxTokens: 2000,
    timeoutMs: 300000,
    async complete(_systemPrompt, _context, options) {
      capturedOptions = options;
      return { text: response };
    },
  };

  const ideas = await generateLLMIdeas(provider, {}, null, []);

  assert.deepEqual(capturedOptions, { maxTokens: 2000, timeout: 300000 });
  assert.equal(ideas.length, 1);
  assert.equal(ideas[0].source, 'llm');
});

test('idea generation keeps safe defaults for providers without limits', async () => {
  let capturedOptions;
  const provider = {
    isConfigured: true,
    async complete(_systemPrompt, _context, options) {
      capturedOptions = options;
      return { text: response };
    },
  };

  await generateLLMIdeas(provider, {}, null, []);

  assert.deepEqual(capturedOptions, { maxTokens: 4096, timeout: 90000 });
});
