/**
 * Tests fuer die LLM-Stream-Parser des Advisors (Ollama-NDJSON + OVH/OpenAI-SSE).
 */

import { describe, it, expect } from 'vitest'
import { parseOllamaLine, parseSSELine } from '../advisor-llm'

describe('parseOllamaLine', () => {
  it('extrahiert message.content', () => {
    expect(parseOllamaLine('{"message":{"content":"Hallo"}}')).toBe('Hallo')
  })
  it('ignoriert leere/kaputte Zeilen', () => {
    expect(parseOllamaLine('')).toBeNull()
    expect(parseOllamaLine('  ')).toBeNull()
    expect(parseOllamaLine('not-json')).toBeNull()
    expect(parseOllamaLine('{"message":{}}')).toBeNull()
  })
})

describe('parseSSELine', () => {
  it('extrahiert choices[0].delta.content aus data:-Zeilen', () => {
    expect(parseSSELine('data: {"choices":[{"delta":{"content":"Hi"}}]}')).toBe('Hi')
  })
  it('ignoriert [DONE], Nicht-data-Zeilen und kaputtes JSON', () => {
    expect(parseSSELine('data: [DONE]')).toBeNull()
    expect(parseSSELine('event: message')).toBeNull()
    expect(parseSSELine('')).toBeNull()
    expect(parseSSELine('data: {bad json')).toBeNull()
    expect(parseSSELine('data: {"choices":[{"delta":{}}]}')).toBeNull()
  })
})
