import { test } from 'node:test';
import { strict as assert } from 'node:assert';
import { validateResearchContent } from '../../lib/validators/research-validator.mjs';

const GOOD = `---
type: ultraresearch-brief
created: 2026-04-30
question: "How to do X?"
confidence: 0.8
dimensions: 3
---

## Executive Summary

3 sentences.

## Dimensions

### Dim A — Confidence: high
`;

test('validateResearch — happy path', () => {
  const r = validateResearchContent(GOOD);
  assert.equal(r.valid, true, JSON.stringify(r.errors));
});

test('validateResearch — wrong type', () => {
  const t = GOOD.replace('type: ultraresearch-brief', 'type: random');
  const r = validateResearchContent(t);
  assert.equal(r.valid, false);
  assert.ok(r.errors.find(e => e.code === 'RESEARCH_WRONG_TYPE'));
});

test('validateResearch — confidence out of range', () => {
  const t = GOOD.replace('confidence: 0.8', 'confidence: 1.5');
  const r = validateResearchContent(t);
  assert.equal(r.valid, false);
  assert.ok(r.errors.find(e => e.code === 'RESEARCH_BAD_CONFIDENCE'));
});

test('validateResearch — missing confidence is warning, not error', () => {
  const t = GOOD.replace(/^confidence: 0\.8\n/m, '');
  const r = validateResearchContent(t);
  assert.equal(r.valid, true);
  assert.ok(r.warnings.find(w => w.code === 'RESEARCH_NO_CONFIDENCE'));
});

test('validateResearch — strict missing body section is error', () => {
  const t = GOOD.replace(/## Dimensions\n\n### Dim A — Confidence: high\n/, '');
  const r = validateResearchContent(t, { strict: true });
  assert.equal(r.valid, false);
  assert.ok(r.errors.find(e => e.code === 'RESEARCH_MISSING_SECTION'));
});

test('validateResearch — bad dimensions value', () => {
  const t = GOOD.replace('dimensions: 3', 'dimensions: 0');
  const r = validateResearchContent(t);
  assert.equal(r.valid, false);
  assert.ok(r.errors.find(e => e.code === 'RESEARCH_BAD_DIMENSIONS'));
});
