import { describe, test } from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';

// Lint-test for the fact-reviewer fasit fixture.
// Mirrors the structure-only discipline of fact-checker-fixture.test.mjs and
// editorial-reviewer-fixture.test.mjs: this test asserts the SHAPE of the
// fixture — the single axis (faktisk-korrekthet), the four checks (F1–F4), the
// 🔴/🟡/🟢 risk sort, the six Del 4 (Security Champions) cases, the
// direction-not-copy boundary, and the cold-reader / pivot-risk rationale.
// Whether the agent's live verdicts actually reproduce the fasit is
// [GATE]/[OPERATØR], never self-certified here.

const FIXTURE_PATH = fileURLToPath(
  new URL('./fixtures/fact-reviewer-cases.md', import.meta.url)
);

const fixture = readFileSync(FIXTURE_PATH, 'utf8');

// The four checks: F1 verifiable claims · F2 quote precision · F3 number
// attribution · F4 source quality.
const CHECKS = ['F1', 'F2', 'F3', 'F4'];

// The 🔴/🟡/🟢 risk sort (the emoji are the safest assertion).
const VERDICTS = ['🔴', '🟡', '🟢'];

describe('fact-reviewer fixture structure', () => {
  test('names the axis "faktisk-korrekthet"', () => {
    assert.ok(
      /faktisk-korrekthet/i.test(fixture),
      'fixture must name the axis "faktisk-korrekthet"'
    );
  });

  test('documents all four checks (F1–F4)', () => {
    for (const check of CHECKS) {
      assert.ok(
        fixture.includes(check),
        `fixture must reference the check "${check}"`
      );
    }
  });

  test('references the 🔴/🟡/🟢 risk sort', () => {
    for (const v of VERDICTS) {
      assert.ok(
        fixture.includes(v),
        `fixture must reference the risk verdict "${v}"`
      );
    }
  });

  test('references the PASS/REWORK/BLOCK gate', () => {
    for (const gate of ['PASS', 'REWORK', 'BLOCK']) {
      assert.ok(
        fixture.includes(gate),
        `fixture must reference the gate decision "${gate}"`
      );
    }
  });

  test('documents exactly 6 Del 4 cases', () => {
    const cases = fixture.match(/^###\s+Case\s+\d+\b/gim) || [];
    assert.equal(
      cases.length,
      6,
      `fixture must document exactly 6 Del 4 cases (found ${cases.length})`
    );
  });

  test('states the direction-not-copy boundary', () => {
    assert.ok(
      /direction, not rewritten copy/i.test(fixture),
      'fixture must state the direction-not-copy boundary'
    );
  });

  test('documents the cold-reader / context-pollution principle', () => {
    assert.ok(
      /context pollution/i.test(fixture) && /framing-bias/i.test(fixture),
      'fixture must document the cold-reader / context-pollution / framing-bias principle'
    );
  });

  test('records the pivot-premise-risk rationale', () => {
    assert.ok(
      /pivot/i.test(fixture),
      'fixture must record why the gate exists (pivot premise never met Step 5)'
    );
  });
});
