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 content-reviewer fasit fixture.
// Mirrors the structure-only discipline of editorial-reviewer-fixture.test.mjs,
// persona-reviewer-fixture.test.mjs, and fact-checker-fixture.test.mjs: this test
// asserts the SHAPE of the fixture — the one judging axis (argument-integritet),
// all five checks (C1–C5), the three severities, the six Del 4 cases, the
// direction-not-copy boundary, and the cold-reader / context-isolation rationale.
// Whether the agent's live flags actually reproduce the fasit directions is
// [GATE]/[OPERATØR], never self-certified here.

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

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

// The five argument-integrity checks.
const CHECKS = ['C1', 'C2', 'C3', 'C4', 'C5'];

// The single judging axis (Norwegian, as the agent uses it).
const AXIS = 'argument-integritet';

// The three-rung severity scale.
const SEVERITIES = ['BLOCK', 'REWORK', 'NICE'];

describe('content-reviewer fixture structure', () => {
  test('names the argument-integritet axis', () => {
    assert.ok(
      new RegExp(AXIS, 'i').test(fixture),
      `fixture must name the axis "${AXIS}"`
    );
  });

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

  test('defines the three-rung severity scale', () => {
    for (const sev of SEVERITIES) {
      assert.ok(
        fixture.includes(sev),
        `fixture must define the severity "${sev}"`
      );
    }
  });

  test('documents exactly six 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('keeps the jury-judges-writer-writes boundary (direction, not copy)', () => {
    assert.ok(
      /direction, not rewritten copy/i.test(fixture),
      'fixture must state the direction-not-copy boundary'
    );
  });

  test('documents the cold-reader / context-isolation rationale', () => {
    assert.ok(
      /context pollution/i.test(fixture),
      'fixture must document the context-isolation principle (context pollution)'
    );
    assert.ok(
      /cold/i.test(fixture),
      'fixture must describe the agent as a cold reader'
    );
  });
});
