"""
Smoke test for the ChatGuard dataset generated by exp_chatguard_dataset.py.

Run the generator first:
    python experiments/exp_chatguard_dataset.py

Then run this test:
    python -m pytest tests/test_chatguard_dataset.py -v
"""

import json
import os

import pytest


def test_dataset_schema():
    """Dataset file must exist and each record has required keys."""
    # Issue 4: absolute path so the test works regardless of CWD
    path = os.path.join(os.path.dirname(__file__), "..", "results", "exp_chatguard_dataset", "chat_pairs.jsonl")
    if not os.path.exists(path):
        pytest.skip("Dataset not generated yet — run exp_chatguard_dataset.py first")
    with open(path) as f:
        records = [json.loads(line) for line in f if line.strip()]
    assert len(records) >= 100
    # Issue 5: validate ALL records, not just the first 5
    for r in records:
        assert "query" in r
        assert "response" in r
        assert "label" in r
        assert "error_type" in r
        assert "source_dataset" in r
        assert r["label"] in (0, 1)
